Skip to content

Commit

Permalink
allow shortcuts with null value
Browse files Browse the repository at this point in the history
  • Loading branch information
veej committed May 14, 2024
1 parent 4de9c27 commit 12d1a10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/bento-design-system/src/DateField/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export type ShortcutProps<Value> = {
};
type SingleDateFieldProps = {
type?: "single";
shortcuts?: ShortcutProps<Date>[];
shortcuts?: ShortcutProps<Date | null>[];
} & FieldProps<Date | null>;
type RangeDateFieldProps = {
type: "range";
shortcuts?: ShortcutProps<[Date, Date]>[];
shortcuts?: ShortcutProps<[Date, Date] | null>[];
} & FieldProps<[Date, Date] | null>;
type Props = (SingleDateFieldProps | RangeDateFieldProps) & {
minDate?: Date;
Expand Down Expand Up @@ -138,6 +138,7 @@ function RangeDateField({ disabled, readOnly, ...props }: Extract<Props, { type:
props.onChange([range.start.toDate(localTimeZone), range.end.toDate(localTimeZone)]);
}
},
shouldForceLeadingZeros: true,
} as const;
const state = useDateRangePickerState(internalProps);
const ref = useRef(null);
Expand Down
17 changes: 11 additions & 6 deletions packages/bento-design-system/src/DateField/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { CalendarDate, createCalendar } from "@internationalized/date";
import { AriaDateFieldOptions, useDateField, useDateSegment } from "@react-aria/datepicker";
import { createCalendar } from "@internationalized/date";
import {
AriaDatePickerProps,
DateValue,
useDateField,
useDateSegment,
} from "@react-aria/datepicker";
import { useLocale } from "@react-aria/i18n";
import {
DateFieldState,
Expand All @@ -25,12 +30,12 @@ import { ValidationState } from "@react-types/shared";
import { Column, Columns } from "../Layout/Columns";

type Props = (
| { type: "single"; fieldProps: AriaDateFieldOptions<CalendarDate> }
| { type: "single"; fieldProps: AriaDatePickerProps<DateValue> }
| {
type: "range";
fieldProps: {
start: AriaDateFieldOptions<CalendarDate>;
end: AriaDateFieldOptions<CalendarDate>;
start: AriaDatePickerProps<DateValue>;
end: AriaDatePickerProps<DateValue>;
};
}
) & {
Expand Down Expand Up @@ -60,7 +65,7 @@ function DateSegment({ segment, state }: { segment: DateSegmentType; state: Date
);
}

function DateField({ fieldProps }: { fieldProps: AriaDateFieldOptions<CalendarDate> }) {
function DateField({ fieldProps }: { fieldProps: AriaDatePickerProps<DateValue> }) {
const { locale } = useLocale();
const ref = useRef(null);
const state = useDateFieldState({
Expand Down

0 comments on commit 12d1a10

Please sign in to comment.