Skip to content

Commit

Permalink
feat: Allow setting disabled to date/timepicker (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-beezee authored Apr 24, 2024
1 parent 34ffa4d commit 3f2bd77
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/stories/form/datepicker/Datepicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ DatepickerTime.args = {
value: new Date("04-01-2022 12:00"),
control: "time",
};

export const DatepickerTimeDisabled = DatepickerTemplate.bind({});
DatepickerTimeDisabled.args = {
onChange: ({ value }: { value: Date }) => {
console.log(value);
},
disabled: true,
value: new Date("04-01-2022 12:00"),
control: "time",
};
9 changes: 8 additions & 1 deletion src/stories/form/datepicker/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,27 @@ export const Datepicker = ({
setText = "Set",
cancelText = "Cancel",
dateFormat = "DD/MM/YYYY",
disabled,
}: DatepickerProps) => {
const [currentDate, setCurrentDate] = useState(
value ? (typeof value === "string" ? value : formatDate(value)) : "",
);
if (control === "time") {
return (
<TimePicker placeholder={placeholder} value={value} onChange={onChange} />
<TimePicker
disabled={disabled}
placeholder={placeholder}
value={value}
onChange={onChange}
/>
);
}

return (
<DateInput
placeholder={placeholder}
value={currentDate}
disabled={disabled}
max={maxDate ? formatDate(maxDate) : undefined}
min={minDate ? formatDate(minDate) : undefined}
onChange={(e) => {
Expand Down
3 changes: 3 additions & 0 deletions src/stories/form/datepicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const TimePicker = ({
value,
placeholder,
onChange,
disabled,
}: {
placeholder: DatepickerProps["placeholder"];
value: DatepickerProps["value"];
onChange: DatepickerProps["onChange"];
disabled?: DatepickerProps["disabled"];
}) => {
const [time, setTime] = useState(
value ? (typeof value === "string" ? value : formatTime(value)) : "",
Expand Down Expand Up @@ -59,6 +61,7 @@ const TimePicker = ({
}}
maskChar="0"
value={time}
disabled={disabled}
onChange={(event) => {
if (onChange) {
onChange({
Expand Down
8 changes: 8 additions & 0 deletions src/stories/form/datepicker/_types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
export interface DatepickerProps {
/** @deprecated since version 2.0 */
select?: "date" | "range";
value?: string | Date;
id: string;
minDate?: Date;
maxDate?: Date;
/** @deprecated since version 2.0 */
locale?: string;
/** @deprecated since version 2.0 */
onOpen?: () => void;
/** @deprecated since version 2.0 */
onCancel?: ({ value, valueText }: { value: Date; valueText: string }) => void;
onChange?: ({ value, valueText }: { value: Date; valueText: string }) => void;
placeholder?: string;
control?: "date" | "calendar" | "time";
/** @deprecated since version 2.0 */
setText?: string;
/** @deprecated since version 2.0 */
cancelText?: string;
/** @deprecated since version 2.0 */
dateFormat?: string;
disabled?: boolean;
}

0 comments on commit 3f2bd77

Please sign in to comment.