import { storiesOf, html } from '@open-wc/storybook';
import {
equalsLengthValidator,
minLengthValidator,
maxLengthValidator,
minMaxLengthValidator,
isEmailValidator,
} from '@lion/validate';
import { LocalizeMixin } from '@lion/localize';
import { LionInput } from '../src/LionInput.js';
storiesOf('Forms| String Validation', module)
.add(
'equalsLength',
() => html`
`,
)
.add(
'minLength',
() => html`
`,
)
.add(
'maxLength',
() => html`
`,
)
.add(
'minMaxLength',
() => html`
`,
)
.add(
'isEmail',
() => html`
`,
)
.add('error/warning/info/success states', () => {
class InputValidationExample extends LocalizeMixin(LionInput) {
static get localizeNamespaces() {
return [
{ 'input-validation-example': locale => import(`./translations/${locale}.js`) },
...super.localizeNamespaces,
];
}
}
if (!customElements.get('input-validation-example')) {
customElements.define('input-validation-example', InputValidationExample);
}
const notEqualsString = (value, stringValue) => stringValue.toString() !== value;
const notEqualsStringValidator = (...factoryParams) => [
(...params) => ({ notEqualsString: notEqualsString(...params) }),
factoryParams,
];
const equalsStringFixedValidator = () => [() => ({ notEqualsStringFixed: false })];
return html`
`;
});