calendar-2k 1.0.17 → 1.0.18
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/README.md +62 -10
- package/build/Calendar2k.types.d.ts +2 -0
- package/build/Calendar2kView.d.ts +2 -2
- package/build/Calendar2kView.js +10 -6
- package/package.json +1 -1
- package/src/Calendar2k.types.ts +2 -0
- package/src/Calendar2kView.tsx +14 -5
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ export default function App() {
|
|
|
109
109
|
|
|
110
110
|
---
|
|
111
111
|
|
|
112
|
-
### Example
|
|
112
|
+
### Example 4 — Time Range Picker
|
|
113
113
|
|
|
114
114
|
Select a start and end time, useful for timetable.
|
|
115
115
|
|
|
@@ -139,13 +139,19 @@ export default function App() {
|
|
|
139
139
|
|
|
140
140
|
## Props
|
|
141
141
|
|
|
142
|
-
| Prop
|
|
143
|
-
|
|
|
144
|
-
| `
|
|
145
|
-
| `value`
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
142
|
+
| Prop | Type | Required | Description |
|
|
143
|
+
| --------------- | -------------------------------- | -------- | --------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `onChangeDate` | `(value: DateValueType) => void` | ❌ | Callback fired when the user selects a date or range |
|
|
145
|
+
| `value` | `DateValueType` | ❌ | Current selected value — a `Date` or `{ start: Date, end: Date }` object |
|
|
146
|
+
| `locales` | `Intl.LocalesArgument` | ❌ | Locale for displaying month/day names and time format (e.g. `"fr"`, `"en-US"`). Defaults to device locale |
|
|
147
|
+
| `mode` | `"date" \| "time" \| "datetime"` | ❌ | Picker mode |
|
|
148
|
+
| `color` | `string` | ❌ | Accent color for the picker UI (any valid CSS/RN color) |
|
|
149
|
+
| `min` | `Date` | ❌ | Earliest selectable date — all dates before this are automatically disabled |
|
|
150
|
+
| `max` | `Date` | ❌ | Latest selectable date — all dates after this are automatically disabled |
|
|
151
|
+
| `disableDate` | `(date: Date) => boolean` | ❌ | Function to disable specific dates — return `true` to disable |
|
|
152
|
+
| `placeholder` | `string` | ❌ | Text shown in the trigger button when no date is selected yet |
|
|
153
|
+
| `customTrigger` | `React.ReactNode` | ❌ | Custom element to replace the default trigger button |
|
|
154
|
+
| `disabled` | `boolean` | ❌ | Disables the entire picker — the trigger becomes non-interactive |
|
|
149
155
|
|
|
150
156
|
---
|
|
151
157
|
|
|
@@ -158,12 +164,47 @@ type DateValueType = Date | { start: Date; end: Date };
|
|
|
158
164
|
|
|
159
165
|
---
|
|
160
166
|
|
|
167
|
+
## Working with the Selected Value
|
|
168
|
+
|
|
169
|
+
`DateValueType` is a standard JavaScript `Date` object (or a pair of them for ranges). Use the built-in `Date` methods to extract any part of the selected value:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
const date = new Date("2025-06-15T14:30:00");
|
|
173
|
+
|
|
174
|
+
date.getFullYear(); // 2025
|
|
175
|
+
date.getMonth(); // 5 (0-indexed, so 5 = June)
|
|
176
|
+
date.getDate(); // 15
|
|
177
|
+
date.getDay(); // 0–6 (day of the week, 0 = Sunday)
|
|
178
|
+
date.getHours(); // 14
|
|
179
|
+
date.getMinutes(); // 30
|
|
180
|
+
date.getSeconds(); // 0
|
|
181
|
+
date.toISOString(); // "2025-06-15T14:30:00.000Z"
|
|
182
|
+
date.toLocaleDateString(); // "6/15/2025" (format depends on locale)
|
|
183
|
+
date.toLocaleTimeString(); // "2:30:00 PM"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For range values, access each bound separately:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
const [date, setDate] = useState<DateValueType>({
|
|
190
|
+
start: new Date(),
|
|
191
|
+
end: new Date(),
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
if (date && "start" in date) {
|
|
195
|
+
date.start.getDate(); // start day
|
|
196
|
+
date.end.getFullYear(); // end year
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
161
202
|
## Modes
|
|
162
203
|
|
|
163
204
|
| Mode | `value` type | Description |
|
|
164
205
|
| ---------- | -------------------------- | ------------------------- |
|
|
165
|
-
| `date` | `Date`
|
|
166
|
-
| `time` | `Date`
|
|
206
|
+
| `date` | `Date` or `{ start, end }` | Pick a single date |
|
|
207
|
+
| `time` | `Date` or `{ start, end }` | Pick a single time |
|
|
167
208
|
| `datetime` | `Date` or `{ start, end }` | Pick date+time or a range |
|
|
168
209
|
|
|
169
210
|
---
|
|
@@ -183,6 +224,17 @@ disableDate={(date) => date < new Date()}
|
|
|
183
224
|
disableDate={(date) => date.toDateString() === new Date("2025-12-25").toDateString()}
|
|
184
225
|
```
|
|
185
226
|
|
|
227
|
+
You can also use `min` and `max` for simpler range-based disabling:
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
// Only allow dates in 2025
|
|
231
|
+
<Calendar2kView
|
|
232
|
+
min={new Date("2025-01-01")}
|
|
233
|
+
max={new Date("2025-12-31")}
|
|
234
|
+
...
|
|
235
|
+
/>
|
|
236
|
+
```
|
|
237
|
+
|
|
186
238
|
---
|
|
187
239
|
|
|
188
240
|
## Platform Support
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type Calendar2kViewProps, type DateValueType } from "./Calendar2k.types";
|
|
3
|
-
export default function Calendar2kView({ onChangeDate, value, locales, color, min, max, disableDate, placeholder, mode, }: Calendar2kViewProps): React.JSX.Element;
|
|
4
|
-
export type { DateValueType };
|
|
3
|
+
export default function Calendar2kView({ onChangeDate, value, locales, color, min, max, disableDate, placeholder, customTrigger, mode, disabled, }: Calendar2kViewProps): React.JSX.Element;
|
|
4
|
+
export type { Calendar2kViewProps, DateValueType };
|
package/build/Calendar2kView.js
CHANGED
|
@@ -104,7 +104,7 @@ var toHexColor_1 = require("./libs/toHexColor");
|
|
|
104
104
|
var ui_1 = require("./ui");
|
|
105
105
|
function Calendar2kView(_a) {
|
|
106
106
|
var _this = this;
|
|
107
|
-
var onChangeDate = _a.onChangeDate, value = _a.value, locales = _a.locales, color = _a.color, min = _a.min, max = _a.max, disableDate = _a.disableDate, placeholder = _a.placeholder, _b = _a.mode, mode = _b === void 0 ? "datetime" : _b;
|
|
107
|
+
var onChangeDate = _a.onChangeDate, value = _a.value, locales = _a.locales, color = _a.color, min = _a.min, max = _a.max, disableDate = _a.disableDate, placeholder = _a.placeholder, customTrigger = _a.customTrigger, _b = _a.mode, mode = _b === void 0 ? "datetime" : _b, disabled = _a.disabled;
|
|
108
108
|
color = (0, toHexColor_1.toHexColor)(color);
|
|
109
109
|
var modeHasTime = mode === null || mode === void 0 ? void 0 : mode.includes("time");
|
|
110
110
|
var modeHasDate = mode === null || mode === void 0 ? void 0 : mode.includes("date");
|
|
@@ -117,6 +117,8 @@ function Calendar2kView(_a) {
|
|
|
117
117
|
return (0, format_1.getWeekDay)(new Date(2026, 4, 3 + i), locales);
|
|
118
118
|
});
|
|
119
119
|
var datetimeOuput = (0, react_1.useMemo)(function () {
|
|
120
|
+
if (customTrigger)
|
|
121
|
+
return "";
|
|
120
122
|
if (!value) {
|
|
121
123
|
if (placeholder)
|
|
122
124
|
return placeholder;
|
|
@@ -241,7 +243,7 @@ function Calendar2kView(_a) {
|
|
|
241
243
|
</ui_1.KView>);
|
|
242
244
|
}
|
|
243
245
|
return (<>
|
|
244
|
-
<react_native_1.Pressable onPress={onToggle} style={{
|
|
246
|
+
<react_native_1.Pressable onPress={onToggle} disabled={disabled} style={{
|
|
245
247
|
width: "100%",
|
|
246
248
|
borderWidth: 1,
|
|
247
249
|
borderColor: "#0003",
|
|
@@ -253,10 +255,12 @@ function Calendar2kView(_a) {
|
|
|
253
255
|
gap: 10,
|
|
254
256
|
alignItems: "center",
|
|
255
257
|
}}>
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
{customTrigger || (<>
|
|
259
|
+
<Icon_1.default mode={mode}/>
|
|
260
|
+
<ui_1.KText fontSize={16} color={value ? undefined : "#0007"}>
|
|
261
|
+
{datetimeOuput}
|
|
262
|
+
</ui_1.KText>
|
|
263
|
+
</>)}
|
|
260
264
|
</react_native_1.Pressable>
|
|
261
265
|
<react_native_1.Modal animationType="slide" visible={isOpen} transparent onRequestClose={onToggle}>
|
|
262
266
|
<ui_1.KView flex={1} justifyContent="flex-end">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "calendar-2k",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "The fastest fully customizable Expo date & time picker, written in TypeScript, supporting Expo Go, single date, time, date range, time range, datetime range selection, flexible date disabling, and dynamic color theming for iOS and Android.",
|
|
5
5
|
"main": "build/Calendar2kView.js",
|
|
6
6
|
"types": "build/Calendar2k.types.d.ts",
|
package/src/Calendar2k.types.ts
CHANGED
package/src/Calendar2kView.tsx
CHANGED
|
@@ -33,7 +33,9 @@ export default function Calendar2kView({
|
|
|
33
33
|
max,
|
|
34
34
|
disableDate,
|
|
35
35
|
placeholder,
|
|
36
|
+
customTrigger,
|
|
36
37
|
mode = "datetime",
|
|
38
|
+
disabled,
|
|
37
39
|
}: Calendar2kViewProps) {
|
|
38
40
|
color = toHexColor(color);
|
|
39
41
|
|
|
@@ -60,6 +62,8 @@ export default function Calendar2kView({
|
|
|
60
62
|
);
|
|
61
63
|
|
|
62
64
|
const datetimeOuput = useMemo(() => {
|
|
65
|
+
if (customTrigger) return "";
|
|
66
|
+
|
|
63
67
|
if (!value) {
|
|
64
68
|
if (placeholder) return placeholder;
|
|
65
69
|
|
|
@@ -196,6 +200,7 @@ export default function Calendar2kView({
|
|
|
196
200
|
<>
|
|
197
201
|
<Pressable
|
|
198
202
|
onPress={onToggle}
|
|
203
|
+
disabled={disabled}
|
|
199
204
|
style={{
|
|
200
205
|
width: "100%",
|
|
201
206
|
borderWidth: 1,
|
|
@@ -209,10 +214,14 @@ export default function Calendar2kView({
|
|
|
209
214
|
alignItems: "center",
|
|
210
215
|
}}
|
|
211
216
|
>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
{customTrigger || (
|
|
218
|
+
<>
|
|
219
|
+
<Icon mode={mode} />
|
|
220
|
+
<KText fontSize={16} color={value ? undefined : "#0007"}>
|
|
221
|
+
{datetimeOuput}
|
|
222
|
+
</KText>
|
|
223
|
+
</>
|
|
224
|
+
)}
|
|
216
225
|
</Pressable>
|
|
217
226
|
<Modal
|
|
218
227
|
animationType="slide"
|
|
@@ -350,4 +359,4 @@ export default function Calendar2kView({
|
|
|
350
359
|
);
|
|
351
360
|
}
|
|
352
361
|
|
|
353
|
-
export type { DateValueType };
|
|
362
|
+
export type { Calendar2kViewProps, DateValueType };
|