@astryxdesign/core 0.5.0-canary.f4d494c → 0.5.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.
Files changed (71) hide show
  1. package/dist/Avatar/Avatar.d.ts +1 -25
  2. package/dist/Avatar/Avatar.d.ts.map +1 -1
  3. package/dist/Avatar/Avatar.js +9 -43
  4. package/dist/Avatar/index.d.ts +2 -2
  5. package/dist/Avatar/index.d.ts.map +1 -1
  6. package/dist/Avatar/index.js +1 -1
  7. package/dist/AvatarGroup/AvatarGroup.d.ts +2 -9
  8. package/dist/AvatarGroup/AvatarGroup.d.ts.map +1 -1
  9. package/dist/AvatarGroup/AvatarGroup.js +2 -5
  10. package/dist/AvatarGroup/AvatarGroupContext.d.ts +1 -2
  11. package/dist/AvatarGroup/AvatarGroupContext.d.ts.map +1 -1
  12. package/dist/AvatarGroup/AvatarGroupOverflow.d.ts.map +1 -1
  13. package/dist/AvatarGroup/AvatarGroupOverflow.js +6 -10
  14. package/dist/DateInput/DateInput.d.ts +0 -43
  15. package/dist/DateInput/DateInput.d.ts.map +1 -1
  16. package/dist/DateInput/DateInput.js +0 -19
  17. package/dist/DateInput/index.d.ts +1 -1
  18. package/dist/DateInput/index.d.ts.map +1 -1
  19. package/dist/HoverCard/HoverCard.d.ts.map +1 -1
  20. package/dist/HoverCard/HoverCard.js +3 -52
  21. package/dist/HoverCard/useHoverCard.d.ts +2 -11
  22. package/dist/HoverCard/useHoverCard.d.ts.map +1 -1
  23. package/dist/HoverCard/useHoverCard.js +0 -2
  24. package/dist/Indicator/CheckboxIndicator.d.ts.map +1 -1
  25. package/dist/Indicator/CheckboxIndicator.js +2 -6
  26. package/dist/Kbd/Kbd.d.ts.map +1 -1
  27. package/dist/Kbd/Kbd.js +26 -2
  28. package/dist/astryx.css +0 -21
  29. package/dist/hooks/useHotkeys.d.ts.map +1 -1
  30. package/dist/hooks/useHotkeys.js +25 -3
  31. package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
  32. package/dist/theme/derivedVarRegistry.js +0 -4
  33. package/dist/theme/syntax/tokens.d.ts +1 -1
  34. package/dist/theme/syntax/tokens.d.ts.map +1 -1
  35. package/dist/theme/syntax/tokens.js +2 -5
  36. package/package.json +3 -3
  37. package/src/Avatar/Avatar.doc.mjs +2 -12
  38. package/src/Avatar/Avatar.test.tsx +0 -80
  39. package/src/Avatar/Avatar.tsx +14 -64
  40. package/src/Avatar/index.ts +2 -2
  41. package/src/AvatarGroup/AvatarGroup.doc.mjs +2 -8
  42. package/src/AvatarGroup/AvatarGroup.test.tsx +0 -24
  43. package/src/AvatarGroup/AvatarGroup.tsx +4 -12
  44. package/src/AvatarGroup/AvatarGroupContext.ts +3 -5
  45. package/src/AvatarGroup/AvatarGroupOverflow.tsx +4 -10
  46. package/src/DateInput/DateInput.doc.mjs +0 -16
  47. package/src/DateInput/DateInput.tsx +0 -52
  48. package/src/DateInput/DateInputTouch.test.tsx +9 -32
  49. package/src/DateInput/index.ts +0 -1
  50. package/src/HoverCard/HoverCard.test.tsx +4 -84
  51. package/src/HoverCard/HoverCard.tsx +3 -65
  52. package/src/HoverCard/useHoverCard.tsx +2 -15
  53. package/src/Indicator/CheckboxIndicator.tsx +8 -14
  54. package/src/Indicator/Indicator.doc.mjs +0 -2
  55. package/src/Kbd/Kbd.test.tsx +17 -0
  56. package/src/Kbd/Kbd.tsx +26 -2
  57. package/src/hooks/useHotkeys.test.ts +18 -0
  58. package/src/hooks/useHotkeys.ts +25 -3
  59. package/src/theme/derivedVarRegistry.test.ts +0 -1
  60. package/src/theme/derivedVarRegistry.ts +0 -1
  61. package/src/theme/syntax/tokens.ts +2 -5
  62. package/dist/DateInput/NativeDateField.d.ts +0 -10
  63. package/dist/DateInput/NativeDateField.d.ts.map +0 -1
  64. package/dist/DateInput/NativeDateField.js +0 -477
  65. package/dist/utils/isApplePlatform.d.ts +0 -18
  66. package/dist/utils/isApplePlatform.d.ts.map +0 -1
  67. package/dist/utils/isApplePlatform.js +0 -37
  68. package/src/DateInput/NativeDateField.test.tsx +0 -565
  69. package/src/DateInput/NativeDateField.tsx +0 -623
  70. package/src/utils/isApplePlatform.test.ts +0 -61
  71. package/src/utils/isApplePlatform.ts +0 -37
@@ -1,623 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- 'use client';
4
-
5
- /**
6
- * @file NativeDateField.tsx
7
- * @input Uses React, Field, Icon, InputClearButton, Spinner, useCalendarConstraints
8
- * @output Exports NativeDateField — the OS-picker touch surface
9
- * @position One of DateInput's three surfaces. `DateInput` picks the pointer
10
- * field on a mouse and, on touch, either `TouchDateField` (the default) or
11
- * this one when the consumer opts in with `nativePicker`.
12
- *
13
- * Hands date picking to the platform: a real `<input type="date">`, whose
14
- * picker the OS draws — the iOS wheel, the Android calendar dialog. The field
15
- * itself still looks like every other Astryx input, and DateInput paints its
16
- * text so `format` and `placeholder` keep applying.
17
- *
18
- * Everything unusual in here was measured on a real iOS device; the comments
19
- * say which behaviour forced which decision, because none of them are
20
- * reproducible in a desktop browser.
21
- *
22
- * SYNC: When modified, update these files to stay in sync:
23
- * - /packages/core/src/DateInput/DateInput.tsx (the `nativePicker` prop)
24
- * - /packages/core/src/DateInput/DateInput.doc.mjs (prop table)
25
- * - /packages/core/src/DateInput/DateInputNative.test.tsx (tests)
26
- */
27
-
28
- import {useCallback, useEffect, useId, useRef, useState} from 'react';
29
- import * as stylex from '@stylexjs/stylex';
30
- import {useCalendarConstraints} from '../Calendar';
31
- import type {DateInputProps} from './DateInput';
32
- import {
33
- Field,
34
- InputClearButton,
35
- inputStatusBorderStyles,
36
- inputStatusFocusWithinStyles,
37
- inputStatusHoverShadowStyles,
38
- inputWrapperStyles,
39
- } from '../Field';
40
- import {useInputStatusIcon, useMergedRefs} from '../hooks';
41
- import {useResolvedRequired} from '../hooks/useResolvedRequired';
42
- import {Icon} from '../Icon';
43
- import {useLocale, useTranslator} from '../i18n';
44
- import {useInputGroup} from '../InputGroup';
45
- import {groupStyles} from '../InputGroup/groupStyles';
46
- import {stableClassName} from '../naming';
47
- import {useSize} from '../SizeContext';
48
- import {Spinner} from '../Spinner';
49
- import {
50
- colorVars,
51
- radiusVars,
52
- sizeVars,
53
- typeScaleVars,
54
- typographyVars,
55
- } from '../theme/tokens.stylex';
56
- import {useTooltip} from '../Tooltip';
57
- import {VisuallyHidden} from '../VisuallyHidden';
58
- import {
59
- focusOutlineStyles,
60
- formatSharedDate,
61
- getInputARIA,
62
- mergeProps,
63
- parseDateInput,
64
- plainDateFromISO,
65
- plainDateToISO,
66
- themeProps,
67
- type ISODateString,
68
- } from '../utils';
69
-
70
- const styles = stylex.create({
71
- wrapper: {
72
- gap: 8,
73
- },
74
- iconButton: {
75
- display: 'flex',
76
- alignItems: 'center',
77
- justifyContent: 'center',
78
- padding: 0,
79
- margin: 0,
80
- borderWidth: 0,
81
- borderStyle: 'none',
82
- backgroundColor: 'transparent',
83
- cursor: {
84
- default: 'pointer',
85
- ':is(:disabled,[aria-disabled="true"])': 'default',
86
- },
87
- borderRadius: radiusVars['--radius-element'],
88
- },
89
- iconButtonDisabled: {
90
- cursor: 'default',
91
- },
92
- input: {
93
- display: 'block',
94
- flex: 1,
95
- minWidth: 0,
96
- borderWidth: 0,
97
- borderStyle: 'none',
98
- padding: 0,
99
- fontFamily: typographyVars['--font-family-body'],
100
- // Below 16px iOS zooms the page when the field takes focus.
101
- fontSize: {
102
- default: typeScaleVars['--text-body-size'],
103
- '@media (pointer: coarse)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
104
- },
105
- lineHeight: typeScaleVars['--text-body-leading'],
106
- color: colorVars['--color-text-primary'],
107
- backgroundColor: 'transparent',
108
- outline: 'none',
109
- // A date control's intrinsic height comes from its inner edit fields, not
110
- // from `line-height`, so it renders ~2px taller than a text input and its
111
- // value sits off the shared baseline inside the same flex row. One line
112
- // box is exactly what the text field occupies.
113
- height: stylex.firstThatWorks(
114
- '1lh',
115
- `calc(max(1rem, ${typeScaleVars['--text-body-size']}) * ${typeScaleVars['--text-body-leading']})`,
116
- ),
117
- // iOS gives date controls their own button-like chrome, with inner
118
- // spacing and a centred value that no reset of ours can reach.
119
- WebkitAppearance: 'none',
120
- appearance: 'none',
121
- // Chromium paints a second calendar glyph inside the field; this surface
122
- // already ships a toggle button, so drop the duplicate.
123
- '::-webkit-calendar-picker-indicator': {
124
- display: 'none',
125
- },
126
- '::-webkit-date-and-time-value': {
127
- textAlign: 'start',
128
- marginBlock: 0,
129
- marginInline: 0,
130
- paddingBlock: 0,
131
- paddingInline: 0,
132
- lineHeight: 'inherit',
133
- minHeight: 0,
134
- },
135
- '::-webkit-datetime-edit': {
136
- paddingBlock: 0,
137
- paddingInline: 0,
138
- lineHeight: 'inherit',
139
- },
140
- },
141
- inputDisabled: {
142
- cursor: 'default',
143
- },
144
- inputInvalid: {
145
- color: colorVars['--color-text-secondary'],
146
- },
147
- // Hides whatever the engine paints inside the control so this field's own
148
- // text can take that space. WebKit renders the value into a single
149
- // `::-webkit-date-and-time-value` run which the UA stylesheet gives no
150
- // colour of its own (the iOS UA colour sits on the INPUT), so it inherits
151
- // this; Chromium's `::-webkit-datetime-edit` fields inherit it too.
152
- // `-webkit-text-fill-color` is what actually wins inside a WebKit date
153
- // control.
154
- inputTextHidden: {
155
- color: 'transparent',
156
- WebkitTextFillColor: 'transparent',
157
- },
158
- // Positioning context for the overlay, standing in for the input's own box
159
- // in the field's flex row.
160
- slot: {
161
- position: 'relative',
162
- display: 'flex',
163
- alignItems: 'center',
164
- flex: 1,
165
- minWidth: 0,
166
- },
167
- // This field's own text, laid over the control. Decorative: the input still
168
- // holds the value and keeps its label, description, and status wiring, so
169
- // announcing this too would just double-speak.
170
- overlay: {
171
- position: 'absolute',
172
- insetInlineStart: 0,
173
- // Both insets, so the overlay is bounded by the slot rather than
174
- // shrink-to-fit. Without the end inset a long formatted date paints past
175
- // the slot and over whatever follows it in the field — measured running
176
- // 24px across the clear button.
177
- insetInlineEnd: 0,
178
- insetBlock: 0,
179
- // A BLOCK box, not a flex one: `text-overflow` only applies to a block
180
- // container, so on a flex container a too-long date hard-clips mid-glyph
181
- // instead of ellipsising (measured identical to `text-overflow: clip` in
182
- // both WebKit and Chromium). Centring then comes from the line box, so
183
- // the overlay carries the same font size and leading as the input it
184
- // covers — one line of that leading fills its height exactly, which puts
185
- // the glyphs on the input's own baseline.
186
- display: 'block',
187
- fontSize: {
188
- default: typeScaleVars['--text-body-size'],
189
- '@media (pointer: coarse)': `max(1rem, ${typeScaleVars['--text-body-size']})`,
190
- },
191
- lineHeight: typeScaleVars['--text-body-leading'],
192
- // A tap has to reach the control underneath — that is what raises the
193
- // picker.
194
- pointerEvents: 'none',
195
- overflow: 'hidden',
196
- whiteSpace: 'nowrap',
197
- textOverflow: 'ellipsis',
198
- },
199
- overlayValue: {
200
- color: colorVars['--color-text-primary'],
201
- },
202
- overlayPlaceholder: {
203
- color: colorVars['--color-text-secondary'],
204
- },
205
- });
206
-
207
- const sizeStyles = stylex.create({
208
- sm: {height: sizeVars['--size-element-sm'], minWidth: 180},
209
- md: {height: sizeVars['--size-element-md'], minWidth: 180},
210
- lg: {height: sizeVars['--size-element-lg'], minWidth: 180},
211
- });
212
-
213
- const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
214
-
215
- /**
216
- * The OS-picker surface. Takes `DateInput`'s props verbatim; see
217
- * {@link DateInput} for when it is chosen over the other two.
218
- */
219
- export function NativeDateField({
220
- label,
221
- isLabelHidden = false,
222
- description,
223
- isOptional = false,
224
- isRequired = false,
225
- isDisabled = false,
226
- disabledMessage,
227
- value,
228
- onChange,
229
- isLoading = false,
230
- min,
231
- max,
232
- dateConstraints,
233
- placeholder: placeholderFromProps,
234
- size: sizeProp,
235
- status,
236
- statusVariant = 'attached',
237
- labelTooltip,
238
- hasClear = false,
239
- // The OS draws the picker, so neither reaches it: both describe a calendar
240
- // grid it does not have. Accepted (the prop types are shared) and ignored.
241
- numberOfMonths: _numberOfMonths,
242
- weekStartsOn: _weekStartsOn,
243
- format = 'date_long',
244
- width,
245
- xstyle,
246
- className,
247
- style,
248
- ref,
249
- ...rest
250
- }: DateInputProps) {
251
- const t = useTranslator();
252
- const locale = useLocale();
253
- const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
254
- const placeholder =
255
- placeholderFromProps ?? t('@astryx.dateInput.placeholder');
256
- const size = useSize(sizeProp, 'md');
257
-
258
- const id = useId();
259
- const inputLabelID = useId();
260
- const descriptionID = useId();
261
- const statusMessageID = useId();
262
- const inputRef = useRef<HTMLInputElement | null>(null);
263
- const mergedInputRef = useMergedRefs(ref, inputRef);
264
- const inputGroup = useInputGroup();
265
-
266
- const isEffectivelyDisabled = isDisabled || isLoading;
267
-
268
- // Disabled-reason tooltip, same contract as the other two surfaces: a
269
- // disabled control swallows pointer events, so the listeners attach to the
270
- // wrapper and the input stays focusable via aria-disabled.
271
- const showsDisabledMessage = isDisabled && !!disabledMessage;
272
- const disabledMessageTooltip = useTooltip({
273
- placement: 'above',
274
- focusTrigger: 'always',
275
- isEnabled: showsDisabledMessage,
276
- });
277
-
278
- const {isDateDisabled} = useCalendarConstraints({min, max, dateConstraints});
279
-
280
- const {statusIcon, describedBy: statusTooltipDescribedBy} =
281
- useInputStatusIcon({
282
- status,
283
- statusVariant,
284
- isInGroup: !!inputGroup,
285
- });
286
-
287
- const {ariaLabelledBy, ariaDescribedBy} = getInputARIA(
288
- inputLabelID,
289
- [
290
- description ? descriptionID : null,
291
- statusVariant !== 'tooltip' && status?.message ? statusMessageID : null,
292
- statusTooltipDescribedBy,
293
- showsDisabledMessage ? disabledMessageTooltip.describedBy : null,
294
- ],
295
- inputGroup,
296
- );
297
-
298
- // A date the picker produced that `dateConstraints` refuses, held so the
299
- // refusal can be announced instead of looking like a dead tap.
300
- const [rejectedValue, setRejectedValue] = useState<string | null>(null);
301
- // Whether the control has focus — which, on a touch device, means its
302
- // picker is open.
303
- const [isFocused, setIsFocused] = useState(false);
304
- // The raw value the control last reported and we acted on, so the same edit
305
- // arriving through both commit paths only fires one change.
306
- const lastCommitRef = useRef<string | null>(null);
307
-
308
- const prevValueRef = useRef(value);
309
- if (value !== prevValueRef.current) {
310
- prevValueRef.current = value;
311
- lastCommitRef.current = null;
312
- if (rejectedValue !== null) {
313
- setRejectedValue(null);
314
- }
315
- }
316
-
317
- // The control's own value is always ISO — the only form it accepts, and
318
- // what the picker reads and writes. `format` rides on the overlay instead.
319
- const nativeValue = value && ISO_DATE.test(value) ? value : '';
320
- const isInputValid = rejectedValue === null;
321
-
322
- const formatValue = useCallback(
323
- (iso: ISODateString): string =>
324
- typeof format === 'function'
325
- ? format(iso)
326
- : formatSharedDate(plainDateFromISO(iso), format, locale),
327
- [format, locale],
328
- );
329
-
330
- // This field paints the closed control's text itself, which is what keeps
331
- // `format` and `placeholder` applying: the OS picker has no segments to
332
- // edit, so our text holds even while the picker is open, and tracks it live.
333
- const overlayText = nativeValue ? formatValue(nativeValue) : placeholder;
334
- const showsOverlay = !!overlayText;
335
-
336
- const commitValue = useCallback(
337
- (newValue: string) => {
338
- if (isEffectivelyDisabled) {
339
- return;
340
- }
341
- // The same edit can arrive twice — React's synthetic change and the
342
- // native listener below both report it — so act on a raw value once.
343
- if (lastCommitRef.current === newValue) {
344
- return;
345
- }
346
- lastCommitRef.current = newValue;
347
-
348
- if (!newValue) {
349
- setRejectedValue(null);
350
- if (value !== undefined) {
351
- onChange?.(undefined);
352
- }
353
- return;
354
- }
355
-
356
- const parsed = parseDateInput(newValue, locale);
357
- if (!parsed) {
358
- return;
359
- }
360
- if (isDateDisabled(parsed)) {
361
- // iOS does not enforce min/max in its picker — those attributes are
362
- // constraint-validation flags, not clamps, and the sheet lets the
363
- // user land on any date. Refuse it here and let the sync effect snap
364
- // the control back; the live region below announces the refusal.
365
- setRejectedValue(newValue);
366
- return;
367
- }
368
-
369
- setRejectedValue(null);
370
- const parsedISO = plainDateToISO(parsed);
371
- if (parsedISO !== value) {
372
- onChange?.(parsedISO);
373
- }
374
- },
375
- [value, onChange, isDateDisabled, isEffectivelyDisabled, locale],
376
- );
377
-
378
- const handleChange = useCallback(
379
- (e: React.ChangeEvent<HTMLInputElement>) => {
380
- commitValue(e.target.value);
381
- },
382
- [commitValue],
383
- );
384
-
385
- // React's synthetic change system does not reliably observe the iOS
386
- // picker's edits. Measured on an iPhone: picking a date fired a native
387
- // `input` event carrying the new date while React's `onChange` never ran —
388
- // so React re-rendered and wrote its own stale value straight back over the
389
- // picker's, and the user's pick (and their Reset) silently reverted. A
390
- // native listener reads what the control actually holds, whatever React's
391
- // synthetic layer made of it.
392
- const commitRef = useRef(commitValue);
393
- useEffect(() => {
394
- commitRef.current = commitValue;
395
- });
396
- useEffect(() => {
397
- const input = inputRef.current;
398
- if (!input) {
399
- return;
400
- }
401
- const handleNative = () => commitRef.current(input.value);
402
- input.addEventListener('input', handleNative);
403
- input.addEventListener('change', handleNative);
404
- return () => {
405
- input.removeEventListener('input', handleNative);
406
- input.removeEventListener('change', handleNative);
407
- };
408
- }, []);
409
-
410
- // The value the control mounts with. Deliberately captured once: React
411
- // writes to the element whenever a `value` OR `defaultValue` prop changes,
412
- // and on iOS ANY write while the picker sheet is open detaches the sheet
413
- // from the field — the wheel and Reset keep moving the sheet's own
414
- // highlight, but nothing they do reaches the input and no event fires, so
415
- // the user's pick appears to do nothing. Holding this constant means React
416
- // touches the element exactly once, at mount; the effect below owns every
417
- // later update and only writes while the field is unfocused.
418
- const initialValueRef = useRef<string | null>(null);
419
- if (initialValueRef.current === null) {
420
- initialValueRef.current = nativeValue;
421
- }
422
-
423
- // Push an externally-changed value in — but never while the control has
424
- // focus, for the reason above. Blur flips `isFocused`, so this doubles as
425
- // the reconcile once the picker closes. (Self-heals a stale
426
- // `initialValueRef` too, on the commit right after a remount.)
427
- useEffect(() => {
428
- if (isFocused) {
429
- return;
430
- }
431
- const input = inputRef.current;
432
- if (input && input.value !== nativeValue) {
433
- input.value = nativeValue;
434
- }
435
- }, [isFocused, nativeValue]);
436
-
437
- const handleBlur = useCallback(() => {
438
- const domValue = inputRef.current?.value;
439
- setIsFocused(false);
440
- // A refused date is reverted by the sync effect the moment focus leaves,
441
- // so the field is once again showing a date that IS valid. Keeping the
442
- // rejection past that point would mark good data invalid, with no way
443
- // back except changing the field again. The live region announced the
444
- // refusal while it happened; that is the feedback.
445
- setRejectedValue(null);
446
- if (domValue !== undefined && domValue !== nativeValue) {
447
- commitValue(domValue);
448
- }
449
- }, [commitValue, nativeValue]);
450
-
451
- // Focusing a date control is what raises the OS picker, so the usual
452
- // focus-restore after a clear would pop the picker the tap just dismissed —
453
- // and on iOS that reads as the clear having done nothing.
454
- const handleClear = useCallback(() => {
455
- onChange?.(undefined);
456
- }, [onChange]);
457
-
458
- const openPicker = useCallback(() => {
459
- if (isEffectivelyDisabled) {
460
- return;
461
- }
462
- const input = inputRef.current;
463
- if (!input) {
464
- return;
465
- }
466
- // Focus first: on touch browsers focusing the control is itself what
467
- // raises the picker, and iOS implements no `showPicker()` for type=date
468
- // (WebKit bug 261703), so focus is the whole mechanism there.
469
- input.focus();
470
- if (typeof input.showPicker === 'function') {
471
- try {
472
- input.showPicker();
473
- } catch {
474
- // showPicker throws without transient user activation and inside a
475
- // cross-origin iframe. The focus above is the fallback.
476
- }
477
- }
478
- }, [isEffectivelyDisabled]);
479
-
480
- const inputWrapper = (
481
- <div
482
- ref={el => {
483
- disabledMessageTooltip.ref(el);
484
- }}
485
- {...rest}
486
- {...mergeProps(
487
- themeProps('date-input', {
488
- size,
489
- status: status?.type ?? null,
490
- disabled: isDisabled ? 'disabled' : null,
491
- }),
492
- stylex.props(
493
- inputWrapperStyles.base,
494
- sizeStyles[size],
495
- styles.wrapper,
496
- isEffectivelyDisabled && inputWrapperStyles.disabled,
497
- status && inputStatusBorderStyles[status.type],
498
- status &&
499
- !isEffectivelyDisabled &&
500
- inputStatusHoverShadowStyles[status.type],
501
- status && inputStatusFocusWithinStyles[status.type],
502
- inputGroup && groupStyles.inGroup,
503
- xstyle,
504
- ),
505
- className,
506
- style,
507
- )}>
508
- {inputGroup && <VisuallyHidden id={inputLabelID}>{label}</VisuallyHidden>}
509
- <button
510
- type="button"
511
- onClick={openPicker}
512
- disabled={isEffectivelyDisabled}
513
- aria-label={t('@astryx.dateInput.openCalendar')}
514
- tabIndex={-1}
515
- {...stylex.props(
516
- focusOutlineStyles.focusVisible,
517
- styles.iconButton,
518
- isEffectivelyDisabled && styles.iconButtonDisabled,
519
- )}>
520
- <Icon
521
- icon="calendar"
522
- size="sm"
523
- color="secondary"
524
- {...themeProps('date-input-toggle-icon', {state: 'collapsed'})}
525
- />
526
- </button>
527
- <span {...stylex.props(styles.slot)}>
528
- <input
529
- ref={mergedInputRef}
530
- id={id}
531
- type="date"
532
- // UNCONTROLLED on purpose, with a value React never rewrites after
533
- // mount — see `initialValueRef` and the sync effect above.
534
- defaultValue={initialValueRef.current ?? ''}
535
- onChange={handleChange}
536
- onFocus={() => setIsFocused(true)}
537
- onBlur={handleBlur}
538
- min={min}
539
- max={max}
540
- disabled={isEffectivelyDisabled && !showsDisabledMessage}
541
- aria-disabled={showsDisabledMessage ? 'true' : undefined}
542
- readOnly={showsDisabledMessage || undefined}
543
- aria-labelledby={ariaLabelledBy}
544
- aria-describedby={ariaDescribedBy}
545
- aria-required={isEffectivelyRequired ? 'true' : undefined}
546
- aria-invalid={
547
- status?.type === 'error' || !isInputValid ? 'true' : undefined
548
- }
549
- aria-busy={isLoading || undefined}
550
- {...stylex.props(
551
- styles.input,
552
- showsOverlay && styles.inputTextHidden,
553
- isEffectivelyDisabled && styles.inputDisabled,
554
- !isInputValid && styles.inputInvalid,
555
- )}
556
- />
557
- {showsOverlay && (
558
- <span
559
- aria-hidden="true"
560
- {...stylex.props(
561
- styles.overlay,
562
- nativeValue ? styles.overlayValue : styles.overlayPlaceholder,
563
- isEffectivelyDisabled && styles.inputDisabled,
564
- !isInputValid && !!nativeValue && styles.inputInvalid,
565
- )}>
566
- {overlayText}
567
- </span>
568
- )}
569
- </span>
570
- {/*
571
- Live region announcing a refused date. The value snaps back on its
572
- own, so without this a screen-reader user would get no feedback that
573
- their pick was rejected (WCAG 3.3.1).
574
- */}
575
- <VisuallyHidden as="div" role="alert" aria-live="assertive">
576
- {!isInputValid ? t('@astryx.dateInput.invalidDate') : ''}
577
- </VisuallyHidden>
578
- {hasClear && value !== undefined && !isEffectivelyDisabled && (
579
- <InputClearButton
580
- label={t('@astryx.dateInput.clear', {label})}
581
- onClick={handleClear}
582
- iconClassName={stableClassName('date-input-clear-icon')}
583
- />
584
- )}
585
- {isLoading && <Spinner size="sm" />}
586
- {statusIcon}
587
- {showsDisabledMessage &&
588
- disabledMessageTooltip.renderTooltip(disabledMessage)}
589
- </div>
590
- );
591
-
592
- if (inputGroup) {
593
- return inputWrapper;
594
- }
595
-
596
- return (
597
- <Field
598
- label={label}
599
- isLabelHidden={isLabelHidden}
600
- description={description}
601
- inputID={id}
602
- descriptionID={description ? descriptionID : undefined}
603
- isOptional={isOptional}
604
- isRequired={isRequired}
605
- isDisabled={isDisabled}
606
- status={
607
- status
608
- ? {
609
- type: status.type,
610
- message: status.message,
611
- messageID: status.message ? statusMessageID : undefined,
612
- }
613
- : undefined
614
- }
615
- statusVariant={statusVariant}
616
- labelTooltip={labelTooltip}
617
- width={width}>
618
- {inputWrapper}
619
- </Field>
620
- );
621
- }
622
-
623
- NativeDateField.displayName = 'NativeDateField';
@@ -1,61 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file isApplePlatform.test.ts
5
- * @input Uses vitest, isApplePlatform
6
- * @output Unit tests for isApplePlatform
7
- * @position Testing; validates isApplePlatform.ts implementation
8
- */
9
-
10
- import {describe, it, expect, vi, afterEach} from 'vitest';
11
- import {isApplePlatform} from './isApplePlatform';
12
-
13
- afterEach(() => {
14
- vi.unstubAllGlobals();
15
- });
16
-
17
- describe('isApplePlatform', () => {
18
- it('trusts a client-hints platform that names one', () => {
19
- vi.stubGlobal('navigator', {
20
- userAgentData: {platform: 'macOS'},
21
- platform: 'Win32',
22
- });
23
- expect(isApplePlatform()).toBe(true);
24
-
25
- vi.stubGlobal('navigator', {
26
- userAgentData: {platform: 'Windows'},
27
- platform: 'MacIntel',
28
- });
29
- expect(isApplePlatform()).toBe(false);
30
- });
31
-
32
- it.each([
33
- ['blank', ''],
34
- ['whitespace', ' '],
35
- ['the spec Unknown sentinel', 'Unknown'],
36
- ['unknown in any case', 'UNKNOWN'],
37
- ['a non-string', null],
38
- ])('falls through to navigator.platform on %s', (_label, platform) => {
39
- vi.stubGlobal('navigator', {
40
- userAgentData: {platform},
41
- platform: 'MacIntel',
42
- });
43
- expect(isApplePlatform()).toBe(true);
44
-
45
- vi.stubGlobal('navigator', {userAgentData: {platform}, platform: 'Win32'});
46
- expect(isApplePlatform()).toBe(false);
47
- });
48
-
49
- it('falls back to navigator.platform when client hints are absent', () => {
50
- vi.stubGlobal('navigator', {platform: 'iPhone'});
51
- expect(isApplePlatform()).toBe(true);
52
-
53
- vi.stubGlobal('navigator', {platform: 'Linux x86_64'});
54
- expect(isApplePlatform()).toBe(false);
55
- });
56
-
57
- it('answers false when there is no navigator at all', () => {
58
- vi.stubGlobal('navigator', undefined);
59
- expect(isApplePlatform()).toBe(false);
60
- });
61
- });