-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UnitInputField): new component (#3801)
* feat: unitinputfield draft * feat: unit input field draft * feat: unit input field * fix: add changeset * fix: update tests for vite * fix: add helper * fix: update test * fix: add prop validate on field * test: update snapshot
- Loading branch information
Showing
9 changed files
with
1,473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ultraviolet/form": minor | ||
--- | ||
|
||
New component `<UnitInputField />` |
5 changes: 5 additions & 0 deletions
5
packages/form/src/components/UnitInputField/__stories__/Playground.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Template } from './Template.stories' | ||
|
||
export const Playground = Template.bind({}) | ||
|
||
Playground.args = Template.args |
17 changes: 17 additions & 0 deletions
17
packages/form/src/components/UnitInputField/__stories__/Required.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { StoryFn } from '@storybook/react' | ||
import { Stack } from '@ultraviolet/ui' | ||
import type { ComponentProps } from 'react' | ||
import { UnitInputField } from '..' | ||
import { Submit } from '../../Submit' | ||
import { Template } from './Template.stories' | ||
|
||
export const Required: StoryFn< | ||
ComponentProps<typeof UnitInputField> | ||
> = args => ( | ||
<Stack gap={1}> | ||
<UnitInputField {...args} /> | ||
<Submit>Submit</Submit> | ||
</Stack> | ||
) | ||
|
||
Required.args = { ...Template.args, required: true } |
37 changes: 37 additions & 0 deletions
37
packages/form/src/components/UnitInputField/__stories__/Template.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { StoryFn } from '@storybook/react' | ||
import { Stack } from '@ultraviolet/ui' | ||
import type { ComponentProps } from 'react' | ||
import { UnitInputField } from '..' | ||
import { Submit } from '../..' | ||
|
||
const optionsSelect = [ | ||
{ | ||
label: 'Seconds', | ||
value: 'seconds', | ||
}, | ||
{ | ||
label: 'Days', | ||
value: 'days', | ||
}, | ||
{ | ||
label: 'Months', | ||
value: 'months', | ||
}, | ||
] | ||
|
||
export const Template: StoryFn< | ||
ComponentProps<typeof UnitInputField> | ||
> = args => ( | ||
<Stack gap="1"> | ||
<UnitInputField {...args} /> | ||
<Submit>Submit</Submit> | ||
</Stack> | ||
) | ||
|
||
Template.args = { | ||
label: 'Label', | ||
name: 'example', | ||
options: optionsSelect, | ||
helper: 'helper', | ||
placeholder: 'Placeholder', | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/form/src/components/UnitInputField/__stories__/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Meta } from '@storybook/react' | ||
import { Snippet, Stack, Text } from '@ultraviolet/ui' | ||
import { useForm } from 'react-hook-form' | ||
import { Form, UnitInputField } from '../..' | ||
import { mockErrors } from '../../../mocks' | ||
|
||
export default { | ||
component: UnitInputField, | ||
decorators: [ | ||
ChildStory => { | ||
const methods = useForm() | ||
const { | ||
errors, | ||
isDirty, | ||
isSubmitting, | ||
touchedFields, | ||
submitCount, | ||
dirtyFields, | ||
isValid, | ||
isLoading, | ||
isSubmitted, | ||
isValidating, | ||
isSubmitSuccessful, | ||
} = methods.formState | ||
|
||
return ( | ||
<Form onRawSubmit={() => {}} errors={mockErrors} methods={methods}> | ||
<Stack gap={2}> | ||
{ChildStory()} | ||
<Stack gap={1}> | ||
<Text variant="bodyStrong" as="p"> | ||
Form input values: | ||
</Text> | ||
<Snippet prefix="lines" initiallyExpanded> | ||
{JSON.stringify(methods.watch(), null, 1)} | ||
</Snippet> | ||
</Stack> | ||
<Stack gap={1}> | ||
<Text variant="bodyStrong" as="p"> | ||
Form values: | ||
</Text> | ||
<Snippet prefix="lines"> | ||
{JSON.stringify( | ||
{ | ||
errors, | ||
isDirty, | ||
isSubmitting, | ||
touchedFields, | ||
submitCount, | ||
dirtyFields, | ||
isValid, | ||
isLoading, | ||
isSubmitted, | ||
isValidating, | ||
isSubmitSuccessful, | ||
}, | ||
null, | ||
1, | ||
)} | ||
</Snippet> | ||
</Stack> | ||
</Stack> | ||
</Form> | ||
) | ||
}, | ||
], | ||
title: 'Form/Components/Fields/UnitInputField', | ||
} as Meta | ||
|
||
export { Playground } from './Playground.stories' | ||
export { Required } from './Required.stories' |
Oops, something went wrong.