@cronocode/react-box 3.1.13 → 3.2.1
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/react-box-rules.md +17 -0
- package/.claude/skills/react-box/SKILL.md +17 -0
- package/BOX_AI_CONTEXT.md +430 -812
- package/components/dropdown/dropdownContext.d.ts +17 -0
- package/components/dropdown/dropdownItemRenderer.d.ts +6 -0
- package/components/dropdown/dropdownItems.d.ts +15 -0
- package/components/dropdown/dropdownSearch.d.ts +8 -0
- package/components/dropdown/utils.d.ts +1 -0
- package/components/dropdown.cjs +1 -1
- package/components/dropdown.d.ts +6 -5
- package/components/dropdown.mjs +212 -160
- package/components/select.cjs +1 -0
- package/components/select.d.ts +39 -0
- package/components/select.mjs +29 -0
- package/core/theme/theme.d.ts +3 -1
- package/core/theme/themeContext.d.ts +1 -1
- package/core.cjs +3 -3
- package/core.mjs +497 -465
- package/package.json +2 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BoxProps } from '../../box';
|
|
2
|
+
import { ClassNameType } from '../../core/classNames';
|
|
3
|
+
export interface DropdownItemProps<TVal = unknown> extends BoxProps {
|
|
4
|
+
value: TVal;
|
|
5
|
+
onClick?(e: React.MouseEvent): void;
|
|
6
|
+
}
|
|
7
|
+
export interface DropdownContextValue<TVal = unknown> {
|
|
8
|
+
valueToUse: TVal[];
|
|
9
|
+
multiple: boolean;
|
|
10
|
+
variant: ClassNameType;
|
|
11
|
+
showCheckbox: boolean;
|
|
12
|
+
itemSelectHandler: (e: React.MouseEvent, ...items: React.ReactElement<DropdownItemProps<TVal>>[]) => void;
|
|
13
|
+
getItemText: (item: React.ReactElement) => string;
|
|
14
|
+
}
|
|
15
|
+
declare const DropdownContext: import('react').Context<DropdownContextValue<any> | null>;
|
|
16
|
+
export declare function useDropdownContext<TVal>(): DropdownContextValue<TVal>;
|
|
17
|
+
export default DropdownContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BoxStyleProps } from '../../types';
|
|
2
|
+
import { DropdownItemProps } from './dropdownContext';
|
|
3
|
+
interface Props<TVal> {
|
|
4
|
+
filteredItems: React.ReactElement<DropdownItemProps<TVal>>[];
|
|
5
|
+
items: React.ReactElement<DropdownItemProps<TVal>>[];
|
|
6
|
+
unselectItem?: React.ReactElement;
|
|
7
|
+
selectAllItem?: React.ReactElement;
|
|
8
|
+
emptyItem?: React.ReactElement;
|
|
9
|
+
showUnselect: boolean;
|
|
10
|
+
showSelectAll: boolean;
|
|
11
|
+
buttonRef: React.RefObject<HTMLButtonElement>;
|
|
12
|
+
itemsProps?: BoxStyleProps;
|
|
13
|
+
}
|
|
14
|
+
export default function DropdownItems<TVal>(props: Props<TVal>): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
search: string;
|
|
3
|
+
onSearchChange: (value: string) => void;
|
|
4
|
+
searchPlaceholder?: string;
|
|
5
|
+
searchBoxRef: React.RefObject<HTMLInputElement>;
|
|
6
|
+
}
|
|
7
|
+
export default function DropdownSearch({ search, onSearchChange, searchPlaceholder, searchBoxRef }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function searchItemText(item: React.ReactElement): string;
|
package/components/dropdown.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),t=require("react"),ne=require("../core.cjs"),se=require("./baseSvg.cjs"),re=require("./button.cjs"),S=require("../box.cjs"),le=require("./tooltip.cjs"),ce=require("./checkbox.cjs"),z=require("./flex.cjs"),F=require("./textbox.cjs"),J=t.createContext(null);function $(){const n=t.useContext(J);if(!n)throw new Error("Dropdown sub-components must be used within Dropdown");return n}function ie({item:n}){const{valueToUse:o,multiple:m,variant:c,showCheckbox:p,itemSelectHandler:r}=$(),{value:l,onClick:k,children:h,...v}=n.props,y=o.includes(l);return s.jsx(S.default,{component:"dropdown.item",variant:[c,{multiple:m}],selected:y,...v,children:p&&m?s.jsxs(s.Fragment,{children:[s.jsx(ce.default,{readOnly:!0,checked:y,mr:2}),h]}):h,props:{...v.props,"aria-selected":y,onClick:w=>{k?.(w),r(w,n)}}},l)}const pe=t.memo(ie,(n,o)=>n.item===o.item);function G(n){const{filteredItems:o,items:m,unselectItem:c,selectAllItem:p,emptyItem:r,showUnselect:l,showSelectAll:k,buttonRef:h,itemsProps:v}=n,{valueToUse:y,variant:w,itemSelectHandler:T}=$(),g=t.useRef(null),[q,A]=t.useState(!1),N=q?0:h.current?.getBoundingClientRect().height??0,C=t.useCallback(d=>{const a=d.top-d.windowScrollY>window.innerHeight/2;A(j=>j===a?j:a)},[]);return s.jsx(S.default,{position:"absolute",inset:0,children:s.jsx(le.default,{ref:g,minWidth:"fit-content",style:{transform:q?"translateY(calc(-100% - 2px))":`translateY(${N}px)`},onPositionChange:C,children:(o.length>0||r)&&s.jsxs(S.default,{component:"dropdown.items",variant:w,...v,children:[l&&c&&s.jsx(S.default,{component:"dropdown.unselect",variant:w,selected:y.length===0,...c.props,props:{...c.props.props,onClick:d=>T(d)}}),k&&p&&s.jsx(S.default,{component:"dropdown.selectAll",variant:w,...p.props,props:{...p.props.props,onClick:d=>T(d,...m)}}),o.map(d=>s.jsx(pe,{item:d},d.props.value)),o.length===0&&r&&s.jsx(S.default,{component:"dropdown.emptyItem",variant:w,...r.props})]})})})}G.displayName="DropdownItems";function ae({search:n,onSearchChange:o,searchPlaceholder:m,searchBoxRef:c}){const p=t.useCallback(l=>o(l.target.value),[o]),r=t.useCallback(l=>l.stopPropagation(),[]);return s.jsx(z.default,{ai:"center",position:"absolute",inset:0,p:3,children:s.jsx(F.default,{clean:!0,placeholder:m,value:n,onChange:p,ref:c,color:"currentColor",width:"fit",props:{onClick:r}})})}function B(n){if(n==null)return"";if(typeof n=="object"){const o=n.props?.children;return o==null?"":typeof o=="object"?(Array.isArray(o)?o:[o]).map(c=>B(c)).join(""):o.toString()}return n.toString()}function ue(n,o){const{name:m,defaultValue:c,value:p,multiple:r=!1,isSearchable:l,searchPlaceholder:k,children:h,hideIcon:v,showCheckbox:y=!1,itemsProps:w,iconProps:T,onChange:g,props:q,...A}=n,[N,C]=t.useState(Array.isArray(c)?c:c?[c]:[]),d="value"in n,a=t.useMemo(()=>d?Array.isArray(p)?p:p?[p]:[]:N,[d,p,N]),[j,H]=t.useState(""),[x,_,O]=ne.useVisibility(),E=t.useRef(null),f=t.useMemo(()=>(Array.isArray(h)?h:[h]).flatMap(e=>e).filter(Boolean),[h]),M=t.useMemo(()=>f.filter(e=>e.type?.displayName==="DropdownItem"),[f]),L=t.useMemo(()=>{const e=new Map;for(const i of M)e.set(i,B(i));return e},[M]),I=t.useCallback(e=>L.get(e)??B(e),[L]),P=t.useMemo(()=>M.filter(e=>l&&j?I(e).toLowerCase().includes(j.toLowerCase()):!0),[l,j,M,I]),V=t.useMemo(()=>f.find(e=>e.type?.displayName==="DropdownUnselect"),[f]),Y=t.useMemo(()=>f.find(e=>e.type?.displayName==="DropdownSelectAll"),[f]),Q=t.useMemo(()=>f.find(e=>e.type?.displayName==="DropdownEmptyItem"),[f]),R=t.useMemo(()=>f.find(e=>e.type?.displayName==="DropdownDisplay"),[f]),X=t.useMemo(()=>{if(x&&l)return null;if(R)return typeof R.props.children=="function"?R.props.children(a,x):R.props.children;const e=P.filter(u=>a.includes(u.props.value));if(r&&e.length>1)return e.map(u=>I(u)).join(", ");const i=e.at(0);return i?.props.children??i?.props.value??(r?null:V?.props.children)},[r,P,a,V,x,l,R,I]),K=t.useCallback((e,...i)=>{if(i.length===0)C([]),g?.(void 0,[]);else if(r&&i.length>1){const u=i.map(D=>D.props.value);C(u),g?.(void 0,u)}else if(i.length===1){const u=i[0];if(r){const D=a.filter(oe=>oe!==u.props.value);D.length===a.length&&D.push(u.props.value),C(D),g?.(u.props.value,D)}else C([u.props.value]),g?.(u.props.value,[u.props.value])}r?(e.stopPropagation(),setTimeout(()=>E.current?.focus(),0)):(_(!1),setTimeout(()=>O.current?.focus(),0))},[r,a,C,g,_,O]);t.useEffect(()=>{x?setTimeout(()=>{E.current?.focus()},0):H("")},[x]);const Z=t.useCallback(()=>_(e=>!e),[_]),W=!!(Y&&r&&P.length>a.length),ee=!!(V&&P.length>0&&!W),te=t.useMemo(()=>({valueToUse:a,multiple:r,variant:A.variant,showCheckbox:y,itemSelectHandler:K,getItemText:I}),[a,r,A.variant,y,K,I]);return s.jsx(J.Provider,{value:te,children:s.jsxs(re.default,{ref:O,onClick:Z,component:"dropdown",props:{tabIndex:0,...q},position:"relative",pr:v?void 0:6,minWidth:x&&l?36:void 0,width:"fit-content",...A,children:[a.map(e=>{const i=JSON.stringify(e);return s.jsx(F.default,{ref:o,name:m,type:"hidden",value:i??""},i)}),l&&x&&s.jsx(ae,{search:j,onSearchChange:H,searchPlaceholder:k,searchBoxRef:E}),X??" ",!v&&s.jsx(z.default,{component:"dropdown.icon",...T,children:s.jsx(se.default,{viewBox:"0 0 10 6",width:"0.6rem",rotate:x?180:0,children:s.jsx("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"m1 1 4 4 4-4"})})}),x&&s.jsx(G,{filteredItems:P,items:M,unselectItem:V,selectAllItem:Y,emptyItem:Q,showUnselect:ee,showSelectAll:W,buttonRef:O,itemsProps:w})]})})}function U(n){const o=m=>null;return o.displayName=n,o}const b=t.forwardRef(ue);b.Item=U("DropdownItem");b.Unselect=U("DropdownUnselect");b.SelectAll=U("DropdownSelectAll");b.EmptyItem=U("DropdownEmptyItem");b.Display=U("DropdownDisplay");b.displayName="Dropdown";exports.default=b;
|
package/components/dropdown.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RefAttributes } from 'react';
|
|
2
2
|
import { BoxProps } from '../box';
|
|
3
|
-
import { ComponentsAndVariants } from '../types';
|
|
3
|
+
import { BoxStyleProps, ComponentsAndVariants } from '../types';
|
|
4
|
+
import { DropdownItemProps } from './dropdown/dropdownContext';
|
|
4
5
|
interface Props<TVal, TKey extends keyof ComponentsAndVariants = 'dropdown'> extends Omit<BoxProps<'button', TKey>, 'ref' | 'tag'> {
|
|
5
6
|
name?: string;
|
|
6
7
|
defaultValue?: TVal | TVal[];
|
|
@@ -11,12 +12,12 @@ interface Props<TVal, TKey extends keyof ComponentsAndVariants = 'dropdown'> ext
|
|
|
11
12
|
hideIcon?: boolean;
|
|
12
13
|
/** Show checkbox for each item in multiple selection mode */
|
|
13
14
|
showCheckbox?: boolean;
|
|
15
|
+
/** BoxProps applied to the opened items container (dropdown.items) */
|
|
16
|
+
itemsProps?: BoxStyleProps;
|
|
17
|
+
/** BoxProps applied to the chevron icon container (dropdown.icon) */
|
|
18
|
+
iconProps?: BoxStyleProps;
|
|
14
19
|
onChange?: (value: TVal | undefined, values: TVal[]) => void;
|
|
15
20
|
}
|
|
16
|
-
interface DropdownItemProps<TVal> extends BoxProps {
|
|
17
|
-
value: TVal;
|
|
18
|
-
onClick?(e: React.MouseEvent): void;
|
|
19
|
-
}
|
|
20
21
|
interface DropdownDisplayProps<TVal> extends Omit<BoxProps, 'children'> {
|
|
21
22
|
children: ((selectedValues: TVal[], isOpen: boolean) => React.ReactNode) | React.ReactNode;
|
|
22
23
|
}
|
package/components/dropdown.mjs
CHANGED
|
@@ -1,178 +1,230 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import G from "./
|
|
10
|
-
import
|
|
11
|
-
|
|
1
|
+
import { jsx as r, jsxs as W, Fragment as ie } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as pe, useContext as ce, memo as ae, useRef as q, useState as K, useCallback as A, forwardRef as de, useMemo as u, useEffect as ue } from "react";
|
|
3
|
+
import { b as me } from "../core.mjs";
|
|
4
|
+
import fe from "./baseSvg.mjs";
|
|
5
|
+
import he from "./button.mjs";
|
|
6
|
+
import b from "../box.mjs";
|
|
7
|
+
import we from "./tooltip.mjs";
|
|
8
|
+
import ye from "./checkbox.mjs";
|
|
9
|
+
import G from "./flex.mjs";
|
|
10
|
+
import Q from "./textbox.mjs";
|
|
11
|
+
const X = pe(null);
|
|
12
|
+
function Z() {
|
|
13
|
+
const o = ce(X);
|
|
14
|
+
if (!o) throw new Error("Dropdown sub-components must be used within Dropdown");
|
|
15
|
+
return o;
|
|
16
|
+
}
|
|
17
|
+
function ve({ item: o }) {
|
|
18
|
+
const { valueToUse: t, multiple: m, variant: l, showCheckbox: p, itemSelectHandler: n } = Z(), { value: s, onClick: P, children: h, ...g } = o.props, v = t.includes(s);
|
|
19
|
+
return /* @__PURE__ */ r(
|
|
20
|
+
b,
|
|
21
|
+
{
|
|
22
|
+
component: "dropdown.item",
|
|
23
|
+
variant: [l, { multiple: m }],
|
|
24
|
+
selected: v,
|
|
25
|
+
...g,
|
|
26
|
+
children: p && m ? /* @__PURE__ */ W(ie, { children: [
|
|
27
|
+
/* @__PURE__ */ r(ye, { readOnly: !0, checked: v, mr: 2 }),
|
|
28
|
+
h
|
|
29
|
+
] }) : h,
|
|
30
|
+
props: {
|
|
31
|
+
...g.props,
|
|
32
|
+
"aria-selected": v,
|
|
33
|
+
onClick: (w) => {
|
|
34
|
+
P?.(w), n(w, o);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
s
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const ge = ae(ve, (o, t) => o.item === t.item);
|
|
42
|
+
function ee(o) {
|
|
43
|
+
const { filteredItems: t, items: m, unselectItem: l, selectAllItem: p, emptyItem: n, showUnselect: s, showSelectAll: P, buttonRef: h, itemsProps: g } = o, { valueToUse: v, variant: w, itemSelectHandler: B } = Z(), C = q(null), [O, T] = K(!1), V = O ? 0 : h.current?.getBoundingClientRect().height ?? 0, I = A((d) => {
|
|
44
|
+
const c = d.top - d.windowScrollY > window.innerHeight / 2;
|
|
45
|
+
T((D) => D === c ? D : c);
|
|
46
|
+
}, []);
|
|
47
|
+
return /* @__PURE__ */ r(b, { position: "absolute", inset: 0, children: /* @__PURE__ */ r(
|
|
48
|
+
we,
|
|
49
|
+
{
|
|
50
|
+
ref: C,
|
|
51
|
+
minWidth: "fit-content",
|
|
52
|
+
style: { transform: O ? "translateY(calc(-100% - 2px))" : `translateY(${V}px)` },
|
|
53
|
+
onPositionChange: I,
|
|
54
|
+
children: (t.length > 0 || n) && /* @__PURE__ */ W(b, { component: "dropdown.items", variant: w, ...g, children: [
|
|
55
|
+
s && l && /* @__PURE__ */ r(
|
|
56
|
+
b,
|
|
57
|
+
{
|
|
58
|
+
component: "dropdown.unselect",
|
|
59
|
+
variant: w,
|
|
60
|
+
selected: v.length === 0,
|
|
61
|
+
...l.props,
|
|
62
|
+
props: { ...l.props.props, onClick: (d) => B(d) }
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
P && p && /* @__PURE__ */ r(
|
|
66
|
+
b,
|
|
67
|
+
{
|
|
68
|
+
component: "dropdown.selectAll",
|
|
69
|
+
variant: w,
|
|
70
|
+
...p.props,
|
|
71
|
+
props: {
|
|
72
|
+
...p.props.props,
|
|
73
|
+
onClick: (d) => B(d, ...m)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
t.map((d) => /* @__PURE__ */ r(ge, { item: d }, d.props.value)),
|
|
78
|
+
t.length === 0 && n && /* @__PURE__ */ r(
|
|
79
|
+
b,
|
|
80
|
+
{
|
|
81
|
+
component: "dropdown.emptyItem",
|
|
82
|
+
variant: w,
|
|
83
|
+
...n.props
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
] })
|
|
87
|
+
}
|
|
88
|
+
) });
|
|
89
|
+
}
|
|
90
|
+
ee.displayName = "DropdownItems";
|
|
91
|
+
function Ce({ search: o, onSearchChange: t, searchPlaceholder: m, searchBoxRef: l }) {
|
|
92
|
+
const p = A((s) => t(s.target.value), [t]), n = A((s) => s.stopPropagation(), []);
|
|
93
|
+
return /* @__PURE__ */ r(G, { ai: "center", position: "absolute", inset: 0, p: 3, children: /* @__PURE__ */ r(
|
|
94
|
+
Q,
|
|
95
|
+
{
|
|
96
|
+
clean: !0,
|
|
97
|
+
placeholder: m,
|
|
98
|
+
value: o,
|
|
99
|
+
onChange: p,
|
|
100
|
+
ref: l,
|
|
101
|
+
color: "currentColor",
|
|
102
|
+
width: "fit",
|
|
103
|
+
props: { onClick: n }
|
|
104
|
+
}
|
|
105
|
+
) });
|
|
106
|
+
}
|
|
107
|
+
function M(o) {
|
|
108
|
+
if (o == null) return "";
|
|
109
|
+
if (typeof o == "object") {
|
|
110
|
+
const t = o.props?.children;
|
|
111
|
+
return t == null ? "" : typeof t == "object" ? (Array.isArray(t) ? t : [t]).map((l) => M(l)).join("") : t.toString();
|
|
112
|
+
}
|
|
113
|
+
return o.toString();
|
|
114
|
+
}
|
|
115
|
+
function Ie(o, t) {
|
|
12
116
|
const {
|
|
13
|
-
name:
|
|
14
|
-
defaultValue:
|
|
15
|
-
value:
|
|
16
|
-
multiple:
|
|
17
|
-
isSearchable:
|
|
18
|
-
searchPlaceholder:
|
|
19
|
-
children:
|
|
20
|
-
hideIcon:
|
|
21
|
-
showCheckbox:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
117
|
+
name: m,
|
|
118
|
+
defaultValue: l,
|
|
119
|
+
value: p,
|
|
120
|
+
multiple: n = !1,
|
|
121
|
+
isSearchable: s,
|
|
122
|
+
searchPlaceholder: P,
|
|
123
|
+
children: h,
|
|
124
|
+
hideIcon: g,
|
|
125
|
+
showCheckbox: v = !1,
|
|
126
|
+
itemsProps: w,
|
|
127
|
+
iconProps: B,
|
|
128
|
+
onChange: C,
|
|
129
|
+
props: O,
|
|
130
|
+
...T
|
|
131
|
+
} = o, [V, I] = K(Array.isArray(l) ? l : l ? [l] : []), d = "value" in o, c = u(
|
|
132
|
+
() => d ? Array.isArray(p) ? p : p ? [p] : [] : V,
|
|
133
|
+
[d, p, V]
|
|
134
|
+
), [D, F] = K(""), [y, E, H] = me(), Y = q(null), f = u(
|
|
135
|
+
() => (Array.isArray(h) ? h : [h]).flatMap((e) => e).filter(Boolean),
|
|
136
|
+
[h]
|
|
137
|
+
), U = u(() => f.filter((e) => e.type?.displayName === "DropdownItem"), [f]), z = u(() => {
|
|
138
|
+
const e = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const i of U)
|
|
140
|
+
e.set(i, M(i));
|
|
141
|
+
return e;
|
|
142
|
+
}, [U]), x = A((e) => z.get(e) ?? M(e), [z]), N = u(() => U.filter((e) => s && D ? x(e).toLowerCase().includes(D.toLowerCase()) : !0), [s, D, U, x]), L = u(() => f.find((e) => e.type?.displayName === "DropdownUnselect"), [f]), J = u(() => f.find((e) => e.type?.displayName === "DropdownSelectAll"), [f]), te = u(() => f.find((e) => e.type?.displayName === "DropdownEmptyItem"), [f]), R = u(() => f.find((e) => e.type?.displayName === "DropdownDisplay"), [f]), oe = u(() => {
|
|
143
|
+
if (y && s) return null;
|
|
144
|
+
if (R)
|
|
145
|
+
return typeof R.props.children == "function" ? R.props.children(c, y) : R.props.children;
|
|
146
|
+
const e = N.filter((a) => c.includes(a.props.value));
|
|
147
|
+
if (n && e.length > 1)
|
|
148
|
+
return e.map((a) => x(a)).join(", ");
|
|
149
|
+
const i = e.at(0);
|
|
150
|
+
return i?.props.children ?? i?.props.value ?? (n ? null : L?.props.children);
|
|
151
|
+
}, [n, N, c, L, y, s, R, x]), _ = A(
|
|
152
|
+
(e, ...i) => {
|
|
153
|
+
if (i.length === 0)
|
|
154
|
+
I([]), C?.(void 0, []);
|
|
155
|
+
else if (n && i.length > 1) {
|
|
156
|
+
const a = i.map((S) => S.props.value);
|
|
157
|
+
I(a), C?.(void 0, a);
|
|
158
|
+
} else if (i.length === 1) {
|
|
159
|
+
const a = i[0];
|
|
160
|
+
if (n) {
|
|
161
|
+
const S = c.filter((le) => le !== a.props.value);
|
|
162
|
+
S.length === c.length && S.push(a.props.value), I(S), C?.(a.props.value, S);
|
|
52
163
|
} else
|
|
53
|
-
|
|
164
|
+
I([a.props.value]), C?.(a.props.value, [a.props.value]);
|
|
54
165
|
}
|
|
55
|
-
|
|
166
|
+
n ? (e.stopPropagation(), setTimeout(() => Y.current?.focus(), 0)) : (E(!1), setTimeout(() => H.current?.focus(), 0));
|
|
56
167
|
},
|
|
57
|
-
[
|
|
168
|
+
[n, c, I, C, E, H]
|
|
169
|
+
);
|
|
170
|
+
ue(() => {
|
|
171
|
+
y ? setTimeout(() => {
|
|
172
|
+
Y.current?.focus();
|
|
173
|
+
}, 0) : F("");
|
|
174
|
+
}, [y]);
|
|
175
|
+
const ne = A(() => E((e) => !e), [E]), $ = !!(J && n && N.length > c.length), re = !!(L && N.length > 0 && !$), se = u(
|
|
176
|
+
() => ({ valueToUse: c, multiple: n, variant: T.variant, showCheckbox: v, itemSelectHandler: _, getItemText: x }),
|
|
177
|
+
[c, n, T.variant, v, _, x]
|
|
58
178
|
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
T.current?.focus(), H.current?.querySelector('[aria-selected="true"]')?.scrollIntoView({ block: "nearest" });
|
|
62
|
-
}, 0) : W("");
|
|
63
|
-
}, [a]);
|
|
64
|
-
const q = j && p && u.length > c.length, ne = v && u.length > 0 && !q;
|
|
65
|
-
return /* @__PURE__ */ V(
|
|
66
|
-
de,
|
|
179
|
+
return /* @__PURE__ */ r(X.Provider, { value: se, children: /* @__PURE__ */ W(
|
|
180
|
+
he,
|
|
67
181
|
{
|
|
68
|
-
ref:
|
|
69
|
-
onClick:
|
|
182
|
+
ref: H,
|
|
183
|
+
onClick: ne,
|
|
70
184
|
component: "dropdown",
|
|
71
|
-
props: { tabIndex: 0, ...
|
|
185
|
+
props: { tabIndex: 0, ...O },
|
|
72
186
|
position: "relative",
|
|
73
|
-
pr:
|
|
74
|
-
minWidth:
|
|
187
|
+
pr: g ? void 0 : 6,
|
|
188
|
+
minWidth: y && s ? 36 : void 0,
|
|
75
189
|
width: "fit-content",
|
|
76
|
-
...
|
|
190
|
+
...T,
|
|
77
191
|
children: [
|
|
78
|
-
c.map((e) =>
|
|
79
|
-
|
|
80
|
-
|
|
192
|
+
c.map((e) => {
|
|
193
|
+
const i = JSON.stringify(e);
|
|
194
|
+
return /* @__PURE__ */ r(Q, { ref: t, name: m, type: "hidden", value: i ?? "" }, i);
|
|
195
|
+
}),
|
|
196
|
+
s && y && /* @__PURE__ */ r(Ce, { search: D, onSearchChange: F, searchPlaceholder: P, searchBoxRef: Y }),
|
|
197
|
+
oe ?? " ",
|
|
198
|
+
!g && /* @__PURE__ */ r(G, { component: "dropdown.icon", ...B, children: /* @__PURE__ */ r(fe, { viewBox: "0 0 10 6", width: "0.6rem", rotate: y ? 180 : 0, children: /* @__PURE__ */ r("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m1 1 4 4 4-4" }) }) }),
|
|
199
|
+
y && /* @__PURE__ */ r(
|
|
200
|
+
ee,
|
|
81
201
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
a && f && e.stopPropagation();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
) }),
|
|
96
|
-
re ?? " ",
|
|
97
|
-
!L && /* @__PURE__ */ o($, { component: "dropdown.icon", children: /* @__PURE__ */ o(ae, { viewBox: "0 0 10 6", width: "0.6rem", rotate: a ? 180 : 0, children: /* @__PURE__ */ o("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m1 1 4 4 4-4" }) }) }),
|
|
98
|
-
/* @__PURE__ */ o(h, { position: "absolute", inset: 0, children: a && /* @__PURE__ */ o(
|
|
99
|
-
me,
|
|
100
|
-
{
|
|
101
|
-
ref: H,
|
|
102
|
-
minWidth: "fit-content",
|
|
103
|
-
style: { transform: Y ? "translateY(calc(-100% - 2px))" : `translateY(${oe}px)` },
|
|
104
|
-
onPositionChange: (e) => te({ top: e.top, scrollY: e.windowScrollY }),
|
|
105
|
-
children: (u.length > 0 || U) && /* @__PURE__ */ V(h, { component: "dropdown.items", children: [
|
|
106
|
-
ne && /* @__PURE__ */ o(
|
|
107
|
-
h,
|
|
108
|
-
{
|
|
109
|
-
component: "dropdown.unselect",
|
|
110
|
-
variant: { compact: x },
|
|
111
|
-
selected: c.length === 0,
|
|
112
|
-
...v.props,
|
|
113
|
-
props: { ...v.props.props, onClick: (e) => B(e) }
|
|
114
|
-
}
|
|
115
|
-
),
|
|
116
|
-
q && /* @__PURE__ */ o(
|
|
117
|
-
h,
|
|
118
|
-
{
|
|
119
|
-
component: "dropdown.selectAll",
|
|
120
|
-
variant: { compact: x },
|
|
121
|
-
...j.props,
|
|
122
|
-
props: { ...j.props.props, onClick: (e) => B(e, ...M) }
|
|
123
|
-
}
|
|
124
|
-
),
|
|
125
|
-
u.map((e) => {
|
|
126
|
-
const { value: n, onClick: t, children: d, ...N } = e.props, O = c.includes(n);
|
|
127
|
-
return /* @__PURE__ */ o(
|
|
128
|
-
h,
|
|
129
|
-
{
|
|
130
|
-
component: "dropdown.item",
|
|
131
|
-
variant: { multiple: p, compact: x },
|
|
132
|
-
selected: O,
|
|
133
|
-
...N,
|
|
134
|
-
children: X && p ? /* @__PURE__ */ V(se, { children: [
|
|
135
|
-
/* @__PURE__ */ o(ue, { readOnly: !0, checked: O, mr: 2 }),
|
|
136
|
-
d
|
|
137
|
-
] }) : d,
|
|
138
|
-
props: {
|
|
139
|
-
...N.props,
|
|
140
|
-
"aria-selected": O,
|
|
141
|
-
onClick: (z) => {
|
|
142
|
-
t?.(z), B(z, e);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
n
|
|
147
|
-
);
|
|
148
|
-
}),
|
|
149
|
-
u.length === 0 && U && /* @__PURE__ */ o(h, { component: "dropdown.emptyItem", variant: { compact: x }, ...U.props })
|
|
150
|
-
] })
|
|
202
|
+
filteredItems: N,
|
|
203
|
+
items: U,
|
|
204
|
+
unselectItem: L,
|
|
205
|
+
selectAllItem: J,
|
|
206
|
+
emptyItem: te,
|
|
207
|
+
showUnselect: re,
|
|
208
|
+
showSelectAll: $,
|
|
209
|
+
buttonRef: H,
|
|
210
|
+
itemsProps: w
|
|
151
211
|
}
|
|
152
|
-
)
|
|
212
|
+
)
|
|
153
213
|
]
|
|
154
214
|
}
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
function g(i) {
|
|
158
|
-
const r = (P) => null;
|
|
159
|
-
return r.displayName = i, r;
|
|
215
|
+
) });
|
|
160
216
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
y.SelectAll = g("DropdownSelectAll");
|
|
165
|
-
y.EmptyItem = g("DropdownEmptyItem");
|
|
166
|
-
y.Display = g("DropdownDisplay");
|
|
167
|
-
y.displayName = "Dropdown";
|
|
168
|
-
function E(i) {
|
|
169
|
-
if (i == null) return "";
|
|
170
|
-
if (typeof i == "object") {
|
|
171
|
-
const r = i.props?.children;
|
|
172
|
-
return r == null ? "" : typeof r == "object" ? (Array.isArray(r) ? r : [r]).map((m) => E(m)).join("") : r.toString();
|
|
173
|
-
}
|
|
174
|
-
return i.toString();
|
|
217
|
+
function j(o) {
|
|
218
|
+
const t = (m) => null;
|
|
219
|
+
return t.displayName = o, t;
|
|
175
220
|
}
|
|
221
|
+
const k = de(Ie);
|
|
222
|
+
k.Item = j("DropdownItem");
|
|
223
|
+
k.Unselect = j("DropdownUnselect");
|
|
224
|
+
k.SelectAll = j("DropdownSelectAll");
|
|
225
|
+
k.EmptyItem = j("DropdownEmptyItem");
|
|
226
|
+
k.Display = j("DropdownDisplay");
|
|
227
|
+
k.displayName = "Dropdown";
|
|
176
228
|
export {
|
|
177
|
-
|
|
229
|
+
k as default
|
|
178
230
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),i=require("react"),s=require("./dropdown.cjs");function M(f,m){const{data:r,def:y,...x}=f,{valueKey:n,displayKey:j,display:a,selectedDisplay:o,placeholder:c,selectAllText:d,emptyText:u}=y,h=i.useMemo(()=>{const e=new Map;for(const t of r)e.set(t[n],t);return e},[r,n]);return l.jsxs(s.default,{ref:m,...x,children:[c&&l.jsx(s.default.Unselect,{children:c}),d&&l.jsx(s.default.SelectAll,{children:d}),u&&l.jsx(s.default.EmptyItem,{children:u}),o&&l.jsx(s.default.Display,{children:(e,t)=>{const S=e.map(v=>h.get(v)).filter(Boolean);return o(S,t)}}),r.map(e=>{const t=e[n];return l.jsx(s.default.Item,{value:t,children:a?a(e):String(e[j??n])},t)})]})}const p=i.forwardRef(M);p.displayName="Select";exports.default=p;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps } from '../box';
|
|
3
|
+
import { BoxStyleProps, ComponentsAndVariants } from '../types';
|
|
4
|
+
interface SelectDef<TRow> {
|
|
5
|
+
/** Key of TRow to use as the option value */
|
|
6
|
+
valueKey: keyof TRow & (string | number);
|
|
7
|
+
/** Key of TRow to display as option text (defaults to valueKey) */
|
|
8
|
+
displayKey?: keyof TRow;
|
|
9
|
+
/** Custom render function for each option */
|
|
10
|
+
display?: (row: TRow) => React.ReactNode;
|
|
11
|
+
/** Custom render function for the selected value display */
|
|
12
|
+
selectedDisplay?: (selectedRows: TRow[], isOpen: boolean) => React.ReactNode;
|
|
13
|
+
/** Placeholder text when nothing is selected */
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
/** Text for "Select all" option in multiple mode */
|
|
16
|
+
selectAllText?: string;
|
|
17
|
+
/** Text shown when search yields no results */
|
|
18
|
+
emptyText?: string;
|
|
19
|
+
}
|
|
20
|
+
interface Props<TRow, TVal extends TRow[keyof TRow], TKey extends keyof ComponentsAndVariants = 'dropdown'> extends Omit<BoxProps<'button', TKey>, 'ref' | 'tag'> {
|
|
21
|
+
data: TRow[];
|
|
22
|
+
def: SelectDef<TRow>;
|
|
23
|
+
name?: string;
|
|
24
|
+
defaultValue?: TVal | TVal[];
|
|
25
|
+
value?: TVal | TVal[];
|
|
26
|
+
multiple?: boolean;
|
|
27
|
+
isSearchable?: boolean;
|
|
28
|
+
searchPlaceholder?: string;
|
|
29
|
+
hideIcon?: boolean;
|
|
30
|
+
showCheckbox?: boolean;
|
|
31
|
+
itemsProps?: BoxStyleProps;
|
|
32
|
+
iconProps?: BoxStyleProps;
|
|
33
|
+
onChange?: (value: TVal | undefined, values: TVal[]) => void;
|
|
34
|
+
}
|
|
35
|
+
interface SelectType {
|
|
36
|
+
<TRow, TVal extends TRow[keyof TRow] = TRow[keyof TRow]>(props: Props<TRow, TVal> & RefAttributes<HTMLInputElement>): React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
declare const Select: SelectType;
|
|
39
|
+
export default Select;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsxs as w, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as v, useMemo as D } from "react";
|
|
3
|
+
import l from "./dropdown.mjs";
|
|
4
|
+
function I(i, m) {
|
|
5
|
+
const { data: n, def: f, ...u } = i, { valueKey: o, displayKey: y, display: s, selectedDisplay: a, placeholder: c, selectAllText: p, emptyText: d } = f, h = D(() => {
|
|
6
|
+
const e = /* @__PURE__ */ new Map();
|
|
7
|
+
for (const t of n)
|
|
8
|
+
e.set(t[o], t);
|
|
9
|
+
return e;
|
|
10
|
+
}, [n, o]);
|
|
11
|
+
return /* @__PURE__ */ w(l, { ref: m, ...u, children: [
|
|
12
|
+
c && /* @__PURE__ */ r(l.Unselect, { children: c }),
|
|
13
|
+
p && /* @__PURE__ */ r(l.SelectAll, { children: p }),
|
|
14
|
+
d && /* @__PURE__ */ r(l.EmptyItem, { children: d }),
|
|
15
|
+
a && /* @__PURE__ */ r(l.Display, { children: (e, t) => {
|
|
16
|
+
const x = e.map((S) => h.get(S)).filter(Boolean);
|
|
17
|
+
return a(x, t);
|
|
18
|
+
} }),
|
|
19
|
+
n.map((e) => {
|
|
20
|
+
const t = e[o];
|
|
21
|
+
return /* @__PURE__ */ r(l.Item, { value: t, children: s ? s(e) : String(e[y ?? o]) }, t);
|
|
22
|
+
})
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
const M = v(I);
|
|
26
|
+
M.displayName = "Select";
|
|
27
|
+
export {
|
|
28
|
+
M as default
|
|
29
|
+
};
|
package/core/theme/theme.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ interface ThemeProps {
|
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
theme?: string;
|
|
5
5
|
use?: 'global' | 'local';
|
|
6
|
+
/** When provided, persists the user-selected theme to localStorage under this key. */
|
|
7
|
+
storageKey?: string;
|
|
6
8
|
}
|
|
7
9
|
declare function Theme(props: ThemeProps): import("react/jsx-runtime").JSX.Element;
|
|
8
10
|
declare namespace Theme {
|
|
9
|
-
function useTheme(): [string, (theme: string) => void];
|
|
11
|
+
function useTheme(): [string, (theme: string | null) => void];
|
|
10
12
|
}
|
|
11
13
|
export default Theme;
|