Skip to content

Commit

Permalink
feat(SliderField): new slider into forms (#3997)
Browse files Browse the repository at this point in the history
* feat(SliderField): new slider into forms

* ci: improve coverage of slider field

* ci: improve double slider coverage

* fix: feedback alex

* fix: feedback dodo
  • Loading branch information
matthprost authored Jul 15, 2024
1 parent 9dcdfc3 commit 7ab5e04
Show file tree
Hide file tree
Showing 20 changed files with 2,825 additions and 165 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-fishes-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/ui": patch
---

Fix `<Slider />` component to avoid loop rendering while using `useEffect` so synchronise states
5 changes: 5 additions & 0 deletions .changeset/poor-turkeys-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/form": minor
---

Add new component `<SliderField />`
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Template } from './Template.stories'

export const Double = Template.bind({})

Double.args = {
double: true,
input: true,
min: 0,
max: 10,
label: 'Label',
name: 'name',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Template } from './Template.stories'

export const Playground = Template.bind({})

Playground.args = {
input: true,
min: 0,
max: 10,
label: 'Label',
name: 'name',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StoryFn } from '@storybook/react'
import { Stack } from '@ultraviolet/ui'
import type { ComponentProps } from 'react'
import { SliderField } from '..'
import { Submit } from '../../Submit'

export const Required: StoryFn<ComponentProps<typeof SliderField>> = args => (
<Stack gap={1}>
<SliderField {...args} />
<Submit>Submit</Submit>
</Stack>
)

Required.args = {
name: 'required-slider',
required: true,
label: 'This slider is required',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { StoryFn } from '@storybook/react'
import type { ComponentProps } from 'react'
import { SliderField } from '..'

export const Template: StoryFn<ComponentProps<typeof SliderField>> = args => (
<SliderField {...args} />
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { Meta } from '@storybook/react'
import { Snippet, Stack, Text } from '@ultraviolet/ui'
import { Form, SliderField } from '../..'
import { useForm } from '../../..'
import { mockErrors } from '../../../mocks'

export default {
component: SliderField,
decorators: [
ChildStory => {
const methods = useForm()
const {
errors,
isDirty,
isSubmitting,
touchedFields,
submitCount,
dirtyFields,
isValid,
isLoading,
isSubmitted,
isValidating,
isSubmitSuccessful,
} = methods.formState

return (
<Form onSubmit={() => {}} errors={mockErrors} methods={methods}>
<Stack gap={2}>
<div
style={{
width: '250px',
}}
>
<ChildStory />
</div>
<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>
)
},
],
parameters: {
docs: {
description: {
component: 'A Slider field',
},
},
},
title: 'Form/Components/Fields/SliderField',
} as Meta

export { Playground } from './Playground.stories'
export { Double } from './Double.stories'
export { Required } from './Required.stories'
Loading

0 comments on commit 7ab5e04

Please sign in to comment.