/* eslint-disable import/no-extraneous-dependencies */
import { storiesOf, html } from '@open-wc/demoing-storybook';
import '@lion/radio/lion-radio.js';
import '../lion-radio-group.js';
import { Required, Validator, loadDefaultFeedbackMessages } from '@lion/validate';
loadDefaultFeedbackMessages();
storiesOf('Forms|Radio Group', module)
.add(
'Default',
() => html`
`,
)
.add(
'Pre Select',
() => html`
`,
)
.add(
'Disabled',
() => html`
`,
)
.add('Validation', () => {
const validate = () => {
const radioGroup = document.querySelector('#dinosGroup');
radioGroup.submitted = !radioGroup.submitted;
};
return html`
`;
})
.add('Validation Item', () => {
class IsBrontosaurus extends Validator {
constructor() {
super();
this.name = 'IsBrontosaurus';
}
execute(value) {
const selectedValue = value['dinos[]'].find(v => v.checked === true);
const hasError = selectedValue ? selectedValue.value !== 'brontosaurus' : false;
return hasError;
}
static async getMessage() {
return 'You need to select "brontosaurus"';
}
}
const validate = () => {
const radioGroup = document.querySelector('#dinosGroup');
radioGroup.submitted = !radioGroup.submitted;
};
return html`
`;
});