@box/blueprint-web 19.5.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 (208) hide show
  1. package/THIRD_PARTY_LICENSES +119 -0
  2. package/dist/lib-esm/accordion/accordion.js +14 -6
  3. package/dist/lib-esm/accordion/accordion.module.js +1 -1
  4. package/dist/lib-esm/accordion/types.d.ts +1 -1
  5. package/dist/lib-esm/blueprint-configuration-context/consts.d.ts +1 -1
  6. package/dist/lib-esm/blueprint-configuration-context/consts.js +1 -1
  7. package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
  8. package/dist/lib-esm/checkbox/types.d.ts +1 -1
  9. package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
  10. package/dist/lib-esm/collapsible/types.d.ts +1 -1
  11. package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
  12. package/dist/lib-esm/components.css +400 -280
  13. package/dist/lib-esm/date-picker/date-picker.js +8 -7
  14. package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
  15. package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
  16. package/dist/lib-esm/index.css +400 -280
  17. package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
  18. package/dist/lib-esm/modal/modal-close.js +2 -2
  19. package/dist/lib-esm/modal/modal-content.d.ts +1 -1
  20. package/dist/lib-esm/modal/modal-content.js +4 -4
  21. package/dist/lib-esm/modal/modal-description.js +2 -2
  22. package/dist/lib-esm/modal/modal-title.js +2 -2
  23. package/dist/lib-esm/modal/modal-trigger.js +2 -2
  24. package/dist/lib-esm/modal/modal.d.ts +1 -1
  25. package/dist/lib-esm/modal/modal.js +1 -1
  26. package/dist/lib-esm/modal/types.d.ts +1 -1
  27. package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
  28. package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
  29. package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
  30. package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
  31. package/dist/lib-esm/primitives/chips/chip.js +2 -2
  32. package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
  33. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
  34. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
  35. package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
  36. package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
  37. package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
  38. package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
  39. package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
  40. package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
  41. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
  42. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
  43. package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
  44. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
  45. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
  46. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
  47. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
  48. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
  49. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
  50. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
  51. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
  52. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
  53. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
  54. package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
  55. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
  56. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
  57. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
  58. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
  59. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
  60. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
  61. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
  62. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
  63. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
  64. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
  65. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
  66. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
  67. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
  68. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
  69. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
  70. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
  71. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
  72. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
  73. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
  74. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
  75. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
  76. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
  77. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
  78. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
  79. package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
  80. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
  81. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
  82. package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
  83. package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
  84. package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
  85. package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
  86. package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
  87. package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
  88. package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
  89. package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
  90. package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
  91. package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
  92. package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
  93. package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
  94. package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
  95. package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
  96. package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
  97. package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
  98. package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
  99. package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
  100. package/dist/lib-esm/radio-group/index.d.ts +1 -1
  101. package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
  102. package/dist/lib-esm/radio-group/radio-group.js +2 -2
  103. package/dist/lib-esm/radio-group/radio-item.js +3 -3
  104. package/dist/lib-esm/radio-group/types.d.ts +1 -1
  105. package/dist/lib-esm/select/select.js +12 -12
  106. package/dist/lib-esm/select/types.d.ts +1 -1
  107. package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
  108. package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
  109. package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
  110. package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
  111. package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
  112. package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
  113. package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
  114. package/dist/lib-esm/side-panel/side-panel.js +1 -1
  115. package/dist/lib-esm/side-panel/types.d.ts +1 -1
  116. package/dist/lib-esm/small-list-item/small-list.js +8 -0
  117. package/dist/lib-esm/switch/switch-item.js +3 -3
  118. package/dist/lib-esm/switch/types.d.ts +1 -1
  119. package/dist/lib-esm/toolbar/index.d.ts +2 -2
  120. package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
  121. package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
  122. package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
  123. package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
  124. package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
  125. package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
  126. package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
  127. package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
  128. package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
  129. package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
  130. package/dist/lib-esm/toolbar/types.d.ts +1 -1
  131. package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
  132. package/dist/lib-esm/tooltip/tooltip.js +6 -6
  133. package/dist/lib-esm/tooltip/types.d.ts +1 -1
  134. package/dist/lib-esm/util-components/base-grid-list-item/base-grid-list-item.module.js +1 -1
  135. package/dist/lib-esm/utils/TooltipWrapper.d.ts +1 -1
  136. package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
  137. package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
  138. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
  139. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
  140. package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
  141. package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
  142. package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
  143. package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
  144. package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
  145. package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
  146. package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
  147. package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
  148. package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
  149. package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
  150. package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
  151. package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
  152. package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
  153. package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
  154. package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
  155. package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
  156. package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
  157. package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
  158. package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
  159. package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
  160. package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
  161. package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
  162. package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
  163. package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
  164. package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
  165. package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
  166. package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
  167. package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
  168. package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
  169. package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
  170. package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
  171. package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
  172. package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
  173. package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
  174. package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
  175. package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
  176. package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
  177. package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
  178. package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
  179. package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
  180. package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
  181. package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
  182. package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
  183. package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
  184. package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
  185. package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
  186. package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
  187. package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
  188. package/dist/lib-esm/utils/radix-compat/select.js +901 -0
  189. package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
  190. package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
  191. package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
  192. package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
  193. package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
  194. package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
  195. package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
  196. package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
  197. package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
  198. package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
  199. package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
  200. package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
  201. package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
  202. package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
  203. package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
  204. package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
  205. package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
  206. package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
  207. package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
  208. package/package.json +8 -19
@@ -0,0 +1,299 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useContext, useId, useCallback, useRef, createContext } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useControllableState } from '../useControllableState.js';
5
+ import { Root as Root$1, getOpenState, Trigger as Trigger$1, Content as Content$1 } from './collapsible.js';
6
+ import { createCollection } from './collection.js';
7
+ import { useComposedRefs } from './compose-refs.js';
8
+ import { Slot } from './slot.js';
9
+
10
+ const ACCORDION_KEYS = ['Home', 'End', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'];
11
+ const {
12
+ CollectionProvider,
13
+ useCollection,
14
+ useCollectionItem,
15
+ useCollectionRef
16
+ } = createCollection();
17
+ const AccordionValueContext = /*#__PURE__*/createContext(null);
18
+ const AccordionImplContext = /*#__PURE__*/createContext(null);
19
+ const AccordionImpl = /*#__PURE__*/forwardRef((props, forwardedRef) => {
20
+ const {
21
+ disabled,
22
+ dir,
23
+ orientation = 'vertical',
24
+ collapsible,
25
+ asChild,
26
+ ...accordionProps
27
+ } = props;
28
+ const accordionRef = useRef(null);
29
+ const collectionRef = useCollectionRef();
30
+ const composedRefs = useComposedRefs(forwardedRef, accordionRef, collectionRef);
31
+ const getItems = useCollection();
32
+ const direction = dir ?? 'ltr';
33
+ const isDirectionLTR = direction === 'ltr';
34
+ // Arrow keys move between triggers and wrap around, like Radix; PageUp/PageDown are not handled.
35
+ const handleKeyDown = composeEventHandlers(props.onKeyDown, event => {
36
+ if (!ACCORDION_KEYS.includes(event.key)) {
37
+ return;
38
+ }
39
+ const {
40
+ target
41
+ } = event;
42
+ const triggerCollection = getItems().filter(item => !item.ref.current?.disabled);
43
+ const triggerIndex = triggerCollection.findIndex(item => item.ref.current === target);
44
+ const triggerCount = triggerCollection.length;
45
+ if (triggerIndex === -1) {
46
+ return;
47
+ }
48
+ event.preventDefault();
49
+ let nextIndex = triggerIndex;
50
+ const homeIndex = 0;
51
+ const endIndex = triggerCount - 1;
52
+ const moveNext = () => {
53
+ nextIndex = triggerIndex + 1;
54
+ if (nextIndex > endIndex) {
55
+ nextIndex = homeIndex;
56
+ }
57
+ };
58
+ const movePrev = () => {
59
+ nextIndex = triggerIndex - 1;
60
+ if (nextIndex < homeIndex) {
61
+ nextIndex = endIndex;
62
+ }
63
+ };
64
+ switch (event.key) {
65
+ case 'Home':
66
+ nextIndex = homeIndex;
67
+ break;
68
+ case 'End':
69
+ nextIndex = endIndex;
70
+ break;
71
+ case 'ArrowRight':
72
+ if (orientation === 'horizontal') {
73
+ if (isDirectionLTR) {
74
+ moveNext();
75
+ } else {
76
+ movePrev();
77
+ }
78
+ }
79
+ break;
80
+ case 'ArrowDown':
81
+ if (orientation === 'vertical') {
82
+ moveNext();
83
+ }
84
+ break;
85
+ case 'ArrowLeft':
86
+ if (orientation === 'horizontal') {
87
+ if (isDirectionLTR) {
88
+ movePrev();
89
+ } else {
90
+ moveNext();
91
+ }
92
+ }
93
+ break;
94
+ case 'ArrowUp':
95
+ if (orientation === 'vertical') {
96
+ movePrev();
97
+ }
98
+ break;
99
+ }
100
+ triggerCollection[nextIndex % triggerCount].ref.current?.focus();
101
+ });
102
+ const Comp = asChild ? Slot : 'div';
103
+ return jsx(AccordionImplContext.Provider, {
104
+ value: {
105
+ disabled,
106
+ direction,
107
+ orientation,
108
+ collapsible
109
+ },
110
+ children: jsx(Comp, {
111
+ ...accordionProps,
112
+ ref: composedRefs,
113
+ "data-orientation": orientation,
114
+ onKeyDown: disabled ? undefined : handleKeyDown
115
+ })
116
+ });
117
+ });
118
+ const AccordionSingle = /*#__PURE__*/forwardRef((props, forwardedRef) => {
119
+ const {
120
+ value: valueProp,
121
+ defaultValue,
122
+ onValueChange = () => undefined,
123
+ collapsible = false,
124
+ type: _type,
125
+ ...accordionSingleProps
126
+ } = props;
127
+ const [value, setValue] = useControllableState({
128
+ prop: valueProp,
129
+ defaultProp: defaultValue,
130
+ onChange: onValueChange
131
+ });
132
+ return jsx(AccordionValueContext.Provider, {
133
+ value: {
134
+ value: value ? [value] : [],
135
+ onItemOpen: setValue,
136
+ onItemClose: useCallback(() => collapsible && setValue(''), [collapsible, setValue])
137
+ },
138
+ children: jsx(AccordionImpl, {
139
+ ...accordionSingleProps,
140
+ ref: forwardedRef,
141
+ collapsible: collapsible
142
+ })
143
+ });
144
+ });
145
+ const AccordionMultiple = /*#__PURE__*/forwardRef((props, forwardedRef) => {
146
+ const {
147
+ value: valueProp,
148
+ defaultValue,
149
+ onValueChange = () => undefined,
150
+ type: _type,
151
+ ...multipleProps
152
+ } = props;
153
+ const [value = [], setValue] = useControllableState({
154
+ prop: valueProp,
155
+ defaultProp: defaultValue,
156
+ onChange: onValueChange
157
+ });
158
+ const onItemOpen = useCallback(itemValue => setValue((prevValue = []) => [...prevValue, itemValue]), [setValue]);
159
+ const onItemClose = useCallback(itemValue => setValue((prevValue = []) => prevValue.filter(item => item !== itemValue)), [setValue]);
160
+ return jsx(AccordionValueContext.Provider, {
161
+ value: {
162
+ value,
163
+ onItemOpen,
164
+ onItemClose
165
+ },
166
+ children: jsx(AccordionImpl, {
167
+ ...multipleProps,
168
+ ref: forwardedRef,
169
+ collapsible: true
170
+ })
171
+ });
172
+ });
173
+ /**
174
+ * Accordion with the Radix API, DOM and keyboard model: every trigger is a tab stop, arrow keys move
175
+ * between triggers with wrapping, and Home/End go to the first/last one.
176
+ */
177
+ const Root = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(CollectionProvider, {
178
+ children: props.type === 'multiple' ? jsx(AccordionMultiple, {
179
+ ...props,
180
+ ref: forwardedRef
181
+ }) : jsx(AccordionSingle, {
182
+ ...props,
183
+ ref: forwardedRef
184
+ })
185
+ }));
186
+ Root.displayName = 'Accordion';
187
+ const AccordionItemContext = /*#__PURE__*/createContext(null);
188
+ const useItemContext = () => {
189
+ const context = useContext(AccordionItemContext);
190
+ const implContext = useContext(AccordionImplContext);
191
+ if (!context || !implContext) {
192
+ throw new Error('Accordion parts must be used within Accordion.Item');
193
+ }
194
+ return {
195
+ ...context,
196
+ implContext
197
+ };
198
+ };
199
+ const Item = /*#__PURE__*/forwardRef((props, forwardedRef) => {
200
+ const {
201
+ value,
202
+ ...accordionItemProps
203
+ } = props;
204
+ const implContext = useContext(AccordionImplContext);
205
+ const valueContext = useContext(AccordionValueContext);
206
+ if (!implContext || !valueContext) {
207
+ throw new Error('Accordion.Item must be used within Accordion');
208
+ }
209
+ const triggerId = useId();
210
+ const open = value && valueContext.value.includes(value) || false;
211
+ const disabled = implContext.disabled || props.disabled;
212
+ const {
213
+ onItemOpen,
214
+ onItemClose
215
+ } = valueContext;
216
+ const handleOpenChange = useCallback(nextOpen => {
217
+ if (nextOpen) {
218
+ onItemOpen(value);
219
+ } else {
220
+ onItemClose(value);
221
+ }
222
+ }, [onItemOpen, onItemClose, value]);
223
+ return jsx(AccordionItemContext.Provider, {
224
+ value: {
225
+ open,
226
+ disabled,
227
+ triggerId
228
+ },
229
+ children: jsx(Root$1, {
230
+ "data-orientation": implContext.orientation,
231
+ "data-state": getOpenState(open),
232
+ ...accordionItemProps,
233
+ ref: forwardedRef,
234
+ disabled: disabled,
235
+ open: open,
236
+ onOpenChange: handleOpenChange
237
+ })
238
+ });
239
+ });
240
+ Item.displayName = 'AccordionItem';
241
+ const Header = /*#__PURE__*/forwardRef(({
242
+ asChild,
243
+ ...headerProps
244
+ }, forwardedRef) => {
245
+ const {
246
+ implContext,
247
+ open,
248
+ disabled
249
+ } = useItemContext();
250
+ const Comp = asChild ? Slot : 'h3';
251
+ return jsx(Comp, {
252
+ "data-disabled": disabled ? '' : undefined,
253
+ "data-orientation": implContext.orientation,
254
+ "data-state": getOpenState(open),
255
+ ...headerProps,
256
+ ref: forwardedRef
257
+ });
258
+ });
259
+ Header.displayName = 'AccordionHeader';
260
+ const Trigger = /*#__PURE__*/forwardRef((triggerProps, forwardedRef) => {
261
+ const {
262
+ implContext,
263
+ open,
264
+ triggerId
265
+ } = useItemContext();
266
+ const ref = useRef(null);
267
+ const composedRefs = useComposedRefs(forwardedRef, ref);
268
+ const collectionItemProps = useCollectionItem(ref, {});
269
+ return jsx(Trigger$1, {
270
+ ...collectionItemProps,
271
+ "aria-disabled": open && !implContext.collapsible || undefined,
272
+ "data-orientation": implContext.orientation,
273
+ id: triggerId,
274
+ ...triggerProps,
275
+ ref: composedRefs
276
+ });
277
+ });
278
+ Trigger.displayName = 'AccordionTrigger';
279
+ const Content = /*#__PURE__*/forwardRef((contentProps, forwardedRef) => {
280
+ const {
281
+ implContext,
282
+ triggerId
283
+ } = useItemContext();
284
+ return jsx(Content$1, {
285
+ "aria-labelledby": triggerId,
286
+ "data-orientation": implContext.orientation,
287
+ role: "region",
288
+ ...contentProps,
289
+ ref: forwardedRef,
290
+ style: {
291
+ '--radix-accordion-content-height': 'var(--radix-collapsible-content-height)',
292
+ '--radix-accordion-content-width': 'var(--radix-collapsible-content-width)',
293
+ ...contentProps.style
294
+ }
295
+ });
296
+ });
297
+ Content.displayName = 'AccordionContent';
298
+
299
+ export { Content, Header, Item, Root, Trigger };
@@ -0,0 +1,9 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * Ariakit dialogs only let the `autoFocus` focusables inside them (Blueprint buttons, for example) focus themselves
4
+ * when the dialog moves focus on show. The compat overlays leave that to the Radix focus scope, so their content
5
+ * opts back in, like it was outside Ariakit dialogs with Radix.
6
+ */
7
+ export declare const AllowAutoFocus: ({ children }: {
8
+ children?: ReactNode;
9
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { FocusableContext } from '@ariakit/react-core/focusable/focusable-context';
3
+
4
+ /**
5
+ * Ariakit dialogs only let the `autoFocus` focusables inside them (Blueprint buttons, for example) focus themselves
6
+ * when the dialog moves focus on show. The compat overlays leave that to the Radix focus scope, so their content
7
+ * opts back in, like it was outside Ariakit dialogs with Radix.
8
+ */
9
+ const AllowAutoFocus = ({
10
+ children
11
+ }) => jsx(FocusableContext.Provider, {
12
+ value: true,
13
+ children: children
14
+ });
15
+
16
+ export { AllowAutoFocus };
@@ -0,0 +1,14 @@
1
+ import { type InputHTMLAttributes } from 'react';
2
+ interface BubbleInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'checked'> {
3
+ checked: boolean | 'indeterminate';
4
+ bubbles?: boolean;
5
+ control: HTMLElement | null;
6
+ }
7
+ /**
8
+ * Hidden native input mirroring a custom checkbox, switch or radio inside a `<form>`, so the value is
9
+ * submitted and `change` events reach form libraries, like the Radix bubble input.
10
+ */
11
+ export declare const BubbleInput: ({ control, checked, bubbles, style, ...inputProps }: BubbleInputProps) => import("react/jsx-runtime").JSX.Element;
12
+ /** Whether a custom control lives inside a form, which is when it needs a bubble input. */
13
+ export declare function isFormControl(control: HTMLElement | null): boolean;
14
+ export {};
@@ -0,0 +1,70 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useRef, useEffect } from 'react';
3
+
4
+ function usePrevious(value) {
5
+ const ref = useRef({
6
+ value,
7
+ previous: value
8
+ });
9
+ if (ref.current.value !== value) {
10
+ ref.current.previous = ref.current.value;
11
+ ref.current.value = value;
12
+ }
13
+ return ref.current.previous;
14
+ }
15
+ const hiddenInputStyle = {
16
+ pointerEvents: 'none',
17
+ opacity: 0,
18
+ margin: 0
19
+ };
20
+ /**
21
+ * Hidden native input mirroring a custom checkbox, switch or radio inside a `<form>`, so the value is
22
+ * submitted and `change` events reach form libraries, like the Radix bubble input.
23
+ */
24
+ const BubbleInput = ({
25
+ control,
26
+ checked,
27
+ bubbles = true,
28
+ style,
29
+ ...inputProps
30
+ }) => {
31
+ const ref = useRef(null);
32
+ const prevChecked = usePrevious(checked);
33
+ const width = control?.offsetWidth;
34
+ const height = control?.offsetHeight;
35
+ useEffect(() => {
36
+ const input = ref.current;
37
+ if (!input) {
38
+ return;
39
+ }
40
+ const inputProto = window.HTMLInputElement.prototype;
41
+ const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
42
+ const setChecked = descriptor.set;
43
+ if (prevChecked !== checked && setChecked) {
44
+ const event = new Event('click', {
45
+ bubbles
46
+ });
47
+ input.indeterminate = checked === 'indeterminate';
48
+ setChecked.call(input, checked === 'indeterminate' ? false : checked);
49
+ input.dispatchEvent(event);
50
+ }
51
+ }, [prevChecked, checked, bubbles]);
52
+ return jsx("input", {
53
+ "aria-hidden": true,
54
+ defaultChecked: checked === 'indeterminate' ? false : checked,
55
+ tabIndex: -1,
56
+ type: "checkbox",
57
+ ...inputProps,
58
+ ref: ref,
59
+ style: {
60
+ ...style,
61
+ ...hiddenInputStyle,
62
+ position: 'absolute',
63
+ width,
64
+ height,
65
+ transform: 'translateX(-100%)'
66
+ }
67
+ });
68
+ };
69
+
70
+ export { BubbleInput };
@@ -0,0 +1,9 @@
1
+ import { type ComponentPropsWithoutRef, type ForwardRefExoticComponent, type ReactElement, type RefAttributes } from 'react';
2
+ type ButtonCheckboxProps = Omit<ComponentPropsWithoutRef<'button'>, 'value'> & {
3
+ checked?: boolean | 'mixed';
4
+ clickOnEnter?: boolean;
5
+ render?: ReactElement;
6
+ value?: string;
7
+ };
8
+ export declare const ButtonCheckbox: ForwardRefExoticComponent<ButtonCheckboxProps & RefAttributes<HTMLButtonElement>>;
9
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Checkbox } from '@ariakit/react';
2
+
3
+ // Ariakit types the checkbox for native inputs; the compat primitives render it as a `<button>` element.
4
+ const ButtonCheckbox = Checkbox;
5
+
6
+ export { ButtonCheckbox };
@@ -0,0 +1,18 @@
1
+ import { type PrimitiveProps } from './types';
2
+ export type CheckedState = boolean | 'indeterminate';
3
+ export interface CheckboxProps extends Omit<PrimitiveProps<'button'>, 'checked' | 'defaultChecked'> {
4
+ checked?: CheckedState;
5
+ defaultChecked?: CheckedState;
6
+ required?: boolean;
7
+ onCheckedChange?(checked: CheckedState): void;
8
+ }
9
+ /**
10
+ * Checkbox rendered as a `<button role="checkbox">` with the Radix API and DOM
11
+ * (`data-state`, `data-disabled`, hidden form input), on top of the Ariakit `Checkbox`.
12
+ */
13
+ export declare const Root: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HTMLButtonElement>>;
14
+ export interface CheckboxIndicatorProps extends PrimitiveProps<'span'> {
15
+ /** Keeps the indicator mounted when unchecked, for styling or animations. */
16
+ forceMount?: true;
17
+ }
18
+ export declare const Indicator: import("react").ForwardRefExoticComponent<CheckboxIndicatorProps & import("react").RefAttributes<HTMLSpanElement>>;
@@ -0,0 +1,131 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState, useRef, useEffect, useContext, createContext } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useControllableState } from '../useControllableState.js';
5
+ import { BubbleInput } from './bubble-input.js';
6
+ import { ButtonCheckbox } from './button-controls.js';
7
+ import { useComposedRefs } from './compose-refs.js';
8
+ import { Presence } from './presence.js';
9
+ import { Slot } from './slot.js';
10
+
11
+ function isIndeterminate(checked) {
12
+ return checked === 'indeterminate';
13
+ }
14
+ function getState(checked) {
15
+ if (isIndeterminate(checked)) {
16
+ return 'indeterminate';
17
+ }
18
+ return checked ? 'checked' : 'unchecked';
19
+ }
20
+ const CheckboxContext = /*#__PURE__*/createContext({
21
+ state: false
22
+ });
23
+ /**
24
+ * Checkbox rendered as a `<button role="checkbox">` with the Radix API and DOM
25
+ * (`data-state`, `data-disabled`, hidden form input), on top of the Ariakit `Checkbox`.
26
+ */
27
+ const Root = /*#__PURE__*/forwardRef((props, forwardedRef) => {
28
+ const {
29
+ name,
30
+ checked: checkedProp,
31
+ defaultChecked,
32
+ required,
33
+ disabled,
34
+ value = 'on',
35
+ onCheckedChange,
36
+ asChild,
37
+ ...checkboxProps
38
+ } = props;
39
+ const [button, setButton] = useState(null);
40
+ const composedRefs = useComposedRefs(forwardedRef, setButton);
41
+ const hasConsumerStoppedPropagationRef = useRef(false);
42
+ // Only a checkbox inside a form needs the hidden input. Until the button mounts it renders, like in Radix.
43
+ const isFormControl = button ? Boolean(button.closest('form')) : true;
44
+ const [checked = false, setChecked] = useControllableState({
45
+ prop: checkedProp,
46
+ defaultProp: defaultChecked,
47
+ onChange: onCheckedChange
48
+ });
49
+ const initialCheckedStateRef = useRef(checked);
50
+ useEffect(() => {
51
+ const form = button?.form;
52
+ if (!form) {
53
+ return undefined;
54
+ }
55
+ const reset = () => setChecked(initialCheckedStateRef.current);
56
+ form.addEventListener('reset', reset);
57
+ return () => form.removeEventListener('reset', reset);
58
+ }, [button, setChecked]);
59
+ return jsxs(CheckboxContext.Provider, {
60
+ value: {
61
+ state: checked,
62
+ disabled
63
+ },
64
+ children: [jsx(ButtonCheckbox, {
65
+ "aria-required": required,
66
+ checked: isIndeterminate(checked) ? 'mixed' : checked,
67
+ clickOnEnter: false,
68
+ "data-disabled": disabled ? '' : undefined,
69
+ "data-state": getState(checked),
70
+ ...checkboxProps,
71
+ ref: composedRefs,
72
+ // Radix ignores Enter on checkboxes, as per WAI-ARIA.
73
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
74
+ if (event.key === 'Enter') {
75
+ event.preventDefault();
76
+ }
77
+ }),
78
+ onClick: composeEventHandlers(props.onClick, event => {
79
+ setChecked(prevChecked => isIndeterminate(prevChecked) ? true : !prevChecked);
80
+ if (isFormControl) {
81
+ hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
82
+ // Inside a form only the hidden input propagates the click, so form events reflect the change.
83
+ if (!hasConsumerStoppedPropagationRef.current) {
84
+ event.stopPropagation();
85
+ }
86
+ }
87
+ }),
88
+ // Ariakit would also make a disabled checkbox `aria-disabled` and ignore pointer events, unlike Radix.
89
+ render: asChild ? jsx(Slot, {
90
+ disabled: disabled
91
+ }) : jsx("button", {
92
+ disabled: disabled,
93
+ type: "button",
94
+ value: value
95
+ })
96
+ }), isFormControl && jsx(BubbleInput, {
97
+ bubbles: !hasConsumerStoppedPropagationRef.current,
98
+ checked: checked,
99
+ control: button,
100
+ disabled: disabled,
101
+ name: name,
102
+ required: required,
103
+ value: value
104
+ })]
105
+ });
106
+ });
107
+ Root.displayName = 'Checkbox';
108
+ const Indicator = /*#__PURE__*/forwardRef(({
109
+ forceMount,
110
+ asChild,
111
+ ...indicatorProps
112
+ }, forwardedRef) => {
113
+ const context = useContext(CheckboxContext);
114
+ const Comp = asChild ? Slot : 'span';
115
+ return jsx(Presence, {
116
+ present: Boolean(forceMount) || isIndeterminate(context.state) || context.state === true,
117
+ children: jsx(Comp, {
118
+ "data-disabled": context.disabled ? '' : undefined,
119
+ "data-state": getState(context.state),
120
+ ...indicatorProps,
121
+ ref: forwardedRef,
122
+ style: {
123
+ pointerEvents: 'none',
124
+ ...indicatorProps.style
125
+ }
126
+ })
127
+ });
128
+ });
129
+ Indicator.displayName = 'CheckboxIndicator';
130
+
131
+ export { Indicator, Root };
@@ -0,0 +1,33 @@
1
+ import { useDisclosureStore } from '@ariakit/react';
2
+ import { type ReactNode } from 'react';
3
+ import { type PrimitiveProps } from './types';
4
+ export declare const getOpenState: (open?: boolean) => "open" | "closed";
5
+ interface CollapsibleContextValue {
6
+ contentId: string;
7
+ disabled?: boolean;
8
+ open: boolean;
9
+ onOpenToggle(): void;
10
+ store: ReturnType<typeof useDisclosureStore>;
11
+ }
12
+ declare const useCollapsibleContext: () => CollapsibleContextValue;
13
+ export interface CollapsibleProps extends PrimitiveProps<'div'> {
14
+ defaultOpen?: boolean;
15
+ open?: boolean;
16
+ disabled?: boolean;
17
+ onOpenChange?(open: boolean): void;
18
+ }
19
+ /**
20
+ * Collapsible section with the Radix API and DOM (`data-state`, size CSS variables, content unmounted
21
+ * after its exit animation), with its state in an Ariakit disclosure store.
22
+ */
23
+ export declare const Root: import("react").ForwardRefExoticComponent<CollapsibleProps & import("react").RefAttributes<HTMLDivElement>>;
24
+ export type CollapsibleTriggerProps = PrimitiveProps<'button'>;
25
+ export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
26
+ asChild?: boolean;
27
+ } & import("react").RefAttributes<HTMLButtonElement>>;
28
+ export interface CollapsibleContentProps extends PrimitiveProps<'div'> {
29
+ forceMount?: true;
30
+ children?: ReactNode;
31
+ }
32
+ export declare const Content: import("react").ForwardRefExoticComponent<CollapsibleContentProps & import("react").RefAttributes<HTMLDivElement>>;
33
+ export { useCollapsibleContext };