rn-grid-date-time-picker 1.3.0 → 1.3.1
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/CHANGELOG.md +21 -0
- package/lib/commonjs/components/DateTimePicker.js +67 -115
- package/lib/commonjs/components/DateTimePicker.js.map +1 -1
- package/lib/commonjs/components/calendar/DayCell.js +17 -6
- package/lib/commonjs/components/calendar/DayCell.js.map +1 -1
- package/lib/commonjs/components/calendar/calendarStyles.js +11 -0
- package/lib/commonjs/components/calendar/calendarStyles.js.map +1 -1
- package/lib/commonjs/components/field/ValueField.js +19 -2
- package/lib/commonjs/components/field/ValueField.js.map +1 -1
- package/lib/commonjs/components/field/fieldText.js +44 -5
- package/lib/commonjs/components/field/fieldText.js.map +1 -1
- package/lib/commonjs/components/theme/styleKeys.js +3 -1
- package/lib/commonjs/components/theme/styleKeys.js.map +1 -1
- package/lib/commonjs/components/types.js +2 -1
- package/lib/commonjs/components/types.js.map +1 -1
- package/lib/module/components/DateTimePicker.js +68 -116
- package/lib/module/components/DateTimePicker.js.map +1 -1
- package/lib/module/components/calendar/DayCell.js +18 -7
- package/lib/module/components/calendar/DayCell.js.map +1 -1
- package/lib/module/components/calendar/calendarStyles.js +11 -0
- package/lib/module/components/calendar/calendarStyles.js.map +1 -1
- package/lib/module/components/field/ValueField.js +20 -3
- package/lib/module/components/field/ValueField.js.map +1 -1
- package/lib/module/components/field/fieldText.js +40 -4
- package/lib/module/components/field/fieldText.js.map +1 -1
- package/lib/module/components/theme/styleKeys.js +3 -1
- package/lib/module/components/theme/styleKeys.js.map +1 -1
- package/lib/module/components/types.js +2 -1
- package/lib/module/components/types.js.map +1 -1
- package/lib/typescript/commonjs/src/components/DateTimePicker.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/calendar/DayCell.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/calendar/calendarStyles.d.ts +9 -0
- package/lib/typescript/commonjs/src/components/calendar/calendarStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/field/ValueField.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/field/fieldText.d.ts +19 -0
- package/lib/typescript/commonjs/src/components/field/fieldText.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/theme/styleKeys.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/types.d.ts +18 -5
- package/lib/typescript/commonjs/src/components/types.d.ts.map +1 -1
- package/lib/typescript/module/src/components/DateTimePicker.d.ts.map +1 -1
- package/lib/typescript/module/src/components/calendar/DayCell.d.ts.map +1 -1
- package/lib/typescript/module/src/components/calendar/calendarStyles.d.ts +9 -0
- package/lib/typescript/module/src/components/calendar/calendarStyles.d.ts.map +1 -1
- package/lib/typescript/module/src/components/field/ValueField.d.ts.map +1 -1
- package/lib/typescript/module/src/components/field/fieldText.d.ts +19 -0
- package/lib/typescript/module/src/components/field/fieldText.d.ts.map +1 -1
- package/lib/typescript/module/src/components/theme/styleKeys.d.ts.map +1 -1
- package/lib/typescript/module/src/components/types.d.ts +18 -5
- package/lib/typescript/module/src/components/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/DateTimePicker.tsx +79 -120
- package/src/components/calendar/DayCell.tsx +25 -6
- package/src/components/calendar/calendarStyles.ts +11 -0
- package/src/components/field/ValueField.tsx +30 -11
- package/src/components/field/fieldText.ts +48 -5
- package/src/components/theme/styleKeys.ts +3 -1
- package/src/components/types.ts +18 -5
|
@@ -119,27 +119,70 @@ export const formatMultipleText = (
|
|
|
119
119
|
)
|
|
120
120
|
.join(', ');
|
|
121
121
|
|
|
122
|
-
/** 'DD-MM-YYYY'
|
|
123
|
-
export const
|
|
122
|
+
/** { date: 'DD-MM-YYYY', time: 'hh:mm AM' } (time '' unless datetime), from the placeholder strings. */
|
|
123
|
+
export const placeholderParts = (
|
|
124
124
|
type: PickerType,
|
|
125
125
|
dateFormat: string,
|
|
126
126
|
timeFormat: TimeFormat,
|
|
127
127
|
strings: PickerStrings = DEFAULT_STRINGS
|
|
128
|
-
): string => {
|
|
128
|
+
): { date: string; time: string } => {
|
|
129
129
|
const parts: Record<string, string> = {
|
|
130
130
|
dd: strings.placeholderDay,
|
|
131
131
|
MM: strings.placeholderMonth,
|
|
132
132
|
yyyy: strings.placeholderYear,
|
|
133
133
|
};
|
|
134
134
|
const date = dateFormat.replace(/yyyy|MM|dd/g, (t) => parts[t] ?? t);
|
|
135
|
-
if (type !== 'datetime') return date;
|
|
135
|
+
if (type !== 'datetime') return { date, time: '' };
|
|
136
136
|
const time =
|
|
137
137
|
timeFormat === '24h'
|
|
138
138
|
? `${strings.placeholderHour24}:${strings.placeholderMinute}`
|
|
139
139
|
: `${strings.placeholderHour}:${strings.placeholderMinute} ${strings.am}`;
|
|
140
|
-
return
|
|
140
|
+
return { date, time };
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
/** 'DD-MM-YYYY' or 'DD-MM-YYYY hh:mm AM', from the placeholder strings. */
|
|
144
|
+
export const placeholderText = (
|
|
145
|
+
type: PickerType,
|
|
146
|
+
dateFormat: string,
|
|
147
|
+
timeFormat: TimeFormat,
|
|
148
|
+
strings: PickerStrings = DEFAULT_STRINGS
|
|
149
|
+
): string => {
|
|
150
|
+
const { date, time } = placeholderParts(
|
|
151
|
+
type,
|
|
152
|
+
dateFormat,
|
|
153
|
+
timeFormat,
|
|
154
|
+
strings
|
|
155
|
+
);
|
|
156
|
+
return time ? `${date}${strings.dateTimeSeparator ?? ' '}${time}` : date;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A placeholder passed in, cut at the first date-time separator into the
|
|
161
|
+
* date and the time ('DD/MM/YYYY HH:MM' -> 'DD/MM/YYYY', 'HH:MM'). Text
|
|
162
|
+
* whose second part isn't a time (no ':'), like 'Pick a time', stays whole.
|
|
163
|
+
*/
|
|
164
|
+
export const splitPlaceholder = (
|
|
165
|
+
text: string,
|
|
166
|
+
separator: string
|
|
167
|
+
): { date: string; time: string } => {
|
|
168
|
+
const at = separator ? text.indexOf(separator) : -1;
|
|
169
|
+
const time = at > 0 ? text.slice(at + separator.length) : '';
|
|
170
|
+
if (!time.includes(':')) return { date: text, time: '' };
|
|
171
|
+
return { date: text.slice(0, at), time };
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** The empty field's placeholder (the one passed in, else the built one) as date and time. */
|
|
175
|
+
export const emptyFieldParts = (
|
|
176
|
+
placeholder: string | undefined,
|
|
177
|
+
type: PickerType,
|
|
178
|
+
dateFormat: string,
|
|
179
|
+
timeFormat: TimeFormat,
|
|
180
|
+
strings: PickerStrings = DEFAULT_STRINGS
|
|
181
|
+
): { date: string; time: string } =>
|
|
182
|
+
placeholder
|
|
183
|
+
? splitPlaceholder(placeholder, strings.dateTimeSeparator ?? ' ')
|
|
184
|
+
: placeholderParts(type, dateFormat, timeFormat, strings);
|
|
185
|
+
|
|
143
186
|
const TIME_KEYS = ['hour', 'minute', 'period'];
|
|
144
187
|
|
|
145
188
|
/** The message shown below the field for the first typed-input problem. */
|
|
@@ -27,7 +27,9 @@ export const STYLE_KEYS = [
|
|
|
27
27
|
'fieldTextDisabled',
|
|
28
28
|
/**
|
|
29
29
|
* Sets the date of a single date-time value apart from its time, e.g.
|
|
30
|
-
* `{ minWidth: '50%' }` starts the time at the middle of the field.
|
|
30
|
+
* `{ minWidth: '50%' }` starts the time at the middle of the field. The empty
|
|
31
|
+
* field's placeholder does the same: a passed `placeholder` is cut at the
|
|
32
|
+
* first `strings.dateTimeSeparator` when what follows is a time ('HH:MM').
|
|
31
33
|
*/
|
|
32
34
|
'fieldDateText',
|
|
33
35
|
'fieldPlaceholder',
|
package/src/components/types.ts
CHANGED
|
@@ -131,6 +131,13 @@ export interface SheetOptions {
|
|
|
131
131
|
fieldPlaceholder?: string;
|
|
132
132
|
/** The calendar icon at the end of that field, as on the on-screen field. Default false. */
|
|
133
133
|
fieldIcon?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* "This date isn't available" above the calendar while the picked date (or a
|
|
136
|
+
* range's end) is a disabled day, e.g. a saved value the rules no longer
|
|
137
|
+
* allow. false hides it; Confirm stays off for that day. Default true;
|
|
138
|
+
* applies inline too.
|
|
139
|
+
*/
|
|
140
|
+
showNotAllowedError?: boolean;
|
|
134
141
|
/**
|
|
135
142
|
* Passed to the sheet body's ScrollView, over the picker's own defaults, e.g.
|
|
136
143
|
* `{ showsVerticalScrollIndicator: true, persistentScrollbar: true }` to keep
|
|
@@ -156,7 +163,8 @@ export type SheetScrollProps = Omit<
|
|
|
156
163
|
|
|
157
164
|
/**
|
|
158
165
|
* The second argument of `onChange` when the picker can show a Hijri calendar:
|
|
159
|
-
* the calendar the date was picked in
|
|
166
|
+
* the calendar the date was picked in, which is the tab on screen when it was
|
|
167
|
+
* saved. The value itself is always Gregorian.
|
|
160
168
|
* The picker remembers it while mounted; to show a stored value back the same
|
|
161
169
|
* way later, store this too and pass it as `dualDefaultTab` (dual) or
|
|
162
170
|
* `calendarSystem`.
|
|
@@ -365,9 +373,9 @@ export interface DateTimePickerProps {
|
|
|
365
373
|
showToday?: boolean;
|
|
366
374
|
/**
|
|
367
375
|
* The calendar the grid uses: 'gregory', 'hijri' (Umm al-Qura), or 'dual':
|
|
368
|
-
* Gregorian and Hijri tabs, one calendar at a time. A
|
|
369
|
-
*
|
|
370
|
-
* calendar. With `calendarSwitch`, this is the one shown first. Default
|
|
376
|
+
* Gregorian and Hijri tabs, one calendar at a time. A selection shows in
|
|
377
|
+
* both tabs and is saved with the tab on screen, and the field writes it in
|
|
378
|
+
* that calendar. With `calendarSwitch`, this is the one shown first. Default
|
|
371
379
|
* 'gregory'; anything Hijri falls back to 'gregory' when the platform has no
|
|
372
380
|
* Hijri calendar.
|
|
373
381
|
*/
|
|
@@ -386,7 +394,12 @@ export interface DateTimePickerProps {
|
|
|
386
394
|
* readers say. Default 'ar-SA' (Arabic).
|
|
387
395
|
*/
|
|
388
396
|
hijriLocale?: string;
|
|
389
|
-
/**
|
|
397
|
+
/**
|
|
398
|
+
* The tab a dual calendar opens on when it has no value. With a value, it
|
|
399
|
+
* opens on the tab that value was saved with (remembered while the picker is
|
|
400
|
+
* mounted; a value from outside counts as saved with this tab). Default
|
|
401
|
+
* 'gregory'.
|
|
402
|
+
*/
|
|
390
403
|
dualDefaultTab?: 'gregory' | 'hijri';
|
|
391
404
|
/**
|
|
392
405
|
* How the on-screen field writes the saved value. 'picked' (default): in the
|