import { storiesOf, html } from '@open-wc/demoing-storybook';
import { LitElement } from '@lion/core';
import { LocalizeMixin } from '@lion/localize';
import '../lion-input-switch.js';
import '@lion/form/lion-form.js';
storiesOf('Forms|Switch', module)
.add(
'All text slots',
() => html`
`,
)
.add(
'Disabled',
() => html`
`,
)
.add('Validation', () => {
const isTrue = value => value && value.checked && value.checked === true;
const isTrueValidator = (...factoryParams) => [
(...params) => ({
isTrue: isTrue(...params),
}),
...factoryParams,
];
const tagName = 'lion-switch-validation-demo';
if (!customElements.get(tagName)) {
customElements.define(
tagName,
class extends LocalizeMixin(LitElement) {
static get localizeNamespaces() {
const result = [
{
'lion-validate+isTrue': () =>
Promise.resolve({
info: {
isTrue: 'You will not get the latest news!',
},
}),
},
...super.localizeNamespaces,
];
return result;
}
render() {
return html`
`;
}
submit() {
const form = this.shadowRoot.querySelector('#postsForm');
if (form.errorState === false) {
console.log(form.serializeGroup());
}
}
},
);
}
return html`
`;
});