@box-kite/react 0.0.1 → 1.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.
- package/.claude/rules/box-kite-rules.md +43 -0
- package/.claude/skills/box-kite/SKILL.md +431 -0
- package/BOX_AI_CONTEXT.md +1833 -0
- package/BOX_KITE_AI_CONTEXT.md +1833 -0
- package/LICENSE +21 -0
- package/README.md +710 -7
- package/a11y.cjs +1 -0
- package/a11y.d.ts +15 -0
- package/a11y.mjs +3 -0
- package/behavior.cjs +1 -0
- package/behavior.mjs +295 -0
- package/box.cjs +1 -0
- package/box.d.ts +46 -0
- package/box.mjs +23 -0
- package/client.cjs +1 -0
- package/client.mjs +163 -0
- package/components/baseSvg.cjs +1 -0
- package/components/baseSvg.d.ts +5 -0
- package/components/baseSvg.mjs +21 -0
- package/components/button.cjs +1 -0
- package/components/button.d.ts +16 -0
- package/components/button.mjs +19 -0
- package/components/chart.cjs +1 -0
- package/components/chart.d.ts +82 -0
- package/components/chart.mjs +261 -0
- package/components/checkbox.cjs +1 -0
- package/components/checkbox.d.ts +28 -0
- package/components/checkbox.mjs +38 -0
- package/components/dataGrid/components/dataGridBody.d.ts +7 -0
- package/components/dataGrid/components/dataGridBottomBar.d.ts +6 -0
- package/components/dataGrid/components/dataGridCell.d.ts +15 -0
- package/components/dataGrid/components/dataGridCellRowDetail.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
- package/components/dataGrid/components/dataGridColumnFilter.d.ts +9 -0
- package/components/dataGrid/components/dataGridColumnGroups.d.ts +7 -0
- package/components/dataGrid/components/dataGridContent.d.ts +6 -0
- package/components/dataGrid/components/dataGridDetailRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridEmptyColumns.d.ts +6 -0
- package/components/dataGrid/components/dataGridFilterCell.d.ts +11 -0
- package/components/dataGrid/components/dataGridFilterRow.d.ts +6 -0
- package/components/dataGrid/components/dataGridGlobalFilter.d.ts +6 -0
- package/components/dataGrid/components/dataGridGroupRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridHeader.d.ts +6 -0
- package/components/dataGrid/components/dataGridHeaderCell.d.ts +9 -0
- package/components/dataGrid/components/dataGridHeaderCellContextMenu.d.ts +11 -0
- package/components/dataGrid/components/dataGridHeaderCellResizer.d.ts +14 -0
- package/components/dataGrid/components/dataGridLoader.d.ts +11 -0
- package/components/dataGrid/components/dataGridPagination.d.ts +6 -0
- package/components/dataGrid/components/dataGridRow.d.ts +8 -0
- package/components/dataGrid/components/dataGridTopBar.d.ts +6 -0
- package/components/dataGrid/components/dataGridTopBarContextMenu.d.ts +6 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +213 -0
- package/components/dataGrid/gridNavigationContext.d.ts +24 -0
- package/components/dataGrid/models/cellModel.d.ts +18 -0
- package/components/dataGrid/models/columnModel.d.ts +150 -0
- package/components/dataGrid/models/columnVisibilityModel.d.ts +24 -0
- package/components/dataGrid/models/detailRowModel.d.ts +22 -0
- package/components/dataGrid/models/filterModel.d.ts +22 -0
- package/components/dataGrid/models/gridModel.d.ts +206 -0
- package/components/dataGrid/models/groupRowCellModel.d.ts +26 -0
- package/components/dataGrid/models/groupRowModel.d.ts +48 -0
- package/components/dataGrid/models/headerCellModel.d.ts +83 -0
- package/components/dataGrid/models/paginationModel.d.ts +32 -0
- package/components/dataGrid/models/rowModel.d.ts +34 -0
- package/components/dataGrid/models/viewportModel.d.ts +44 -0
- package/components/dataGrid/useGrid.d.ts +8 -0
- package/components/dataGrid/useGridNavigation.d.ts +21 -0
- package/components/dataGrid.cjs +1 -0
- package/components/dataGrid.d.ts +2 -0
- package/components/dataGrid.mjs +3178 -0
- package/components/dropdown/dropdownContext.d.ts +44 -0
- package/components/dropdown/dropdownItems.d.ts +22 -0
- package/components/dropdown/dropdownRowRenderer.d.ts +8 -0
- package/components/dropdown/dropdownSearch.d.ts +21 -0
- package/components/dropdown/utils.d.ts +1 -0
- package/components/dropdown.cjs +1 -0
- package/components/dropdown.d.ts +47 -0
- package/components/dropdown.mjs +479 -0
- package/components/flex.cjs +1 -0
- package/components/flex.d.ts +6 -0
- package/components/flex.mjs +16 -0
- package/components/form.cjs +1 -0
- package/components/form.d.ts +10 -0
- package/components/form.mjs +58 -0
- package/components/grid.cjs +1 -0
- package/components/grid.d.ts +6 -0
- package/components/grid.mjs +16 -0
- package/components/icon.cjs +1 -0
- package/components/icon.d.ts +36 -0
- package/components/icon.mjs +41 -0
- package/components/overlay.cjs +1 -0
- package/components/overlay.d.ts +43 -0
- package/components/overlay.mjs +82 -0
- package/components/presence.cjs +1 -0
- package/components/presence.d.ts +30 -0
- package/components/presence.mjs +11 -0
- package/components/radioButton.cjs +1 -0
- package/components/radioButton.d.ts +24 -0
- package/components/radioButton.mjs +32 -0
- package/components/radioGroup.cjs +1 -0
- package/components/radioGroup.d.ts +38 -0
- package/components/radioGroup.mjs +79 -0
- package/components/select.cjs +1 -0
- package/components/select.d.ts +42 -0
- package/components/select.mjs +36 -0
- package/components/semantics.cjs +1 -0
- package/components/semantics.d.ts +34 -0
- package/components/semantics.mjs +17 -0
- package/components/svg.cjs +1 -0
- package/components/svg.d.ts +63 -0
- package/components/svg.mjs +141 -0
- package/components/switch.cjs +1 -0
- package/components/switch.d.ts +20 -0
- package/components/switch.mjs +25 -0
- package/components/textarea.cjs +1 -0
- package/components/textarea.d.ts +27 -0
- package/components/textarea.mjs +33 -0
- package/components/textbox.cjs +1 -0
- package/components/textbox.d.ts +26 -0
- package/components/textbox.mjs +33 -0
- package/components/tooltip.cjs +1 -0
- package/components/tooltip.d.ts +63 -0
- package/components/tooltip.mjs +108 -0
- package/components/visuallyHidden.cjs +1 -0
- package/components/visuallyHidden.d.ts +6 -0
- package/components/visuallyHidden.mjs +23 -0
- package/effects.cjs +1 -0
- package/effects.mjs +6 -0
- package/forms.cjs +1 -0
- package/forms.mjs +21 -0
- package/icons/dotsIcon.d.ts +2 -0
- package/icons/expandIcon.d.ts +2 -0
- package/icons/groupingIcon.d.ts +2 -0
- package/icons/pinIcon.d.ts +2 -0
- package/icons/searchIcon.d.ts +2 -0
- package/icons/sortIcon.d.ts +2 -0
- package/motion.cjs +1 -0
- package/motion.mjs +66 -0
- package/package.json +203 -7
- package/platform.cjs +1 -0
- package/platform.mjs +32 -0
- package/react/a11y/callbacks.d.ts +12 -0
- package/react/a11y/useControllableState.d.ts +25 -0
- package/react/a11y/useDismiss.d.ts +25 -0
- package/react/a11y/useFocusReturn.d.ts +18 -0
- package/react/a11y/useIdentifier.d.ts +17 -0
- package/react/a11y/useRovingFocus.d.ts +84 -0
- package/react/animation/usePresence.d.ts +32 -0
- package/react/boxClassNames.d.ts +25 -0
- package/react/boxProps.d.ts +49 -0
- package/react/boxTagProps.d.ts +7 -0
- package/react/clientRuntime.d.ts +11 -0
- package/react/effects.d.ts +10 -0
- package/react/forms/labelledControl.d.ts +17 -0
- package/react/forms/placeholderProp.d.ts +13 -0
- package/react/hooks/usePortalContainer.d.ts +1 -0
- package/react/hooks/useVirtualization.d.ts +43 -0
- package/react/hooks/useVisibility.d.ts +9 -0
- package/react/reactTypes.d.ts +10 -0
- package/react/resolveStyles.d.ts +18 -0
- package/react/styleElements.d.ts +3 -0
- package/react/svg/attributesInProps.d.ts +4 -0
- package/react/svg/svgNaming.d.ts +15 -0
- package/react/theme/theme.d.ts +26 -0
- package/react/theme/themeContext.d.ts +7 -0
- package/react/useStyles.d.ts +22 -0
- package/react-shared.cjs +1 -0
- package/react-shared.mjs +105 -0
- package/rolldown-runtime.cjs +1 -0
- package/rsc.cjs +1 -0
- package/rsc.d.ts +27 -0
- package/rsc.mjs +18 -0
- package/ssg.cjs +1 -0
- package/ssg.d.ts +24 -0
- package/ssg.mjs +25 -0
- package/utils/animation/animationUtils.d.ts +29 -0
- package/utils/array/arrayUtils.d.ts +15 -0
- package/utils/box/boxUtils.d.ts +5 -0
- package/utils/chart/chartUtils.d.ts +98 -0
- package/utils/dom/domUtils.d.ts +26 -0
- package/utils/environment/environmentUtils.d.ts +18 -0
- package/utils/fn/fnUtils.d.ts +4 -0
- package/utils/form/formUtils.d.ts +8 -0
- package/utils/memo.d.ts +10 -0
- package/utils/object/objectUtils.d.ts +13 -0
- package/utils/string/fuzzySearch.d.ts +27 -0
- package/utils/string/stringUtils.d.ts +4 -0
|
@@ -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("./baseSvg.cjs"),i=require("./button.cjs"),a=require("./flex.cjs"),o=require("./checkbox.cjs"),s=require("./textbox.cjs"),c=require("./overlay.cjs"),l=require("./presence.cjs");let u=require("react"),d=require("react/jsx-runtime");var f=(0,u.createContext)(null);function p(){let e=(0,u.useContext)(f);if(!e)throw Error(`Dropdown sub-components must be used within Dropdown`);return e}var m={item:`dropdown.item`,unselect:`dropdown.unselect`,selectAll:`dropdown.selectAll`};function h({row:e,index:n}){let{valueToUse:r,multiple:i,variant:a,showCheckbox:s,selectRow:c,optionId:l,activeIndex:u,rowRef:f,isRowDisabled:h}=p(),g=e.kind===`item`,_=h(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,te=s&&i&&g;return(0,d.jsx)(t.default,{ref:f(n),component:m[e.kind],variant:[a,g?{multiple:i,highlighted:n===u}:{highlighted:n===u}],selected:v,...x,id:l(n),children:te?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.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 g=(0,u.memo)(h,(e,t)=>e.row.element===t.row.element&&e.index===t.index);function _(e,t,n){return e?{role:`listbox`,"aria-labelledby":n,...t?{"aria-multiselectable":!0}:{}}:{role:`status`}}function v(e){let{presence:n,rows:r,emptyItem:i,triggerRef:a,popupRef:o,listboxId:s,labelledBy:l,itemsProps:f}=e,{present:m,ref:h,props:v}=n,{multiple:y,variant:b}=p(),[x,te]=(0,u.useState)(!1),ne=x?0:a.current?.getBoundingClientRect().height??0,S=(0,u.useCallback)(e=>{let t=e.top-e.windowScrollY>window.innerHeight/2;te(e=>e===t?e:t)},[]);return(0,d.jsx)(t.default,{position:`absolute`,inset:0,children:(0,d.jsx)(c.default,{ref:o,minWidth:`fit-content`,style:{transform:x?`translateY(calc(-100% - 2px))`:`translateY(${ne}px)`},onPositionChange:S,children:(0,d.jsxs)(t.default,{ref:h,component:`dropdown.items`,...f,variant:[b,{up:x,closed:!m&&!x,closedUp:!m&&x}],id:s,props:{..._(r.length>0,y,l),...v},children:[r.map((e,t)=>(0,d.jsx)(g,{row:e,index:t},ee(e,t))),r.length===0&&i&&(0,d.jsx)(t.default,{component:`dropdown.emptyItem`,variant:b,...i.props})]})})})}function ee(e,t){return e.kind===`item`?e.element.props.value:`${e.kind}-${t}`}v.displayName=`DropdownItems`;function y({id:e,value:t,onValueChange:n,placeholder:r,inputRef:i,comboboxProps:o,onOpen:c}){let l=(0,u.useCallback)(e=>n(e.target.value),[n]),f=(0,u.useCallback)(e=>{e.stopPropagation(),c(e)},[c]);return(0,d.jsx)(a.default,{ai:`center`,position:`absolute`,inset:0,p:3,children:(0,d.jsx)(s.default,{clean:!0,id:e,value:t,placeholder:r,onChange:l,ref:i,color:`currentColor`,width:`fit`,props:{role:`combobox`,"aria-autocomplete":`list`,autoComplete:`off`,spellCheck:!1,...o,onClick:f}})})}function b(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=>b(e)).join(``):t.toString()}return e.toString()}function x(e){let t=e?.props?.disabled;return(Array.isArray(t)?t[0]:t)===!0}function te(e){return e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey}var ne=new Set([` `,`Home`,`End`,`ArrowLeft`,`ArrowRight`]);function S(o,c){let{name:p,defaultValue:m,value:h,multiple:g=!1,isSearchable:_,searchPlaceholder:ee,children:S,hideIcon:C,showCheckbox:w=!1,label:re,labelProps:ie,itemsProps:ae,iconProps:oe,onChange:T,props:se,...E}=o,[ce,D]=(0,u.useState)(Array.isArray(m)?m:m?[m]:[]),le=`value`in o,O=(0,u.useMemo)(()=>le?Array.isArray(h)?h:h?[h]:[]:ce,[le,h,ce]),[ue,de]=(0,u.useState)(null),[k,A]=(0,u.useState)(!1),j=(0,u.useRef)(null),fe=(0,u.useCallback)(e=>{j.current=e},[]),pe=(0,u.useRef)(null),M=(0,u.useRef)(null),N=n.n(`dropdown`),P=E.id??`${N}-trigger`,me=`${N}-listbox`,he=`${N}-label`,F=re!=null&&re!==!1,I=(0,u.useCallback)(e=>`${N}-option-${e}`,[N]),L=n.o((e=!1)=>{A(!1),e||de(null)}),R=(0,u.useMemo)(()=>(Array.isArray(S)?S:[S]).flatMap(e=>e).filter(Boolean),[S]),z=(0,u.useMemo)(()=>R.filter(e=>e.type?.displayName===`DropdownItem`),[R]),ge=(0,u.useMemo)(()=>{let e=new Map;for(let t of z)e.set(t,b(t));return e},[z]),B=(0,u.useCallback)(e=>ge.get(e)??b(e),[ge]),V=_?ue??``:``,H=(0,u.useMemo)(()=>V?z.filter(e=>B(e).toLowerCase().includes(V.toLowerCase())):z,[V,z,B]),U=(0,u.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownUnselect`),[R]),W=(0,u.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownSelectAll`),[R]),_e=(0,u.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownEmptyItem`),[R]),G=(0,u.useMemo)(()=>R.find(e=>e.type?.displayName===`DropdownDisplay`),[R]),K=(0,u.useMemo)(()=>!_||G?``:z.filter(e=>O.includes(e.props.value)).map(e=>B(e)).join(`, `),[_,G,z,O,B]),ve=!!(W&&g&&H.length>O.length),ye=!!(U&&H.length>0&&!ve),q=(0,u.useMemo)(()=>{let e=[];ye&&U&&e.push({kind:`unselect`,element:U}),ve&&W&&e.push({kind:`selectAll`,element:W});for(let t of H)e.push({kind:`item`,element:t});return e},[ye,U,ve,W,H]),J=(0,u.useCallback)(e=>x(q[e]?.element),[q]),be=(0,u.useCallback)(e=>{let t=q[e];return t?B(t.element):``},[q,B]),xe=(0,u.useMemo)(()=>{if(_&&(k||K!==``))return null;if(G)return typeof G.props.children==`function`?G.props.children(O,k):G.props.children;let e=H.filter(e=>O.includes(e.props.value));if(g&&e.length>1)return e.map(e=>B(e)).join(`, `);let t=e.at(0);return t?.props.children??t?.props.value??(g?null:U?.props.children)},[g,H,O,U,k,_,K,G,B]),Se=(0,u.useCallback)((e,...t)=>{if(t.length===0)D([]),T?.(void 0,[]);else if(g&&t.length>1){let e=t.map(e=>e.props.value);D(e),T?.(void 0,e)}else if(t.length===1){let e=t[0];if(g){let t=O.filter(t=>t!==e.props.value);t.length===O.length&&t.push(e.props.value),D(t),T?.(e.props.value,t)}else D([e.props.value]),T?.(e.props.value,[e.props.value])}e.stopPropagation(),g?_&&setTimeout(()=>M.current?.focus(),0):L()},[g,_,O,T,L]),Y=n.o((e,t)=>{let n=q[e];!n||J(e)||(n.kind===`unselect`?Se(t):n.kind===`selectAll`?Se(t,...z):Se(t,n.element))}),X=n.t({count:q.length,focusItems:!1,defaultActiveIndex:-1,isDisabled:J,textOf:_?void 0:be,onSelect:Y}),Ce=X.setActiveIndex,we=(0,u.useCallback)(e=>Ce(-1,{reason:`programmatic`,event:e}),[Ce]);n.i({enabled:k,inside:[j,pe],onDismiss:e=>L(e===`escape`)}),n.r({enabled:k,returnTo:_?M:j}),(0,u.useEffect)(()=>{k&&M.current?.focus()},[k]);let Z=X.activeIndex,Te=X.activeItem;e.n(()=>{!k||Z===-1||Te()?.scrollIntoView?.({block:`nearest`})},[k,Z,Te]);let Ee=e=>{let t=e===`first`?1:-1;for(let n=e===`first`?0:q.length-1;n>=0&&n<q.length;n+=t)if(!J(n))return n;return-1},Q=e=>{let t=q.findIndex(e=>e.kind===`item`&&O.includes(e.element.props.value));return t!==-1&&!J(t)?t:e===`none`?-1:Ee(e)},$=(e,t)=>{A(!0),X.setActiveIndex(e,{reason:`programmatic`,event:t})},De=n.o(e=>{k?L():$(Q(`none`),e)}),Oe=n.o(e=>{k||$(Q(`none`),e)}),ke=n.o(e=>{de(e),k||A(!0),we()}),Ae=e=>{let{key:t}=e;if(_){if(t===`ArrowDown`||t===`ArrowUp`){e.preventDefault(),$(Q(t===`ArrowUp`?`last`:e.altKey?`none`:`first`),e);return}t===`Escape`&&de(``);return}if(t===`ArrowDown`||t===`Enter`||t===` `){e.preventDefault(),$(Q(e.altKey?`none`:`first`),e);return}if(t===`ArrowUp`){e.preventDefault(),$(Q(`last`),e);return}if(t===`Home`||t===`End`){e.preventDefault(),$(Ee(t===`Home`?`first`:`last`),e);return}te(e)&&(A(!0),X.onKeyDown(e))},je=n.o(e=>{if(se?.onKeyDown?.(e),!e.defaultPrevented){if(!k){Ae(e);return}if(e.key===`Tab`){!g&&X.activeIndex!==-1&&Y(X.activeIndex,e),L();return}if(e.altKey&&e.key===`ArrowUp`){e.preventDefault(),X.activeIndex!==-1&&Y(X.activeIndex,e),L();return}if(_&&ne.has(e.key)){we(e);return}X.onKeyDown(e)}}),Me=q.length>0||!!_e,Ne=k&&Z!==-1&&Me?I(Z):void 0,Pe=X.itemProps,Fe=(0,u.useMemo)(()=>({valueToUse:O,multiple:g,variant:E.variant,showCheckbox:w,selectRow:Y,optionId:I,activeIndex:Z,rowRef:e=>Pe(e).ref,isRowDisabled:J}),[O,g,E.variant,w,Y,I,Z,Pe,J]),Ie={"aria-expanded":k,"aria-controls":k&&Me?me:void 0,"aria-activedescendant":Ne,"aria-labelledby":F?he:void 0,...se,onKeyDown:je},Le=O.map(e=>{let t=JSON.stringify(e);return(0,d.jsx)(s.default,{ref:c,name:p,type:`hidden`,value:t??``},t)}),Re=!C&&(0,d.jsx)(a.default,{component:`dropdown.icon`,...oe,children:(0,d.jsx)(r.default,{viewBox:`0 0 10 6`,width:`0.6rem`,rotate:k?180:0,children:(0,d.jsx)(`path`,{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`m1 1 4 4 4-4`})})}),ze=Me&&(0,d.jsx)(l.default,{present:k,children:e=>(0,d.jsx)(v,{presence:e,rows:q,emptyItem:_e,triggerRef:j,popupRef:pe,listboxId:me,labelledBy:F?he:P,itemsProps:ae})}),Be=_?(0,d.jsxs)(t.default,{ref:fe,component:`dropdown`,props:{onClick:De},position:`relative`,pe:C?void 0:6,minWidth:k?36:void 0,width:`fit-content`,...E,id:void 0,children:[Le,(0,d.jsx)(y,{id:P,value:ue??K,onValueChange:ke,placeholder:k?ee:void 0,inputRef:M,comboboxProps:Ie,onOpen:Oe}),xe??(0,d.jsx)(t.default,{tag:`span`,visibility:`hidden`,children:K||`\xA0`}),Re,ze]}):(0,d.jsxs)(i.default,{ref:fe,onClick:De,component:`dropdown`,type:`button`,props:{tabIndex:0,role:`combobox`,...Ie},position:`relative`,pe:C?void 0:6,width:`fit-content`,...E,id:P,children:[Le,xe??`\xA0`,Re,ze]});return(0,d.jsx)(f.Provider,{value:Fe,children:F?(0,d.jsxs)(a.default,{d:`column`,gap:1,width:`fit-content`,...ie,children:[(0,d.jsx)(t.default,{tag:`span`,id:he,children:re}),Be]}):Be})}function C(e){let t=e=>null;return t.displayName=e,t}var w=(0,u.forwardRef)(S);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,47 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps } from '../box';
|
|
3
|
+
import { BoxStyleProps, ComponentsAndVariants } from '@box-kite/core/types';
|
|
4
|
+
import { DropdownItemProps } from './dropdown/dropdownContext';
|
|
5
|
+
interface Props<TVal, TKey extends keyof ComponentsAndVariants = 'dropdown'> extends Omit<BoxProps<'button', TKey>, 'ref' | 'tag'> {
|
|
6
|
+
name?: string;
|
|
7
|
+
defaultValue?: TVal | TVal[];
|
|
8
|
+
value?: TVal | TVal[];
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Turn the control into the APG *editable* combobox: a text field that filters the listbox, and a
|
|
12
|
+
* different pattern rather than a decoration — the field carries the role, the ARIA and your `props`.
|
|
13
|
+
* Printable keys type instead of jumping, Home/End and left/right move the caret, and Escape closes
|
|
14
|
+
* the listbox before it clears the field.
|
|
15
|
+
*/
|
|
16
|
+
isSearchable?: boolean;
|
|
17
|
+
searchPlaceholder?: string;
|
|
18
|
+
hideIcon?: boolean;
|
|
19
|
+
/** Show checkbox for each item in multiple selection mode */
|
|
20
|
+
showCheckbox?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The dropdown's name, rendered above it and pointed at by `aria-labelledby`. A combobox is not named by
|
|
23
|
+
* what it contains — accname does not read a combobox at all, and the trigger text is its *value* — so
|
|
24
|
+
* without this (or your own `aria-label`) it has no accessible name.
|
|
25
|
+
*/
|
|
26
|
+
label?: React.ReactNode;
|
|
27
|
+
/** Styles for the wrapper the label and the trigger share. Only rendered when there is a label. */
|
|
28
|
+
labelProps?: BoxProps<'div'>;
|
|
29
|
+
/** BoxProps applied to the opened items container (dropdown.items) */
|
|
30
|
+
itemsProps?: BoxStyleProps;
|
|
31
|
+
/** BoxProps applied to the chevron icon container (dropdown.icon) */
|
|
32
|
+
iconProps?: BoxStyleProps;
|
|
33
|
+
onChange?: (value: TVal | undefined, values: TVal[]) => void;
|
|
34
|
+
}
|
|
35
|
+
interface DropdownDisplayProps<TVal> extends Omit<BoxProps, 'children'> {
|
|
36
|
+
children: ((selectedValues: TVal[], isOpen: boolean) => React.ReactNode) | React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
interface DropdownType {
|
|
39
|
+
<TVal>(props: Props<TVal> & RefAttributes<HTMLInputElement>): React.ReactNode;
|
|
40
|
+
Item: <TVal>(props: DropdownItemProps<TVal>) => React.ReactNode;
|
|
41
|
+
Unselect: (props: BoxProps) => React.ReactNode;
|
|
42
|
+
SelectAll: (props: BoxProps) => React.ReactNode;
|
|
43
|
+
EmptyItem: (props: BoxProps) => React.ReactNode;
|
|
44
|
+
Display: <TVal>(props: DropdownDisplayProps<TVal>) => React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
declare const Dropdown: DropdownType;
|
|
47
|
+
export default Dropdown;
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { n as e } from "../effects.mjs";
|
|
3
|
+
import t from "../box.mjs";
|
|
4
|
+
import { i as n, n as r, o as i, r as a, t as o } from "../behavior.mjs";
|
|
5
|
+
import s from "./baseSvg.mjs";
|
|
6
|
+
import c from "./button.mjs";
|
|
7
|
+
import l from "./flex.mjs";
|
|
8
|
+
import u from "./checkbox.mjs";
|
|
9
|
+
import d from "./textbox.mjs";
|
|
10
|
+
import ee from "./overlay.mjs";
|
|
11
|
+
import f from "./presence.mjs";
|
|
12
|
+
import { createContext as p, forwardRef as m, memo as h, useCallback as g, useContext as _, useEffect as v, useMemo as y, useRef as b, useState as x } from "react";
|
|
13
|
+
import { Fragment as S, jsx as C, jsxs as w } from "react/jsx-runtime";
|
|
14
|
+
//#region src/components/dropdown/dropdownContext.ts
|
|
15
|
+
var te = p(null);
|
|
16
|
+
function ne() {
|
|
17
|
+
let e = _(te);
|
|
18
|
+
if (!e) throw Error("Dropdown sub-components must be used within Dropdown");
|
|
19
|
+
return e;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/dropdown/dropdownRowRenderer.tsx
|
|
23
|
+
var T = {
|
|
24
|
+
item: "dropdown.item",
|
|
25
|
+
unselect: "dropdown.unselect",
|
|
26
|
+
selectAll: "dropdown.selectAll"
|
|
27
|
+
};
|
|
28
|
+
function E({ row: e, index: n }) {
|
|
29
|
+
let { valueToUse: r, multiple: i, variant: a, showCheckbox: o, selectRow: s, optionId: c, activeIndex: l, rowRef: d, isRowDisabled: ee } = ne(), f = e.kind === "item", p = ee(n), m = f ? r.includes(e.element.props.value) : e.kind === "unselect" && r.length === 0, { value: h, onClick: g, children: _, ...v } = e.element.props, y = o && i && f;
|
|
30
|
+
return /* @__PURE__ */ C(t, {
|
|
31
|
+
ref: d(n),
|
|
32
|
+
component: T[e.kind],
|
|
33
|
+
variant: [a, f ? {
|
|
34
|
+
multiple: i,
|
|
35
|
+
highlighted: n === l
|
|
36
|
+
} : { highlighted: n === l }],
|
|
37
|
+
selected: m,
|
|
38
|
+
...v,
|
|
39
|
+
id: c(n),
|
|
40
|
+
children: y ? /* @__PURE__ */ w(S, { children: [/* @__PURE__ */ C(u, {
|
|
41
|
+
readOnly: !0,
|
|
42
|
+
checked: m,
|
|
43
|
+
me: 2,
|
|
44
|
+
props: {
|
|
45
|
+
tabIndex: -1,
|
|
46
|
+
"aria-hidden": !0
|
|
47
|
+
}
|
|
48
|
+
}), _] }) : _,
|
|
49
|
+
props: {
|
|
50
|
+
role: "option",
|
|
51
|
+
...p ? { "aria-disabled": !0 } : {},
|
|
52
|
+
...v.props,
|
|
53
|
+
onClick: p ? void 0 : (e) => {
|
|
54
|
+
g?.(e), s(n, e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
var re = h(E, (e, t) => e.row.element === t.row.element && e.index === t.index);
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/components/dropdown/dropdownItems.tsx
|
|
62
|
+
function D(e, t, n) {
|
|
63
|
+
return e ? {
|
|
64
|
+
role: "listbox",
|
|
65
|
+
"aria-labelledby": n,
|
|
66
|
+
...t ? { "aria-multiselectable": !0 } : {}
|
|
67
|
+
} : { role: "status" };
|
|
68
|
+
}
|
|
69
|
+
function ie(e) {
|
|
70
|
+
let { presence: n, rows: r, emptyItem: i, triggerRef: a, popupRef: o, listboxId: s, labelledBy: c, itemsProps: l } = e, { present: u, ref: d, props: f } = n, { multiple: p, variant: m } = ne(), [h, _] = x(!1), v = h ? 0 : a.current?.getBoundingClientRect().height ?? 0, y = g((e) => {
|
|
71
|
+
let t = e.top - e.windowScrollY > window.innerHeight / 2;
|
|
72
|
+
_((e) => e === t ? e : t);
|
|
73
|
+
}, []);
|
|
74
|
+
return /* @__PURE__ */ C(t, {
|
|
75
|
+
position: "absolute",
|
|
76
|
+
inset: 0,
|
|
77
|
+
children: /* @__PURE__ */ C(ee, {
|
|
78
|
+
ref: o,
|
|
79
|
+
minWidth: "fit-content",
|
|
80
|
+
style: { transform: h ? "translateY(calc(-100% - 2px))" : `translateY(${v}px)` },
|
|
81
|
+
onPositionChange: y,
|
|
82
|
+
children: /* @__PURE__ */ w(t, {
|
|
83
|
+
ref: d,
|
|
84
|
+
component: "dropdown.items",
|
|
85
|
+
...l,
|
|
86
|
+
variant: [m, {
|
|
87
|
+
up: h,
|
|
88
|
+
closed: !u && !h,
|
|
89
|
+
closedUp: !u && h
|
|
90
|
+
}],
|
|
91
|
+
id: s,
|
|
92
|
+
props: {
|
|
93
|
+
...D(r.length > 0, p, c),
|
|
94
|
+
...f
|
|
95
|
+
},
|
|
96
|
+
children: [r.map((e, t) => /* @__PURE__ */ C(re, {
|
|
97
|
+
row: e,
|
|
98
|
+
index: t
|
|
99
|
+
}, ae(e, t))), r.length === 0 && i && /* @__PURE__ */ C(t, {
|
|
100
|
+
component: "dropdown.emptyItem",
|
|
101
|
+
variant: m,
|
|
102
|
+
...i.props
|
|
103
|
+
})]
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function ae(e, t) {
|
|
109
|
+
return e.kind === "item" ? e.element.props.value : `${e.kind}-${t}`;
|
|
110
|
+
}
|
|
111
|
+
ie.displayName = "DropdownItems";
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/components/dropdown/dropdownSearch.tsx
|
|
114
|
+
function oe({ id: e, value: t, onValueChange: n, placeholder: r, inputRef: i, comboboxProps: a, onOpen: o }) {
|
|
115
|
+
let s = g((e) => n(e.target.value), [n]), c = g((e) => {
|
|
116
|
+
e.stopPropagation(), o(e);
|
|
117
|
+
}, [o]);
|
|
118
|
+
return /* @__PURE__ */ C(l, {
|
|
119
|
+
ai: "center",
|
|
120
|
+
position: "absolute",
|
|
121
|
+
inset: 0,
|
|
122
|
+
p: 3,
|
|
123
|
+
children: /* @__PURE__ */ C(d, {
|
|
124
|
+
clean: !0,
|
|
125
|
+
id: e,
|
|
126
|
+
value: t,
|
|
127
|
+
placeholder: r,
|
|
128
|
+
onChange: s,
|
|
129
|
+
ref: i,
|
|
130
|
+
color: "currentColor",
|
|
131
|
+
width: "fit",
|
|
132
|
+
props: {
|
|
133
|
+
role: "combobox",
|
|
134
|
+
"aria-autocomplete": "list",
|
|
135
|
+
autoComplete: "off",
|
|
136
|
+
spellCheck: !1,
|
|
137
|
+
...a,
|
|
138
|
+
onClick: c
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/components/dropdown/utils.ts
|
|
145
|
+
function se(e) {
|
|
146
|
+
if (e == null) return "";
|
|
147
|
+
if (typeof e == "object") {
|
|
148
|
+
let t = e.props?.children;
|
|
149
|
+
return t == null ? "" : typeof t == "object" ? (Array.isArray(t) ? t : [t]).map((e) => se(e)).join("") : t.toString();
|
|
150
|
+
}
|
|
151
|
+
return e.toString();
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/components/dropdown.tsx
|
|
155
|
+
function ce(e) {
|
|
156
|
+
let t = e?.props?.disabled;
|
|
157
|
+
return (Array.isArray(t) ? t[0] : t) === !0;
|
|
158
|
+
}
|
|
159
|
+
function le(e) {
|
|
160
|
+
return e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
161
|
+
}
|
|
162
|
+
var ue = /* @__PURE__ */ new Set([
|
|
163
|
+
" ",
|
|
164
|
+
"Home",
|
|
165
|
+
"End",
|
|
166
|
+
"ArrowLeft",
|
|
167
|
+
"ArrowRight"
|
|
168
|
+
]);
|
|
169
|
+
function de(u, ee) {
|
|
170
|
+
let { name: p, defaultValue: m, value: h, multiple: _ = !1, isSearchable: S, searchPlaceholder: ne, children: T, hideIcon: E, showCheckbox: re = !1, label: D, labelProps: ae, itemsProps: de, iconProps: O, onChange: k, props: fe, ...A } = u, [pe, j] = x(Array.isArray(m) ? m : m ? [m] : []), me = "value" in u, M = y(() => me ? Array.isArray(h) ? h : h ? [h] : [] : pe, [
|
|
171
|
+
me,
|
|
172
|
+
h,
|
|
173
|
+
pe
|
|
174
|
+
]), [he, ge] = x(null), [N, P] = x(!1), F = b(null), _e = g((e) => {
|
|
175
|
+
F.current = e;
|
|
176
|
+
}, []), ve = b(null), I = b(null), L = r("dropdown"), ye = A.id ?? `${L}-trigger`, be = `${L}-listbox`, xe = `${L}-label`, Se = D != null && D !== !1, Ce = g((e) => `${L}-option-${e}`, [L]), R = i((e = !1) => {
|
|
177
|
+
P(!1), e || ge(null);
|
|
178
|
+
}), z = y(() => (Array.isArray(T) ? T : [T]).flatMap((e) => e).filter(Boolean), [T]), B = y(() => z.filter((e) => e.type?.displayName === "DropdownItem"), [z]), we = y(() => {
|
|
179
|
+
let e = /* @__PURE__ */ new Map();
|
|
180
|
+
for (let t of B) e.set(t, se(t));
|
|
181
|
+
return e;
|
|
182
|
+
}, [B]), V = g((e) => we.get(e) ?? se(e), [we]), Te = S ? he ?? "" : "", H = y(() => Te ? B.filter((e) => V(e).toLowerCase().includes(Te.toLowerCase())) : B, [
|
|
183
|
+
Te,
|
|
184
|
+
B,
|
|
185
|
+
V
|
|
186
|
+
]), U = y(() => z.find((e) => e.type?.displayName === "DropdownUnselect"), [z]), W = y(() => z.find((e) => e.type?.displayName === "DropdownSelectAll"), [z]), Ee = y(() => z.find((e) => e.type?.displayName === "DropdownEmptyItem"), [z]), G = y(() => z.find((e) => e.type?.displayName === "DropdownDisplay"), [z]), K = y(() => !S || G ? "" : B.filter((e) => M.includes(e.props.value)).map((e) => V(e)).join(", "), [
|
|
187
|
+
S,
|
|
188
|
+
G,
|
|
189
|
+
B,
|
|
190
|
+
M,
|
|
191
|
+
V
|
|
192
|
+
]), De = !!(W && _ && H.length > M.length), Oe = !!(U && H.length > 0 && !De), q = y(() => {
|
|
193
|
+
let e = [];
|
|
194
|
+
Oe && U && e.push({
|
|
195
|
+
kind: "unselect",
|
|
196
|
+
element: U
|
|
197
|
+
}), De && W && e.push({
|
|
198
|
+
kind: "selectAll",
|
|
199
|
+
element: W
|
|
200
|
+
});
|
|
201
|
+
for (let t of H) e.push({
|
|
202
|
+
kind: "item",
|
|
203
|
+
element: t
|
|
204
|
+
});
|
|
205
|
+
return e;
|
|
206
|
+
}, [
|
|
207
|
+
Oe,
|
|
208
|
+
U,
|
|
209
|
+
De,
|
|
210
|
+
W,
|
|
211
|
+
H
|
|
212
|
+
]), J = g((e) => ce(q[e]?.element), [q]), ke = g((e) => {
|
|
213
|
+
let t = q[e];
|
|
214
|
+
return t ? V(t.element) : "";
|
|
215
|
+
}, [q, V]), Ae = y(() => {
|
|
216
|
+
if (S && (N || K !== "")) return null;
|
|
217
|
+
if (G) return typeof G.props.children == "function" ? G.props.children(M, N) : G.props.children;
|
|
218
|
+
let e = H.filter((e) => M.includes(e.props.value));
|
|
219
|
+
if (_ && e.length > 1) return e.map((e) => V(e)).join(", ");
|
|
220
|
+
let t = e.at(0);
|
|
221
|
+
return t?.props.children ?? t?.props.value ?? (_ ? null : U?.props.children);
|
|
222
|
+
}, [
|
|
223
|
+
_,
|
|
224
|
+
H,
|
|
225
|
+
M,
|
|
226
|
+
U,
|
|
227
|
+
N,
|
|
228
|
+
S,
|
|
229
|
+
K,
|
|
230
|
+
G,
|
|
231
|
+
V
|
|
232
|
+
]), je = g((e, ...t) => {
|
|
233
|
+
if (t.length === 0) j([]), k?.(void 0, []);
|
|
234
|
+
else if (_ && t.length > 1) {
|
|
235
|
+
let e = t.map((e) => e.props.value);
|
|
236
|
+
j(e), k?.(void 0, e);
|
|
237
|
+
} else if (t.length === 1) {
|
|
238
|
+
let e = t[0];
|
|
239
|
+
if (_) {
|
|
240
|
+
let t = M.filter((t) => t !== e.props.value);
|
|
241
|
+
t.length === M.length && t.push(e.props.value), j(t), k?.(e.props.value, t);
|
|
242
|
+
} else j([e.props.value]), k?.(e.props.value, [e.props.value]);
|
|
243
|
+
}
|
|
244
|
+
e.stopPropagation(), _ ? S && setTimeout(() => I.current?.focus(), 0) : R();
|
|
245
|
+
}, [
|
|
246
|
+
_,
|
|
247
|
+
S,
|
|
248
|
+
M,
|
|
249
|
+
k,
|
|
250
|
+
R
|
|
251
|
+
]), Y = i((e, t) => {
|
|
252
|
+
let n = q[e];
|
|
253
|
+
!n || J(e) || (n.kind === "unselect" ? je(t) : n.kind === "selectAll" ? je(t, ...B) : je(t, n.element));
|
|
254
|
+
}), X = o({
|
|
255
|
+
count: q.length,
|
|
256
|
+
focusItems: !1,
|
|
257
|
+
defaultActiveIndex: -1,
|
|
258
|
+
isDisabled: J,
|
|
259
|
+
textOf: S ? void 0 : ke,
|
|
260
|
+
onSelect: Y
|
|
261
|
+
}), Me = X.setActiveIndex, Ne = g((e) => Me(-1, {
|
|
262
|
+
reason: "programmatic",
|
|
263
|
+
event: e
|
|
264
|
+
}), [Me]);
|
|
265
|
+
n({
|
|
266
|
+
enabled: N,
|
|
267
|
+
inside: [F, ve],
|
|
268
|
+
onDismiss: (e) => R(e === "escape")
|
|
269
|
+
}), a({
|
|
270
|
+
enabled: N,
|
|
271
|
+
returnTo: S ? I : F
|
|
272
|
+
}), v(() => {
|
|
273
|
+
N && I.current?.focus();
|
|
274
|
+
}, [N]);
|
|
275
|
+
let Z = X.activeIndex, Pe = X.activeItem;
|
|
276
|
+
e(() => {
|
|
277
|
+
!N || Z === -1 || Pe()?.scrollIntoView?.({ block: "nearest" });
|
|
278
|
+
}, [
|
|
279
|
+
N,
|
|
280
|
+
Z,
|
|
281
|
+
Pe
|
|
282
|
+
]);
|
|
283
|
+
let Fe = (e) => {
|
|
284
|
+
let t = e === "first" ? 1 : -1;
|
|
285
|
+
for (let n = e === "first" ? 0 : q.length - 1; n >= 0 && n < q.length; n += t) if (!J(n)) return n;
|
|
286
|
+
return -1;
|
|
287
|
+
}, Q = (e) => {
|
|
288
|
+
let t = q.findIndex((e) => e.kind === "item" && M.includes(e.element.props.value));
|
|
289
|
+
return t !== -1 && !J(t) ? t : e === "none" ? -1 : Fe(e);
|
|
290
|
+
}, $ = (e, t) => {
|
|
291
|
+
P(!0), X.setActiveIndex(e, {
|
|
292
|
+
reason: "programmatic",
|
|
293
|
+
event: t
|
|
294
|
+
});
|
|
295
|
+
}, Ie = i((e) => {
|
|
296
|
+
N ? R() : $(Q("none"), e);
|
|
297
|
+
}), Le = i((e) => {
|
|
298
|
+
N || $(Q("none"), e);
|
|
299
|
+
}), Re = i((e) => {
|
|
300
|
+
ge(e), N || P(!0), Ne();
|
|
301
|
+
}), ze = (e) => {
|
|
302
|
+
let { key: t } = e;
|
|
303
|
+
if (S) {
|
|
304
|
+
if (t === "ArrowDown" || t === "ArrowUp") {
|
|
305
|
+
e.preventDefault(), $(Q(t === "ArrowUp" ? "last" : e.altKey ? "none" : "first"), e);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
t === "Escape" && ge("");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (t === "ArrowDown" || t === "Enter" || t === " ") {
|
|
312
|
+
e.preventDefault(), $(Q(e.altKey ? "none" : "first"), e);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (t === "ArrowUp") {
|
|
316
|
+
e.preventDefault(), $(Q("last"), e);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (t === "Home" || t === "End") {
|
|
320
|
+
e.preventDefault(), $(Fe(t === "Home" ? "first" : "last"), e);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
le(e) && (P(!0), X.onKeyDown(e));
|
|
324
|
+
}, Be = i((e) => {
|
|
325
|
+
if (fe?.onKeyDown?.(e), !e.defaultPrevented) {
|
|
326
|
+
if (!N) {
|
|
327
|
+
ze(e);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (e.key === "Tab") {
|
|
331
|
+
!_ && X.activeIndex !== -1 && Y(X.activeIndex, e), R();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (e.altKey && e.key === "ArrowUp") {
|
|
335
|
+
e.preventDefault(), X.activeIndex !== -1 && Y(X.activeIndex, e), R();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (S && ue.has(e.key)) {
|
|
339
|
+
Ne(e);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
X.onKeyDown(e);
|
|
343
|
+
}
|
|
344
|
+
}), Ve = q.length > 0 || !!Ee, He = N && Z !== -1 && Ve ? Ce(Z) : void 0, Ue = X.itemProps, We = y(() => ({
|
|
345
|
+
valueToUse: M,
|
|
346
|
+
multiple: _,
|
|
347
|
+
variant: A.variant,
|
|
348
|
+
showCheckbox: re,
|
|
349
|
+
selectRow: Y,
|
|
350
|
+
optionId: Ce,
|
|
351
|
+
activeIndex: Z,
|
|
352
|
+
rowRef: (e) => Ue(e).ref,
|
|
353
|
+
isRowDisabled: J
|
|
354
|
+
}), [
|
|
355
|
+
M,
|
|
356
|
+
_,
|
|
357
|
+
A.variant,
|
|
358
|
+
re,
|
|
359
|
+
Y,
|
|
360
|
+
Ce,
|
|
361
|
+
Z,
|
|
362
|
+
Ue,
|
|
363
|
+
J
|
|
364
|
+
]), Ge = {
|
|
365
|
+
"aria-expanded": N,
|
|
366
|
+
"aria-controls": N && Ve ? be : void 0,
|
|
367
|
+
"aria-activedescendant": He,
|
|
368
|
+
"aria-labelledby": Se ? xe : void 0,
|
|
369
|
+
...fe,
|
|
370
|
+
onKeyDown: Be
|
|
371
|
+
}, Ke = M.map((e) => {
|
|
372
|
+
let t = JSON.stringify(e);
|
|
373
|
+
return /* @__PURE__ */ C(d, {
|
|
374
|
+
ref: ee,
|
|
375
|
+
name: p,
|
|
376
|
+
type: "hidden",
|
|
377
|
+
value: t ?? ""
|
|
378
|
+
}, t);
|
|
379
|
+
}), qe = !E && /* @__PURE__ */ C(l, {
|
|
380
|
+
component: "dropdown.icon",
|
|
381
|
+
...O,
|
|
382
|
+
children: /* @__PURE__ */ C(s, {
|
|
383
|
+
viewBox: "0 0 10 6",
|
|
384
|
+
width: "0.6rem",
|
|
385
|
+
rotate: N ? 180 : 0,
|
|
386
|
+
children: /* @__PURE__ */ C("path", {
|
|
387
|
+
stroke: "currentColor",
|
|
388
|
+
strokeLinecap: "round",
|
|
389
|
+
strokeLinejoin: "round",
|
|
390
|
+
strokeWidth: "2",
|
|
391
|
+
d: "m1 1 4 4 4-4"
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
}), Je = Ve && /* @__PURE__ */ C(f, {
|
|
395
|
+
present: N,
|
|
396
|
+
children: (e) => /* @__PURE__ */ C(ie, {
|
|
397
|
+
presence: e,
|
|
398
|
+
rows: q,
|
|
399
|
+
emptyItem: Ee,
|
|
400
|
+
triggerRef: F,
|
|
401
|
+
popupRef: ve,
|
|
402
|
+
listboxId: be,
|
|
403
|
+
labelledBy: Se ? xe : ye,
|
|
404
|
+
itemsProps: de
|
|
405
|
+
})
|
|
406
|
+
}), Ye = S ? /* @__PURE__ */ w(t, {
|
|
407
|
+
ref: _e,
|
|
408
|
+
component: "dropdown",
|
|
409
|
+
props: { onClick: Ie },
|
|
410
|
+
position: "relative",
|
|
411
|
+
pe: E ? void 0 : 6,
|
|
412
|
+
minWidth: N ? 36 : void 0,
|
|
413
|
+
width: "fit-content",
|
|
414
|
+
...A,
|
|
415
|
+
id: void 0,
|
|
416
|
+
children: [
|
|
417
|
+
Ke,
|
|
418
|
+
/* @__PURE__ */ C(oe, {
|
|
419
|
+
id: ye,
|
|
420
|
+
value: he ?? K,
|
|
421
|
+
onValueChange: Re,
|
|
422
|
+
placeholder: N ? ne : void 0,
|
|
423
|
+
inputRef: I,
|
|
424
|
+
comboboxProps: Ge,
|
|
425
|
+
onOpen: Le
|
|
426
|
+
}),
|
|
427
|
+
Ae ?? /* @__PURE__ */ C(t, {
|
|
428
|
+
tag: "span",
|
|
429
|
+
visibility: "hidden",
|
|
430
|
+
children: K || "\xA0"
|
|
431
|
+
}),
|
|
432
|
+
qe,
|
|
433
|
+
Je
|
|
434
|
+
]
|
|
435
|
+
}) : /* @__PURE__ */ w(c, {
|
|
436
|
+
ref: _e,
|
|
437
|
+
onClick: Ie,
|
|
438
|
+
component: "dropdown",
|
|
439
|
+
type: "button",
|
|
440
|
+
props: {
|
|
441
|
+
tabIndex: 0,
|
|
442
|
+
role: "combobox",
|
|
443
|
+
...Ge
|
|
444
|
+
},
|
|
445
|
+
position: "relative",
|
|
446
|
+
pe: E ? void 0 : 6,
|
|
447
|
+
width: "fit-content",
|
|
448
|
+
...A,
|
|
449
|
+
id: ye,
|
|
450
|
+
children: [
|
|
451
|
+
Ke,
|
|
452
|
+
Ae ?? "\xA0",
|
|
453
|
+
qe,
|
|
454
|
+
Je
|
|
455
|
+
]
|
|
456
|
+
});
|
|
457
|
+
return /* @__PURE__ */ C(te.Provider, {
|
|
458
|
+
value: We,
|
|
459
|
+
children: Se ? /* @__PURE__ */ w(l, {
|
|
460
|
+
d: "column",
|
|
461
|
+
gap: 1,
|
|
462
|
+
width: "fit-content",
|
|
463
|
+
...ae,
|
|
464
|
+
children: [/* @__PURE__ */ C(t, {
|
|
465
|
+
tag: "span",
|
|
466
|
+
id: xe,
|
|
467
|
+
children: D
|
|
468
|
+
}), Ye]
|
|
469
|
+
}) : Ye
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function O(e) {
|
|
473
|
+
let t = (e) => null;
|
|
474
|
+
return t.displayName = e, t;
|
|
475
|
+
}
|
|
476
|
+
var k = m(de);
|
|
477
|
+
k.Item = O("DropdownItem"), k.Unselect = O("DropdownUnselect"), k.SelectAll = O("DropdownSelectAll"), k.EmptyItem = O("DropdownEmptyItem"), k.Display = O("DropdownDisplay"), k.displayName = "Dropdown";
|
|
478
|
+
//#endregion
|
|
479
|
+
export { k as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../rolldown-runtime.cjs");let t=require("react"),n=require("react/jsx-runtime"),r=require("@box-kite/react");r=e.t(r,1);function i(e,t){let{inline:i,...a}=e;return(0,n.jsx)(r.default,{ref:t,display:i?`inline-flex`:`flex`,...a})}var a=(0,t.forwardRef)(i);a.displayName=`Flex`,exports.default=a;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps } from '../box';
|
|
3
|
+
import { ExtractElementFromTag } from '../react/reactTypes';
|
|
4
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
5
|
+
declare const _default: <TTag extends keyof React.JSX.IntrinsicElements = "div", TKey extends keyof ComponentsAndVariants = never>(props: BoxProps<TTag, TKey> & RefAttributes<ExtractElementFromTag<TTag>>) => React.ReactNode;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { forwardRef as e } from "react";
|
|
2
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import n from "@box-kite/react";
|
|
4
|
+
//#region src/components/flex.tsx
|
|
5
|
+
function r(e, r) {
|
|
6
|
+
let { inline: i, ...a } = e;
|
|
7
|
+
return /* @__PURE__ */ t(n, {
|
|
8
|
+
ref: r,
|
|
9
|
+
display: i ? "inline-flex" : "flex",
|
|
10
|
+
...a
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
var i = e(r);
|
|
14
|
+
i.displayName = "Flex";
|
|
15
|
+
//#endregion
|
|
16
|
+
export { i as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../box.cjs");let t=require("react"),n=require("react/jsx-runtime");var r;(function(e){function t(e){let t=Array.from(e.elements).reduce((e,t)=>{let n=t.name;return n?(e[n]||(e[n]=[]),e[n].push(t),e):e},{});return Object.entries(t).reduce((e,[t,r])=>{if(r.length===1){let i=r[0];n(e,t,i.type===`checkbox`||i.type===`radio`?i.checked:i.value)}else n(e,t,r.reduce((e,t)=>(t.type===`checkbox`||t.type===`radio`?t.checked&&e.push(t.value):e.push(t.value),e),[]));return e},{})}e.getFormEntries=t;function n(e,t,n){if(t.includes(`.`)){let r=t.split(`.`),i=e;r.forEach((e,t)=>{if(r.length>t+1){let t=e.match(/^(.+)\[(\d)\]$/);if(t){let[,e,n]=t;i[e]=i[e]||[],i[e][n]=i[e][n]||{},i=i[e][n]}else i[e]=i[e]||{},i=i[e]}else i[e]=n})}else e[t]=n}})(r||={});var i=r;function a(r){let{onSubmit:a,props:o}=r,s=(0,t.useRef)(null),c=(0,t.useCallback)(e=>{e.preventDefault();let t=i.getFormEntries(s.current);a(t,e)},[a]),l={...o,onSubmit:c,ref:s};return(0,n.jsx)(e.default,{tag:`form`,...r,props:l})}a.displayName=`Form`,exports.default=a;
|