import { storiesOf, html } from '@open-wc/demoing-storybook'; import '../lion-fieldset.js'; import '@lion/input/lion-input.js'; import { localize } from '@lion/localize'; import { Validator, MinLength, loadDefaultFeedbackMessages } from '@lion/validate'; import '../../form-system/stories/helper-wc/h-output.js'; localize.locale = 'en-GB'; loadDefaultFeedbackMessages(); storiesOf('Forms|Fieldset', module) .add( 'Default', () => html`

A native fieldset element should always have a legend-element for a11y purposes. Our fieldset element is not native and should not have a legend-element. Our fieldset instead has a label attribute or you can add a label with a div- or heading-element using the slot="label". Please don't use the the label-element because that is reserved for input-elements.

`, ) .add( 'Data', () => html` `, ) .add('Disabled', () => { function toggleDisabled() { const fieldset = document.querySelector('#fieldset'); fieldset.disabled = !fieldset.disabled; } return html` `; }) .add( 'Sub Fieldsets Data', () => html`
Personal data

`, ) .add('Validation', () => { const DemoValidator = class extends Validator { constructor() { super(); this.name = 'DemoValidator'; } execute(value) { if (value && value.input1) { return true; // el.hasError = true } return false; } static async getMessage() { return '[Fieldset Error] Demo error message'; } }; return html` `; }) .add('Validation 2 inputs', () => { const IsCatsAndDogs = class extends Validator { constructor() { super(); this.name = 'IsCatsAndDogs'; } execute(value) { if (!(value && value.input1 && value.input2)) { return false; } return !(value.input1 === 'cats' && value.input2 === 'dogs'); } static async getMessage() { return '[Fieldset Error] Input 1 needs to be "cats" and Input 2 needs to be "dogs"'; } }; return html` `; }) .add('Validation 2 fields', () => { const IsCats = class extends Validator { constructor() { super(); this.name = 'IsCats'; } execute(value) { return value.input1 !== 'cats'; } static async getMessage() { return '[Fieldset Nr. 1 Error] Input 1 needs to be "cats"'; } }; const IsDogs = class extends Validator { constructor() { super(); this.name = 'IsDogs'; } execute(value) { return value.input1 !== 'dogs'; } static async getMessage() { return '[Fieldset Nr. 2 Error] Input 1 needs to be "dogs"'; } }; return html`
`; });