import { storiesOf, html } from '@open-wc/demoing-storybook';
import { Unparseable } from '@lion/validate';
import '@lion/input/lion-input.js';
import './helper-wc/h-output.js';
function newDateValid(d) {
const result = d ? new Date(d) : new Date();
return !isNaN(result.getTime()) ? result : null; // eslint-disable-line no-restricted-globals
}
storiesOf('Form Fundaments|Formatting and Parsing', module)
.add(
'model value',
() => html`
Note: we always use lion-input to demonstrate, but all things that extend lion-input have
this functionality!
{
console.log(target);
}}"
>
`,
)
.add(
'parser',
() => html`
`,
)
.add(
'formatter',
() => html`
`,
)
/* .add(
'preprocessor',
() => html`
`,
) */
.add(
'(de)serializer',
() => html`
`,
)
.add(
'Unparseable',
() => html`
{
if (modelValue instanceof Unparseable) {
console.log(`End user attempted to create a valid entry and most likely is in
the process of doing so. We can retrieve the intermediate state via modelValue.viewValue`);
} else if (errorState) {
console.log(`We know now end user entered a valid type, but some constraints
(for instance min date) were not met`);
} else {
console.log(`Now we know end user entered a valid input: the field is valid
and modelValue can be used in Application context for further processing`);
}
}}"
>
`,
)
.add(
'Unparseable restore',
() => html`
`,
);