calendar-2k 1.0.13 → 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 CHANGED
@@ -109,7 +109,7 @@ export default function App() {
109
109
 
110
110
  ---
111
111
 
112
- ### Example 3 — Time Range Picker
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 | Type | Required | Description |
143
- | -------------- | -------------------------------- | -------- | ------------------------------------------------------------------------ |
144
- | `mode` | `"date" \| "time" \| "datetime"` | | Picker mode |
145
- | `value` | `DateValueType` | | Current selected value — a `Date` or `{ start: Date, end: Date }` object |
146
- | `onChangeDate` | `(value: DateValueType) => void` | | Callback fired when the user selects a date or range |
147
- | `color` | `string` | ❌ | Accent color for the picker UI (any valid CSS/RN color) |
148
- | `disableDate` | `(date: Date) => boolean` | ❌ | Function to disable specific dates return `true` to disable |
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` | Pick a single date |
166
- | `time` | `Date` | Pick a single time |
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,16 +224,27 @@ 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
189
241
 
190
- | Platform | Supported |
191
- | -------- | --------- |
192
- | iOS | ✅ |
193
- | Android | ✅ |
194
- | Expo Go | ✅ |
195
- | Web | |
242
+ | Platform | Supported |
243
+ | -------- | -------------- |
244
+ | iOS | ✅ |
245
+ | Android | ✅ |
246
+ | Expo Go | ✅ |
247
+ | Web | 🚧 Coming soon |
196
248
 
197
249
  ---
198
250
 
@@ -211,8 +263,4 @@ Your support helps me maintain this project and build more free open-source tool
211
263
 
212
264
  ---
213
265
 
214
- ⭐ You can also support for free by **starring the repo** — it helps a lot!
215
-
216
- ## License
217
-
218
266
  MIT
@@ -15,6 +15,8 @@ export type Calendar2kViewProps = {
15
15
  max?: Date;
16
16
  disableDate?: (date: Date) => boolean;
17
17
  placeholder?: string;
18
+ customTrigger?: React.ReactNode;
19
+ disabled?: boolean;
18
20
  };
19
21
  export type DayColumnProps = {
20
22
  label: string;
@@ -1,7 +1,8 @@
1
1
  import { NativeModule } from "expo";
2
2
  import { Calendar2kModuleEvents } from "./Calendar2k.types";
3
- declare class Calendar2kModule extends NativeModule<Calendar2kModuleEvents> {}
3
+ declare class Calendar2kModule extends NativeModule<Calendar2kModuleEvents> {
4
+ }
4
5
  declare const _default: Calendar2kModule;
5
6
  export default _default;
6
- export * from "./Calendar2k.types.d";
7
+ export type { DateValueType } from "./Calendar2k.types";
7
8
  export { default as Calendar2kView } from "./Calendar2kView";
@@ -1,18 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
4
  };
@@ -20,6 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
6
  exports.Calendar2kView = void 0;
21
7
  var expo_1 = require("expo");
22
8
  exports.default = (0, expo_1.requireNativeModule)("Calendar2k");
23
- __exportStar(require("./Calendar2k.types"), exports);
24
9
  var Calendar2kView_1 = require("./Calendar2kView");
25
10
  Object.defineProperty(exports, "Calendar2kView", { enumerable: true, get: function () { return __importDefault(Calendar2kView_1).default; } });
@@ -1,3 +1,4 @@
1
1
  import * as React from "react";
2
- import { type Calendar2kViewProps } from "./Calendar2k.types";
3
- export default function Calendar2kView({ onChangeDate, value, locales, color, min, max, disableDate, placeholder, mode, }: Calendar2kViewProps): React.JSX.Element;
2
+ import { type Calendar2kViewProps, type DateValueType } from "./Calendar2k.types";
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 };
@@ -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
- <Icon_1.default mode={mode}/>
257
- <ui_1.KText fontSize={16} color={value ? undefined : "#0007"}>
258
- {datetimeOuput}
259
- </ui_1.KText>
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.13",
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",
@@ -18,6 +18,8 @@ export type Calendar2kViewProps = {
18
18
  max?: Date;
19
19
  disableDate?: (date: Date) => boolean;
20
20
  placeholder?: string;
21
+ customTrigger?: React.ReactNode;
22
+ disabled?: boolean;
21
23
  };
22
24
 
23
25
  export type DayColumnProps = {
@@ -18,8 +18,8 @@ import { toHexColor } from "./libs/toHexColor";
18
18
  import { KText, KTouchableOpacity, KView } from "./ui";
19
19
 
20
20
  import {
21
- DateValueType,
22
21
  type Calendar2kViewProps,
22
+ type DateValueType,
23
23
  type DayColumnProps,
24
24
  type DayProps,
25
25
  } from "./Calendar2k.types";
@@ -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
- <Icon mode={mode} />
213
- <KText fontSize={16} color={value ? undefined : "#0007"}>
214
- {datetimeOuput}
215
- </KText>
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"
@@ -349,3 +358,5 @@ export default function Calendar2kView({
349
358
  </>
350
359
  );
351
360
  }
361
+
362
+ export type { Calendar2kViewProps, DateValueType };