Skip to content

Commit

Permalink
fix: feedback and add prop to DateField
Browse files Browse the repository at this point in the history
  • Loading branch information
lisalupi committed Feb 6, 2025
1 parent 969e2eb commit 09040f2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-files-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/form": patch
---

Add prop `input` to `<DateInputFieldV2 />`
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 { DateField } from '..'
import { Submit } from '../../Submit'

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

Input.args = {
name: 'date',
required: true,
input: 'calendar',
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ export { Required } from './Required.stories'
export { MinMaxDate } from './MinMaxDate.stories'
export { MinMaxDateWithTimeField } from './MinMaxWithTimeField.stories'
export { MinMaxDateRange } from './MinMaxDateRange.stories'
export { Input } from './Input.stories'
2 changes: 2 additions & 0 deletions packages/form/src/components/DateField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const DateField = <
'data-testid': dataTestId,
shouldUnregister = false,
showMonthYearPicker,
input = 'text',
}: DateFieldProps<TFieldValues, TFieldName>) => {
const { getError } = useErrors()
const {
Expand Down Expand Up @@ -152,6 +153,7 @@ export const DateField = <
? (field.value as [Date | null, Date | null])[1]
: undefined
}
input={input}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,7 @@ exports[`DateInput > render correctly with showMonthYearPicker with default date
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -1584,12 +1579,7 @@ exports[`DateInput > render correctly with showMonthYearPicker with excluded mon
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -5180,12 +5170,7 @@ exports[`DateInput > renders correctly with a array of dates to exclude 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -6448,12 +6433,7 @@ exports[`DateInput > renders correctly with date-fns locale es 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -7594,12 +7574,7 @@ exports[`DateInput > renders correctly with date-fns locale fr 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -8740,12 +8715,7 @@ exports[`DateInput > renders correctly with date-fns locale ru 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-32::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-38 {
Expand Down Expand Up @@ -9816,7 +9786,7 @@ exports[`DateInput > renders correctly with input = "calendar 1`] = `
padding: 1rem;
border-radius: 0.25rem;
background-color: #ffffff;
width: 264px;
width: 16.5rem;
}
.emotion-7[data-is-active='true'] {
Expand All @@ -9827,6 +9797,10 @@ exports[`DateInput > renders correctly with input = "calendar 1`] = `
border: 1px solid #e9eaeb;
}
.emotion-7[data-disabled="true"] {
cursor: not-allowed;
}
.emotion-9 {
display: -webkit-box;
display: -webkit-flex;
Expand Down Expand Up @@ -9951,12 +9925,7 @@ exports[`DateInput > renders correctly with input = "calendar 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-18::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-24 {
Expand Down Expand Up @@ -10668,7 +10637,7 @@ exports[`DateInput > renders correctly with input = "calendar disabled 1`] = `
padding: 1rem;
border-radius: 0.25rem;
background-color: #ffffff;
width: 264px;
width: 16.5rem;
}
.emotion-7[data-is-active='true'] {
Expand All @@ -10679,6 +10648,10 @@ exports[`DateInput > renders correctly with input = "calendar disabled 1`] = `
border: 1px solid #e9eaeb;
}
.emotion-7[data-disabled="true"] {
cursor: not-allowed;
}
.emotion-9 {
display: -webkit-box;
display: -webkit-flex;
Expand Down Expand Up @@ -10794,12 +10767,7 @@ exports[`DateInput > renders correctly with input = "calendar disabled 1`] = `
text-transform: none;
-webkit-text-decoration: none;
text-decoration: none;
display: inline-block;
text-transform: lowercase;
}
.emotion-18::first-letter {
text-transform: uppercase;
text-transform: capitalize;
}
.emotion-24 {
Expand Down Expand Up @@ -10910,7 +10878,7 @@ exports[`DateInput > renders correctly with input = "calendar disabled 1`] = `
</label>
<div
class="emotion-6 emotion-7 emotion-8"
data-disabled="false"
data-disabled="true"
data-is-active="false"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import { Daily } from './CalendarDaily'
import { Monthly } from './CalendarMonthly'

const CapitalizedText = styled(Text)`
display: inline-block;
text-transform: lowercase;
&::first-letter {
text-transform: uppercase;
}
text-transform: capitalize;
`
export const CalendarContent = () => {
const {
Expand Down Expand Up @@ -97,11 +92,7 @@ export const CalendarContent = () => {
}
/>
</Stack>
{showMonthYearPicker ? (
<Monthly disabled={disabled} />
) : (
<Daily disabled={disabled} />
)}
{showMonthYearPicker ? <Monthly /> : <Daily />}
</Stack>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CapitalizedText = styled(Text)`
}
`

export const Daily = ({ disabled }: { disabled: boolean }) => {
export const Daily = () => {
const {
value,
yearToShow,
Expand All @@ -56,6 +56,7 @@ export const Daily = ({ disabled }: { disabled: boolean }) => {
format,
setVisible,
readOnly,
disabled,
} = useContext(DateInputContext)

const [rangeState, setRangeState] = useState<'start' | 'none' | 'done'>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ text-transform: lowercase;
}
`

export const Monthly = ({ disabled }: { disabled: boolean }) => {
export const Monthly = () => {
const {
yearToShow,
setValue,
Expand All @@ -47,6 +47,7 @@ export const Monthly = ({ disabled }: { disabled: boolean }) => {
format,
setVisible,
readOnly,
disabled,
} = useContext(DateInputContext)
const [rangeState, setRangeState] = useState<'start' | 'none' | 'done'>(
range?.start ? 'start' : 'none',
Expand Down
8 changes: 6 additions & 2 deletions packages/ui/src/components/DateInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ width: 100%;`

const StyledCard = styled(Card)`
${({ theme }) => styleCalendarContainer(theme)}
width: 264px;
width: 16.5rem;
&[data-disabled="true"] {
cursor: not-allowed;
}
`

type DateInputProps<IsRange extends undefined | boolean = false> = {
Expand Down Expand Up @@ -337,7 +341,7 @@ export const DateInput = <IsRange extends undefined | boolean>({
</Text>
)}

<StyledCard>
<StyledCard disabled={disabled}>
<CalendarContent />
</StyledCard>
</Stack>
Expand Down

0 comments on commit 09040f2

Please sign in to comment.