Skip to content

Commit

Permalink
feat(UnitInputField): new component (#3801)
Browse files Browse the repository at this point in the history
* 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
lisalupi committed May 23, 2024
1 parent 638c99a commit 3a808ce
Show file tree
Hide file tree
Showing 9 changed files with 1,473 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-suits-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/form": minor
---

New component `<UnitInputField />`
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
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 }
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',
}
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'
Loading

0 comments on commit 3a808ce

Please sign in to comment.