Skip to content

Commit

Permalink
feat(DatePicker): add minDate and maxDate props for date range selection
Browse files Browse the repository at this point in the history
  • Loading branch information
agjs committed Dec 1, 2024
1 parent 2ad5382 commit db22850
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@programmer_network/yail",
"version": "1.0.197",
"version": "1.0.198",
"description": "Programmer Network's official UI library for React",
"author": "Aleksandar Grbic - (https://programmer.network)",
"publishConfig": {
Expand Down
23 changes: 23 additions & 0 deletions src/Components/Inputs/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ export const Default = () => {
/>
);
};

export const WithMinAndMaxDate = () => {
const [date, setDate] = useState(new Date());

return (
<DatePicker
name='datetime'
minDate={new Date()}
maxDate={new Date(new Date().setDate(new Date().getDate() + 7))}
selected={date}
timeIntervals={60}
showTimeSelect
timeCaption='Time'
onChange={input => {
if (!input.datetime) {
return;
}

setDate(input.datetime);
}}
/>
);
};
6 changes: 5 additions & 1 deletion src/Components/Inputs/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const DatePicker: FC<IDatePickerProps> = props => {
timeFormat = "HH:mm",
timeCaption = "time",
timeIntervals = 15,
dateFormat = "MMMM d, yyyy h:mm aa"
dateFormat = "MMMM d, yyyy h:mm aa",
minDate,
maxDate
} = props;

const handleChange = (date: Date | null) => {
Expand All @@ -42,6 +44,8 @@ const DatePicker: FC<IDatePickerProps> = props => {
timeCaption={timeCaption}
dateFormat={dateFormat}
showPopperArrow={false}
minDate={minDate}
maxDate={maxDate}
/>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions src/Components/Inputs/DatePicker/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ li.react-datepicker__time-list-item {
.react-datepicker__input-container input {
@apply yl-w-full yl-appearance-none yl-rounded-md yl-border-2 yl-border-primary-text-color yl-bg-transparent yl-p-2 yl-text-primary-text-color hover:yl-cursor-pointer hover:yl-border-primary focus:yl-border-primary focus:yl-outline-none focus:yl-ring-transparent !important;
}

.react-datepicker__day--disabled {
@apply yl-cursor-not-allowed yl-text-primary-text-color/40 !important;
}
2 changes: 2 additions & 0 deletions src/Components/Inputs/DatePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface IDatePickerProps extends InputHeaderProps {
timeCaption?: string;
dateFormat?: string;
showTimeSelect?: boolean;
minDate?: Date;
maxDate?: Date;
}

0 comments on commit db22850

Please sign in to comment.