Co-authored-by: Alex Ghiu <alex.ghiu@ing.com> Co-authored-by: Gerjan van Geest <Gerjan.van.Geest@ing.com> Co-authored-by: Thijs Louisse <Thijs.Louisse@ing.com> Co-authored-by: Joren Broekema <joren.broekema@ing.com> Co-authored-by: Erik Kroes <erik.kroes@ing.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import { storiesOf, html } from '@open-wc/demoing-storybook';
|
|
import { Validator } from '@lion/validate';
|
|
|
|
import '../lion-input-email.js';
|
|
import '../../fieldset/lion-fieldset.js';
|
|
|
|
storiesOf('Forms|Input Email', module)
|
|
.add(
|
|
'Default',
|
|
() => html`
|
|
<lion-input-email name="email" label="Label"></lion-input-email>
|
|
`,
|
|
)
|
|
.add(
|
|
'Faulty prefilled',
|
|
() => html`
|
|
<lion-input-email .modelValue=${'foo'} label="Email"></lion-input-email>
|
|
`,
|
|
)
|
|
.add('Custom validator', () => {
|
|
class GmailOnly extends Validator {
|
|
constructor(...args) {
|
|
super(...args);
|
|
this.name = 'GmailOnly';
|
|
}
|
|
|
|
execute(value) {
|
|
let hasError = false;
|
|
if (!(value.indexOf('gmail.com') !== -1)) {
|
|
hasError = true;
|
|
}
|
|
return hasError;
|
|
}
|
|
|
|
static async getMessage() {
|
|
return 'You can only use gmail.com email addresses.';
|
|
}
|
|
}
|
|
|
|
return html`
|
|
<lion-input-email
|
|
.modelValue=${'foo@bar.com'}
|
|
.validators=${[new GmailOnly()]}
|
|
label="Email"
|
|
></lion-input-email>
|
|
`;
|
|
});
|