@octanejs/aria 0.0.4 → 0.0.5

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 (93) hide show
  1. package/package.json +7 -5
  2. package/src/autocomplete/useAutocomplete.ts +656 -0
  3. package/src/collections/BaseCollection.ts +374 -0
  4. package/src/collections/CollectionBuilder.ts +343 -0
  5. package/src/collections/Document.ts +451 -0
  6. package/src/collections/Hidden.ts +84 -0
  7. package/src/collections/useCachedChildren.ts +103 -0
  8. package/src/components/Autocomplete.ts +124 -0
  9. package/src/components/Breadcrumbs.ts +170 -0
  10. package/src/components/Button.ts +209 -0
  11. package/src/components/Checkbox.ts +593 -0
  12. package/src/components/Collection.ts +301 -0
  13. package/src/components/ComboBox.ts +477 -0
  14. package/src/components/Dialog.ts +195 -0
  15. package/src/components/Disclosure.ts +322 -0
  16. package/src/components/DragAndDrop.ts +177 -0
  17. package/src/components/FieldError.ts +79 -0
  18. package/src/components/Form.ts +65 -0
  19. package/src/components/GridList.ts +1099 -0
  20. package/src/components/Group.ts +146 -0
  21. package/src/components/Header.ts +32 -0
  22. package/src/components/Heading.ts +45 -0
  23. package/src/components/Input.ts +139 -0
  24. package/src/components/Keyboard.ts +23 -0
  25. package/src/components/Label.ts +30 -0
  26. package/src/components/Link.ts +137 -0
  27. package/src/components/ListBox.ts +886 -0
  28. package/src/components/Menu.ts +685 -0
  29. package/src/components/Meter.ts +100 -0
  30. package/src/components/Modal.ts +352 -0
  31. package/src/components/NumberField.ts +221 -0
  32. package/src/components/OverlayArrow.ts +117 -0
  33. package/src/components/Popover.ts +385 -0
  34. package/src/components/ProgressBar.ts +112 -0
  35. package/src/components/RadioGroup.ts +542 -0
  36. package/src/components/SearchField.ts +208 -0
  37. package/src/components/Select.ts +505 -0
  38. package/src/components/SelectionIndicator.ts +52 -0
  39. package/src/components/Separator.ts +97 -0
  40. package/src/components/SharedElementTransition.ts +209 -0
  41. package/src/components/Slider.ts +472 -0
  42. package/src/components/Switch.ts +449 -0
  43. package/src/components/Tabs.ts +675 -0
  44. package/src/components/TagGroup.ts +443 -0
  45. package/src/components/Text.ts +27 -0
  46. package/src/components/TextArea.ts +92 -0
  47. package/src/components/TextField.ts +200 -0
  48. package/src/components/ToggleButton.ts +147 -0
  49. package/src/components/ToggleButtonGroup.ts +106 -0
  50. package/src/components/Toolbar.ts +74 -0
  51. package/src/components/Tooltip.ts +249 -0
  52. package/src/components/index.ts +302 -0
  53. package/src/components/useDragAndDrop.ts +164 -0
  54. package/src/components/utils.ts +521 -0
  55. package/src/intl/autocomplete/ar-AE.json +3 -0
  56. package/src/intl/autocomplete/bg-BG.json +3 -0
  57. package/src/intl/autocomplete/cs-CZ.json +3 -0
  58. package/src/intl/autocomplete/da-DK.json +3 -0
  59. package/src/intl/autocomplete/de-DE.json +3 -0
  60. package/src/intl/autocomplete/el-GR.json +3 -0
  61. package/src/intl/autocomplete/en-US.json +3 -0
  62. package/src/intl/autocomplete/es-ES.json +3 -0
  63. package/src/intl/autocomplete/et-EE.json +3 -0
  64. package/src/intl/autocomplete/fi-FI.json +3 -0
  65. package/src/intl/autocomplete/fr-FR.json +3 -0
  66. package/src/intl/autocomplete/he-IL.json +3 -0
  67. package/src/intl/autocomplete/hr-HR.json +3 -0
  68. package/src/intl/autocomplete/hu-HU.json +3 -0
  69. package/src/intl/autocomplete/index.ts +75 -0
  70. package/src/intl/autocomplete/it-IT.json +3 -0
  71. package/src/intl/autocomplete/ja-JP.json +3 -0
  72. package/src/intl/autocomplete/ko-KR.json +3 -0
  73. package/src/intl/autocomplete/lt-LT.json +3 -0
  74. package/src/intl/autocomplete/lv-LV.json +3 -0
  75. package/src/intl/autocomplete/nb-NO.json +3 -0
  76. package/src/intl/autocomplete/nl-NL.json +3 -0
  77. package/src/intl/autocomplete/pl-PL.json +3 -0
  78. package/src/intl/autocomplete/pt-BR.json +3 -0
  79. package/src/intl/autocomplete/pt-PT.json +3 -0
  80. package/src/intl/autocomplete/ro-RO.json +3 -0
  81. package/src/intl/autocomplete/ru-RU.json +3 -0
  82. package/src/intl/autocomplete/sk-SK.json +3 -0
  83. package/src/intl/autocomplete/sl-SI.json +3 -0
  84. package/src/intl/autocomplete/sr-SP.json +3 -0
  85. package/src/intl/autocomplete/sv-SE.json +3 -0
  86. package/src/intl/autocomplete/tr-TR.json +3 -0
  87. package/src/intl/autocomplete/uk-UA.json +3 -0
  88. package/src/intl/autocomplete/zh-CN.json +3 -0
  89. package/src/intl/autocomplete/zh-TW.json +3 -0
  90. package/src/stately/autocomplete/useAutocompleteState.ts +85 -0
  91. package/src/utils/animation.ts +149 -0
  92. package/src/utils/useLoadMoreSentinel.ts +78 -0
  93. package/src/utils/useViewportSize.ts +123 -0
@@ -0,0 +1,593 @@
1
+ // Ported from react-aria-components (source: .react-spectrum/packages/react-aria-components/src/Checkbox.tsx).
2
+ // octane adaptations: `.tsx` → `.ts`, JSX → `createElement`; NO forwardRef — the forwarded ref
3
+ // is `props.ref`, passed into `useContextProps` explicitly and re-applied as the merged object
4
+ // ref; the plain-`.ts` components use the S()/subSlot component-slot convention (`useContext`
5
+ // stays slotless — context-identity keyed); `useCheckboxAria` keeps upstream's conditional hook
6
+ // calls (octane hooks are slot-keyed, so the group/standalone branches use distinct sub-slots);
7
+ // the ported useCheckbox/useCheckboxGroupItem already carry octane's native change-event wiring
8
+ // for the hidden checkbox input — inputProps pass through untouched.
9
+ import type { HoverEvents, RefObject } from '@react-types/shared';
10
+ import { createContext, createElement, useContext, useMemo } from 'octane';
11
+
12
+ import { type AriaCheckboxProps, type CheckboxAria, useCheckbox } from '../checkbox/useCheckbox';
13
+ import { type AriaCheckboxGroupProps, useCheckboxGroup } from '../checkbox/useCheckboxGroup';
14
+ import { useCheckboxGroupItem } from '../checkbox/useCheckboxGroupItem';
15
+ import { useFocusRing } from '../focus/useFocusRing';
16
+ import { useHover } from '../interactions/useHover';
17
+ import { S, subSlot } from '../internal';
18
+ import {
19
+ type CheckboxGroupState,
20
+ useCheckboxGroupState,
21
+ } from '../stately/checkbox/useCheckboxGroupState';
22
+ import { useToggleState } from '../stately/toggle/useToggleState';
23
+ import { filterDOMProps } from '../utils/filterDOMProps';
24
+ import { mergeProps } from '../utils/mergeProps';
25
+ import { mergeRefs } from '../utils/mergeRefs';
26
+ import { useObjectRef } from '../utils/useObjectRef';
27
+ import { VisuallyHidden } from '../visually-hidden/VisuallyHidden';
28
+ import { FieldErrorContext } from './FieldError';
29
+ import { FormContext } from './Form';
30
+ import { LabelContext } from './Label';
31
+ import { TextContext } from './Text';
32
+ import {
33
+ type ClassNameOrFunction,
34
+ type ContextValue,
35
+ dom,
36
+ Provider,
37
+ type RACValidation,
38
+ removeDataAttributes,
39
+ type RenderProps,
40
+ type SlotProps,
41
+ useContextProps,
42
+ useRenderProps,
43
+ useSlot,
44
+ useSlottedContext,
45
+ } from './utils';
46
+
47
+ // octane adaptation: structural bag (upstream's `GlobalDOMAttributes` drags React handler types).
48
+ type GlobalDOMAttributes = Record<string, any>;
49
+
50
+ export interface CheckboxGroupProps
51
+ extends
52
+ Omit<
53
+ AriaCheckboxGroupProps,
54
+ | 'children'
55
+ | 'label'
56
+ | 'description'
57
+ | 'errorMessage'
58
+ | 'validationState'
59
+ | 'validationBehavior'
60
+ >,
61
+ RACValidation,
62
+ RenderProps<CheckboxGroupRenderProps, 'div'>,
63
+ SlotProps,
64
+ GlobalDOMAttributes {
65
+ /**
66
+ * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
67
+ * element. A function may be provided to compute the class based on component state.
68
+ *
69
+ * @default 'react-aria-CheckboxGroup'
70
+ */
71
+ className?: ClassNameOrFunction<CheckboxGroupRenderProps>;
72
+ }
73
+
74
+ export interface CheckboxProps
75
+ extends
76
+ Omit<AriaCheckboxProps, 'children' | 'validationState' | 'validationBehavior'>,
77
+ HoverEvents,
78
+ RACValidation,
79
+ RenderProps<CheckboxRenderProps, 'label'>,
80
+ SlotProps,
81
+ Omit<GlobalDOMAttributes, 'onClick'> {
82
+ /**
83
+ * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
84
+ * element. A function may be provided to compute the class based on component state.
85
+ *
86
+ * @default 'react-aria-Checkbox'
87
+ */
88
+ className?: ClassNameOrFunction<CheckboxRenderProps>;
89
+ /**
90
+ * A ref for the HTML input element.
91
+ */
92
+ inputRef?: RefObject<HTMLInputElement | null>;
93
+ }
94
+
95
+ export interface CheckboxFieldProps
96
+ extends
97
+ Omit<AriaCheckboxProps, 'children' | 'validationState' | 'validationBehavior'>,
98
+ RACValidation,
99
+ RenderProps<CheckboxFieldRenderProps>,
100
+ SlotProps,
101
+ Omit<GlobalDOMAttributes, 'onClick'> {
102
+ /**
103
+ * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
104
+ * element. A function may be provided to compute the class based on component state.
105
+ *
106
+ * @default 'react-aria-CheckboxField'
107
+ */
108
+ className?: ClassNameOrFunction<CheckboxFieldRenderProps>;
109
+ /**
110
+ * A ref for the HTML input element.
111
+ */
112
+ inputRef?: RefObject<HTMLInputElement | null>;
113
+ }
114
+
115
+ export interface CheckboxButtonProps
116
+ extends
117
+ HoverEvents,
118
+ RenderProps<CheckboxButtonRenderProps, 'label'>,
119
+ SlotProps,
120
+ GlobalDOMAttributes {
121
+ /**
122
+ * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
123
+ * element. A function may be provided to compute the class based on component state.
124
+ *
125
+ * @default 'react-aria-CheckboxButton'
126
+ */
127
+ className?: ClassNameOrFunction<CheckboxButtonRenderProps>;
128
+ }
129
+
130
+ export interface CheckboxGroupRenderProps {
131
+ /**
132
+ * Whether the checkbox group is disabled.
133
+ *
134
+ * @selector [data-disabled]
135
+ */
136
+ isDisabled: boolean;
137
+ /**
138
+ * Whether the checkbox group is read only.
139
+ *
140
+ * @selector [data-readonly]
141
+ */
142
+ isReadOnly: boolean;
143
+ /**
144
+ * Whether the checkbox group is required.
145
+ *
146
+ * @selector [data-required]
147
+ */
148
+ isRequired: boolean;
149
+ /**
150
+ * Whether the checkbox group is invalid.
151
+ *
152
+ * @selector [data-invalid]
153
+ */
154
+ isInvalid: boolean;
155
+ /**
156
+ * State of the checkbox group.
157
+ */
158
+ state: CheckboxGroupState;
159
+ }
160
+
161
+ export interface CheckboxRenderProps {
162
+ /**
163
+ * Whether the checkbox is selected.
164
+ *
165
+ * @selector [data-selected]
166
+ */
167
+ isSelected: boolean;
168
+ /**
169
+ * Whether the checkbox is indeterminate.
170
+ *
171
+ * @selector [data-indeterminate]
172
+ */
173
+ isIndeterminate: boolean;
174
+ /**
175
+ * Whether the checkbox is currently hovered with a mouse.
176
+ *
177
+ * @selector [data-hovered]
178
+ */
179
+ isHovered: boolean;
180
+ /**
181
+ * Whether the checkbox is currently in a pressed state.
182
+ *
183
+ * @selector [data-pressed]
184
+ */
185
+ isPressed: boolean;
186
+ /**
187
+ * Whether the checkbox is focused, either via a mouse or keyboard.
188
+ *
189
+ * @selector [data-focused]
190
+ */
191
+ isFocused: boolean;
192
+ /**
193
+ * Whether the checkbox is keyboard focused.
194
+ *
195
+ * @selector [data-focus-visible]
196
+ */
197
+ isFocusVisible: boolean;
198
+ /**
199
+ * Whether the checkbox is disabled.
200
+ *
201
+ * @selector [data-disabled]
202
+ */
203
+ isDisabled: boolean;
204
+ /**
205
+ * Whether the checkbox is read only.
206
+ *
207
+ * @selector [data-readonly]
208
+ */
209
+ isReadOnly: boolean;
210
+ /**
211
+ * Whether the checkbox invalid.
212
+ *
213
+ * @selector [data-invalid]
214
+ */
215
+ isInvalid: boolean;
216
+ /**
217
+ * Whether the checkbox is required.
218
+ *
219
+ * @selector [data-required]
220
+ */
221
+ isRequired: boolean;
222
+ }
223
+
224
+ export interface CheckboxFieldRenderProps {
225
+ /**
226
+ * Whether the checkbox is selected.
227
+ *
228
+ * @selector [data-selected]
229
+ */
230
+ isSelected: boolean;
231
+ /**
232
+ * Whether the checkbox is indeterminate.
233
+ *
234
+ * @selector [data-indeterminate]
235
+ */
236
+ isIndeterminate: boolean;
237
+ /**
238
+ * Whether the checkbox is disabled.
239
+ *
240
+ * @selector [data-disabled]
241
+ */
242
+ isDisabled: boolean;
243
+ /**
244
+ * Whether the checkbox is read only.
245
+ *
246
+ * @selector [data-readonly]
247
+ */
248
+ isReadOnly: boolean;
249
+ /**
250
+ * Whether the checkbox invalid.
251
+ *
252
+ * @selector [data-invalid]
253
+ */
254
+ isInvalid: boolean;
255
+ /**
256
+ * Whether the checkbox is required.
257
+ *
258
+ * @selector [data-required]
259
+ */
260
+ isRequired: boolean;
261
+ }
262
+
263
+ export interface CheckboxButtonRenderProps extends CheckboxRenderProps {}
264
+
265
+ export const CheckboxContext = createContext<ContextValue<CheckboxProps, HTMLLabelElement>>(null);
266
+ export const CheckboxFieldContext =
267
+ createContext<ContextValue<CheckboxFieldProps, HTMLDivElement>>(null);
268
+ export const CheckboxGroupContext =
269
+ createContext<ContextValue<CheckboxGroupProps, HTMLDivElement>>(null);
270
+ export const CheckboxGroupStateContext = createContext<CheckboxGroupState | null>(null);
271
+
272
+ /**
273
+ * A checkbox group allows a user to select multiple items from a list of options.
274
+ */
275
+ export function CheckboxGroup(props: CheckboxGroupProps): any {
276
+ const slot = S('CheckboxGroup');
277
+ let ref: any;
278
+ [props, ref] = useContextProps(props, props.ref, CheckboxGroupContext, subSlot(slot, 'ctx'));
279
+ let { validationBehavior: formValidationBehavior } =
280
+ useSlottedContext(FormContext, undefined, subSlot(slot, 'form')) || {};
281
+ let validationBehavior = props.validationBehavior ?? formValidationBehavior ?? 'native';
282
+ let state = useCheckboxGroupState(
283
+ {
284
+ ...props,
285
+ validationBehavior,
286
+ },
287
+ subSlot(slot, 'state'),
288
+ );
289
+ let [labelRef, label] = useSlot(
290
+ !props['aria-label'] && !props['aria-labelledby'],
291
+ subSlot(slot, 'labelSlot'),
292
+ );
293
+ let { groupProps, labelProps, descriptionProps, errorMessageProps, ...validation } =
294
+ useCheckboxGroup(
295
+ {
296
+ ...props,
297
+ label,
298
+ validationBehavior,
299
+ },
300
+ state,
301
+ subSlot(slot, 'group'),
302
+ );
303
+
304
+ let renderProps = useRenderProps(
305
+ {
306
+ ...props,
307
+ values: {
308
+ isDisabled: state.isDisabled,
309
+ isReadOnly: state.isReadOnly,
310
+ isRequired: props.isRequired || false,
311
+ isInvalid: state.isInvalid,
312
+ state,
313
+ },
314
+ defaultClassName: 'react-aria-CheckboxGroup',
315
+ },
316
+ subSlot(slot, 'render'),
317
+ );
318
+
319
+ let DOMProps = filterDOMProps(props, { global: true });
320
+
321
+ return createElement(dom.div, {
322
+ ...mergeProps(DOMProps, renderProps, groupProps),
323
+ ref,
324
+ slot: props.slot || undefined,
325
+ 'data-readonly': state.isReadOnly || undefined,
326
+ 'data-required': props.isRequired || undefined,
327
+ 'data-invalid': state.isInvalid || undefined,
328
+ 'data-disabled': props.isDisabled || undefined,
329
+ children: createElement(Provider, {
330
+ values: [
331
+ [CheckboxGroupStateContext, state],
332
+ [LabelContext, { ...labelProps, ref: labelRef, elementType: 'span' }],
333
+ [
334
+ TextContext,
335
+ {
336
+ slots: {
337
+ description: descriptionProps,
338
+ errorMessage: errorMessageProps,
339
+ },
340
+ },
341
+ ],
342
+ [FieldErrorContext, validation],
343
+ ] as any,
344
+ children: renderProps.children,
345
+ }),
346
+ });
347
+ }
348
+
349
+ interface InternalCheckboxContextValue extends CheckboxAria {
350
+ inputRef: RefObject<HTMLInputElement | null>;
351
+ defaultClassName: string;
352
+ isIndeterminate?: boolean;
353
+ isRequired?: boolean;
354
+ }
355
+
356
+ const InternalCheckboxContext = createContext<InternalCheckboxContextValue | null>(null);
357
+
358
+ /**
359
+ * A checkbox allows a user to select an item, with support for validation and help text.
360
+ */
361
+ export function CheckboxField(props: CheckboxFieldProps): any {
362
+ const slot = S('CheckboxField');
363
+ let { inputRef: userProvidedInputRef = null, ...otherProps } = props;
364
+ let ref: any;
365
+ [props, ref] = useContextProps(
366
+ otherProps as CheckboxFieldProps,
367
+ (otherProps as any).ref,
368
+ CheckboxFieldContext,
369
+ subSlot(slot, 'ctx'),
370
+ );
371
+ let groupState = useContext(CheckboxGroupStateContext);
372
+ let [aria, inputRef] = useCheckboxAria(props, userProvidedInputRef, subSlot(slot, 'aria'));
373
+ let {
374
+ descriptionProps,
375
+ errorMessageProps,
376
+ isSelected,
377
+ isDisabled,
378
+ isReadOnly,
379
+ isInvalid,
380
+ validationDetails,
381
+ validationErrors,
382
+ } = aria;
383
+
384
+ let renderProps = useRenderProps(
385
+ {
386
+ ...props,
387
+ defaultClassName: 'react-aria-CheckboxField',
388
+ values: {
389
+ isSelected,
390
+ isIndeterminate: props.isIndeterminate || false,
391
+ isDisabled,
392
+ isReadOnly,
393
+ isInvalid,
394
+ isRequired: props.isRequired || false,
395
+ },
396
+ },
397
+ subSlot(slot, 'render'),
398
+ );
399
+
400
+ let DOMProps = filterDOMProps(props, { global: true });
401
+ delete DOMProps.id;
402
+ delete (DOMProps as any).onClick;
403
+
404
+ return createElement(dom.div, {
405
+ ...mergeProps(DOMProps, renderProps),
406
+ ref,
407
+ slot: props.slot || undefined,
408
+ 'data-selected': isSelected || undefined,
409
+ 'data-indeterminate': props.isIndeterminate || undefined,
410
+ 'data-disabled': isDisabled || undefined,
411
+ 'data-readonly': isReadOnly || undefined,
412
+ 'data-invalid': isInvalid || undefined,
413
+ 'data-required': props.isRequired || undefined,
414
+ children: createElement(Provider, {
415
+ values: [
416
+ [
417
+ InternalCheckboxContext,
418
+ {
419
+ ...aria,
420
+ inputRef,
421
+ defaultClassName: 'react-aria-CheckboxButton',
422
+ isIndeterminate: props.isIndeterminate,
423
+ isRequired: props.isRequired,
424
+ },
425
+ ],
426
+ [
427
+ TextContext,
428
+ {
429
+ slots: {
430
+ description: descriptionProps,
431
+ errorMessage: errorMessageProps,
432
+ },
433
+ },
434
+ ],
435
+ // In a CheckboxGroup, validation is handled at the group level instead of repeated on each checkbox.
436
+ [FieldErrorContext, groupState ? null : { isInvalid, validationDetails, validationErrors }],
437
+ ] as any,
438
+ children: renderProps.children,
439
+ }),
440
+ });
441
+ }
442
+
443
+ function useCheckboxAria(
444
+ props: CheckboxProps | CheckboxFieldProps,
445
+ userProvidedInputRef: RefObject<HTMLInputElement | null> | null,
446
+ slot: symbol | undefined,
447
+ ): [CheckboxAria, RefObject<HTMLInputElement | null>] {
448
+ let { validationBehavior: formValidationBehavior } =
449
+ useSlottedContext(FormContext, undefined, subSlot(slot, 'form')) || {};
450
+ let validationBehavior = props.validationBehavior ?? formValidationBehavior ?? 'native';
451
+ let groupState = useContext(CheckboxGroupStateContext);
452
+ let inputRef = useObjectRef(
453
+ useMemo(
454
+ () => mergeRefs(userProvidedInputRef, props.inputRef !== undefined ? props.inputRef : null),
455
+ [userProvidedInputRef, props.inputRef],
456
+ subSlot(slot, 'mergeRefs'),
457
+ ),
458
+ subSlot(slot, 'objectRef'),
459
+ );
460
+ let checkboxProps = {
461
+ ...removeDataAttributes(props),
462
+ children: typeof props.children === 'function' ? true : props.children,
463
+ value: props.value!,
464
+ validationBehavior,
465
+ };
466
+
467
+ // octane divergence from React's rules of hooks (intentional, supported): hooks are
468
+ // slot-keyed, so the group/standalone branches may run conditionally as long as each
469
+ // call site keeps a distinct stable slot.
470
+ let aria = groupState
471
+ ? useCheckboxGroupItem(checkboxProps, groupState, inputRef, subSlot(slot, 'groupItem'))
472
+ : useCheckbox(
473
+ checkboxProps,
474
+ useToggleState(props, subSlot(slot, 'toggleState')),
475
+ inputRef,
476
+ subSlot(slot, 'checkbox'),
477
+ );
478
+ return [aria, inputRef];
479
+ }
480
+
481
+ /**
482
+ * A checkbox allows a user to select multiple items from a list of individual items, or
483
+ * to mark one individual item as selected.
484
+ *
485
+ * @deprecated Use CheckboxField + CheckboxButton instead.
486
+ */
487
+ export function Checkbox(props: CheckboxProps): any {
488
+ const slot = S('Checkbox');
489
+ let { inputRef: userProvidedInputRef = null, ...otherProps } = props;
490
+ let ref: any;
491
+ [props, ref] = useContextProps(
492
+ otherProps as CheckboxProps,
493
+ (otherProps as any).ref,
494
+ CheckboxContext,
495
+ subSlot(slot, 'ctx'),
496
+ );
497
+ let [aria, inputRef] = useCheckboxAria(props, userProvidedInputRef, subSlot(slot, 'aria'));
498
+
499
+ return createElement(InternalCheckboxContext.Provider, {
500
+ value: {
501
+ ...aria,
502
+ inputRef,
503
+ defaultClassName: 'react-aria-Checkbox',
504
+ isIndeterminate: props.isIndeterminate,
505
+ isRequired: props.isRequired,
506
+ },
507
+ children: createElement(CheckboxButton, { ...props, ref } as any),
508
+ });
509
+ }
510
+
511
+ /**
512
+ * A checkbox button is the clickable area of a checkbox, including the indicator and label.
513
+ */
514
+ export function CheckboxButton(props: CheckboxButtonProps): any {
515
+ const slot = S('CheckboxButton');
516
+ let {
517
+ labelProps,
518
+ inputProps,
519
+ isSelected,
520
+ isDisabled,
521
+ isReadOnly,
522
+ isPressed,
523
+ isInvalid,
524
+ inputRef,
525
+ defaultClassName,
526
+ isIndeterminate,
527
+ isRequired,
528
+ } = useContext(InternalCheckboxContext)!;
529
+ let { isFocused, isFocusVisible, focusProps } = useFocusRing(
530
+ undefined,
531
+ subSlot(slot, 'focusRing'),
532
+ );
533
+ let isInteractionDisabled = isDisabled || isReadOnly;
534
+
535
+ let { hoverProps, isHovered } = useHover(
536
+ {
537
+ ...props,
538
+ isDisabled: isInteractionDisabled,
539
+ },
540
+ subSlot(slot, 'hover'),
541
+ );
542
+
543
+ let renderProps = useRenderProps(
544
+ {
545
+ ...props,
546
+ defaultClassName,
547
+ values: {
548
+ isSelected,
549
+ isIndeterminate: isIndeterminate || false,
550
+ isPressed,
551
+ isHovered,
552
+ isFocused,
553
+ isFocusVisible,
554
+ isDisabled,
555
+ isReadOnly,
556
+ isInvalid,
557
+ isRequired: isRequired || false,
558
+ },
559
+ },
560
+ subSlot(slot, 'render'),
561
+ );
562
+
563
+ let DOMProps = filterDOMProps(props, { global: true });
564
+ delete DOMProps.id;
565
+ delete (DOMProps as any).onClick;
566
+
567
+ return createElement(
568
+ dom.label,
569
+ {
570
+ ...mergeProps(DOMProps, labelProps, hoverProps, renderProps),
571
+ ref: (props as any).ref,
572
+ slot: props.slot || undefined,
573
+ 'data-selected': isSelected || undefined,
574
+ 'data-indeterminate': isIndeterminate || undefined,
575
+ 'data-pressed': isPressed || undefined,
576
+ 'data-hovered': isHovered || undefined,
577
+ 'data-focused': isFocused || undefined,
578
+ 'data-focus-visible': isFocusVisible || undefined,
579
+ 'data-disabled': isDisabled || undefined,
580
+ 'data-readonly': isReadOnly || undefined,
581
+ 'data-invalid': isInvalid || undefined,
582
+ 'data-required': isRequired || undefined,
583
+ },
584
+ createElement(VisuallyHidden, {
585
+ elementType: 'span',
586
+ children: createElement('input', {
587
+ ...mergeProps(inputProps, focusProps),
588
+ ref: inputRef,
589
+ }),
590
+ }),
591
+ renderProps.children,
592
+ );
593
+ }