@box-kite/react 0.0.1 → 2.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 (280) hide show
  1. package/.claude/rules/box-kite-rules.md +65 -0
  2. package/.claude/skills/box-kite/SKILL.md +138 -0
  3. package/.claude/skills/box-kite/references/components.md +235 -0
  4. package/.claude/skills/box-kite/references/extending.md +42 -0
  5. package/.claude/skills/box-kite/references/patterns.md +27 -0
  6. package/.claude/skills/box-kite/references/styling.md +222 -0
  7. package/.cursor/rules/box-kite.mdc +73 -0
  8. package/AGENTS.md +102 -0
  9. package/BOX_AI_CONTEXT.md +2804 -0
  10. package/BOX_KITE_AI_CONTEXT.md +2804 -0
  11. package/LICENSE +21 -0
  12. package/README.md +744 -7
  13. package/a11y.cjs +1 -0
  14. package/a11y.d.ts +15 -0
  15. package/a11y.mjs +4 -0
  16. package/anchor.cjs +1 -0
  17. package/anchor.d.ts +14 -0
  18. package/anchor.mjs +3 -0
  19. package/behavior.cjs +1 -0
  20. package/behavior.mjs +277 -0
  21. package/box.cjs +1 -0
  22. package/box.d.ts +46 -0
  23. package/box.mjs +23 -0
  24. package/client.cjs +1 -0
  25. package/client.mjs +164 -0
  26. package/components/accordion.cjs +1 -0
  27. package/components/accordion.d.ts +114 -0
  28. package/components/accordion.mjs +251 -0
  29. package/components/baseSvg.cjs +1 -0
  30. package/components/baseSvg.d.ts +5 -0
  31. package/components/baseSvg.mjs +21 -0
  32. package/components/button.cjs +1 -0
  33. package/components/button.d.ts +19 -0
  34. package/components/button.mjs +19 -0
  35. package/components/chart.cjs +1 -0
  36. package/components/chart.d.ts +83 -0
  37. package/components/chart.mjs +236 -0
  38. package/components/checkbox.cjs +1 -0
  39. package/components/checkbox.d.ts +36 -0
  40. package/components/checkbox.mjs +38 -0
  41. package/components/combobox/comboboxChips.d.ts +21 -0
  42. package/components/combobox/comboboxListbox.d.ts +47 -0
  43. package/components/combobox.cjs +1 -0
  44. package/components/combobox.d.ts +121 -0
  45. package/components/combobox.mjs +563 -0
  46. package/components/dataGrid/components/dataGridAggregateValue.d.ts +10 -0
  47. package/components/dataGrid/components/dataGridBody.d.ts +7 -0
  48. package/components/dataGrid/components/dataGridBottomBar.d.ts +6 -0
  49. package/components/dataGrid/components/dataGridCell.d.ts +16 -0
  50. package/components/dataGrid/components/dataGridCellEditor.d.ts +15 -0
  51. package/components/dataGrid/components/dataGridCellPlaceholder.d.ts +14 -0
  52. package/components/dataGrid/components/dataGridCellRowDetail.d.ts +6 -0
  53. package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
  54. package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
  55. package/components/dataGrid/components/dataGridCellTree.d.ts +16 -0
  56. package/components/dataGrid/components/dataGridColumnFilter.d.ts +9 -0
  57. package/components/dataGrid/components/dataGridColumnGroups.d.ts +7 -0
  58. package/components/dataGrid/components/dataGridContent.d.ts +6 -0
  59. package/components/dataGrid/components/dataGridDataSourceError.d.ts +12 -0
  60. package/components/dataGrid/components/dataGridDetailRow.d.ts +8 -0
  61. package/components/dataGrid/components/dataGridEmptyColumns.d.ts +6 -0
  62. package/components/dataGrid/components/dataGridExport.d.ts +10 -0
  63. package/components/dataGrid/components/dataGridFilterCell.d.ts +11 -0
  64. package/components/dataGrid/components/dataGridFilterRow.d.ts +6 -0
  65. package/components/dataGrid/components/dataGridFooter.d.ts +11 -0
  66. package/components/dataGrid/components/dataGridGlobalFilter.d.ts +6 -0
  67. package/components/dataGrid/components/dataGridGroupRow.d.ts +8 -0
  68. package/components/dataGrid/components/dataGridHeader.d.ts +6 -0
  69. package/components/dataGrid/components/dataGridHeaderCell.d.ts +9 -0
  70. package/components/dataGrid/components/dataGridHeaderCellContextMenu.d.ts +11 -0
  71. package/components/dataGrid/components/dataGridHeaderCellResizer.d.ts +14 -0
  72. package/components/dataGrid/components/dataGridLoader.d.ts +11 -0
  73. package/components/dataGrid/components/dataGridPagination.d.ts +6 -0
  74. package/components/dataGrid/components/dataGridRow.d.ts +8 -0
  75. package/components/dataGrid/components/dataGridTopBar.d.ts +6 -0
  76. package/components/dataGrid/components/dataGridTopBarContextMenu.d.ts +6 -0
  77. package/components/dataGrid/contracts/dataGridContract.d.ts +671 -0
  78. package/components/dataGrid/export/gridExport.d.ts +10 -0
  79. package/components/dataGrid/gridNavigationContext.d.ts +32 -0
  80. package/components/dataGrid/models/aggregateCellModel.d.ts +34 -0
  81. package/components/dataGrid/models/aggregationModel.d.ts +32 -0
  82. package/components/dataGrid/models/cellKeys.d.ts +11 -0
  83. package/components/dataGrid/models/cellModel.d.ts +44 -0
  84. package/components/dataGrid/models/columnModel.d.ts +160 -0
  85. package/components/dataGrid/models/columnVisibilityModel.d.ts +24 -0
  86. package/components/dataGrid/models/dataSourceModel.d.ts +177 -0
  87. package/components/dataGrid/models/detailRowModel.d.ts +22 -0
  88. package/components/dataGrid/models/editModel.d.ts +77 -0
  89. package/components/dataGrid/models/exportModel.d.ts +51 -0
  90. package/components/dataGrid/models/filterModel.d.ts +22 -0
  91. package/components/dataGrid/models/gridModel.d.ts +293 -0
  92. package/components/dataGrid/models/groupRowCellModel.d.ts +34 -0
  93. package/components/dataGrid/models/groupRowModel.d.ts +68 -0
  94. package/components/dataGrid/models/headerCellModel.d.ts +83 -0
  95. package/components/dataGrid/models/paginationModel.d.ts +32 -0
  96. package/components/dataGrid/models/rowModel.d.ts +46 -0
  97. package/components/dataGrid/models/sourceGroupRowModel.d.ts +45 -0
  98. package/components/dataGrid/models/sourceLevel.d.ts +71 -0
  99. package/components/dataGrid/models/sourceRowModel.d.ts +29 -0
  100. package/components/dataGrid/models/sourceTreeRowModel.d.ts +23 -0
  101. package/components/dataGrid/models/treeModel.d.ts +94 -0
  102. package/components/dataGrid/models/treeRow.d.ts +22 -0
  103. package/components/dataGrid/models/treeRowModel.d.ts +50 -0
  104. package/components/dataGrid/models/viewportModel.d.ts +44 -0
  105. package/components/dataGrid/useGrid.d.ts +8 -0
  106. package/components/dataGrid/useGridNavigation.d.ts +21 -0
  107. package/components/dataGrid.cjs +1 -0
  108. package/components/dataGrid.d.ts +4 -0
  109. package/components/dataGrid.mjs +4907 -0
  110. package/components/dialog.cjs +1 -0
  111. package/components/dialog.d.ts +151 -0
  112. package/components/dialog.mjs +223 -0
  113. package/components/dropdown/dropdownContext.d.ts +44 -0
  114. package/components/dropdown/dropdownItems.d.ts +22 -0
  115. package/components/dropdown/dropdownRowRenderer.d.ts +8 -0
  116. package/components/dropdown/dropdownSearch.d.ts +21 -0
  117. package/components/dropdown/utils.d.ts +1 -0
  118. package/components/dropdown.cjs +1 -0
  119. package/components/dropdown.d.ts +77 -0
  120. package/components/dropdown.mjs +491 -0
  121. package/components/flex.cjs +1 -0
  122. package/components/flex.d.ts +6 -0
  123. package/components/flex.mjs +16 -0
  124. package/components/form.cjs +1 -0
  125. package/components/form.d.ts +10 -0
  126. package/components/form.mjs +58 -0
  127. package/components/grid.cjs +1 -0
  128. package/components/grid.d.ts +6 -0
  129. package/components/grid.mjs +16 -0
  130. package/components/icon.cjs +1 -0
  131. package/components/icon.d.ts +37 -0
  132. package/components/icon.mjs +41 -0
  133. package/components/menu.cjs +1 -0
  134. package/components/menu.d.ts +234 -0
  135. package/components/menu.mjs +422 -0
  136. package/components/overlay.cjs +1 -0
  137. package/components/overlay.d.ts +47 -0
  138. package/components/overlay.mjs +52 -0
  139. package/components/popover.cjs +1 -0
  140. package/components/popover.d.ts +100 -0
  141. package/components/popover.mjs +69 -0
  142. package/components/presence.cjs +1 -0
  143. package/components/presence.d.ts +36 -0
  144. package/components/presence.mjs +11 -0
  145. package/components/progress.cjs +1 -0
  146. package/components/progress.d.ts +47 -0
  147. package/components/progress.mjs +28 -0
  148. package/components/radioButton.cjs +1 -0
  149. package/components/radioButton.d.ts +32 -0
  150. package/components/radioButton.mjs +32 -0
  151. package/components/radioGroup.cjs +1 -0
  152. package/components/radioGroup.d.ts +51 -0
  153. package/components/radioGroup.mjs +83 -0
  154. package/components/select.cjs +1 -0
  155. package/components/select.d.ts +51 -0
  156. package/components/select.mjs +36 -0
  157. package/components/semantics.cjs +1 -0
  158. package/components/semantics.d.ts +39 -0
  159. package/components/semantics.mjs +17 -0
  160. package/components/slider.cjs +1 -0
  161. package/components/slider.d.ts +98 -0
  162. package/components/slider.mjs +250 -0
  163. package/components/svg.cjs +1 -0
  164. package/components/svg.d.ts +65 -0
  165. package/components/svg.mjs +141 -0
  166. package/components/switch.cjs +1 -0
  167. package/components/switch.d.ts +29 -0
  168. package/components/switch.mjs +25 -0
  169. package/components/tabs.cjs +1 -0
  170. package/components/tabs.d.ts +87 -0
  171. package/components/tabs.mjs +324 -0
  172. package/components/textarea.cjs +1 -0
  173. package/components/textarea.d.ts +41 -0
  174. package/components/textarea.mjs +33 -0
  175. package/components/textbox.cjs +1 -0
  176. package/components/textbox.d.ts +38 -0
  177. package/components/textbox.mjs +33 -0
  178. package/components/toaster.cjs +1 -0
  179. package/components/toaster.d.ts +106 -0
  180. package/components/toaster.mjs +295 -0
  181. package/components/tooltip.cjs +1 -0
  182. package/components/tooltip.d.ts +98 -0
  183. package/components/tooltip.mjs +110 -0
  184. package/components/visuallyHidden.cjs +1 -0
  185. package/components/visuallyHidden.d.ts +6 -0
  186. package/components/visuallyHidden.mjs +23 -0
  187. package/docs/a11y.md +199 -0
  188. package/docs/anchor.md +139 -0
  189. package/docs/components.md +48 -0
  190. package/docs/index.md +11 -0
  191. package/docs/props.md +1777 -0
  192. package/effects.cjs +1 -0
  193. package/effects.mjs +6 -0
  194. package/forms.cjs +1 -0
  195. package/forms.mjs +21 -0
  196. package/gridExport.cjs +2 -0
  197. package/gridExport.mjs +244 -0
  198. package/icons/dotsIcon.d.ts +2 -0
  199. package/icons/expandIcon.d.ts +2 -0
  200. package/icons/groupingIcon.d.ts +2 -0
  201. package/icons/pinIcon.d.ts +2 -0
  202. package/icons/searchIcon.d.ts +2 -0
  203. package/icons/sortIcon.d.ts +2 -0
  204. package/identity.cjs +1 -0
  205. package/identity.mjs +12 -0
  206. package/keyboard.cjs +1 -0
  207. package/keyboard.mjs +30 -0
  208. package/layer.cjs +1 -0
  209. package/layer.mjs +127 -0
  210. package/motion.cjs +1 -0
  211. package/motion.mjs +66 -0
  212. package/package.json +327 -7
  213. package/placement.cjs +1 -0
  214. package/placement.mjs +180 -0
  215. package/platform.cjs +1 -0
  216. package/platform.mjs +45 -0
  217. package/react/a11y/callbacks.d.ts +12 -0
  218. package/react/a11y/useControllableState.d.ts +25 -0
  219. package/react/a11y/useDismiss.d.ts +25 -0
  220. package/react/a11y/useFocusReturn.d.ts +18 -0
  221. package/react/a11y/useRovingFocus.d.ts +84 -0
  222. package/react/anchor/useAnchorPosition.d.ts +79 -0
  223. package/react/animation/usePresence.d.ts +32 -0
  224. package/react/boxClassNames.d.ts +25 -0
  225. package/react/boxProps.d.ts +49 -0
  226. package/react/boxTagProps.d.ts +7 -0
  227. package/react/clientRuntime.d.ts +11 -0
  228. package/react/dialog/useScrollLock.d.ts +12 -0
  229. package/react/effects.d.ts +10 -0
  230. package/react/forms/labelledControl.d.ts +17 -0
  231. package/react/forms/placeholderProp.d.ts +13 -0
  232. package/react/hooks/usePortalContainer.d.ts +6 -0
  233. package/react/hooks/useVirtualization.d.ts +32 -0
  234. package/react/hooks/useVisibility.d.ts +9 -0
  235. package/react/identity/useIdentifier.d.ts +17 -0
  236. package/react/popover/usePopoverLayer.d.ts +87 -0
  237. package/react/reactTypes.d.ts +10 -0
  238. package/react/resolveStyles.d.ts +18 -0
  239. package/react/styleElements.d.ts +3 -0
  240. package/react/svg/attributesInProps.d.ts +4 -0
  241. package/react/svg/svgNaming.d.ts +15 -0
  242. package/react/theme/theme.d.ts +26 -0
  243. package/react/theme/themeContext.d.ts +7 -0
  244. package/react/useStyles.d.ts +22 -0
  245. package/react-shared.cjs +1 -0
  246. package/react-shared.mjs +122 -0
  247. package/rolldown-runtime.cjs +1 -0
  248. package/rsc.cjs +1 -0
  249. package/rsc.d.ts +27 -0
  250. package/rsc.mjs +18 -0
  251. package/ssg.cjs +1 -0
  252. package/ssg.d.ts +24 -0
  253. package/ssg.mjs +25 -0
  254. package/utils/accordion/accordionUtils.d.ts +48 -0
  255. package/utils/anchor/anchorUtils.d.ts +79 -0
  256. package/utils/animation/animationUtils.d.ts +29 -0
  257. package/utils/array/arrayUtils.d.ts +15 -0
  258. package/utils/array/lazyList.d.ts +10 -0
  259. package/utils/box/boxUtils.d.ts +5 -0
  260. package/utils/chart/chartPalette.d.ts +15 -0
  261. package/utils/chart/chartUtils.d.ts +92 -0
  262. package/utils/combobox/comboboxUtils.d.ts +89 -0
  263. package/utils/dom/domUtils.d.ts +32 -0
  264. package/utils/environment/environmentUtils.d.ts +28 -0
  265. package/utils/export/csvUtils.d.ts +23 -0
  266. package/utils/export/downloadUtils.d.ts +12 -0
  267. package/utils/export/xlsxUtils.d.ts +56 -0
  268. package/utils/export/zipUtils.d.ts +26 -0
  269. package/utils/fn/fnUtils.d.ts +4 -0
  270. package/utils/form/formUtils.d.ts +8 -0
  271. package/utils/keyboard/typeaheadUtils.d.ts +31 -0
  272. package/utils/memo.d.ts +10 -0
  273. package/utils/menu/menuUtils.d.ts +25 -0
  274. package/utils/object/objectUtils.d.ts +13 -0
  275. package/utils/slider/sliderUtils.d.ts +67 -0
  276. package/utils/string/fuzzySearch.d.ts +27 -0
  277. package/utils/string/stringUtils.d.ts +4 -0
  278. package/utils/tabs/tabsUtils.d.ts +75 -0
  279. package/utils/toast/toastStore.d.ts +73 -0
  280. package/utils/virtual/virtualUtils.d.ts +47 -0
@@ -0,0 +1 @@
1
+ "use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../client.cjs"),n=require("../effects.cjs"),r=require("../box.cjs"),i=require("../behavior.cjs"),a=require("../identity.cjs"),o=require("./semantics.cjs");let s=require("react"),c=require("react/jsx-runtime");var l=0;function u(r){let{classNames:i,styleElements:a}=t.i({overflow:`hidden`},!1),o=i.slice(1).join(` `);return n.n(()=>{let t=e.n();if(!(!r||!t||!o))return l+=1,t.classList.add(o),()=>{--l,l===0&&t.classList.remove(o)}},[r,o]),a}var d=(0,s.createContext)(null);function f(e){let t=(0,s.useContext)(d);if(!t)throw Error(`<${e}> must be rendered inside a <Dialog>.`);return t}function p(e){return(0,c.jsx)(h,{role:`dialog`,...e})}function m(e){return(0,c.jsx)(h,{role:`alertdialog`,...e,modal:!0,dismissible:!1})}function h(t){let{role:o,trigger:l,children:f,open:p,defaultOpen:m=!1,onOpenChange:h,label:_,labelledBy:v,describedBy:y,modal:b=!0,dismissible:x=!0,lockScroll:S=b,initialFocus:C,props:w,...T}=t,E=a.t(`dialog`),D=T.id??E,[O,k]=i.i({value:p,defaultValue:m,onChange:h}),[A,j]=(0,s.useState)(null),[M,N]=(0,s.useState)(null),[P,F]=(0,s.useState)(!1),[I,L]=(0,s.useState)({title:0,description:0}),R=u(O&&S);i.n({enabled:O,returnTo:M});let z=(0,s.useCallback)(e=>(L(t=>({...t,[e]:t[e]+1})),()=>L(t=>({...t,[e]:t[e]-1}))),[]),B=(0,s.useMemo)(()=>({titleId:`${D}-title`,descriptionId:`${D}-description`,register:z}),[D,z]);g({dialog:A,isOpen:O,domOpen:P,setDomOpen:F,setOpen:k,modal:b,dismissible:x,triggerElement:M}),n.n(()=>{let t=e.c(C);!O||!t||t.focus()},[O,C]);let V=i.a(e=>{k(e=>!e,{reason:`trigger`,event:e})}),H=(0,s.useMemo)(()=>({ref:N,props:{"aria-expanded":O,"aria-haspopup":`dialog`,"aria-controls":O?D:void 0,onClick:V}}),[D,V,O]),U=T;return(0,c.jsxs)(c.Fragment,{children:[R,l?.(H),(0,c.jsx)(d.Provider,{value:B,children:(0,c.jsx)(r.default,{ref:j,tag:`dialog`,component:`dialog`,...U,id:D,props:{role:o,"aria-label":I.title||v?void 0:_,"aria-labelledby":v??(I.title?B.titleId:void 0),"aria-describedby":y??(I.description?B.descriptionId:void 0),...w},children:f})})]})}function g(t){let{dialog:r,isOpen:a,domOpen:o,setDomOpen:c,setOpen:l,modal:u,dismissible:d,triggerElement:f}=t,p=(0,s.useRef)(`imperative`),m=e.i(),h=d?`any`:`closerequest`;n.n(()=>{!r||a===o||(c(a),a?u?r.showModal():r.show():r.close())},[r,a,o,u,c]),n.n(()=>{if(!r)return;let e=new AbortController;return r.addEventListener(`close`,e=>{c(!1),l(!1,{reason:p.current,event:e}),p.current=`imperative`},{signal:e.signal}),()=>e.abort()},[r,c,l]),n.n(()=>{if(!(!r||!m))return r.setAttribute(`closedby`,h),()=>r.removeAttribute(`closedby`)},[r,m,h]),n.n(()=>{if(!a||!r)return;let t=new AbortController,n=(e,n)=>document.addEventListener(e,n,{signal:t.signal,capture:!0});return n(`keydown`,e=>{e.key===`Escape`&&(p.current=`escape`)}),n(`pointerdown`,t=>{e.l(t,[f])?p.current=`trigger`:!e.l(t,[r])||_(r,t)?p.current=`outside-pointer`:p.current=`imperative`}),()=>t.abort()},[a,r,f]),i.r({enabled:a&&!u&&!m,inside:[r],escapeKey:!0,outsidePointer:!1,onDismiss:(e,t)=>l(!1,{reason:`escape`,event:t})}),n.n(()=>{if(!r||!a||!d||m)return;let t=new AbortController;return document.addEventListener(`pointerdown`,t=>{e.l(t,[f])||e.l(t,[r])&&!_(r,t)||l(!1,{reason:`outside-pointer`,event:t})},{signal:t.signal,capture:!0}),()=>t.abort()},[r,a,d,m,f,l])}function _(e,t){let n=e.getBoundingClientRect();return t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom}function v(e){let t=f(`Dialog.Title`);return n.n(()=>t.register(`title`),[t]),(0,c.jsx)(o.H2,{id:t.titleId,component:`dialog.title`,...e})}function y(e){let t=f(`Dialog.Description`);return n.n(()=>t.register(`description`),[t]),(0,c.jsx)(o.P,{id:t.descriptionId,component:`dialog.description`,...e})}v.displayName=`Dialog.Title`,y.displayName=`Dialog.Description`;var b={Title:v,Description:y},x=Object.assign(p,b),S=Object.assign(m,b);p.displayName=`Dialog`,m.displayName=`AlertDialog`,exports.AlertDialog=S,exports.default=x;
@@ -0,0 +1,151 @@
1
+ import { BoxProps } from '../box';
2
+ import { ChangeHandler } from '../react/a11y/useControllableState';
3
+ import { ComponentsAndVariants } from '@box-kite/core/types';
4
+ import { ElementLike } from '../utils/dom/domUtils';
5
+ /** Why the dialog opened or closed — `onOpenChange` gets this alongside the event that did it. */
6
+ export type DialogReason = 'trigger' | 'escape' | 'outside-pointer' | 'imperative';
7
+ /** The DOM attributes the trigger has to carry. */
8
+ export interface DialogTriggerAttributes {
9
+ 'aria-expanded': boolean;
10
+ 'aria-haspopup': 'dialog';
11
+ 'aria-controls'?: string;
12
+ onClick(event: React.MouseEvent): void;
13
+ }
14
+ /**
15
+ * What the trigger has to carry: spread it onto the control itself, not a wrapper. The `ref` is what
16
+ * focus returns to when the dialog closes, so it is not optional decoration.
17
+ *
18
+ * ```tsx
19
+ * {(trigger) => <Button {...trigger}>Edit</Button>} // a Box component
20
+ * {(trigger) => <button ref={trigger.ref} {...trigger.props}>} // a plain element
21
+ * ```
22
+ */
23
+ export interface DialogTrigger {
24
+ ref: React.RefCallback<HTMLElement>;
25
+ props: DialogTriggerAttributes;
26
+ }
27
+ type DialogBoxProps<TKey extends keyof ComponentsAndVariants> = Omit<BoxProps<'dialog', TKey>, 'open'>;
28
+ export interface DialogProps<TKey extends keyof ComponentsAndVariants = 'dialog'> extends DialogBoxProps<TKey> {
29
+ /** The control that opens it, handed the ref and props that wire it up. Leave it out to open the dialog from anywhere else. */
30
+ trigger?: (trigger: DialogTrigger) => React.ReactNode;
31
+ /** The dialog's content — a `Dialog.Title`, usually a `Dialog.Description`, and the controls. */
32
+ children?: React.ReactNode;
33
+ /** Controlled open state. Leave it out and the dialog owns it. */
34
+ open?: boolean;
35
+ /** Whether it starts open, when the dialog owns its own state. */
36
+ defaultOpen?: boolean;
37
+ /**
38
+ * Fires with the new state and why it changed — `'trigger'`, `'escape'`, `'outside-pointer'` or
39
+ * `'imperative'`. A close cannot be refused: the browser has already done it by the time this runs.
40
+ */
41
+ onOpenChange?: ChangeHandler<boolean, DialogReason>;
42
+ /** The dialog's accessible name, when no `Dialog.Title` supplies one. A dialog without a name is unusable. */
43
+ label?: string;
44
+ /** Names the dialog after an element already on the page, instead of `label` or a `Dialog.Title`. */
45
+ labelledBy?: string;
46
+ /** Describes it from an element already on the page, instead of a `Dialog.Description`. */
47
+ describedBy?: string;
48
+ /**
49
+ * Whether the rest of the page is blocked while it is open. Default `true`, which is `showModal()`: the
50
+ * top layer, a `::backdrop`, an inert page, Escape and focus containment, all the browser's.
51
+ */
52
+ modal?: boolean;
53
+ /** Whether a press outside closes it. Default `true` — `false` is what makes a decision unavoidable. */
54
+ dismissible?: boolean;
55
+ /**
56
+ * Whether the page behind it stops scrolling. Default: whatever `modal` is, because a modal dialog that
57
+ * scrolls the page behind it is the commonest complaint about every library that blocks it unasked.
58
+ */
59
+ lockScroll?: boolean;
60
+ /**
61
+ * Where focus lands on open, instead of the first focusable thing inside. An **alert dialog owes this to
62
+ * its least destructive action** — APG's rule, so that a keyboard user cannot confirm a deletion by
63
+ * reflex. An `autofocus` attribute inside does the same job with no ref.
64
+ */
65
+ initialFocus?: ElementLike;
66
+ }
67
+ /** Everything an alert dialog does not get to choose: it is modal, and a decision cannot be dismissed. */
68
+ export type AlertDialogProps<TKey extends keyof ComponentsAndVariants = 'dialog'> = Omit<DialogProps<TKey>, 'modal' | 'dismissible' | 'lockScroll'>;
69
+ /** Every Box prop, on an `<h2>` — `tag` takes any of the six headings instead. */
70
+ export type DialogTitleProps<TKey extends keyof ComponentsAndVariants = 'dialog.title'> = BoxProps<'h2', TKey>;
71
+ /** Every Box prop, on a `<p>`. */
72
+ export type DialogDescriptionProps<TKey extends keyof ComponentsAndVariants = 'dialog.description'> = BoxProps<'p', TKey>;
73
+ /**
74
+ * A modal dialog on the platform's own `<dialog>`: `showModal()` supplies the top layer, the
75
+ * `::backdrop`, an inert page behind it, Escape, focus containment and focus return — so none of that is
76
+ * written here.
77
+ *
78
+ * ```tsx
79
+ * <Dialog trigger={(t) => <Button {...t}>Rename</Button>}>
80
+ * <Dialog.Title>Rename this view</Dialog.Title>
81
+ * <Textbox label="Name" />
82
+ * </Dialog>
83
+ * ```
84
+ *
85
+ * **The dialog is always rendered**, and closed means `display: none` — the same shape as `<Popover>`, and
86
+ * what lets the browser own show and hide. The exit is therefore a plain CSS transition rather than a
87
+ * `<Presence>`, since nothing unmounts; content that is expensive to render should be gated by the
88
+ * consumer with `{open && <Heavy />}`.
89
+ *
90
+ * **A close cannot be refused.** The `cancel` event is cancelable, but by the time `onOpenChange` runs the
91
+ * browser has closed the dialog, so a controlled `<Dialog open>` hears about a dismissal afterwards and
92
+ * keeping `open` true re-shows it. Say `dismissible={false}` to make a decision unavoidable instead, which
93
+ * is what `<AlertDialog>` does.
94
+ *
95
+ * **Nothing is portalled**, so the theme, the custom properties, the text direction and the tab order
96
+ * around the declaration all reach inside — a top-layer element inherits normally (measured in Chrome
97
+ * 152, with a local `Box.Theme` wrapper around the dialog).
98
+ *
99
+ * A non-modal dialog (`modal={false}`) is `show()`: no top layer, no backdrop, nothing inert, and the UA
100
+ * positions it against its containing block rather than the viewport. It is the right shape for a
101
+ * persistent panel; for one anchored to a trigger, reach for `<Popover>`.
102
+ *
103
+ * @a11y `role="dialog"` (`alertdialog` on `<AlertDialog>`), named by a `Dialog.Title`, `label` or
104
+ * `labelledBy`, and described by a `Dialog.Description` or `describedBy`.
105
+ * @a11y The trigger carries `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`.
106
+ * @a11y Focus is contained while a modal dialog is open and returns to the trigger when it closes, both
107
+ * from the platform. `initialFocus` is what an alert dialog needs to land on its least destructive action.
108
+ * @keyboard Escape — Closes it, from anywhere inside, and returns focus to the trigger.
109
+ * @keyboard Tab — Cycles focus inside a modal dialog and never leaves it; in a non-modal one it moves on.
110
+ * @keyboard Enter, Space — On the trigger, opens the dialog.
111
+ */
112
+ declare function DialogImpl<TKey extends keyof ComponentsAndVariants = 'dialog'>(props: DialogProps<TKey>): import("react").JSX.Element;
113
+ /**
114
+ * A dialog that interrupts to ask something: `role="alertdialog"`, always modal, and **never dismissed by
115
+ * a press outside**, because a decision that can be clicked away is one the user did not make.
116
+ *
117
+ * ```tsx
118
+ * <AlertDialog trigger={(t) => <Button {...t}>Delete</Button>} initialFocus={cancelRef}>
119
+ * <AlertDialog.Title>Delete this view?</AlertDialog.Title>
120
+ * <AlertDialog.Description>Nothing here can be undone.</AlertDialog.Description>
121
+ * <Button ref={cancelRef}>Cancel</Button>
122
+ * </AlertDialog>
123
+ * ```
124
+ *
125
+ * Escape still closes it — a keyboard user must always have a way out (APG), and the platform's own close
126
+ * request is that way. `initialFocus` is what puts focus on the least destructive action.
127
+ *
128
+ * @a11y `role="alertdialog"`, which tells a screen reader the content is an alert rather than a panel, so
129
+ * the name and description are announced together on open.
130
+ * @a11y A press outside is ignored on purpose; Escape is not, so the dialog is never a trap.
131
+ * @keyboard Escape — Closes it and returns focus to the trigger.
132
+ * @keyboard Tab — Cycles focus inside it and never leaves.
133
+ */
134
+ declare function AlertDialogImpl<TKey extends keyof ComponentsAndVariants = 'dialog'>(props: AlertDialogProps<TKey>): import("react").JSX.Element;
135
+ /**
136
+ * The dialog's heading, and what names it: rendering one is what puts `aria-labelledby` on the dialog, so
137
+ * a name and a visible title cannot drift apart. An `<h2>` by default — `tag` takes any of the six.
138
+ */
139
+ declare function DialogTitle<TKey extends keyof ComponentsAndVariants = 'dialog.title'>(props: DialogTitleProps<TKey>): import("react").JSX.Element;
140
+ /** The dialog's supporting text, and what describes it: rendering one puts `aria-describedby` on the dialog. */
141
+ declare function DialogDescription<TKey extends keyof ComponentsAndVariants = 'dialog.description'>(props: DialogDescriptionProps<TKey>): import("react").JSX.Element;
142
+ declare const Dialog: typeof DialogImpl & {
143
+ Title: typeof DialogTitle;
144
+ Description: typeof DialogDescription;
145
+ };
146
+ declare const AlertDialog: typeof AlertDialogImpl & {
147
+ Title: typeof DialogTitle;
148
+ Description: typeof DialogDescription;
149
+ };
150
+ export { AlertDialog };
151
+ export default Dialog;
@@ -0,0 +1,223 @@
1
+ "use client";
2
+ import { c as e, i as t, l as n, n as r } from "../platform.mjs";
3
+ import { i } from "../client.mjs";
4
+ import { n as a } from "../effects.mjs";
5
+ import o from "../box.mjs";
6
+ import { a as s, i as c, n as l, r as u } from "../behavior.mjs";
7
+ import { t as d } from "../identity.mjs";
8
+ import { H2 as f, P as p } from "./semantics.mjs";
9
+ import { createContext as m, useCallback as h, useContext as g, useMemo as _, useRef as v, useState as y } from "react";
10
+ import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
11
+ //#region src/react/dialog/useScrollLock.ts
12
+ var C = 0;
13
+ function w(e) {
14
+ let { classNames: t, styleElements: n } = i({ overflow: "hidden" }, !1), o = t.slice(1).join(" ");
15
+ return a(() => {
16
+ let t = r();
17
+ if (!(!e || !t || !o)) return C += 1, t.classList.add(o), () => {
18
+ --C, C === 0 && t.classList.remove(o);
19
+ };
20
+ }, [e, o]), n;
21
+ }
22
+ //#endregion
23
+ //#region src/components/dialog.tsx
24
+ var T = m(null);
25
+ function E(e) {
26
+ let t = g(T);
27
+ if (!t) throw Error(`<${e}> must be rendered inside a <Dialog>.`);
28
+ return t;
29
+ }
30
+ function D(e) {
31
+ return /* @__PURE__ */ x(k, {
32
+ role: "dialog",
33
+ ...e
34
+ });
35
+ }
36
+ function O(e) {
37
+ return /* @__PURE__ */ x(k, {
38
+ role: "alertdialog",
39
+ ...e,
40
+ modal: !0,
41
+ dismissible: !1
42
+ });
43
+ }
44
+ function k(t) {
45
+ let { role: n, trigger: r, children: i, open: u, defaultOpen: f = !1, onOpenChange: p, label: m, labelledBy: g, describedBy: v, modal: C = !0, dismissible: E = !0, lockScroll: D = C, initialFocus: O, props: k, ...j } = t, M = d("dialog"), N = j.id ?? M, [P, F] = c({
46
+ value: u,
47
+ defaultValue: f,
48
+ onChange: p
49
+ }), [I, L] = y(null), [R, z] = y(null), [B, V] = y(!1), [H, U] = y({
50
+ title: 0,
51
+ description: 0
52
+ }), W = w(P && D);
53
+ l({
54
+ enabled: P,
55
+ returnTo: R
56
+ });
57
+ let G = h((e) => (U((t) => ({
58
+ ...t,
59
+ [e]: t[e] + 1
60
+ })), () => U((t) => ({
61
+ ...t,
62
+ [e]: t[e] - 1
63
+ }))), []), K = _(() => ({
64
+ titleId: `${N}-title`,
65
+ descriptionId: `${N}-description`,
66
+ register: G
67
+ }), [N, G]);
68
+ A({
69
+ dialog: I,
70
+ isOpen: P,
71
+ domOpen: B,
72
+ setDomOpen: V,
73
+ setOpen: F,
74
+ modal: C,
75
+ dismissible: E,
76
+ triggerElement: R
77
+ }), a(() => {
78
+ let t = e(O);
79
+ !P || !t || t.focus();
80
+ }, [P, O]);
81
+ let q = s((e) => {
82
+ F((e) => !e, {
83
+ reason: "trigger",
84
+ event: e
85
+ });
86
+ }), J = _(() => ({
87
+ ref: z,
88
+ props: {
89
+ "aria-expanded": P,
90
+ "aria-haspopup": "dialog",
91
+ "aria-controls": P ? N : void 0,
92
+ onClick: q
93
+ }
94
+ }), [
95
+ N,
96
+ q,
97
+ P
98
+ ]), Y = j;
99
+ return /* @__PURE__ */ S(b, { children: [
100
+ W,
101
+ r?.(J),
102
+ /* @__PURE__ */ x(T.Provider, {
103
+ value: K,
104
+ children: /* @__PURE__ */ x(o, {
105
+ ref: L,
106
+ tag: "dialog",
107
+ component: "dialog",
108
+ ...Y,
109
+ id: N,
110
+ props: {
111
+ role: n,
112
+ "aria-label": H.title || g ? void 0 : m,
113
+ "aria-labelledby": g ?? (H.title ? K.titleId : void 0),
114
+ "aria-describedby": v ?? (H.description ? K.descriptionId : void 0),
115
+ ...k
116
+ },
117
+ children: i
118
+ })
119
+ })
120
+ ] });
121
+ }
122
+ function A(e) {
123
+ let { dialog: r, isOpen: i, domOpen: o, setDomOpen: s, setOpen: c, modal: l, dismissible: d, triggerElement: f } = e, p = v("imperative"), m = t(), h = d ? "any" : "closerequest";
124
+ a(() => {
125
+ !r || i === o || (s(i), i ? l ? r.showModal() : r.show() : r.close());
126
+ }, [
127
+ r,
128
+ i,
129
+ o,
130
+ l,
131
+ s
132
+ ]), a(() => {
133
+ if (!r) return;
134
+ let e = new AbortController();
135
+ return r.addEventListener("close", (e) => {
136
+ s(!1), c(!1, {
137
+ reason: p.current,
138
+ event: e
139
+ }), p.current = "imperative";
140
+ }, { signal: e.signal }), () => e.abort();
141
+ }, [
142
+ r,
143
+ s,
144
+ c
145
+ ]), a(() => {
146
+ if (!(!r || !m)) return r.setAttribute("closedby", h), () => r.removeAttribute("closedby");
147
+ }, [
148
+ r,
149
+ m,
150
+ h
151
+ ]), a(() => {
152
+ if (!i || !r) return;
153
+ let e = new AbortController(), t = (t, n) => document.addEventListener(t, n, {
154
+ signal: e.signal,
155
+ capture: !0
156
+ });
157
+ return t("keydown", (e) => {
158
+ e.key === "Escape" && (p.current = "escape");
159
+ }), t("pointerdown", (e) => {
160
+ n(e, [f]) ? p.current = "trigger" : !n(e, [r]) || j(r, e) ? p.current = "outside-pointer" : p.current = "imperative";
161
+ }), () => e.abort();
162
+ }, [
163
+ i,
164
+ r,
165
+ f
166
+ ]), u({
167
+ enabled: i && !l && !m,
168
+ inside: [r],
169
+ escapeKey: !0,
170
+ outsidePointer: !1,
171
+ onDismiss: (e, t) => c(!1, {
172
+ reason: "escape",
173
+ event: t
174
+ })
175
+ }), a(() => {
176
+ if (!r || !i || !d || m) return;
177
+ let e = new AbortController();
178
+ return document.addEventListener("pointerdown", (e) => {
179
+ n(e, [f]) || n(e, [r]) && !j(r, e) || c(!1, {
180
+ reason: "outside-pointer",
181
+ event: e
182
+ });
183
+ }, {
184
+ signal: e.signal,
185
+ capture: !0
186
+ }), () => e.abort();
187
+ }, [
188
+ r,
189
+ i,
190
+ d,
191
+ m,
192
+ f,
193
+ c
194
+ ]);
195
+ }
196
+ function j(e, t) {
197
+ let n = e.getBoundingClientRect();
198
+ return t.clientX < n.left || t.clientX > n.right || t.clientY < n.top || t.clientY > n.bottom;
199
+ }
200
+ function M(e) {
201
+ let t = E("Dialog.Title");
202
+ return a(() => t.register("title"), [t]), /* @__PURE__ */ x(f, {
203
+ id: t.titleId,
204
+ component: "dialog.title",
205
+ ...e
206
+ });
207
+ }
208
+ function N(e) {
209
+ let t = E("Dialog.Description");
210
+ return a(() => t.register("description"), [t]), /* @__PURE__ */ x(p, {
211
+ id: t.descriptionId,
212
+ component: "dialog.description",
213
+ ...e
214
+ });
215
+ }
216
+ M.displayName = "Dialog.Title", N.displayName = "Dialog.Description";
217
+ var P = {
218
+ Title: M,
219
+ Description: N
220
+ }, F = Object.assign(D, P), I = Object.assign(O, P);
221
+ D.displayName = "Dialog", O.displayName = "AlertDialog";
222
+ //#endregion
223
+ export { I as AlertDialog, F as default };
@@ -0,0 +1,44 @@
1
+ import { BoxProps } from '../../box';
2
+ import { ClassNameType } from '@box-kite/core';
3
+ export interface DropdownItemProps<TVal = unknown> extends BoxProps {
4
+ value: TVal;
5
+ onClick?(e: React.MouseEvent): void;
6
+ }
7
+ /**
8
+ * A row of the open listbox, in the order the keyboard walks them. "Clear" and "Select all" are rows
9
+ * rather than decorations beside the list, so they carry `role="option"` too. One array up front is what
10
+ * makes an index mean the same thing to the roving-focus hook, to `aria-activedescendant` and to the markup.
11
+ */
12
+ export type DropdownRow<TVal = unknown> = {
13
+ kind: 'unselect';
14
+ element: React.ReactElement<{
15
+ props?: object;
16
+ }>;
17
+ } | {
18
+ kind: 'selectAll';
19
+ element: React.ReactElement<{
20
+ props?: object;
21
+ }>;
22
+ } | {
23
+ kind: 'item';
24
+ element: React.ReactElement<DropdownItemProps<TVal>>;
25
+ };
26
+ export interface DropdownContextValue<TVal = unknown> {
27
+ valueToUse: TVal[];
28
+ multiple: boolean;
29
+ variant: ClassNameType;
30
+ showCheckbox: boolean;
31
+ /** Choose the row at `index` — the one path a click and an Enter both take. */
32
+ selectRow: (index: number, event: React.SyntheticEvent) => void;
33
+ /** The id `aria-activedescendant` names when the keyboard is on the row at `index`. */
34
+ optionId: (index: number) => string;
35
+ /** The row the keyboard is on, or `-1` when it is on none of them. */
36
+ activeIndex: number;
37
+ /** Collects a row's element, so the active one can be named and scrolled to. */
38
+ rowRef: (index: number) => (element: HTMLElement | null) => void;
39
+ /** Whether a row is a disabled option: skipped by the arrows, and inert to a click. */
40
+ isRowDisabled: (index: number) => boolean;
41
+ }
42
+ declare const DropdownContext: import('react').Context<DropdownContextValue<any> | null>;
43
+ export declare function useDropdownContext<TVal>(): DropdownContextValue<TVal>;
44
+ export default DropdownContext;
@@ -0,0 +1,22 @@
1
+ import { Ref } from 'react';
2
+ import { BoxStyleProps } from '@box-kite/core/types';
3
+ import { PresenceHandle } from '../presence';
4
+ import { DropdownRow } from './dropdownContext';
5
+ interface Props<TVal> {
6
+ /** Which way the popup is going, from the `<Presence>` that owns its mount. */
7
+ presence: PresenceHandle;
8
+ /** Every row the listbox shows, already in keyboard order. */
9
+ rows: DropdownRow<TVal>[];
10
+ emptyItem?: React.ReactElement;
11
+ /** The shell the popup hangs off: a button in select-only mode, the field's wrapper otherwise. */
12
+ triggerRef: React.RefObject<HTMLElement | null>;
13
+ /** The layer element — what the dismissal hook treats as *inside* the popup. */
14
+ popupRef: Ref<HTMLDivElement>;
15
+ /** `aria-controls` on the trigger names this. */
16
+ listboxId: string;
17
+ /** What names the listbox: the dropdown's own label when it has one, else its trigger. */
18
+ labelledBy: string;
19
+ itemsProps?: BoxStyleProps;
20
+ }
21
+ export default function DropdownItems<TVal>(props: Props<TVal>): import("react").JSX.Element;
22
+ export {};
@@ -0,0 +1,8 @@
1
+ import { DropdownRow } from './dropdownContext';
2
+ interface Props<TVal> {
3
+ row: DropdownRow<TVal>;
4
+ /** Position in the listbox — what `aria-activedescendant`, the arrow keys and the ref share. */
5
+ index: number;
6
+ }
7
+ declare const DropdownRowRenderer: <TVal>(props: Props<TVal>) => React.ReactNode;
8
+ export default DropdownRowRenderer;
@@ -0,0 +1,21 @@
1
+ interface Props {
2
+ /** The combobox's own id. `aria-labelledby` on the listbox falls back to it. */
3
+ id: string;
4
+ /** What the field shows: the query while one is being typed, the value the rest of the time. */
5
+ value: string;
6
+ onValueChange: (value: string) => void;
7
+ /** Only while the listbox is open — a closed field shows the value, not an invitation to type. */
8
+ placeholder?: string;
9
+ inputRef: React.RefObject<HTMLInputElement | null>;
10
+ /** Everything that makes this input the combobox: the ARIA, the keys, the consumer's own props. */
11
+ comboboxProps: Record<string, unknown>;
12
+ /** A press on the field opens the listbox. It never closes it — the caret has to be placeable. */
13
+ onOpen: (event: React.MouseEvent) => void;
14
+ }
15
+ /**
16
+ * The textbox half of the APG editable combobox, and it *is* the combobox: the role, the ARIA and the
17
+ * consumer's props live on this input rather than on a wrapper, which is what stops one focusable element
18
+ * containing another (bug #47). Pattern: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/
19
+ */
20
+ export default function DropdownSearch({ id, value, onValueChange, placeholder, inputRef, comboboxProps, onOpen }: Props): import("react").JSX.Element;
21
+ export {};
@@ -0,0 +1 @@
1
+ export declare function searchItemText(item: React.ReactElement): string;
@@ -0,0 +1 @@
1
+ "use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../effects.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs"),r=require("../identity.cjs"),i=require("./baseSvg.cjs"),a=require("./button.cjs"),o=require("./flex.cjs"),s=require("./checkbox.cjs"),c=require("./overlay.cjs"),l=require("./presence.cjs"),u=require("./textbox.cjs");let d=require("react"),f=require("react/jsx-runtime");var p=(0,d.createContext)(null);function m(){let e=(0,d.useContext)(p);if(!e)throw Error(`Dropdown sub-components must be used within Dropdown`);return e}var h={item:`dropdown.item`,unselect:`dropdown.unselect`,selectAll:`dropdown.selectAll`};function g({row:e,index:n}){let{valueToUse:r,multiple:i,variant:a,showCheckbox:o,selectRow:c,optionId:l,activeIndex:u,rowRef:d,isRowDisabled:p}=m(),g=e.kind===`item`,_=p(n),v=g?r.includes(e.element.props.value):e.kind===`unselect`&&r.length===0,{value:ee,onClick:y,children:b,...x}=e.element.props,S=o&&i&&g;return(0,f.jsx)(t.default,{ref:d(n),component:h[e.kind],variant:[a,g?{multiple:i,highlighted:n===u}:{highlighted:n===u}],selected:v,...x,id:l(n),children:S?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(s.default,{readOnly:!0,checked:v,me:2,props:{tabIndex:-1,"aria-hidden":!0}}),b]}):b,props:{role:`option`,..._?{"aria-disabled":!0}:{},...x.props,onClick:_?void 0:e=>{y?.(e),c(n,e)}}})}var _=(0,d.memo)(g,(e,t)=>e.row.element===t.row.element&&e.index===t.index);function v(e,t,n){return e?{role:`listbox`,"aria-labelledby":n,...t?{"aria-multiselectable":!0}:{}}:{role:`status`}}function ee(e){let{presence:n,rows:r,emptyItem:i,triggerRef:a,popupRef:o,listboxId:s,labelledBy:l,itemsProps:u}=e,{present:p,ref:h,props:g}=n,{multiple:ee,variant:b}=m(),[x,S]=(0,d.useState)(!1),te=(0,d.useCallback)(e=>S(e===`top`),[]);return(0,f.jsx)(c.default,{ref:o,anchor:a,side:`bottom`,align:`start`,offset:.5,onSideChange:te,children:(0,f.jsxs)(t.default,{ref:h,component:`dropdown.items`,...u,variant:[b,{closed:!p&&!x,closedUp:!p&&x}],id:s,props:{...v(r.length>0,ee,l),...g},children:[r.map((e,t)=>(0,f.jsx)(_,{row:e,index:t},y(e,t))),r.length===0&&i&&(0,f.jsx)(t.default,{component:`dropdown.emptyItem`,variant:b,...i.props})]})})}function y(e,t){return e.kind===`item`?e.element.props.value:`${e.kind}-${t}`}ee.displayName=`DropdownItems`;function b({id:e,value:t,onValueChange:n,placeholder:r,inputRef:i,comboboxProps:a,onOpen:s}){let c=(0,d.useCallback)(e=>n(e.target.value),[n]),l=(0,d.useCallback)(e=>{e.stopPropagation(),s(e)},[s]);return(0,f.jsx)(o.default,{ai:`center`,position:`absolute`,inset:0,p:3,children:(0,f.jsx)(u.default,{clean:!0,id:e,value:t,placeholder:r,onChange:c,ref:i,color:`currentColor`,width:`fit`,props:{role:`combobox`,"aria-autocomplete":`list`,autoComplete:`off`,spellCheck:!1,...a,onClick:l}})})}function x(e){if(e==null)return``;if(typeof e==`object`){let t=e.props?.children;return t==null?``:typeof t==`object`?(Array.isArray(t)?t:[t]).map(e=>x(e)).join(``):t.toString()}return e.toString()}function S(e){return e==null?[]:Array.isArray(e)?e:[e]}function te(e){let t=e?.props?.disabled;return(Array.isArray(t)?t[0]:t)===!0}function ne(e){return e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey}var re=new Set([` `,`Home`,`End`,`ArrowLeft`,`ArrowRight`]);function ie(s,c){let{name:m,defaultValue:h,value:g,defaultOpen:_,multiple:v=!1,isSearchable:y,searchPlaceholder:ie,children:C,hideIcon:w,showCheckbox:ae=!1,label:oe,labelProps:se,itemsProps:ce,iconProps:le,onValueChange:ue,onChange:de,props:fe,...T}=s,E=(0,d.useRef)(void 0),pe=n.a((e,t)=>{ue?.(v?e:e[0],t),de?.(E.current,e)}),me=`value`in s,he=(0,d.useMemo)(()=>me?S(g):void 0,[me,g]),[D,O]=n.i({value:he,defaultValue:()=>S(h),onChange:pe}),[ge,_e]=(0,d.useState)(null),[k,A]=(0,d.useState)(!!_),j=(0,d.useRef)(null),ve=(0,d.useCallback)(e=>{j.current=e},[]),ye=(0,d.useRef)(null),M=(0,d.useRef)(null),N=r.t(`dropdown`),P=T.id??`${N}-trigger`,be=`${N}-listbox`,F=`${N}-label`,I=oe!=null&&oe!==!1,xe=(0,d.useCallback)(e=>`${N}-option-${e}`,[N]),L=n.a((e=!1)=>{A(!1),e||_e(null)}),R=(0,d.useMemo)(()=>(Array.isArray(C)?C:[C]).flatMap(e=>e).filter(Boolean),[C]),z=(0,d.useMemo)(()=>R.filter(e=>e.type?.displayName===`DropdownItem`),[R]),Se=(0,d.useMemo)(()=>{let e=new Map;for(let t of z)e.set(t,x(t));return e},[z]),B=(0,d.useCallback)(e=>Se.get(e)??x(e),[Se]),Ce=y?ge??``:``,V=(0,d.useMemo)(()=>Ce?z.filter(e=>B(e).toLowerCase().includes(Ce.toLowerCase())):z,[Ce,z,B]),H=(0,d.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownUnselect`),[R]),U=(0,d.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownSelectAll`),[R]),we=(0,d.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownEmptyItem`),[R]),W=(0,d.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownDisplay`),[R]),G=(0,d.useMemo)(()=>!y||W?``:z.filter(e=>D.includes(e.props.value)).map(e=>B(e)).join(`, `),[y,W,z,D,B]),Te=!!(U&&v&&V.length>D.length),Ee=!!(H&&V.length>0&&!Te),K=(0,d.useMemo)(()=>{let e=[];Ee&&H&&e.push({kind:`unselect`,element:H}),Te&&U&&e.push({kind:`selectAll`,element:U});for(let t of V)e.push({kind:`item`,element:t});return e},[Ee,H,Te,U,V]),q=(0,d.useCallback)(e=>te(K[e]?.element),[K]),De=(0,d.useCallback)(e=>{let t=K[e];return t?B(t.element):``},[K,B]),Oe=(0,d.useMemo)(()=>{if(y&&(k||G!==``))return null;if(W)return typeof W.props.children==`function`?W.props.children(D,k):W.props.children;let e=V.filter(e=>D.includes(e.props.value));if(v&&e.length>1)return e.map(e=>B(e)).join(`, `);let t=e.at(0);return t?.props.children??t?.props.value??(v?null:H?.props.children)},[v,V,D,H,k,y,G,W,B]),ke=(0,d.useCallback)((e,...t)=>{if(t.length===0)E.current=void 0,O([],{reason:`clear`,event:e});else if(v&&t.length>1)E.current=void 0,O(t.map(e=>e.props.value),{reason:`select-all`,event:e});else if(t.length===1){let n=t[0];if(E.current=n.props.value,v){let t=D.filter(e=>e!==n.props.value),r=t.length!==D.length;r||t.push(n.props.value),O(t,{reason:r?`deselect`:`select`,event:e})}else O([n.props.value],{reason:`select`,event:e})}e.stopPropagation(),v?y&&setTimeout(()=>M.current?.focus(),0):L()},[v,y,D,O,L]),J=n.a((e,t)=>{let n=K[e];!n||q(e)||(n.kind===`unselect`?ke(t):n.kind===`selectAll`?ke(t,...z):ke(t,n.element))}),Ae=e=>{let t=e===`first`?1:-1;for(let n=e===`first`?0:K.length-1;n>=0&&n<K.length;n+=t)if(!q(n))return n;return-1},Y=e=>{let t=K.findIndex(e=>e.kind===`item`&&D.includes(e.element.props.value));return t!==-1&&!q(t)?t:e===`none`?-1:Ae(e)},X=n.t({count:K.length,focusItems:!1,defaultActiveIndex:_?Y(`none`):-1,isDisabled:q,textOf:y?void 0:De,onSelect:J}),je=X.setActiveIndex,Me=(0,d.useCallback)(e=>je(-1,{reason:`programmatic`,event:e}),[je]);n.r({enabled:k,inside:[j,ye],onDismiss:e=>L(e===`escape`)}),n.n({enabled:k,returnTo:y?M:j}),(0,d.useEffect)(()=>{k&&M.current?.focus()},[k]);let Z=X.activeIndex,Ne=X.activeItem;e.n(()=>{!k||Z===-1||Ne()?.scrollIntoView?.({block:`nearest`})},[k,Z,Ne]);let Q=(e,t)=>{A(!0),X.setActiveIndex(e,{reason:`programmatic`,event:t})},Pe=n.a(e=>{k?L():Q(Y(`none`),e)}),Fe=n.a(e=>{k||Q(Y(`none`),e)}),Ie=n.a(e=>{_e(e),k||A(!0),Me()}),Le=e=>{let{key:t}=e;if(y){if(t===`ArrowDown`||t===`ArrowUp`){e.preventDefault(),Q(Y(t===`ArrowUp`?`last`:e.altKey?`none`:`first`),e);return}t===`Escape`&&_e(``);return}if(t===`ArrowDown`||t===`Enter`||t===` `){e.preventDefault(),Q(Y(e.altKey?`none`:`first`),e);return}if(t===`ArrowUp`){e.preventDefault(),Q(Y(`last`),e);return}if(t===`Home`||t===`End`){e.preventDefault(),Q(Ae(t===`Home`?`first`:`last`),e);return}ne(e)&&(A(!0),X.onKeyDown(e))},Re=n.a(e=>{if(fe?.onKeyDown?.(e),!e.defaultPrevented){if(!k){Le(e);return}if(e.key===`Tab`){!v&&X.activeIndex!==-1&&J(X.activeIndex,e),L();return}if(e.altKey&&e.key===`ArrowUp`){e.preventDefault(),X.activeIndex!==-1&&J(X.activeIndex,e),L();return}if(y&&re.has(e.key)){Me(e);return}X.onKeyDown(e)}}),$=K.length>0||!!we,ze=k&&Z!==-1&&$?xe(Z):void 0,Be=X.itemProps,Ve=(0,d.useMemo)(()=>({valueToUse:D,multiple:v,variant:T.variant,showCheckbox:ae,selectRow:J,optionId:xe,activeIndex:Z,rowRef:e=>Be(e).ref,isRowDisabled:q}),[D,v,T.variant,ae,J,xe,Z,Be,q]),He={"aria-expanded":k,"aria-controls":k&&$?be:void 0,"aria-activedescendant":ze,"aria-labelledby":I?F:void 0,...fe,onKeyDown:Re},Ue=D.map(e=>{let t=JSON.stringify(e);return(0,f.jsx)(u.default,{ref:c,name:m,type:`hidden`,value:t??``},t)}),We=!w&&(0,f.jsx)(o.default,{component:`dropdown.icon`,...le,children:(0,f.jsx)(i.default,{viewBox:`0 0 10 6`,width:`0.6rem`,rotate:k?180:0,children:(0,f.jsx)(`path`,{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`m1 1 4 4 4-4`})})}),Ge=$&&(0,f.jsx)(l.default,{present:k,children:e=>(0,f.jsx)(ee,{presence:e,rows:K,emptyItem:we,triggerRef:j,popupRef:ye,listboxId:be,labelledBy:I?F:P,itemsProps:ce})}),Ke=y?(0,f.jsxs)(t.default,{ref:ve,component:`dropdown`,props:{onClick:Pe},position:`relative`,pe:w?void 0:6,minWidth:k?36:void 0,width:`fit-content`,...T,id:void 0,children:[Ue,(0,f.jsx)(b,{id:P,value:ge??G,onValueChange:Ie,placeholder:k?ie:void 0,inputRef:M,comboboxProps:He,onOpen:Fe}),Oe??(0,f.jsx)(t.default,{tag:`span`,visibility:`hidden`,children:G||`\xA0`}),We]}):(0,f.jsxs)(a.default,{ref:ve,onClick:Pe,component:`dropdown`,type:`button`,props:{tabIndex:0,role:`combobox`,...He},position:`relative`,pe:w?void 0:6,width:`fit-content`,...T,id:P,children:[Ue,Oe??`\xA0`,We]});return(0,f.jsx)(p.Provider,{value:Ve,children:I?(0,f.jsxs)(o.default,{d:`column`,gap:1,width:`fit-content`,...se,children:[(0,f.jsx)(t.default,{tag:`span`,id:F,children:oe}),Ke,Ge]}):(0,f.jsxs)(f.Fragment,{children:[Ke,Ge]})})}function C(e){let t=e=>null;return t.displayName=e,t}var w=(0,d.forwardRef)(ie);w.Item=C(`DropdownItem`),w.Unselect=C(`DropdownUnselect`),w.SelectAll=C(`DropdownSelectAll`),w.EmptyItem=C(`DropdownEmptyItem`),w.Display=C(`DropdownDisplay`),w.displayName=`Dropdown`,exports.default=w;
@@ -0,0 +1,77 @@
1
+ import { RefAttributes } from 'react';
2
+ import { BoxProps } from '../box';
3
+ import { ChangeHandler } from '../react/a11y/useControllableState';
4
+ import { BoxStyleProps, ComponentsAndVariants } from '@box-kite/core/types';
5
+ import { DropdownItemProps } from './dropdown/dropdownContext';
6
+ /**
7
+ * Why the selection changed. `select-all` and `clear` are the two rows that act on the whole list —
8
+ * `Dropdown.SelectAll` and `Dropdown.Unselect` — rather than on the option under the pointer.
9
+ */
10
+ export type DropdownValueReason = 'select' | 'deselect' | 'select-all' | 'clear';
11
+ interface Props<TVal, TKey extends keyof ComponentsAndVariants = 'dropdown'> extends Omit<BoxProps<'button', TKey>, 'ref' | 'tag'> {
12
+ /** What the selection submits under: the component renders a hidden input carrying it. */
13
+ name?: string;
14
+ /** What is selected to begin with, when the dropdown owns its own value. An array in `multiple` mode. */
15
+ defaultValue?: TVal | TVal[];
16
+ /** Controlled selection. Pair it with `onValueChange`, or nothing the user picks sticks. */
17
+ value?: TVal | TVal[];
18
+ /**
19
+ * Open the listbox as soon as the dropdown mounts, highlighting the selected option the way a press on
20
+ * the trigger would. For a dropdown that only exists because the user asked to choose — a grid's cell
21
+ * editor — where a second press to open a list that is the whole control is a gesture nobody meant.
22
+ */
23
+ defaultOpen?: boolean;
24
+ /** Let more than one option be chosen. Enter and Space then toggle without closing the listbox. */
25
+ multiple?: boolean;
26
+ /**
27
+ * Turn the control into the APG *editable* combobox: a text field that filters the listbox, and a
28
+ * different pattern rather than a decoration — the field carries the role, the ARIA and your `props`.
29
+ * Printable keys type instead of jumping, Home/End and left/right move the caret, and Escape closes
30
+ * the listbox before it clears the field.
31
+ */
32
+ isSearchable?: boolean;
33
+ /** The placeholder for the `isSearchable` field. Not a name — see `label`. */
34
+ searchPlaceholder?: string;
35
+ /** Drop the chevron. It is decoration either way: it is `aria-hidden` and never focusable. */
36
+ hideIcon?: boolean;
37
+ /** Show checkbox for each item in multiple selection mode */
38
+ showCheckbox?: boolean;
39
+ /**
40
+ * The dropdown's name, rendered above it and pointed at by `aria-labelledby`. A combobox is not named by
41
+ * what it contains — accname does not read a combobox at all, and the trigger text is its *value* — so
42
+ * without this (or your own `aria-label`) it has no accessible name.
43
+ */
44
+ label?: React.ReactNode;
45
+ /** Styles for the wrapper the label and the trigger share. Only rendered when there is a label. */
46
+ labelProps?: BoxProps<'div'>;
47
+ /** BoxProps applied to the opened items container (dropdown.items) */
48
+ itemsProps?: BoxStyleProps;
49
+ /** BoxProps applied to the chevron icon container (dropdown.icon) */
50
+ iconProps?: BoxStyleProps;
51
+ /**
52
+ * Fires with the selection in whatever shape `value` takes — the whole array in `multiple` mode, the
53
+ * one chosen option otherwise, `undefined` for nothing — and why it changed.
54
+ */
55
+ onValueChange?: ChangeHandler<TVal | TVal[] | undefined, DropdownValueReason>;
56
+ /**
57
+ * The older callback, whose first argument is the option *acted on* rather than the selection. Both
58
+ * fire, so either one can be passed.
59
+ * @deprecated `onValueChange` is what every component reports a value change under, and it carries the
60
+ * reason — which is the thing a `(value, values)` pair cannot say. This spelling still works.
61
+ */
62
+ onChange?: (value: TVal | undefined, values: TVal[]) => void;
63
+ }
64
+ interface DropdownDisplayProps<TVal> extends Omit<BoxProps, 'children'> {
65
+ /** What the trigger shows: a node, or a function given the selected values and whether it is open. */
66
+ children: ((selectedValues: TVal[], isOpen: boolean) => React.ReactNode) | React.ReactNode;
67
+ }
68
+ interface DropdownType {
69
+ <TVal>(props: Props<TVal> & RefAttributes<HTMLInputElement>): React.ReactNode;
70
+ Item: <TVal>(props: DropdownItemProps<TVal>) => React.ReactNode;
71
+ Unselect: (props: BoxProps) => React.ReactNode;
72
+ SelectAll: (props: BoxProps) => React.ReactNode;
73
+ EmptyItem: (props: BoxProps) => React.ReactNode;
74
+ Display: <TVal>(props: DropdownDisplayProps<TVal>) => React.ReactNode;
75
+ }
76
+ declare const Dropdown: DropdownType;
77
+ export default Dropdown;