Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit db22850

Browse files
committedDec 1, 2024·
feat(DatePicker): add minDate and maxDate props for date range selection
1 parent 2ad5382 commit db22850

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed
 

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.197",
3+
"version": "1.0.198",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

‎src/Components/Inputs/DatePicker/DatePicker.stories.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,26 @@ export const Default = () => {
3232
/>
3333
);
3434
};
35+
36+
export const WithMinAndMaxDate = () => {
37+
const [date, setDate] = useState(new Date());
38+
39+
return (
40+
<DatePicker
41+
name='datetime'
42+
minDate={new Date()}
43+
maxDate={new Date(new Date().setDate(new Date().getDate() + 7))}
44+
selected={date}
45+
timeIntervals={60}
46+
showTimeSelect
47+
timeCaption='Time'
48+
onChange={input => {
49+
if (!input.datetime) {
50+
return;
51+
}
52+
53+
setDate(input.datetime);
54+
}}
55+
/>
56+
);
57+
};

‎src/Components/Inputs/DatePicker/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const DatePicker: FC<IDatePickerProps> = props => {
1515
timeFormat = "HH:mm",
1616
timeCaption = "time",
1717
timeIntervals = 15,
18-
dateFormat = "MMMM d, yyyy h:mm aa"
18+
dateFormat = "MMMM d, yyyy h:mm aa",
19+
minDate,
20+
maxDate
1921
} = props;
2022

2123
const handleChange = (date: Date | null) => {
@@ -42,6 +44,8 @@ const DatePicker: FC<IDatePickerProps> = props => {
4244
timeCaption={timeCaption}
4345
dateFormat={dateFormat}
4446
showPopperArrow={false}
47+
minDate={minDate}
48+
maxDate={maxDate}
4549
/>
4650
</div>
4751
);

‎src/Components/Inputs/DatePicker/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ li.react-datepicker__time-list-item {
9292
.react-datepicker__input-container input {
9393
@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;
9494
}
95+
96+
.react-datepicker__day--disabled {
97+
@apply yl-cursor-not-allowed yl-text-primary-text-color/40 !important;
98+
}

‎src/Components/Inputs/DatePicker/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export interface IDatePickerProps extends InputHeaderProps {
88
timeCaption?: string;
99
dateFormat?: string;
1010
showTimeSelect?: boolean;
11+
minDate?: Date;
12+
maxDate?: Date;
1113
}

0 commit comments

Comments
 (0)
Please sign in to comment.