Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow setting disabled to date/timepicker #186

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading