/* eslint-disable import/no-extraneous-dependencies */ import '@lion/radio/lion-radio.js'; import { loadDefaultFeedbackMessages, Required, Validator } from '@lion/validate'; import { html, storiesOf } from '@open-wc/demoing-storybook'; import '../lion-radio-group.js'; loadDefaultFeedbackMessages(); storiesOf('Forms|Radio Group') .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` `; });