File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
packages/form/src/components/TextInputField/__stories__ Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ import type { StoryFn } from '@storybook/react-vite'
2+ import { Stack } from '@ultraviolet/ui'
3+ import type { ComponentProps } from 'react'
4+ import { Submit } from '../../Submit'
5+ import { SubmitErrorAlert } from '../../SubmitErrorAlert'
6+ import { TextInputField } from '..'
7+ import { Template } from './Template.stories'
8+
9+ const emailValidate = {
10+ pattern : async ( value : string ) => {
11+ const res = await new Promise < string | true > ( resolve => {
12+ setTimeout ( ( ) => {
13+ resolve ( value . includes ( '@' ) ? true : `Email must have a @. ${ value } ` )
14+ } , 500 )
15+ } )
16+
17+ return res
18+ } ,
19+ }
20+
21+ export const AsyncValidation : StoryFn <
22+ ComponentProps < typeof TextInputField >
23+ > = args => (
24+ < Stack gap = { 1 } >
25+ < TextInputField { ...args } validate = { emailValidate } />
26+ < SubmitErrorAlert />
27+ < Submit > Submit</ Submit >
28+ </ Stack >
29+ )
30+
31+ AsyncValidation . args = {
32+ ...Template . args ,
33+ required : true ,
34+ }
Original file line number Diff line number Diff line change @@ -8,7 +8,10 @@ export default {
88 component : TextInputField ,
99 decorators : [
1010 ChildStory => {
11- const methods = useForm ( )
11+ const methods = useForm ( {
12+ mode : 'onChange' ,
13+ } )
14+
1215 const {
1316 errors,
1417 isDirty,
@@ -69,3 +72,4 @@ export default {
6972
7073export { Playground } from './Playground.stories'
7174export { Required } from './Required.stories'
75+ export { AsyncValidation } from './AsyncValidation.stories'
You can’t perform that action at this time.
0 commit comments