@react-stately/datepicker 3.0.0-rc.1 → 3.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/dist/module.js CHANGED
@@ -2,6 +2,7 @@ import {toCalendarDate as $7UzoM$toCalendarDate, toCalendarDateTime as $7UzoM$to
2
2
  import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
3
3
  import {useOverlayTriggerState as $7UzoM$useOverlayTriggerState} from "@react-stately/overlays";
4
4
  import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
5
+ import {MessageDictionary as $7UzoM$MessageDictionary} from "@internationalized/message";
5
6
 
6
7
 
7
8
 
@@ -155,6 +156,396 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
155
156
 
156
157
 
157
158
 
159
+ // These placeholders are based on the strings used by the <input type="date">
160
+ // implementations in Chrome and Firefox. Additional languages are supported
161
+ // here than React Spectrum's typical translations.
162
+ const $3e3ed55ab2966714$var$placeholders = new $7UzoM$MessageDictionary({
163
+ ach: {
164
+ year: 'mwaka',
165
+ month: 'dwe',
166
+ day: 'nino'
167
+ },
168
+ af: {
169
+ year: 'jjjj',
170
+ month: 'mm',
171
+ day: 'dd'
172
+ },
173
+ am: {
174
+ year: 'ዓዓዓዓ',
175
+ month: 'ሚሜ',
176
+ day: 'ቀቀ'
177
+ },
178
+ an: {
179
+ year: 'aaaa',
180
+ month: 'mm',
181
+ day: 'dd'
182
+ },
183
+ ar: {
184
+ year: 'سنة',
185
+ month: 'شهر',
186
+ day: 'يوم'
187
+ },
188
+ ast: {
189
+ year: 'aaaa',
190
+ month: 'mm',
191
+ day: 'dd'
192
+ },
193
+ az: {
194
+ year: 'iiii',
195
+ month: 'aa',
196
+ day: 'gg'
197
+ },
198
+ be: {
199
+ year: 'гггг',
200
+ month: 'мм',
201
+ day: 'дд'
202
+ },
203
+ bg: {
204
+ year: 'гггг',
205
+ month: 'мм',
206
+ day: 'дд'
207
+ },
208
+ bn: {
209
+ year: 'yyyy',
210
+ month: 'মিমি',
211
+ day: 'dd'
212
+ },
213
+ br: {
214
+ year: 'bbbb',
215
+ month: 'mm',
216
+ day: 'dd'
217
+ },
218
+ bs: {
219
+ year: 'gggg',
220
+ month: 'mm',
221
+ day: 'dd'
222
+ },
223
+ ca: {
224
+ year: 'aaaa',
225
+ month: 'mm',
226
+ day: 'dd'
227
+ },
228
+ cak: {
229
+ year: 'jjjj',
230
+ month: 'ii',
231
+ day: "q'q'"
232
+ },
233
+ ckb: {
234
+ year: 'ساڵ',
235
+ month: 'مانگ',
236
+ day: 'ڕۆژ'
237
+ },
238
+ cs: {
239
+ year: 'rrrr',
240
+ month: 'mm',
241
+ day: 'dd'
242
+ },
243
+ cy: {
244
+ year: 'bbbb',
245
+ month: 'mm',
246
+ day: 'dd'
247
+ },
248
+ da: {
249
+ year: 'åååå',
250
+ month: 'mm',
251
+ day: 'dd'
252
+ },
253
+ de: {
254
+ year: 'jjjj',
255
+ month: 'mm',
256
+ day: 'tt'
257
+ },
258
+ dsb: {
259
+ year: 'llll',
260
+ month: 'mm',
261
+ day: 'źź'
262
+ },
263
+ el: {
264
+ year: 'εεεε',
265
+ month: 'μμ',
266
+ day: 'ηη'
267
+ },
268
+ en: {
269
+ year: 'yyyy',
270
+ month: 'mm',
271
+ day: 'dd'
272
+ },
273
+ eo: {
274
+ year: 'jjjj',
275
+ month: 'mm',
276
+ day: 'tt'
277
+ },
278
+ es: {
279
+ year: 'aaaa',
280
+ month: 'mm',
281
+ day: 'dd'
282
+ },
283
+ et: {
284
+ year: 'aaaa',
285
+ month: 'kk',
286
+ day: 'pp'
287
+ },
288
+ eu: {
289
+ year: 'uuuu',
290
+ month: 'hh',
291
+ day: 'ee'
292
+ },
293
+ fa: {
294
+ year: 'سال',
295
+ month: 'ماه',
296
+ day: 'روز'
297
+ },
298
+ ff: {
299
+ year: 'hhhh',
300
+ month: 'll',
301
+ day: 'ññ'
302
+ },
303
+ fi: {
304
+ year: 'vvvv',
305
+ month: 'kk',
306
+ day: 'pp'
307
+ },
308
+ fr: {
309
+ year: 'aaaa',
310
+ month: 'mm',
311
+ day: 'jj'
312
+ },
313
+ fy: {
314
+ year: 'jjjj',
315
+ month: 'mm',
316
+ day: 'dd'
317
+ },
318
+ ga: {
319
+ year: 'bbbb',
320
+ month: 'mm',
321
+ day: 'll'
322
+ },
323
+ gd: {
324
+ year: 'bbbb',
325
+ month: 'mm',
326
+ day: 'll'
327
+ },
328
+ gl: {
329
+ year: 'aaaa',
330
+ month: 'mm',
331
+ day: 'dd'
332
+ },
333
+ he: {
334
+ year: 'שנה',
335
+ month: 'חודש',
336
+ day: 'יום'
337
+ },
338
+ hr: {
339
+ year: 'gggg',
340
+ month: 'mm',
341
+ day: 'dd'
342
+ },
343
+ hsb: {
344
+ year: 'llll',
345
+ month: 'mm',
346
+ day: 'dd'
347
+ },
348
+ hu: {
349
+ year: 'éééé',
350
+ month: 'hh',
351
+ day: 'nn'
352
+ },
353
+ ia: {
354
+ year: 'aaaa',
355
+ month: 'mm',
356
+ day: 'dd'
357
+ },
358
+ id: {
359
+ year: 'tttt',
360
+ month: 'bb',
361
+ day: 'hh'
362
+ },
363
+ it: {
364
+ year: 'aaaa',
365
+ month: 'mm',
366
+ day: 'gg'
367
+ },
368
+ ja: {
369
+ year: ' 年 ',
370
+ month: '月',
371
+ day: '日'
372
+ },
373
+ ka: {
374
+ year: 'წწწწ',
375
+ month: 'თთ',
376
+ day: 'რრ'
377
+ },
378
+ kk: {
379
+ year: 'жжжж',
380
+ month: 'аа',
381
+ day: 'кк'
382
+ },
383
+ kn: {
384
+ year: 'ವವವವ',
385
+ month: 'ಮಿಮೀ',
386
+ day: 'ದಿದಿ'
387
+ },
388
+ ko: {
389
+ year: '연도',
390
+ month: '월',
391
+ day: '일'
392
+ },
393
+ lb: {
394
+ year: 'jjjj',
395
+ month: 'mm',
396
+ day: 'dd'
397
+ },
398
+ lo: {
399
+ year: 'ປປປປ',
400
+ month: 'ດດ',
401
+ day: 'ວວ'
402
+ },
403
+ lt: {
404
+ year: 'mmmm',
405
+ month: 'mm',
406
+ day: 'dd'
407
+ },
408
+ lv: {
409
+ year: 'gggg',
410
+ month: 'mm',
411
+ day: 'dd'
412
+ },
413
+ meh: {
414
+ year: 'aaaa',
415
+ month: 'mm',
416
+ day: 'dd'
417
+ },
418
+ ml: {
419
+ year: 'വർഷം',
420
+ month: 'മാസം',
421
+ day: 'തീയതി'
422
+ },
423
+ ms: {
424
+ year: 'tttt',
425
+ month: 'mm',
426
+ day: 'hh'
427
+ },
428
+ nl: {
429
+ year: 'jjjj',
430
+ month: 'mm',
431
+ day: 'dd'
432
+ },
433
+ nn: {
434
+ year: 'åååå',
435
+ month: 'mm',
436
+ day: 'dd'
437
+ },
438
+ no: {
439
+ year: 'åååå',
440
+ month: 'mm',
441
+ day: 'dd'
442
+ },
443
+ oc: {
444
+ year: 'aaaa',
445
+ month: 'mm',
446
+ day: 'jj'
447
+ },
448
+ pl: {
449
+ year: 'rrrr',
450
+ month: 'mm',
451
+ day: 'dd'
452
+ },
453
+ pt: {
454
+ year: 'aaaa',
455
+ month: 'mm',
456
+ day: 'dd'
457
+ },
458
+ rm: {
459
+ year: 'oooo',
460
+ month: 'mm',
461
+ day: 'dd'
462
+ },
463
+ ro: {
464
+ year: 'aaaa',
465
+ month: 'll',
466
+ day: 'zz'
467
+ },
468
+ ru: {
469
+ year: 'гггг',
470
+ month: 'мм',
471
+ day: 'дд'
472
+ },
473
+ sc: {
474
+ year: 'aaaa',
475
+ month: 'mm',
476
+ day: 'dd'
477
+ },
478
+ scn: {
479
+ year: 'aaaa',
480
+ month: 'mm',
481
+ day: 'jj'
482
+ },
483
+ sk: {
484
+ year: 'rrrr',
485
+ month: 'mm',
486
+ day: 'dd'
487
+ },
488
+ sl: {
489
+ year: 'llll',
490
+ month: 'mm',
491
+ day: 'dd'
492
+ },
493
+ sr: {
494
+ year: 'гггг',
495
+ month: 'мм',
496
+ day: 'дд'
497
+ },
498
+ sv: {
499
+ year: 'åååå',
500
+ month: 'mm',
501
+ day: 'dd'
502
+ },
503
+ szl: {
504
+ year: 'rrrr',
505
+ month: 'mm',
506
+ day: 'dd'
507
+ },
508
+ tg: {
509
+ year: 'сссс',
510
+ month: 'мм',
511
+ day: 'рр'
512
+ },
513
+ th: {
514
+ year: 'ปปปป',
515
+ month: 'ดด',
516
+ day: 'วว'
517
+ },
518
+ tr: {
519
+ year: 'yyyy',
520
+ month: 'aa',
521
+ day: 'gg'
522
+ },
523
+ uk: {
524
+ year: 'рррр',
525
+ month: 'мм',
526
+ day: 'дд'
527
+ },
528
+ 'zh-CN': {
529
+ year: '年',
530
+ month: '月',
531
+ day: '日'
532
+ },
533
+ 'zh-TW': {
534
+ year: '年',
535
+ month: '月',
536
+ day: '日'
537
+ }
538
+ }, 'en');
539
+ function $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(field, value, locale) {
540
+ // Use the actual placeholder value for the era and day period fields.
541
+ if (field === 'era' || field === 'dayPeriod') return value;
542
+ if (field === 'year' || field === 'month' || field === 'day') return $3e3ed55ab2966714$var$placeholders.getStringForLocale(field, locale);
543
+ // For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
544
+ return '––';
545
+ }
546
+
547
+
548
+
158
549
 
159
550
  const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
160
551
  year: true,
@@ -301,11 +692,14 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
301
692
  let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
302
693
  let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
303
694
  if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
695
+ let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
696
+ let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(segment.type, segment.value, locale) : null;
304
697
  return {
305
698
  type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
306
- text: segment.value,
699
+ text: isPlaceholder ? placeholder : segment.value,
307
700
  ...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
308
- isPlaceholder: $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
701
+ isPlaceholder: isPlaceholder,
702
+ placeholder: placeholder,
309
703
  isEditable: isEditable
310
704
  };
311
705
  })
@@ -315,29 +709,41 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
315
709
  dateFormatter,
316
710
  resolvedOptions,
317
711
  displayValue,
318
- calendar
319
- ]);
320
- let hasEra = $7UzoM$useMemo(()=>segments.some((s)=>s.type === 'era'
321
- )
322
- , [
323
- segments
712
+ calendar,
713
+ locale
324
714
  ]);
715
+ // When the era field appears, mark it valid if the year field is already valid.
716
+ // If the era field disappears, remove it from the valid segments.
717
+ if (allSegments.era && validSegments.year && !validSegments.era) {
718
+ validSegments.era = true;
719
+ setValidSegments({
720
+ ...validSegments
721
+ });
722
+ } else if (!allSegments.era && validSegments.era) {
723
+ delete validSegments.era;
724
+ setValidSegments({
725
+ ...validSegments
726
+ });
727
+ }
325
728
  let markValid = (part)=>{
326
729
  validSegments[part] = true;
327
- if (part === 'year' && hasEra) validSegments.era = true;
730
+ if (part === 'year' && allSegments.era) validSegments.era = true;
328
731
  setValidSegments({
329
732
  ...validSegments
330
733
  });
331
734
  };
332
735
  let adjustSegment = (type, amount)=>{
333
- markValid(type);
334
- setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
736
+ if (!validSegments[type]) {
737
+ markValid(type);
738
+ if (Object.keys(validSegments).length >= Object.keys(allSegments).length) setValue(displayValue);
739
+ } else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
335
740
  };
336
741
  let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
337
742
  var _maxGranularity1;
338
743
  return {
339
744
  value: calendarValue,
340
745
  dateValue: dateValue,
746
+ calendar: calendar,
341
747
  setValue: setValue,
342
748
  segments: segments,
343
749
  dateFormatter: dateFormatter,
@@ -363,20 +769,16 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
363
769
  markValid(part);
364
770
  setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
365
771
  },
366
- confirmPlaceholder (part) {
772
+ confirmPlaceholder () {
367
773
  if (props.isDisabled || props.isReadOnly) return;
368
- if (!part) {
369
- // Confirm the rest of the placeholder if any of the segments are valid.
370
- let numValid = Object.keys(validSegments).length;
371
- if (numValid > 0 && numValid < Object.keys(allSegments).length) {
372
- validSegments = {
373
- ...allSegments
374
- };
375
- setValidSegments(validSegments);
376
- setValue(displayValue.copy());
377
- }
378
- } else if (!validSegments[part]) {
379
- markValid(part);
774
+ // Confirm the placeholder if only the day period is not filled in.
775
+ let validKeys = Object.keys(validSegments);
776
+ let allKeys = Object.keys(allSegments);
777
+ if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
778
+ validSegments = {
779
+ ...allSegments
780
+ };
781
+ setValidSegments(validSegments);
380
782
  setValue(displayValue.copy());
381
783
  }
382
784
  },
@@ -511,6 +913,7 @@ function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
511
913
  case 'day':
512
914
  case 'month':
513
915
  case 'year':
916
+ case 'era':
514
917
  return value.set({
515
918
  [part]: segmentValue
516
919
  });
@@ -567,16 +970,13 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
567
970
  setPlaceholderValue(placeholderValue);
568
971
  }
569
972
  let value1 = controlledValue || placeholderValue;
570
- let valueRef = $7UzoM$useRef(value1);
571
- valueRef.current = value1;
572
973
  let setValue = (value)=>{
573
- valueRef.current = value;
574
974
  setPlaceholderValue(value);
575
975
  if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
576
976
  else setControlledValue(null);
577
977
  };
578
978
  let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
579
- let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
979
+ let [granularity] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
580
980
  let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
581
981
  var _shouldCloseOnSelect;
582
982
  let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
@@ -708,19 +1108,6 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
708
1108
  start: startFormatter.format(startDate),
709
1109
  end: endFormatter.format(endDate)
710
1110
  };
711
- },
712
- confirmPlaceholder () {
713
- // Need to use ref value here because the value can be set in the same tick as
714
- // a blur, which means the component won't have re-rendered yet.
715
- let value = valueRef.current;
716
- if (value && Boolean(value.start) !== Boolean(value.end)) {
717
- let calendar = (value.start || value.end).calendar;
718
- let placeholder = $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
719
- setValue({
720
- start: value.start || placeholder,
721
- end: value.end || placeholder
722
- });
723
- }
724
1111
  }
725
1112
  };
726
1113
  }