@box/blueprint-web 19.6.0 → 20.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.
Files changed (200) hide show
  1. package/THIRD_PARTY_LICENSES +119 -0
  2. package/dist/lib-esm/accordion/accordion.js +6 -6
  3. package/dist/lib-esm/accordion/types.d.ts +1 -1
  4. package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
  5. package/dist/lib-esm/checkbox/types.d.ts +1 -1
  6. package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
  7. package/dist/lib-esm/collapsible/types.d.ts +1 -1
  8. package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
  9. package/dist/lib-esm/date-picker/date-picker.js +8 -7
  10. package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
  11. package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
  12. package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
  13. package/dist/lib-esm/modal/modal-close.js +2 -2
  14. package/dist/lib-esm/modal/modal-content.d.ts +1 -1
  15. package/dist/lib-esm/modal/modal-content.js +4 -4
  16. package/dist/lib-esm/modal/modal-description.js +2 -2
  17. package/dist/lib-esm/modal/modal-title.js +2 -2
  18. package/dist/lib-esm/modal/modal-trigger.js +2 -2
  19. package/dist/lib-esm/modal/modal.d.ts +1 -1
  20. package/dist/lib-esm/modal/modal.js +1 -1
  21. package/dist/lib-esm/modal/types.d.ts +1 -1
  22. package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
  23. package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
  24. package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
  25. package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
  26. package/dist/lib-esm/primitives/chips/chip.js +2 -2
  27. package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
  28. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
  29. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
  30. package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
  31. package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
  32. package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
  33. package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
  34. package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
  35. package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
  36. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
  37. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
  38. package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
  39. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
  40. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
  41. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
  42. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
  43. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
  44. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
  45. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
  46. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
  47. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
  48. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
  49. package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
  50. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
  51. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
  52. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
  53. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
  54. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
  55. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
  56. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
  57. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
  58. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
  59. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
  60. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
  61. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
  62. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
  63. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
  64. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
  65. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
  66. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
  67. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
  68. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
  69. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
  70. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
  71. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
  72. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
  73. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
  74. package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
  75. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
  76. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
  77. package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
  78. package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
  79. package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
  80. package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
  81. package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
  82. package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
  83. package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
  84. package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
  85. package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
  86. package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
  87. package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
  88. package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
  89. package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
  90. package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
  91. package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
  92. package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
  93. package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
  94. package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
  95. package/dist/lib-esm/radio-group/index.d.ts +1 -1
  96. package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
  97. package/dist/lib-esm/radio-group/radio-group.js +2 -2
  98. package/dist/lib-esm/radio-group/radio-item.js +3 -3
  99. package/dist/lib-esm/radio-group/types.d.ts +1 -1
  100. package/dist/lib-esm/select/select.js +12 -12
  101. package/dist/lib-esm/select/types.d.ts +1 -1
  102. package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
  103. package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
  104. package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
  105. package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
  106. package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
  107. package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
  108. package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
  109. package/dist/lib-esm/side-panel/side-panel.js +1 -1
  110. package/dist/lib-esm/side-panel/types.d.ts +1 -1
  111. package/dist/lib-esm/switch/switch-item.js +3 -3
  112. package/dist/lib-esm/switch/types.d.ts +1 -1
  113. package/dist/lib-esm/toolbar/index.d.ts +2 -2
  114. package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
  115. package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
  116. package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
  117. package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
  118. package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
  119. package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
  120. package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
  121. package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
  122. package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
  123. package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
  124. package/dist/lib-esm/toolbar/types.d.ts +1 -1
  125. package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
  126. package/dist/lib-esm/tooltip/tooltip.js +6 -6
  127. package/dist/lib-esm/tooltip/types.d.ts +1 -1
  128. package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
  129. package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
  130. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
  131. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
  132. package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
  133. package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
  134. package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
  135. package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
  136. package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
  137. package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
  138. package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
  139. package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
  140. package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
  141. package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
  142. package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
  143. package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
  144. package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
  145. package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
  146. package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
  147. package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
  148. package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
  149. package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
  150. package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
  151. package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
  152. package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
  153. package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
  154. package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
  155. package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
  156. package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
  157. package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
  158. package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
  159. package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
  160. package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
  161. package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
  162. package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
  163. package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
  164. package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
  165. package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
  166. package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
  167. package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
  168. package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
  169. package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
  170. package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
  171. package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
  172. package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
  173. package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
  174. package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
  175. package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
  176. package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
  177. package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
  178. package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
  179. package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
  180. package/dist/lib-esm/utils/radix-compat/select.js +901 -0
  181. package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
  182. package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
  183. package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
  184. package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
  185. package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
  186. package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
  187. package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
  188. package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
  189. package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
  190. package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
  191. package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
  192. package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
  193. package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
  194. package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
  195. package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
  196. package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
  197. package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
  198. package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
  199. package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
  200. package/package.json +8 -19
@@ -0,0 +1,189 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { Button } from '@ariakit/react';
3
+ import { forwardRef, useContext, useState, useRef, useEffect, createContext } from 'react';
4
+ import { composeEventHandlers } from '../composeEventHandlers.js';
5
+ import { useControllableState } from '../useControllableState.js';
6
+ import { BubbleInput } from './bubble-input.js';
7
+ import { useComposedRefs } from './compose-refs.js';
8
+ import { Presence } from './presence.js';
9
+ import { RovingFocusGroup, RovingFocusGroupItem } from './roving-focus.js';
10
+ import { Slot } from './slot.js';
11
+
12
+ const ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
13
+ /** Radio groups don't activate on Enter, as per WAI-ARIA. */
14
+ const preventEnterActivation = event => {
15
+ if (event.key === 'Enter') {
16
+ event.preventDefault();
17
+ }
18
+ };
19
+ const RadioGroupContext = /*#__PURE__*/createContext(null);
20
+ /**
21
+ * Radio group with the Radix keyboard model: the group is the tab stop and moves focus to the checked
22
+ * radio, arrow keys move focus (and check while the key is pressed), Home/End move focus only.
23
+ */
24
+ const Root = /*#__PURE__*/forwardRef((props, forwardedRef) => {
25
+ const {
26
+ name,
27
+ required = false,
28
+ disabled = false,
29
+ orientation,
30
+ dir,
31
+ loop = true,
32
+ defaultValue,
33
+ value: valueProp,
34
+ onValueChange,
35
+ asChild,
36
+ ...groupProps
37
+ } = props;
38
+ const [value, setValue] = useControllableState({
39
+ prop: valueProp,
40
+ defaultProp: defaultValue,
41
+ onChange: onValueChange
42
+ });
43
+ const Comp = asChild ? Slot : 'div';
44
+ return jsx(RadioGroupContext.Provider, {
45
+ value: {
46
+ name,
47
+ required,
48
+ disabled,
49
+ value,
50
+ onValueChange: nextValue => setValue(nextValue)
51
+ },
52
+ children: jsx(RovingFocusGroup, {
53
+ asChild: true,
54
+ dir: dir ?? 'ltr',
55
+ loop: loop,
56
+ orientation: orientation,
57
+ children: jsx(Comp, {
58
+ "aria-orientation": orientation,
59
+ "aria-required": required,
60
+ "data-disabled": disabled ? '' : undefined,
61
+ dir: dir ?? 'ltr',
62
+ role: "radiogroup",
63
+ ...groupProps,
64
+ ref: forwardedRef
65
+ })
66
+ })
67
+ });
68
+ });
69
+ Root.displayName = 'RadioGroup';
70
+ const RadioContext = /*#__PURE__*/createContext({
71
+ checked: false
72
+ });
73
+ const Item = /*#__PURE__*/forwardRef((props, forwardedRef) => {
74
+ const {
75
+ disabled,
76
+ value,
77
+ asChild,
78
+ required: _required,
79
+ ...itemProps
80
+ } = props;
81
+ const context = useContext(RadioGroupContext);
82
+ if (!context) {
83
+ throw new Error('RadioGroup.Item must be used within RadioGroup');
84
+ }
85
+ const isDisabled = context.disabled || disabled;
86
+ const checked = context.value === value;
87
+ const [button, setButton] = useState(null);
88
+ const composedRefs = useComposedRefs(forwardedRef, setButton);
89
+ const isArrowKeyPressedRef = useRef(false);
90
+ const hasConsumerStoppedPropagationRef = useRef(false);
91
+ const isFormControl = button ? Boolean(button.closest('form')) : true;
92
+ useEffect(() => {
93
+ const handleKeyDown = event => {
94
+ if (ARROW_KEYS.includes(event.key)) {
95
+ isArrowKeyPressedRef.current = true;
96
+ }
97
+ };
98
+ const handleKeyUp = () => {
99
+ isArrowKeyPressedRef.current = false;
100
+ };
101
+ document.addEventListener('keydown', handleKeyDown);
102
+ document.addEventListener('keyup', handleKeyUp);
103
+ return () => {
104
+ document.removeEventListener('keydown', handleKeyDown);
105
+ document.removeEventListener('keyup', handleKeyUp);
106
+ };
107
+ }, []);
108
+ const radioProps = {
109
+ 'aria-checked': checked,
110
+ 'data-disabled': isDisabled ? '' : undefined,
111
+ 'data-state': checked ? 'checked' : 'unchecked',
112
+ ...itemProps
113
+ };
114
+ return jsxs(RadioContext.Provider, {
115
+ value: {
116
+ checked,
117
+ disabled: isDisabled
118
+ },
119
+ children: [jsx(RovingFocusGroupItem, {
120
+ active: checked,
121
+ asChild: true,
122
+ focusable: !isDisabled,
123
+ children: jsx(Button, {
124
+ role: "radio",
125
+ ...radioProps,
126
+ ref: composedRefs,
127
+ clickOnEnter: false,
128
+ // Like Radix, the consumer's onKeyDown is replaced.
129
+ onKeyDown: preventEnterActivation,
130
+ onClick: composeEventHandlers(itemProps.onClick, event => {
131
+ if (!checked) {
132
+ context.onValueChange(value);
133
+ }
134
+ if (isFormControl) {
135
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
136
+ if (!hasConsumerStoppedPropagationRef.current) {
137
+ event.stopPropagation();
138
+ }
139
+ }
140
+ }),
141
+ onFocus: composeEventHandlers(itemProps.onFocus, () => {
142
+ // Arrow key navigation checks the radio it moves focus to.
143
+ if (isArrowKeyPressedRef.current) {
144
+ button?.click();
145
+ }
146
+ }),
147
+ // Ariakit would also make a disabled radio `aria-disabled` and ignore pointer events, unlike Radix.
148
+ render: asChild ? jsx(Slot, {
149
+ disabled: isDisabled
150
+ }) : jsx("button", {
151
+ disabled: isDisabled,
152
+ type: "button",
153
+ value: value
154
+ }),
155
+ value: value
156
+ })
157
+ }), isFormControl && jsx(BubbleInput, {
158
+ bubbles: !hasConsumerStoppedPropagationRef.current,
159
+ checked: checked,
160
+ control: button,
161
+ disabled: isDisabled,
162
+ name: context.name,
163
+ required: context.required,
164
+ type: "radio",
165
+ value: value
166
+ })]
167
+ });
168
+ });
169
+ Item.displayName = 'RadioGroupItem';
170
+ const Indicator = /*#__PURE__*/forwardRef(({
171
+ forceMount,
172
+ asChild,
173
+ ...indicatorProps
174
+ }, forwardedRef) => {
175
+ const context = useContext(RadioContext);
176
+ const Comp = asChild ? Slot : 'span';
177
+ return jsx(Presence, {
178
+ present: Boolean(forceMount) || context.checked,
179
+ children: jsx(Comp, {
180
+ "data-disabled": context.disabled ? '' : undefined,
181
+ "data-state": context.checked ? 'checked' : 'unchecked',
182
+ ...indicatorProps,
183
+ ref: forwardedRef
184
+ })
185
+ });
186
+ });
187
+ Indicator.displayName = 'RadioGroupIndicator';
188
+
189
+ export { Indicator, Item, Root };
@@ -0,0 +1,35 @@
1
+ import { type HTMLAttributes, type ReactNode } from 'react';
2
+ export type Orientation = 'horizontal' | 'vertical';
3
+ export type Direction = 'ltr' | 'rtl';
4
+ export declare function wrapArray<T>(array: T[], startIndex: number): T[];
5
+ export interface RovingFocusGroupProps extends HTMLAttributes<HTMLElement> {
6
+ /** The orientation of the group. Arrow keys of the other axis are ignored. Both axes work when omitted. */
7
+ orientation?: Orientation;
8
+ /** Reading direction; flips the horizontal arrow keys when `rtl`. */
9
+ dir?: Direction;
10
+ /** Whether focus loops from the last item to the first and back. */
11
+ loop?: boolean;
12
+ currentTabStopId?: string | null;
13
+ defaultCurrentTabStopId?: string;
14
+ onCurrentTabStopIdChange?: (tabStopId: string | null) => void;
15
+ /** Called when the group receives focus from the keyboard, before focus moves to an item. */
16
+ onEntryFocus?: (event: Event) => void;
17
+ preventScrollOnEntryFocus?: boolean;
18
+ asChild?: boolean;
19
+ children?: ReactNode;
20
+ }
21
+ /**
22
+ * Roving tab index group with the Radix semantics: the group element is the tab stop and moves focus
23
+ * to the active item, then the last focused item, then the first item.
24
+ */
25
+ export declare const RovingFocusGroup: import("react").ForwardRefExoticComponent<RovingFocusGroupProps & import("react").RefAttributes<HTMLElement>>;
26
+ export interface RovingFocusGroupItemProps extends HTMLAttributes<HTMLElement> {
27
+ /** Whether the item can receive focus. Non-focusable items are skipped. */
28
+ focusable?: boolean;
29
+ /** Whether the item is preferred when the group receives focus. */
30
+ active?: boolean;
31
+ tabStopId?: string;
32
+ asChild?: boolean;
33
+ children?: ReactNode;
34
+ }
35
+ export declare const RovingFocusGroupItem: import("react").ForwardRefExoticComponent<RovingFocusGroupItemProps & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,237 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useId, useContext, useRef, useEffect, useCallback, createContext, useState, useMemo } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useControllableState } from '../useControllableState.js';
5
+ import { createCollection } from './collection.js';
6
+ import { useComposedRefs } from './compose-refs.js';
7
+ import { Slot } from './slot.js';
8
+
9
+ const ENTRY_FOCUS = 'rovingFocusGroup.onEntryFocus';
10
+ const EVENT_OPTIONS = {
11
+ bubbles: false,
12
+ cancelable: true
13
+ };
14
+ const MAP_KEY_TO_FOCUS_INTENT = {
15
+ ArrowLeft: 'prev',
16
+ ArrowUp: 'prev',
17
+ ArrowRight: 'next',
18
+ ArrowDown: 'next',
19
+ PageUp: 'first',
20
+ Home: 'first',
21
+ PageDown: 'last',
22
+ End: 'last'
23
+ };
24
+ function getDirectionAwareKey(key, dir) {
25
+ if (dir !== 'rtl') {
26
+ return key;
27
+ }
28
+ if (key === 'ArrowLeft') {
29
+ return 'ArrowRight';
30
+ }
31
+ return key === 'ArrowRight' ? 'ArrowLeft' : key;
32
+ }
33
+ function getFocusIntent(event, orientation, dir) {
34
+ const key = getDirectionAwareKey(event.key, dir);
35
+ if (orientation === 'vertical' && ['ArrowLeft', 'ArrowRight'].includes(key)) {
36
+ return undefined;
37
+ }
38
+ if (orientation === 'horizontal' && ['ArrowUp', 'ArrowDown'].includes(key)) {
39
+ return undefined;
40
+ }
41
+ return MAP_KEY_TO_FOCUS_INTENT[key];
42
+ }
43
+ function focusFirstCandidate(candidates, preventScroll = false) {
44
+ const previouslyFocusedElement = document.activeElement;
45
+ for (const candidate of candidates) {
46
+ if (candidate === previouslyFocusedElement) {
47
+ return;
48
+ }
49
+ candidate?.focus({
50
+ preventScroll
51
+ });
52
+ if (document.activeElement !== previouslyFocusedElement) {
53
+ return;
54
+ }
55
+ }
56
+ }
57
+ function wrapArray(array, startIndex) {
58
+ return array.map((_, index) => array[(startIndex + index) % array.length]);
59
+ }
60
+ const {
61
+ CollectionProvider,
62
+ useCollection,
63
+ useCollectionItem,
64
+ useCollectionRef
65
+ } = createCollection();
66
+ const RovingFocusContext = /*#__PURE__*/createContext(null);
67
+ const RovingFocusGroupImpl = /*#__PURE__*/forwardRef((props, forwardedRef) => {
68
+ const {
69
+ orientation,
70
+ loop = false,
71
+ dir,
72
+ currentTabStopId: currentTabStopIdProp,
73
+ defaultCurrentTabStopId,
74
+ onCurrentTabStopIdChange,
75
+ onEntryFocus,
76
+ preventScrollOnEntryFocus = false,
77
+ asChild,
78
+ ...groupProps
79
+ } = props;
80
+ const ref = useRef(null);
81
+ const collectionRef = useCollectionRef();
82
+ const composedRefs = useComposedRefs(forwardedRef, ref, collectionRef);
83
+ const [currentTabStopId = null, setCurrentTabStopId] = useControllableState({
84
+ prop: currentTabStopIdProp,
85
+ defaultProp: defaultCurrentTabStopId,
86
+ onChange: onCurrentTabStopIdChange
87
+ });
88
+ const [isTabbingBackOut, setIsTabbingBackOut] = useState(false);
89
+ const getItems = useCollection();
90
+ const isClickFocusRef = useRef(false);
91
+ const [focusableItemsCount, setFocusableItemsCount] = useState(0);
92
+ const onEntryFocusRef = useRef(onEntryFocus);
93
+ onEntryFocusRef.current = onEntryFocus;
94
+ useEffect(() => {
95
+ const node = ref.current;
96
+ if (!node) {
97
+ return undefined;
98
+ }
99
+ const handleEntryFocus = event => onEntryFocusRef.current?.(event);
100
+ node.addEventListener(ENTRY_FOCUS, handleEntryFocus);
101
+ return () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
102
+ }, []);
103
+ const contextValue = useMemo(() => ({
104
+ orientation,
105
+ dir,
106
+ loop,
107
+ currentTabStopId,
108
+ onItemFocus: tabStopId => setCurrentTabStopId(tabStopId),
109
+ onItemShiftTab: () => setIsTabbingBackOut(true),
110
+ onFocusableItemAdd: () => setFocusableItemsCount(count => count + 1),
111
+ onFocusableItemRemove: () => setFocusableItemsCount(count => count - 1)
112
+ }), [orientation, dir, loop, currentTabStopId, setCurrentTabStopId]);
113
+ const Comp = asChild ? Slot : 'div';
114
+ return jsx(RovingFocusContext.Provider, {
115
+ value: contextValue,
116
+ children: jsx(Comp, {
117
+ tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
118
+ "data-orientation": orientation,
119
+ ...groupProps,
120
+ ref: composedRefs,
121
+ style: {
122
+ outline: 'none',
123
+ ...props.style
124
+ },
125
+ onMouseDown: composeEventHandlers(props.onMouseDown, () => {
126
+ isClickFocusRef.current = true;
127
+ }),
128
+ onFocus: composeEventHandlers(props.onFocus, event => {
129
+ const isKeyboardFocus = !isClickFocusRef.current;
130
+ if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
131
+ const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
132
+ event.currentTarget.dispatchEvent(entryFocusEvent);
133
+ if (!entryFocusEvent.defaultPrevented) {
134
+ const items = getItems().filter(item => item.focusable);
135
+ const activeItem = items.find(item => item.active);
136
+ const currentItem = items.find(item => item.id === currentTabStopId);
137
+ const candidateItems = [activeItem, currentItem, ...items].filter(Boolean);
138
+ focusFirstCandidate(candidateItems.map(item => item?.ref.current ?? null), preventScrollOnEntryFocus);
139
+ }
140
+ }
141
+ isClickFocusRef.current = false;
142
+ }),
143
+ onBlur: composeEventHandlers(props.onBlur, () => setIsTabbingBackOut(false))
144
+ })
145
+ });
146
+ });
147
+ /**
148
+ * Roving tab index group with the Radix semantics: the group element is the tab stop and moves focus
149
+ * to the active item, then the last focused item, then the first item.
150
+ */
151
+ const RovingFocusGroup = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(CollectionProvider, {
152
+ children: jsx(RovingFocusGroupImpl, {
153
+ ...props,
154
+ ref: forwardedRef
155
+ })
156
+ }));
157
+ const RovingFocusGroupItem = /*#__PURE__*/forwardRef((props, forwardedRef) => {
158
+ const {
159
+ focusable = true,
160
+ active = false,
161
+ tabStopId,
162
+ asChild,
163
+ ...itemProps
164
+ } = props;
165
+ const autoId = useId();
166
+ const id = tabStopId || autoId;
167
+ const context = useContext(RovingFocusContext);
168
+ if (!context) {
169
+ throw new Error('RovingFocusGroupItem must be used within RovingFocusGroup');
170
+ }
171
+ const isCurrentTabStop = context.currentTabStopId === id;
172
+ const getItems = useCollection();
173
+ const ref = useRef(null);
174
+ const composedRefs = useComposedRefs(forwardedRef, ref);
175
+ const collectionItemProps = useCollectionItem(ref, {
176
+ id,
177
+ focusable,
178
+ active
179
+ });
180
+ const {
181
+ onFocusableItemAdd,
182
+ onFocusableItemRemove
183
+ } = context;
184
+ useEffect(() => {
185
+ if (!focusable) {
186
+ return undefined;
187
+ }
188
+ onFocusableItemAdd();
189
+ return () => onFocusableItemRemove();
190
+ }, [focusable, onFocusableItemAdd, onFocusableItemRemove]);
191
+ const handleKeyDown = useCallback(event => {
192
+ if (event.key === 'Tab' && event.shiftKey) {
193
+ context.onItemShiftTab();
194
+ return;
195
+ }
196
+ if (event.target !== event.currentTarget) {
197
+ return;
198
+ }
199
+ const focusIntent = getFocusIntent(event, context.orientation, context.dir);
200
+ if (focusIntent === undefined) {
201
+ return;
202
+ }
203
+ event.preventDefault();
204
+ const items = getItems().filter(item => item.focusable);
205
+ let candidateNodes = items.map(item => item.ref.current);
206
+ if (focusIntent === 'last') {
207
+ candidateNodes.reverse();
208
+ } else if (focusIntent === 'prev' || focusIntent === 'next') {
209
+ if (focusIntent === 'prev') {
210
+ candidateNodes.reverse();
211
+ }
212
+ const currentIndex = candidateNodes.indexOf(event.currentTarget);
213
+ candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
214
+ }
215
+ // Focus is moved outside of the keydown handler, like in Radix.
216
+ setTimeout(() => focusFirstCandidate(candidateNodes));
217
+ }, [context, getItems]);
218
+ const Comp = asChild ? Slot : 'span';
219
+ return jsx(Comp, {
220
+ ...collectionItemProps,
221
+ tabIndex: isCurrentTabStop ? 0 : -1,
222
+ "data-orientation": context.orientation,
223
+ ...itemProps,
224
+ ref: composedRefs,
225
+ onMouseDown: composeEventHandlers(props.onMouseDown, event => {
226
+ if (!focusable) {
227
+ event.preventDefault();
228
+ } else {
229
+ context.onItemFocus(id);
230
+ }
231
+ }),
232
+ onFocus: composeEventHandlers(props.onFocus, () => context.onItemFocus(id)),
233
+ onKeyDown: composeEventHandlers(props.onKeyDown, handleKeyDown)
234
+ });
235
+ });
236
+
237
+ export { RovingFocusGroup, RovingFocusGroupItem, wrapArray };
@@ -0,0 +1,82 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type PopperArrowProps } from './popper';
3
+ import { type Direction, type DismissableLayerProps, type PopperContentProps, type PortalProps, type PrimitiveProps } from './types';
4
+ export interface SelectProps {
5
+ children?: ReactNode;
6
+ value?: string;
7
+ defaultValue?: string;
8
+ onValueChange?(value: string): void;
9
+ open?: boolean;
10
+ defaultOpen?: boolean;
11
+ onOpenChange?(open: boolean): void;
12
+ dir?: Direction;
13
+ name?: string;
14
+ autoComplete?: string;
15
+ disabled?: boolean;
16
+ required?: boolean;
17
+ }
18
+ /**
19
+ * Select with the Radix API, DOM and keyboard model; its listbox is an Ariakit popover. Inside a form, a hidden
20
+ * native `<select>` mirrors the value.
21
+ */
22
+ export declare const Root: {
23
+ (props: SelectProps): import("react/jsx-runtime").JSX.Element;
24
+ displayName: string;
25
+ };
26
+ export type SelectTriggerProps = PrimitiveProps<'button'>;
27
+ export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
28
+ asChild?: boolean;
29
+ } & import("react").RefAttributes<HTMLButtonElement>>;
30
+ export interface SelectValueProps extends Omit<PrimitiveProps<'span'>, 'placeholder'> {
31
+ placeholder?: ReactNode;
32
+ }
33
+ export declare const Value: import("react").ForwardRefExoticComponent<SelectValueProps & import("react").RefAttributes<HTMLSpanElement>>;
34
+ export type SelectIconProps = PrimitiveProps<'span'>;
35
+ export declare const Icon: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
36
+ asChild?: boolean;
37
+ } & import("react").RefAttributes<HTMLSpanElement>>;
38
+ export interface SelectPortalProps extends Omit<PortalProps, 'forceMount'> {
39
+ children?: ReactNode;
40
+ }
41
+ export declare const Portal: {
42
+ ({ children, container }: SelectPortalProps): import("react/jsx-runtime").JSX.Element;
43
+ displayName: string;
44
+ };
45
+ export interface SelectContentProps extends PrimitiveProps<'div'>, Omit<PopperContentProps, 'updatePositionStrategy' | 'onPlaced'>, Pick<DismissableLayerProps, 'onEscapeKeyDown' | 'onPointerDownOutside'> {
46
+ /** Only `popper` positioning is supported; `item-aligned` is treated the same way. */
47
+ position?: 'item-aligned' | 'popper';
48
+ onCloseAutoFocus?: (event: Event) => void;
49
+ }
50
+ export declare const Content: import("react").ForwardRefExoticComponent<SelectContentProps & import("react").RefAttributes<HTMLDivElement>>;
51
+ export type SelectViewportProps = PrimitiveProps<'div'>;
52
+ export declare const Viewport: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
53
+ asChild?: boolean;
54
+ } & import("react").RefAttributes<HTMLDivElement>>;
55
+ export type SelectGroupProps = PrimitiveProps<'div'>;
56
+ export declare const Group: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
57
+ asChild?: boolean;
58
+ } & import("react").RefAttributes<HTMLDivElement>>;
59
+ export type SelectLabelProps = PrimitiveProps<'div'>;
60
+ export declare const Label: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
61
+ asChild?: boolean;
62
+ } & import("react").RefAttributes<HTMLDivElement>>;
63
+ export interface SelectItemProps extends PrimitiveProps<'div'> {
64
+ value: string;
65
+ disabled?: boolean;
66
+ textValue?: string;
67
+ }
68
+ export declare const Item: import("react").ForwardRefExoticComponent<SelectItemProps & import("react").RefAttributes<HTMLDivElement>>;
69
+ export type SelectItemTextProps = PrimitiveProps<'span'>;
70
+ export declare const ItemText: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
71
+ asChild?: boolean;
72
+ } & import("react").RefAttributes<HTMLSpanElement>>;
73
+ export type SelectItemIndicatorProps = PrimitiveProps<'span'>;
74
+ export declare const ItemIndicator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
75
+ asChild?: boolean;
76
+ } & import("react").RefAttributes<HTMLSpanElement>>;
77
+ export type SelectSeparatorProps = PrimitiveProps<'div'>;
78
+ export declare const Separator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
79
+ asChild?: boolean;
80
+ } & import("react").RefAttributes<HTMLDivElement>>;
81
+ export type SelectArrowProps = PopperArrowProps;
82
+ export declare const Arrow: import("react").ForwardRefExoticComponent<Omit<PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;