import { storiesOf, html } from '@open-wc/demoing-storybook';
import '../lion-fieldset.js';
import { localize } from '@lion/localize';
import { minLengthValidator } from '@lion/validate';
import '../../form-system/stories/helper-wc/h-output.js';
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`
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', () => {
function isDemoValidator() {
return false;
}
const demoValidator = (...factoryParams) => [
(...params) => ({ validator: isDemoValidator(...params) }),
...factoryParams,
];
try {
localize.addData('en-GB', 'lion-validate+validator', {
error: {
validator: 'Demo error message',
},
});
} catch (error) {
// expected as it's a demo
}
return html`
{
document.getElementById('someId').serializeGroup();
}}
>
Submit
Tab-able
`;
})
.add('Validation 2 inputs', () => {
const isCatsAndDogs = value => ({
isCatsAndDogs: value.input1 === 'cats' && value.input2 === 'dogs',
});
localize.locale = 'en-GB';
try {
localize.addData('en-GB', 'lion-validate+isCatsAndDogs', {
error: {
isCatsAndDogs:
'[Fieldset Error] Input 1 needs to be "cats" and Input 2 needs to be "dogs"',
},
});
} catch (error) {
// expected as it's a demo
}
return html`
`;
})
.add('Validation 2 fieldsets', () => {
const isCats = value => ({
isCats: value.input1 === 'cats',
});
localize.locale = 'en-GB';
try {
localize.addData('en-GB', 'lion-validate+isCats', {
error: {
isCats: '[Fieldset Nr. 1 Error] Input 1 needs to be "cats"',
},
});
} catch (error) {
// expected as it's a demo
}
const isDogs = value => ({
isDogs: value.input1 === 'dogs',
});
localize.locale = 'en-GB';
try {
localize.addData('en-GB', 'lion-validate+isDogs', {
error: {
isDogs: '[Fieldset Nr. 2 Error] Input 1 needs to be "dogs"',
},
});
} catch (error) {
// expected as it's a demo
}
return html`
Fieldset Nr. 1
Fieldset Nr. 2
`;
});