@react-cupertino-ui/date-picker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/dist/index.css +195 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +199 -0
- package/dist/index.scss +214 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anderson Lima
|
|
4
|
+
|
|
5
|
+
This project is inspired by Apple's design principles but is not affiliated with, endorsed, or sponsored by Apple Inc.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
.react-cupertino-ui-date-picker {
|
|
2
|
+
--date-picker-bg: rgba(255, 255, 255, 0.78);
|
|
3
|
+
position: relative;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: 1rem;
|
|
7
|
+
padding: 1.25rem;
|
|
8
|
+
border-radius: 24px;
|
|
9
|
+
background: var(--date-picker-bg);
|
|
10
|
+
color: var(--foreground, #0a0a0a);
|
|
11
|
+
box-shadow: 0 12px 30px rgba(15, 15, 15, 0.08);
|
|
12
|
+
min-width: min(22rem, 100%);
|
|
13
|
+
transition: background 200ms ease, box-shadow 200ms ease;
|
|
14
|
+
}
|
|
15
|
+
.react-cupertino-ui-date-picker.glass {
|
|
16
|
+
background: rgba(255, 255, 255, 0.65);
|
|
17
|
+
backdrop-filter: blur(var(--glass-blur, 32px)) saturate(var(--glass-saturation, 180%));
|
|
18
|
+
-webkit-backdrop-filter: blur(var(--glass-blur, 32px)) saturate(var(--glass-saturation, 180%));
|
|
19
|
+
border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.18));
|
|
20
|
+
box-shadow: var(--glass-shadow, 0 8px 32px rgba(0, 0, 0, 0.12));
|
|
21
|
+
position: relative;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
}
|
|
24
|
+
.react-cupertino-ui-date-picker.glass::before {
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset: 0;
|
|
28
|
+
background: var(--glass-highlight, linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, transparent 55%));
|
|
29
|
+
border-radius: inherit;
|
|
30
|
+
opacity: var(--glass-highlight-opacity, 0.95);
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
mix-blend-mode: screen;
|
|
33
|
+
}
|
|
34
|
+
.react-cupertino-ui-date-picker.layout-wheel {
|
|
35
|
+
flex-direction: row;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: center;
|
|
38
|
+
gap: 0.75rem;
|
|
39
|
+
}
|
|
40
|
+
.react-cupertino-ui-date-picker.layout-calendar, .react-cupertino-ui-date-picker.layout-compact {
|
|
41
|
+
width: min(22rem, 100%);
|
|
42
|
+
}
|
|
43
|
+
.react-cupertino-ui-date-picker .picker-column {
|
|
44
|
+
flex: 1;
|
|
45
|
+
min-width: 60px;
|
|
46
|
+
}
|
|
47
|
+
.react-cupertino-ui-date-picker .picker-column.year-column {
|
|
48
|
+
flex: 1.2;
|
|
49
|
+
}
|
|
50
|
+
.react-cupertino-ui-date-picker .picker-column.month-column {
|
|
51
|
+
flex: 1.5;
|
|
52
|
+
}
|
|
53
|
+
.react-cupertino-ui-date-picker .picker-column.day-column {
|
|
54
|
+
flex: 0.8;
|
|
55
|
+
}
|
|
56
|
+
.react-cupertino-ui-date-picker .picker-column.hour-column, .react-cupertino-ui-date-picker .picker-column.minute-column {
|
|
57
|
+
flex: 1;
|
|
58
|
+
}
|
|
59
|
+
.react-cupertino-ui-date-picker .picker-column.separator {
|
|
60
|
+
flex: 0;
|
|
61
|
+
min-width: 10px;
|
|
62
|
+
text-align: center;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
color: color-mix(in srgb, currentColor, transparent 30%);
|
|
65
|
+
}
|
|
66
|
+
.react-cupertino-ui-date-picker__calendar {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
gap: 0.75rem;
|
|
70
|
+
}
|
|
71
|
+
.react-cupertino-ui-date-picker__calendar-header {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
gap: 0.75rem;
|
|
76
|
+
}
|
|
77
|
+
.react-cupertino-ui-date-picker__month-button {
|
|
78
|
+
width: 2.25rem;
|
|
79
|
+
height: 2.25rem;
|
|
80
|
+
border-radius: 999px;
|
|
81
|
+
border: none;
|
|
82
|
+
background: rgba(255, 255, 255, 0.3);
|
|
83
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
|
|
84
|
+
color: inherit;
|
|
85
|
+
display: inline-flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
transition: transform 150ms ease, background 150ms ease;
|
|
90
|
+
}
|
|
91
|
+
.react-cupertino-ui-date-picker__month-button:disabled {
|
|
92
|
+
opacity: 0.4;
|
|
93
|
+
cursor: not-allowed;
|
|
94
|
+
}
|
|
95
|
+
.react-cupertino-ui-date-picker__month-button:active {
|
|
96
|
+
transform: scale(0.92);
|
|
97
|
+
}
|
|
98
|
+
.react-cupertino-ui-date-picker__month-label {
|
|
99
|
+
font-size: 1.05rem;
|
|
100
|
+
font-weight: 600;
|
|
101
|
+
text-transform: capitalize;
|
|
102
|
+
}
|
|
103
|
+
.react-cupertino-ui-date-picker__weekday-row {
|
|
104
|
+
display: grid;
|
|
105
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
106
|
+
gap: 0.35rem;
|
|
107
|
+
text-align: center;
|
|
108
|
+
}
|
|
109
|
+
.react-cupertino-ui-date-picker__weekday {
|
|
110
|
+
font-size: 0.75rem;
|
|
111
|
+
font-weight: 600;
|
|
112
|
+
color: color-mix(in srgb, currentColor, transparent 45%);
|
|
113
|
+
text-transform: uppercase;
|
|
114
|
+
}
|
|
115
|
+
.react-cupertino-ui-date-picker__calendar-grid {
|
|
116
|
+
display: grid;
|
|
117
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
118
|
+
gap: 0.35rem;
|
|
119
|
+
}
|
|
120
|
+
.react-cupertino-ui-date-picker__day {
|
|
121
|
+
position: relative;
|
|
122
|
+
border: none;
|
|
123
|
+
border-radius: 12px;
|
|
124
|
+
padding: 0.65rem 0;
|
|
125
|
+
background: rgba(255, 255, 255, 0.25);
|
|
126
|
+
color: inherit;
|
|
127
|
+
font-weight: 500;
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
|
|
130
|
+
}
|
|
131
|
+
.react-cupertino-ui-date-picker__day:disabled {
|
|
132
|
+
opacity: 0.35;
|
|
133
|
+
cursor: not-allowed;
|
|
134
|
+
}
|
|
135
|
+
.react-cupertino-ui-date-picker__day.is-outside {
|
|
136
|
+
opacity: 0.4;
|
|
137
|
+
}
|
|
138
|
+
.react-cupertino-ui-date-picker__day.is-today {
|
|
139
|
+
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
|
|
140
|
+
}
|
|
141
|
+
.react-cupertino-ui-date-picker__day.is-selected {
|
|
142
|
+
background: linear-gradient(120deg, #0a84ff 0%, #5ac8fa 100%);
|
|
143
|
+
color: white;
|
|
144
|
+
box-shadow: 0 12px 28px rgba(10, 132, 255, 0.35);
|
|
145
|
+
}
|
|
146
|
+
.react-cupertino-ui-date-picker__time-row {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
justify-content: space-between;
|
|
150
|
+
gap: 1rem;
|
|
151
|
+
}
|
|
152
|
+
.react-cupertino-ui-date-picker__time-row label {
|
|
153
|
+
display: block;
|
|
154
|
+
font-size: 0.8rem;
|
|
155
|
+
margin-bottom: 0.25rem;
|
|
156
|
+
color: color-mix(in srgb, currentColor, transparent 40%);
|
|
157
|
+
}
|
|
158
|
+
.react-cupertino-ui-date-picker__time-row select {
|
|
159
|
+
width: 100%;
|
|
160
|
+
border-radius: 16px;
|
|
161
|
+
padding: 0.45rem 0.75rem;
|
|
162
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
163
|
+
background: rgba(255, 255, 255, 0.8);
|
|
164
|
+
font-size: 0.95rem;
|
|
165
|
+
}
|
|
166
|
+
.react-cupertino-ui-date-picker__compact {
|
|
167
|
+
display: flex;
|
|
168
|
+
flex-direction: column;
|
|
169
|
+
gap: 0.75rem;
|
|
170
|
+
}
|
|
171
|
+
.react-cupertino-ui-date-picker__compact-row {
|
|
172
|
+
display: grid;
|
|
173
|
+
grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
|
|
174
|
+
gap: 0.5rem;
|
|
175
|
+
}
|
|
176
|
+
.react-cupertino-ui-date-picker__compact-row label {
|
|
177
|
+
display: block;
|
|
178
|
+
font-size: 0.8rem;
|
|
179
|
+
margin-bottom: 0.25rem;
|
|
180
|
+
color: color-mix(in srgb, currentColor, transparent 40%);
|
|
181
|
+
}
|
|
182
|
+
.react-cupertino-ui-date-picker__compact-row select {
|
|
183
|
+
width: 100%;
|
|
184
|
+
border-radius: 999px;
|
|
185
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
186
|
+
padding: 0.5rem 0.9rem;
|
|
187
|
+
font-size: 0.95rem;
|
|
188
|
+
background: rgba(255, 255, 255, 0.9);
|
|
189
|
+
transition: border-color 120ms ease;
|
|
190
|
+
}
|
|
191
|
+
.react-cupertino-ui-date-picker__compact-row select:focus-visible {
|
|
192
|
+
outline: none;
|
|
193
|
+
border-color: #0a84ff;
|
|
194
|
+
box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
|
|
195
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "./index.scss";
|
|
3
|
+
export interface DatePickerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
4
|
+
value: Date;
|
|
5
|
+
onChange: (date: Date) => void;
|
|
6
|
+
mode?: "date" | "time" | "datetime";
|
|
7
|
+
minDate?: Date;
|
|
8
|
+
maxDate?: Date;
|
|
9
|
+
className?: string;
|
|
10
|
+
glass?: boolean;
|
|
11
|
+
layout?: "wheel" | "calendar" | "compact";
|
|
12
|
+
locale?: string;
|
|
13
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
14
|
+
}
|
|
15
|
+
declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<HTMLDivElement>>;
|
|
16
|
+
export { DatePicker };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
4
|
+
import { Picker } from "@react-cupertino-ui/picker";
|
|
5
|
+
import { cn } from "@react-cupertino-ui/shared/lib/utils";
|
|
6
|
+
import "./index.scss";
|
|
7
|
+
const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate();
|
|
8
|
+
const monthStart = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
|
|
9
|
+
const startOfDay = (date) => {
|
|
10
|
+
const next = new Date(date);
|
|
11
|
+
next.setHours(0, 0, 0, 0);
|
|
12
|
+
return next;
|
|
13
|
+
};
|
|
14
|
+
const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() &&
|
|
15
|
+
a.getMonth() === b.getMonth() &&
|
|
16
|
+
a.getDate() === b.getDate();
|
|
17
|
+
const DatePicker = React.forwardRef((props, ref) => {
|
|
18
|
+
const { value, onChange, mode = "date", minDate, maxDate, className, glass = true, layout: layoutProp = "wheel", locale: localeProp, weekStartsOn = 0, ...rest } = props;
|
|
19
|
+
const locale = React.useMemo(() => {
|
|
20
|
+
if (localeProp) {
|
|
21
|
+
return localeProp;
|
|
22
|
+
}
|
|
23
|
+
if (typeof navigator !== "undefined") {
|
|
24
|
+
return navigator.language;
|
|
25
|
+
}
|
|
26
|
+
return "en-US";
|
|
27
|
+
}, [localeProp]);
|
|
28
|
+
const includesDate = mode !== "time";
|
|
29
|
+
const includesTime = mode !== "date";
|
|
30
|
+
const resolvedLayout = layoutProp === "calendar" && !includesDate ? "wheel" : layoutProp;
|
|
31
|
+
const clampDate = React.useCallback((nextDate) => {
|
|
32
|
+
const next = new Date(nextDate);
|
|
33
|
+
if (minDate && next < minDate) {
|
|
34
|
+
return new Date(minDate);
|
|
35
|
+
}
|
|
36
|
+
if (maxDate && next > maxDate) {
|
|
37
|
+
return new Date(maxDate);
|
|
38
|
+
}
|
|
39
|
+
return next;
|
|
40
|
+
}, [maxDate, minDate]);
|
|
41
|
+
const updateDate = React.useCallback((updater) => {
|
|
42
|
+
const draft = new Date(value.getTime());
|
|
43
|
+
updater(draft);
|
|
44
|
+
const next = clampDate(draft);
|
|
45
|
+
onChange(next);
|
|
46
|
+
}, [clampDate, onChange, value]);
|
|
47
|
+
const yearOptions = React.useMemo(() => {
|
|
48
|
+
const currentYear = value.getFullYear();
|
|
49
|
+
const start = minDate ? minDate.getFullYear() : currentYear - 100;
|
|
50
|
+
const end = maxDate ? maxDate.getFullYear() : currentYear + 100;
|
|
51
|
+
const result = [];
|
|
52
|
+
for (let year = start; year <= end; year += 1) {
|
|
53
|
+
result.push({ value: year, label: year.toString() });
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}, [maxDate, minDate, value]);
|
|
57
|
+
const monthOptions = React.useMemo(() => {
|
|
58
|
+
return Array.from({ length: 12 }, (_, index) => ({
|
|
59
|
+
value: index,
|
|
60
|
+
label: new Date(2000, index, 1).toLocaleString(locale, { month: "long" }),
|
|
61
|
+
}));
|
|
62
|
+
}, [locale]);
|
|
63
|
+
const dayOptions = React.useMemo(() => {
|
|
64
|
+
const totalDays = getDaysInMonth(value.getFullYear(), value.getMonth());
|
|
65
|
+
const startDay = minDate &&
|
|
66
|
+
minDate.getFullYear() === value.getFullYear() &&
|
|
67
|
+
minDate.getMonth() === value.getMonth()
|
|
68
|
+
? minDate.getDate()
|
|
69
|
+
: 1;
|
|
70
|
+
const endDay = maxDate &&
|
|
71
|
+
maxDate.getFullYear() === value.getFullYear() &&
|
|
72
|
+
maxDate.getMonth() === value.getMonth()
|
|
73
|
+
? maxDate.getDate()
|
|
74
|
+
: totalDays;
|
|
75
|
+
const result = [];
|
|
76
|
+
for (let day = startDay; day <= endDay; day += 1) {
|
|
77
|
+
result.push({ value: day, label: day.toString() });
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}, [maxDate, minDate, value]);
|
|
81
|
+
const hours = React.useMemo(() => {
|
|
82
|
+
const result = [];
|
|
83
|
+
for (let hour = 0; hour < 24; hour += 1) {
|
|
84
|
+
result.push({ value: hour, label: hour.toString().padStart(2, "0") });
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}, []);
|
|
88
|
+
const minutes = React.useMemo(() => {
|
|
89
|
+
const result = [];
|
|
90
|
+
for (let minute = 0; minute < 60; minute += 1) {
|
|
91
|
+
result.push({ value: minute, label: minute.toString().padStart(2, "0") });
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}, []);
|
|
95
|
+
const [displayedMonth, setDisplayedMonth] = React.useState(() => monthStart(value));
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (resolvedLayout === "calendar") {
|
|
98
|
+
setDisplayedMonth(monthStart(value));
|
|
99
|
+
}
|
|
100
|
+
}, [resolvedLayout, value]);
|
|
101
|
+
const goToMonth = (offset) => {
|
|
102
|
+
setDisplayedMonth((prev) => {
|
|
103
|
+
const next = new Date(prev);
|
|
104
|
+
next.setMonth(prev.getMonth() + offset);
|
|
105
|
+
return monthStart(next);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const canNavigate = React.useMemo(() => {
|
|
109
|
+
const minMonth = minDate ? monthStart(minDate) : null;
|
|
110
|
+
const maxMonth = maxDate ? monthStart(maxDate) : null;
|
|
111
|
+
return {
|
|
112
|
+
prev: !minMonth || monthStart(displayedMonth) > minMonth,
|
|
113
|
+
next: !maxMonth || monthStart(displayedMonth) < maxMonth,
|
|
114
|
+
};
|
|
115
|
+
}, [displayedMonth, maxDate, minDate]);
|
|
116
|
+
const weekdayLabels = React.useMemo(() => {
|
|
117
|
+
return Array.from({ length: 7 }, (_, index) => {
|
|
118
|
+
const weekday = (weekStartsOn + index) % 7;
|
|
119
|
+
const reference = new Date(2021, 4, 2 + weekday);
|
|
120
|
+
return reference.toLocaleDateString(locale, { weekday: "short" });
|
|
121
|
+
});
|
|
122
|
+
}, [locale, weekStartsOn]);
|
|
123
|
+
const calendarDays = React.useMemo(() => {
|
|
124
|
+
const start = monthStart(displayedMonth);
|
|
125
|
+
const totalDays = getDaysInMonth(start.getFullYear(), start.getMonth());
|
|
126
|
+
const startOffset = (start.getDay() - weekStartsOn + 7) % 7;
|
|
127
|
+
const totalCells = Math.ceil((startOffset + totalDays) / 7) * 7;
|
|
128
|
+
const cells = [];
|
|
129
|
+
for (let index = 0; index < totalCells; index += 1) {
|
|
130
|
+
const day = index - startOffset + 1;
|
|
131
|
+
const date = new Date(start.getFullYear(), start.getMonth(), day);
|
|
132
|
+
cells.push({ date, inCurrentMonth: date.getMonth() === start.getMonth() });
|
|
133
|
+
}
|
|
134
|
+
return cells;
|
|
135
|
+
}, [displayedMonth, weekStartsOn]);
|
|
136
|
+
const dateFormatter = React.useMemo(() => {
|
|
137
|
+
return new Intl.DateTimeFormat(locale, {
|
|
138
|
+
weekday: "long",
|
|
139
|
+
month: "long",
|
|
140
|
+
day: "numeric",
|
|
141
|
+
year: "numeric",
|
|
142
|
+
});
|
|
143
|
+
}, [locale]);
|
|
144
|
+
const isDateDisabled = React.useCallback((date) => {
|
|
145
|
+
if (minDate && startOfDay(date) < startOfDay(minDate)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (maxDate && startOfDay(date) > startOfDay(maxDate)) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}, [maxDate, minDate]);
|
|
153
|
+
const handleCalendarSelect = (day) => {
|
|
154
|
+
if (!includesDate) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
updateDate((draft) => {
|
|
158
|
+
draft.setFullYear(day.getFullYear(), day.getMonth(), day.getDate());
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const handleSelectChange = (type, next) => {
|
|
162
|
+
updateDate((draft) => {
|
|
163
|
+
if (type === "year")
|
|
164
|
+
draft.setFullYear(next);
|
|
165
|
+
if (type === "month")
|
|
166
|
+
draft.setMonth(next);
|
|
167
|
+
if (type === "day")
|
|
168
|
+
draft.setDate(next);
|
|
169
|
+
if (type === "hour")
|
|
170
|
+
draft.setHours(next);
|
|
171
|
+
if (type === "minute")
|
|
172
|
+
draft.setMinutes(next);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const renderWheelPickers = () => {
|
|
176
|
+
return (_jsxs(_Fragment, { children: [includesDate && (_jsxs(_Fragment, { children: [_jsx("div", { className: "picker-column year-column", children: _jsx(Picker, { options: yearOptions, value: value.getFullYear(), onChange: (val) => handleSelectChange("year", Number(val)) }) }), _jsx("div", { className: "picker-column month-column", children: _jsx(Picker, { options: monthOptions, value: value.getMonth(), onChange: (val) => handleSelectChange("month", Number(val)) }) }), _jsx("div", { className: "picker-column day-column", children: _jsx(Picker, { options: dayOptions, value: value.getDate(), onChange: (val) => handleSelectChange("day", Number(val)) }) })] })), includesTime && (_jsxs(_Fragment, { children: [_jsx("div", { className: "picker-column hour-column", children: _jsx(Picker, { options: hours, value: value.getHours(), onChange: (val) => handleSelectChange("hour", Number(val)) }) }), _jsx("div", { className: "picker-column separator", children: ":" }), _jsx("div", { className: "picker-column minute-column", children: _jsx(Picker, { options: minutes, value: value.getMinutes(), onChange: (val) => handleSelectChange("minute", Number(val)) }) })] }))] }));
|
|
177
|
+
};
|
|
178
|
+
const calendarHourSelectId = React.useId();
|
|
179
|
+
const calendarMinuteSelectId = React.useId();
|
|
180
|
+
const renderCalendar = () => {
|
|
181
|
+
return (_jsxs("div", { className: "react-cupertino-ui-date-picker__calendar", children: [_jsxs("div", { className: "react-cupertino-ui-date-picker__calendar-header", children: [_jsx("button", { type: "button", className: "react-cupertino-ui-date-picker__month-button", onClick: () => goToMonth(-1), disabled: !canNavigate.prev, "aria-label": "Previous month", children: _jsx(ChevronLeft, { size: 16 }) }), _jsx("div", { className: "react-cupertino-ui-date-picker__month-label", children: displayedMonth.toLocaleDateString(locale, { month: "long", year: "numeric" }) }), _jsx("button", { type: "button", className: "react-cupertino-ui-date-picker__month-button", onClick: () => goToMonth(1), disabled: !canNavigate.next, "aria-label": "Next month", children: _jsx(ChevronRight, { size: 16 }) })] }), _jsx("div", { className: "react-cupertino-ui-date-picker__weekday-row", children: weekdayLabels.map((weekday) => (_jsx("span", { className: "react-cupertino-ui-date-picker__weekday", children: weekday }, weekday))) }), _jsx("div", { className: "react-cupertino-ui-date-picker__calendar-grid", children: calendarDays.map(({ date, inCurrentMonth }) => {
|
|
182
|
+
const disabled = isDateDisabled(date);
|
|
183
|
+
const isSelected = includesDate && isSameDay(date, value);
|
|
184
|
+
const isToday = isSameDay(date, new Date());
|
|
185
|
+
return (_jsx("button", { type: "button", className: cn("react-cupertino-ui-date-picker__day", isSelected && "is-selected", isToday && "is-today", !inCurrentMonth && "is-outside"), onClick: () => handleCalendarSelect(date), disabled: disabled, "aria-label": `Select ${dateFormatter.format(date)}`, children: _jsx("span", { children: date.getDate() }) }, date.toISOString()));
|
|
186
|
+
}) }), includesTime && (_jsxs("div", { className: "react-cupertino-ui-date-picker__time-row", children: [_jsxs("div", { children: [_jsx("label", { htmlFor: calendarHourSelectId, children: "Hour" }), _jsx("select", { id: calendarHourSelectId, value: value.getHours(), onChange: (event) => handleSelectChange("hour", Number(event.target.value)), children: hours.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: calendarMinuteSelectId, children: "Minutes" }), _jsx("select", { id: calendarMinuteSelectId, value: value.getMinutes(), onChange: (event) => handleSelectChange("minute", Number(event.target.value)), children: minutes.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] })] }))] }));
|
|
187
|
+
};
|
|
188
|
+
const monthSelectId = React.useId();
|
|
189
|
+
const daySelectId = React.useId();
|
|
190
|
+
const yearSelectId = React.useId();
|
|
191
|
+
const hourSelectId = React.useId();
|
|
192
|
+
const minuteSelectId = React.useId();
|
|
193
|
+
const renderCompact = () => {
|
|
194
|
+
return (_jsxs("div", { className: "react-cupertino-ui-date-picker__compact", children: [includesDate && (_jsxs("div", { className: "react-cupertino-ui-date-picker__compact-row", children: [_jsxs("div", { children: [_jsx("label", { htmlFor: monthSelectId, children: "Month" }), _jsx("select", { id: monthSelectId, value: value.getMonth(), onChange: (event) => handleSelectChange("month", Number(event.target.value)), children: monthOptions.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: daySelectId, children: "Day" }), _jsx("select", { id: daySelectId, value: value.getDate(), onChange: (event) => handleSelectChange("day", Number(event.target.value)), children: dayOptions.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: yearSelectId, children: "Year" }), _jsx("select", { id: yearSelectId, value: value.getFullYear(), onChange: (event) => handleSelectChange("year", Number(event.target.value)), children: yearOptions.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] })] })), includesTime && (_jsxs("div", { className: "react-cupertino-ui-date-picker__compact-row", children: [_jsxs("div", { children: [_jsx("label", { htmlFor: hourSelectId, children: "Hour" }), _jsx("select", { id: hourSelectId, value: value.getHours(), onChange: (event) => handleSelectChange("hour", Number(event.target.value)), children: hours.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: minuteSelectId, children: "Minutes" }), _jsx("select", { id: minuteSelectId, value: value.getMinutes(), onChange: (event) => handleSelectChange("minute", Number(event.target.value)), children: minutes.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) })] })] }))] }));
|
|
195
|
+
};
|
|
196
|
+
return (_jsxs("div", { ref: ref, className: cn("react-cupertino-ui-date-picker", glass && "glass", `layout-${resolvedLayout}`, className), "data-mode": mode, ...rest, children: [resolvedLayout === "wheel" && renderWheelPickers(), resolvedLayout === "calendar" && renderCalendar(), resolvedLayout === "compact" && renderCompact()] }));
|
|
197
|
+
});
|
|
198
|
+
DatePicker.displayName = "DatePicker";
|
|
199
|
+
export { DatePicker };
|
package/dist/index.scss
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
@use "@/styles/mixins/glass" as glass;
|
|
2
|
+
|
|
3
|
+
.react-cupertino-ui-date-picker {
|
|
4
|
+
--date-picker-bg: rgba(255, 255, 255, 0.78);
|
|
5
|
+
position: relative;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: 1rem;
|
|
9
|
+
padding: 1.25rem;
|
|
10
|
+
border-radius: 24px;
|
|
11
|
+
background: var(--date-picker-bg);
|
|
12
|
+
color: var(--foreground, #0a0a0a);
|
|
13
|
+
box-shadow: 0 12px 30px rgba(15, 15, 15, 0.08);
|
|
14
|
+
min-width: min(22rem, 100%);
|
|
15
|
+
transition: background 200ms ease, box-shadow 200ms ease;
|
|
16
|
+
|
|
17
|
+
&.glass {
|
|
18
|
+
@include glass.glass-panel(light, var(--glass-blur, 32px), 0.65);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&.layout-wheel {
|
|
22
|
+
flex-direction: row;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
gap: 0.75rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&.layout-calendar,
|
|
29
|
+
&.layout-compact {
|
|
30
|
+
width: min(22rem, 100%);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.picker-column {
|
|
34
|
+
flex: 1;
|
|
35
|
+
min-width: 60px;
|
|
36
|
+
|
|
37
|
+
&.year-column {
|
|
38
|
+
flex: 1.2;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&.month-column {
|
|
42
|
+
flex: 1.5;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&.day-column {
|
|
46
|
+
flex: 0.8;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&.hour-column,
|
|
50
|
+
&.minute-column {
|
|
51
|
+
flex: 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&.separator {
|
|
55
|
+
flex: 0;
|
|
56
|
+
min-width: 10px;
|
|
57
|
+
text-align: center;
|
|
58
|
+
font-weight: 600;
|
|
59
|
+
color: color-mix(in srgb, currentColor, transparent 30%);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&__calendar {
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-direction: column;
|
|
66
|
+
gap: 0.75rem;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&__calendar-header {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: space-between;
|
|
73
|
+
gap: 0.75rem;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&__month-button {
|
|
77
|
+
width: 2.25rem;
|
|
78
|
+
height: 2.25rem;
|
|
79
|
+
border-radius: 999px;
|
|
80
|
+
border: none;
|
|
81
|
+
background: rgba(255, 255, 255, 0.3);
|
|
82
|
+
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
|
|
83
|
+
color: inherit;
|
|
84
|
+
display: inline-flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
transition: transform 150ms ease, background 150ms ease;
|
|
89
|
+
|
|
90
|
+
&:disabled {
|
|
91
|
+
opacity: 0.4;
|
|
92
|
+
cursor: not-allowed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&:active {
|
|
96
|
+
transform: scale(0.92);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
&__month-label {
|
|
101
|
+
font-size: 1.05rem;
|
|
102
|
+
font-weight: 600;
|
|
103
|
+
text-transform: capitalize;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&__weekday-row {
|
|
107
|
+
display: grid;
|
|
108
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
109
|
+
gap: 0.35rem;
|
|
110
|
+
text-align: center;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&__weekday {
|
|
114
|
+
font-size: 0.75rem;
|
|
115
|
+
font-weight: 600;
|
|
116
|
+
color: color-mix(in srgb, currentColor, transparent 45%);
|
|
117
|
+
text-transform: uppercase;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&__calendar-grid {
|
|
121
|
+
display: grid;
|
|
122
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
123
|
+
gap: 0.35rem;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&__day {
|
|
127
|
+
position: relative;
|
|
128
|
+
border: none;
|
|
129
|
+
border-radius: 12px;
|
|
130
|
+
padding: 0.65rem 0;
|
|
131
|
+
background: rgba(255, 255, 255, 0.25);
|
|
132
|
+
color: inherit;
|
|
133
|
+
font-weight: 500;
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
|
|
136
|
+
|
|
137
|
+
&:disabled {
|
|
138
|
+
opacity: 0.35;
|
|
139
|
+
cursor: not-allowed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
&.is-outside {
|
|
143
|
+
opacity: 0.4;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
&.is-today {
|
|
147
|
+
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&.is-selected {
|
|
151
|
+
background: linear-gradient(120deg, #0a84ff 0%, #5ac8fa 100%);
|
|
152
|
+
color: white;
|
|
153
|
+
box-shadow: 0 12px 28px rgba(10, 132, 255, 0.35);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&__time-row {
|
|
158
|
+
display: flex;
|
|
159
|
+
align-items: center;
|
|
160
|
+
justify-content: space-between;
|
|
161
|
+
gap: 1rem;
|
|
162
|
+
|
|
163
|
+
label {
|
|
164
|
+
display: block;
|
|
165
|
+
font-size: 0.8rem;
|
|
166
|
+
margin-bottom: 0.25rem;
|
|
167
|
+
color: color-mix(in srgb, currentColor, transparent 40%);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
select {
|
|
171
|
+
width: 100%;
|
|
172
|
+
border-radius: 16px;
|
|
173
|
+
padding: 0.45rem 0.75rem;
|
|
174
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
175
|
+
background: rgba(255, 255, 255, 0.8);
|
|
176
|
+
font-size: 0.95rem;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&__compact {
|
|
181
|
+
display: flex;
|
|
182
|
+
flex-direction: column;
|
|
183
|
+
gap: 0.75rem;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
&__compact-row {
|
|
187
|
+
display: grid;
|
|
188
|
+
grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
|
|
189
|
+
gap: 0.5rem;
|
|
190
|
+
|
|
191
|
+
label {
|
|
192
|
+
display: block;
|
|
193
|
+
font-size: 0.8rem;
|
|
194
|
+
margin-bottom: 0.25rem;
|
|
195
|
+
color: color-mix(in srgb, currentColor, transparent 40%);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
select {
|
|
199
|
+
width: 100%;
|
|
200
|
+
border-radius: 999px;
|
|
201
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
202
|
+
padding: 0.5rem 0.9rem;
|
|
203
|
+
font-size: 0.95rem;
|
|
204
|
+
background: rgba(255, 255, 255, 0.9);
|
|
205
|
+
transition: border-color 120ms ease;
|
|
206
|
+
|
|
207
|
+
&:focus-visible {
|
|
208
|
+
outline: none;
|
|
209
|
+
border-color: #0a84ff;
|
|
210
|
+
box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-cupertino-ui/date-picker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "DatePicker component from React Cupertino UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/**/*.css",
|
|
14
|
+
"./dist/**/*.scss"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json && npm run build:styles",
|
|
18
|
+
"build:styles": "node ../../../scripts/build-styles.mjs"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": "^18.3.1",
|
|
22
|
+
"react-dom": "^18.3.1"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-cupertino-ui/picker": "workspace:*",
|
|
26
|
+
"@react-cupertino-ui/shared": "workspace:*",
|
|
27
|
+
"lucide-react": "^0.417.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.2.2"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "3f53987bdb936a331665691b517c2ba9984777f8",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|