import '@lion/input/lion-input.js';
import { localize } from '@lion/localize';
import { loadDefaultFeedbackMessages, MinLength, Validator } from '@lion/validate';
import { html, storiesOf } from '@open-wc/demoing-storybook';
import '../../form-system/stories/helper-wc/h-output.js';
import '../lion-fieldset.js';
localize.locale = 'en-GB';
loadDefaultFeedbackMessages();
storiesOf('Forms|Fieldset')
.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`
console.log(ev.target.parentElement.modelValue)}>
Log to Action Logger
`,
)
.add('Disabled', () => {
function toggleDisabled() {
const fieldset = document.querySelector('#fieldset');
fieldset.disabled = !fieldset.disabled;
}
return html`
Toggle disabled
`;
})
.add(
'Sub Fieldsets Data',
() => html`
Personal data
console.log(ev.target.parentElement.modelValue)}>
Log to Action Logger
console.log(ev.target.parentElement.formElements.nameGroup.modelValue)}
>
Log nameGroup to Action Logger
`,
)
.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`
Fieldset no. 1
Fieldset no. 2
`;
});