@luxfi/ui 5.5.3 → 5.6.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 (244) hide show
  1. package/dist/accordion.cjs +213 -0
  2. package/dist/accordion.js +186 -0
  3. package/dist/alert.cjs +553 -0
  4. package/dist/alert.js +531 -0
  5. package/dist/avatar.cjs +149 -0
  6. package/dist/avatar.js +125 -0
  7. package/dist/badge.cjs +611 -0
  8. package/dist/badge.js +589 -0
  9. package/dist/button.cjs +689 -0
  10. package/dist/button.js +664 -0
  11. package/dist/checkbox.cjs +265 -0
  12. package/dist/checkbox.js +241 -0
  13. package/dist/close-button.cjs +73 -0
  14. package/dist/close-button.js +51 -0
  15. package/dist/collapsible.cjs +702 -0
  16. package/dist/collapsible.js +679 -0
  17. package/dist/color-mode.cjs +96 -0
  18. package/dist/color-mode.js +72 -0
  19. package/dist/dialog.cjs +279 -0
  20. package/dist/dialog.js +246 -0
  21. package/dist/drawer.cjs +207 -0
  22. package/dist/drawer.js +175 -0
  23. package/dist/empty-state.cjs +93 -0
  24. package/dist/empty-state.js +71 -0
  25. package/dist/field.cjs +183 -0
  26. package/dist/field.js +160 -0
  27. package/dist/heading.cjs +46 -0
  28. package/dist/heading.js +40 -0
  29. package/dist/icon-button.cjs +491 -0
  30. package/dist/icon-button.js +470 -0
  31. package/dist/image.cjs +572 -0
  32. package/dist/image.js +551 -0
  33. package/dist/index.cjs +5779 -0
  34. package/dist/index.js +5619 -0
  35. package/dist/input-group.cjs +155 -0
  36. package/dist/input-group.js +133 -0
  37. package/dist/input.cjs +65 -0
  38. package/dist/input.js +59 -0
  39. package/dist/link.cjs +630 -0
  40. package/dist/link.js +606 -0
  41. package/dist/menu.cjs +305 -0
  42. package/dist/menu.js +269 -0
  43. package/dist/pin-input.cjs +182 -0
  44. package/dist/pin-input.js +160 -0
  45. package/dist/popover.cjs +327 -0
  46. package/dist/popover.js +294 -0
  47. package/dist/progress-circle.cjs +152 -0
  48. package/dist/progress-circle.js +128 -0
  49. package/dist/progress.cjs +117 -0
  50. package/dist/progress.js +94 -0
  51. package/dist/provider.cjs +62 -0
  52. package/dist/provider.js +40 -0
  53. package/dist/radio.cjs +177 -0
  54. package/dist/radio.js +153 -0
  55. package/dist/rating.cjs +80 -0
  56. package/dist/rating.js +58 -0
  57. package/dist/select.cjs +791 -0
  58. package/dist/select.js +757 -0
  59. package/dist/separator.cjs +57 -0
  60. package/dist/separator.js +51 -0
  61. package/dist/skeleton.cjs +370 -0
  62. package/dist/skeleton.js +346 -0
  63. package/dist/slider.cjs +138 -0
  64. package/dist/slider.js +115 -0
  65. package/dist/switch.cjs +163 -0
  66. package/dist/switch.js +140 -0
  67. package/dist/table.cjs +1044 -0
  68. package/dist/table.js +1013 -0
  69. package/dist/tabs.cjs +240 -0
  70. package/dist/tabs.js +213 -0
  71. package/dist/tag.cjs +651 -0
  72. package/dist/tag.js +628 -0
  73. package/dist/textarea.cjs +65 -0
  74. package/dist/textarea.js +59 -0
  75. package/dist/toaster.cjs +99 -0
  76. package/dist/toaster.js +96 -0
  77. package/dist/tooltip.cjs +171 -0
  78. package/dist/tooltip.js +148 -0
  79. package/dist/utils.cjs +11 -0
  80. package/dist/utils.js +9 -0
  81. package/package.json +270 -65
  82. package/src/accordion.tsx +285 -0
  83. package/src/alert.tsx +221 -0
  84. package/src/avatar.tsx +174 -0
  85. package/src/badge.tsx +158 -0
  86. package/src/button.tsx +411 -0
  87. package/src/checkbox.tsx +307 -0
  88. package/src/close-button.tsx +51 -0
  89. package/src/collapsible.tsx +126 -0
  90. package/src/color-mode.tsx +125 -0
  91. package/src/dialog.tsx +356 -0
  92. package/src/drawer.tsx +186 -0
  93. package/src/empty-state.tsx +97 -0
  94. package/src/field.tsx +202 -0
  95. package/src/heading.tsx +55 -0
  96. package/src/icon-button.tsx +192 -0
  97. package/src/image.tsx +280 -0
  98. package/src/index.ts +192 -0
  99. package/src/input-group.tsx +159 -0
  100. package/src/input.tsx +60 -0
  101. package/src/link.tsx +326 -0
  102. package/src/menu.tsx +471 -0
  103. package/src/pin-input.tsx +187 -0
  104. package/src/popover.tsx +400 -0
  105. package/src/progress-circle.tsx +180 -0
  106. package/src/progress.tsx +109 -0
  107. package/src/provider.tsx +12 -0
  108. package/src/radio.tsx +175 -0
  109. package/src/rating.tsx +79 -0
  110. package/src/select.tsx +696 -0
  111. package/src/separator.tsx +59 -0
  112. package/src/skeleton.tsx +302 -0
  113. package/src/slider.tsx +152 -0
  114. package/src/switch.tsx +158 -0
  115. package/src/table.tsx +621 -0
  116. package/src/tabs.tsx +354 -0
  117. package/src/tag.tsx +159 -0
  118. package/src/textarea.tsx +60 -0
  119. package/src/toaster.tsx +117 -0
  120. package/src/tokens.css +438 -0
  121. package/src/tooltip.tsx +184 -0
  122. package/src/utils/cn.ts +7 -0
  123. package/src/utils.ts +6 -0
  124. package/tokens.css +438 -0
  125. package/commerce/ui/conf.ts +0 -13
  126. package/commerce/ui/context.tsx +0 -123
  127. package/commerce/ui/store.ts +0 -295
  128. package/components/access-code-input.tsx +0 -71
  129. package/components/analytics.tsx +0 -23
  130. package/components/auth/auth-listener.tsx +0 -29
  131. package/components/auth/auth-token/clear-auth-token.tsx +0 -12
  132. package/components/auth/auth-token/set-auth-token.tsx +0 -16
  133. package/components/auth/common-auth-domains.ts +0 -17
  134. package/components/auth/login-panel.tsx +0 -111
  135. package/components/auth/mobile-login-button.tsx +0 -107
  136. package/components/auth/signup-panel.tsx +0 -113
  137. package/components/back-button.tsx +0 -49
  138. package/components/chat-widget.tsx +0 -85
  139. package/components/commerce/bag-button.tsx +0 -98
  140. package/components/commerce/buy-button.tsx +0 -34
  141. package/components/commerce/checkout-button.tsx +0 -129
  142. package/components/commerce/checkout-panel/cart-accordian.tsx +0 -66
  143. package/components/commerce/checkout-panel/checkout-panel-props.ts +0 -10
  144. package/components/commerce/checkout-panel/desktop-bag-carousel.tsx +0 -36
  145. package/components/commerce/checkout-panel/desktop-cp.tsx +0 -83
  146. package/components/commerce/checkout-panel/index.tsx +0 -126
  147. package/components/commerce/checkout-panel/mobile-cp.tsx +0 -67
  148. package/components/commerce/checkout-panel/policy-links.tsx +0 -29
  149. package/components/commerce/checkout-panel/steps-indicator.tsx +0 -39
  150. package/components/commerce/checkout-panel/thank-you.tsx +0 -18
  151. package/components/commerce/desktop-bag-popup.tsx +0 -78
  152. package/components/commerce/drawer/index.tsx +0 -88
  153. package/components/commerce/drawer/micro.tsx +0 -145
  154. package/components/commerce/drawer/shell.tsx +0 -85
  155. package/components/contact-dialog/contact-form.tsx +0 -116
  156. package/components/contact-dialog/disclaimer.tsx +0 -13
  157. package/components/contact-dialog/index.tsx +0 -64
  158. package/components/copyright.tsx +0 -21
  159. package/components/drawer-margin.tsx +0 -28
  160. package/components/footer.tsx +0 -78
  161. package/components/header/desktop-nav-menu.tsx +0 -204
  162. package/components/header/desktop.tsx +0 -65
  163. package/components/header/index.tsx +0 -50
  164. package/components/header/mobile-bag-drawer.tsx +0 -51
  165. package/components/header/mobile-menu-toggle-button.tsx +0 -35
  166. package/components/header/mobile-nav-menu-ai.tsx +0 -51
  167. package/components/header/mobile-nav-menu-item.tsx +0 -47
  168. package/components/header/mobile-nav-menu.tsx +0 -102
  169. package/components/header/mobile.tsx +0 -170
  170. package/components/header/theme-toggle.tsx +0 -26
  171. package/components/icons/avatar.tsx +0 -11
  172. package/components/icons/bag-icon.tsx +0 -10
  173. package/components/icons/index.ts +0 -6
  174. package/components/icons/left-arrow.tsx +0 -11
  175. package/components/icons/lux-logo.tsx +0 -10
  176. package/components/icons/right-arrow.tsx +0 -10
  177. package/components/icons/social-icon.tsx +0 -35
  178. package/components/icons/social-svg.css +0 -3
  179. package/components/index.ts +0 -26
  180. package/components/logo.tsx +0 -92
  181. package/components/main.tsx +0 -27
  182. package/components/mini-chart/index.tsx +0 -8
  183. package/components/mini-chart/mini-chart-props.ts +0 -44
  184. package/components/mini-chart/mini-chart.tsx +0 -85
  185. package/components/mini-chart/wrapper.tsx +0 -23
  186. package/components/not-found/index.tsx +0 -28
  187. package/components/not-found/not-found-content.mdx +0 -5
  188. package/components/tooltip.tsx +0 -31
  189. package/environment.d.ts +0 -6
  190. package/next/analytics/fpixel.ts +0 -16
  191. package/next/analytics/google-analytics.ts +0 -14
  192. package/next/analytics/index.ts +0 -3
  193. package/next/analytics/pixel-analytics.tsx +0 -55
  194. package/next/font/get-app-router-font-classes.ts +0 -17
  195. package/next/font/load-and-return-lux-next-fonts-on-import.ts +0 -68
  196. package/next/font/local/Druk-Wide-Bold.ttf +0 -0
  197. package/next/font/local/Druk-Wide-Medium.ttf +0 -0
  198. package/next/font/local/InterVariable-Italic.ttf +0 -0
  199. package/next/font/local/InterVariable-Italic.woff2 +0 -0
  200. package/next/font/local/InterVariable.ttf +0 -0
  201. package/next/font/local/InterVariable.woff2 +0 -0
  202. package/next/font/next-font-desc.ts +0 -28
  203. package/next/font/pages-router-font-vars.tsx +0 -18
  204. package/next/head-metadata/from-next/metadata-types.ts +0 -158
  205. package/next/head-metadata/from-next/opengraph-types.ts +0 -267
  206. package/next/head-metadata/from-next/twitter-types.ts +0 -92
  207. package/next/head-metadata/index.tsx +0 -208
  208. package/next/index.ts +0 -2
  209. package/next/middleware/determine-device-mw.ts +0 -29
  210. package/root-layout/WHY_THIS_IS_SEPARATE.txt +0 -2
  211. package/root-layout/index.tsx +0 -112
  212. package/site-def/footer/community.tsx +0 -61
  213. package/site-def/footer/company.ts +0 -37
  214. package/site-def/footer/ecosystem.ts +0 -37
  215. package/site-def/footer/index.tsx +0 -26
  216. package/site-def/footer/legal.ts +0 -28
  217. package/site-def/footer/network.ts +0 -45
  218. package/site-def/footer/svg/warpcast-logo.svg +0 -12
  219. package/site-def/index.ts +0 -4
  220. package/site-def/main-nav.tsx +0 -460
  221. package/style/cart-animation.css +0 -29
  222. package/style/checkout-animation.css +0 -23
  223. package/style/drawer-handle-overrides.css +0 -160
  224. package/style/fonts/COPY_TO_PUBLIC_FOR_NON_NEXT.txt +0 -0
  225. package/style/fonts/Druk-Wide-Bold.ttf +0 -0
  226. package/style/fonts/Druk-Wide-Medium.ttf +0 -0
  227. package/style/fonts/InterVariable-Italic.ttf +0 -0
  228. package/style/fonts/InterVariable-Italic.woff2 +0 -0
  229. package/style/fonts/InterVariable.ttf +0 -0
  230. package/style/fonts/InterVariable.woff2 +0 -0
  231. package/style/lux-colors.css +0 -85
  232. package/style/lux-fonts.css +0 -30
  233. package/style/lux-global-non-next.css +0 -52
  234. package/style/lux-global.css +0 -51
  235. package/tailwind/fontFamily.tailwind.lux.ts +0 -18
  236. package/tailwind/index.ts +0 -2
  237. package/tailwind/lux-tw-fonts.ts +0 -40
  238. package/tailwind/tailwind.config.lux-preset.ts +0 -10
  239. package/tsconfig.json +0 -15
  240. package/types/chatbot-config.ts +0 -7
  241. package/types/chatbot-suggested-question.ts +0 -7
  242. package/types/contact-info.ts +0 -11
  243. package/types/index.ts +0 -4
  244. package/types/site-def.ts +0 -46
package/src/select.tsx ADDED
@@ -0,0 +1,696 @@
1
+ 'use client';
2
+
3
+ import * as RadixSelect from '@radix-ui/react-select';
4
+ import { useDebounce } from '@uidotdev/usehooks';
5
+ import * as React from 'react';
6
+
7
+ // Minimal ListCollection compatible with Chakra's API but without the dependency
8
+ export interface ListCollection<T> {
9
+ items: Array<T>;
10
+ }
11
+
12
+ export function createListCollection<T>(config: { items: Array<T> }): ListCollection<T> {
13
+ return { items: config.items };
14
+ }
15
+
16
+ import { cn } from './utils';
17
+
18
+ import { Skeleton } from './skeleton';
19
+
20
+ // Inline chevron icon (east-mini arrow)
21
+ const ArrowIcon = ({ className }: { readonly className?: string }) => (
22
+ <svg className={ className } viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
23
+ <path d="M7.5 15L12.5 10L7.5 5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
24
+ </svg>
25
+ );
26
+
27
+ // Inline check icon
28
+ const CheckIcon = ({ className }: { readonly className?: string }) => (
29
+ <svg className={ className } viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
30
+ <path d="M16.667 5L7.5 14.167 3.333 10" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
31
+ </svg>
32
+ );
33
+
34
+ // Inline FilterInput for SelectAsync
35
+ interface FilterInputProps {
36
+ readonly placeholder?: string;
37
+ readonly initialValue?: string;
38
+ readonly onChange?: (value: string) => void;
39
+ }
40
+
41
+ function FilterInput({ placeholder, initialValue = '', onChange }: FilterInputProps) {
42
+ const [ value, setValue ] = React.useState(initialValue);
43
+ const handleChange = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
44
+ setValue(e.target.value);
45
+ onChange?.(e.target.value);
46
+ }, [ onChange ]);
47
+ return (
48
+ <input
49
+ type="text"
50
+ placeholder={ placeholder }
51
+ value={ value }
52
+ onChange={ handleChange }
53
+ className={ cn(
54
+ 'w-full px-3 py-2 text-sm outline-none',
55
+ 'bg-transparent border-b border-[var(--color-border-divider)]',
56
+ 'placeholder:text-[var(--color-input-placeholder)]',
57
+ ) }
58
+ />
59
+ );
60
+ }
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Types
64
+ // ---------------------------------------------------------------------------
65
+
66
+ export type ViewMode = 'default' | 'compact';
67
+
68
+ export interface SelectOption<Value extends string = string> {
69
+ label: string;
70
+ renderLabel?: (place: 'item' | 'value-text') => React.ReactNode;
71
+ value: Value;
72
+ icon?: React.ReactNode;
73
+ afterElement?: React.ReactNode;
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Internal context — replaces Chakra's useSelectContext
78
+ // ---------------------------------------------------------------------------
79
+
80
+ interface SelectInternalContextValue {
81
+ value: Array<string>;
82
+ selectedItems: Array<SelectOption>;
83
+ collection: ListCollection<SelectOption>;
84
+ onValueChange: (details: { value: Array<string>; items: Array<SelectOption> }) => void;
85
+ open: boolean;
86
+ size?: 'sm' | 'lg';
87
+ variant?: string;
88
+ disabled?: boolean;
89
+ }
90
+
91
+ const SelectInternalContext = React.createContext<SelectInternalContextValue | null>(null);
92
+
93
+ function useSelectInternalContext(): SelectInternalContextValue {
94
+ const ctx = React.useContext(SelectInternalContext);
95
+ if (!ctx) {
96
+ throw new Error('Select compound components must be rendered inside <SelectRoot>');
97
+ }
98
+ return ctx;
99
+ }
100
+
101
+ // ---------------------------------------------------------------------------
102
+ // SelectRoot
103
+ // ---------------------------------------------------------------------------
104
+
105
+ export interface SelectRootProps {
106
+ children?: React.ReactNode;
107
+ collection?: ListCollection<SelectOption>;
108
+ defaultValue?: Array<string>;
109
+ value?: Array<string>;
110
+ onValueChange?: (details: { value: Array<string>; items: Array<SelectOption> }) => void;
111
+ onInteractOutside?: () => void;
112
+ name?: string;
113
+ disabled?: boolean;
114
+ readOnly?: boolean;
115
+ required?: boolean;
116
+ invalid?: boolean;
117
+ size?: 'sm' | 'lg';
118
+ variant?: string;
119
+ open?: boolean;
120
+ defaultOpen?: boolean;
121
+ onOpenChange?: (open: boolean) => void;
122
+ // Chakra compat — accepted but handled via className/style
123
+ positioning?: { sameWidth?: boolean; offset?: { mainAxis?: number; crossAxis?: number } };
124
+ lazyMount?: boolean;
125
+ unmountOnExit?: boolean;
126
+ asChild?: boolean;
127
+ className?: string;
128
+ style?: React.CSSProperties;
129
+ // Chakra style prop shims
130
+ w?: string | Record<string, string>;
131
+ maxW?: string | Record<string, string>;
132
+ minW?: string | Record<string, string>;
133
+ hideFrom?: string;
134
+ }
135
+
136
+ export const SelectRoot = React.forwardRef<HTMLDivElement, SelectRootProps>(
137
+ function SelectRoot(props, ref) {
138
+ const {
139
+ children,
140
+ collection: collectionProp,
141
+ defaultValue: defaultValueArr,
142
+ value: valueProp,
143
+ onValueChange: onValueChangeProp,
144
+ onInteractOutside,
145
+ name,
146
+ disabled,
147
+ readOnly,
148
+ required,
149
+ invalid,
150
+ size,
151
+ variant,
152
+ open: openProp,
153
+ defaultOpen,
154
+ onOpenChange,
155
+ positioning: _positioning,
156
+ lazyMount: _lazyMount,
157
+ unmountOnExit: _unmountOnExit,
158
+ asChild: _asChild,
159
+ className,
160
+ style,
161
+ w,
162
+ maxW,
163
+ minW,
164
+ hideFrom: _hideFrom,
165
+ } = props;
166
+
167
+ // Provide a fallback empty collection
168
+ const collection = collectionProp ?? createListCollection<SelectOption>({ items: [] });
169
+
170
+ // Controlled / uncontrolled value (always Array<string> externally)
171
+ const [ internalValue, setInternalValue ] = React.useState<Array<string>>(defaultValueArr ?? []);
172
+ const currentValue = valueProp ?? internalValue;
173
+
174
+ const selectedItems = React.useMemo(() => {
175
+ return currentValue
176
+ .map((v) => collection.items.find((item) => item.value === v))
177
+ .filter(Boolean) as Array<SelectOption>;
178
+ }, [ currentValue, collection.items ]);
179
+
180
+ const [ open, setOpen ] = React.useState(defaultOpen ?? false);
181
+ const isOpen = openProp ?? open;
182
+
183
+ const handleOpenChange = React.useCallback((nextOpen: boolean) => {
184
+ setOpen(nextOpen);
185
+ onOpenChange?.(nextOpen);
186
+ if (!nextOpen) {
187
+ onInteractOutside?.();
188
+ }
189
+ }, [ onOpenChange, onInteractOutside ]);
190
+
191
+ const handleRadixValueChange = React.useCallback((radixValue: string) => {
192
+ const nextArr = [ radixValue ];
193
+ if (!valueProp) {
194
+ setInternalValue(nextArr);
195
+ }
196
+ const items = collection.items.filter((item) => nextArr.includes(item.value));
197
+ onValueChangeProp?.({ value: nextArr, items });
198
+ }, [ valueProp, collection.items, onValueChangeProp ]);
199
+
200
+ const ctxValue = React.useMemo<SelectInternalContextValue>(() => ({
201
+ value: currentValue,
202
+ selectedItems,
203
+ collection,
204
+ onValueChange: (details) => {
205
+ if (!valueProp) {
206
+ setInternalValue(details.value);
207
+ }
208
+ onValueChangeProp?.(details);
209
+ },
210
+ open: isOpen,
211
+ size,
212
+ variant,
213
+ disabled,
214
+ }), [ currentValue, selectedItems, collection, valueProp, onValueChangeProp, isOpen, size, variant, disabled ]);
215
+
216
+ // Extract Chakra-style shorthand props into inline style
217
+ const resolveVal = (v: string | Record<string, string> | undefined) => {
218
+ if (!v) return undefined;
219
+ if (typeof v === 'string') return v;
220
+ return v.base ?? v.lg ?? Object.values(v)[0];
221
+ };
222
+ const inlineStyle = React.useMemo(() => {
223
+ const s: React.CSSProperties = { ...style };
224
+ const rw = resolveVal(w); if (rw) s.width = rw;
225
+ const rmw = resolveVal(maxW); if (rmw) s.maxWidth = rmw;
226
+ const rminw = resolveVal(minW); if (rminw) s.minWidth = rminw;
227
+ return s;
228
+ }, [ style, w, maxW, minW ]);
229
+
230
+ return (
231
+ <SelectInternalContext.Provider value={ ctxValue }>
232
+ <RadixSelect.Root
233
+ value={ currentValue[0] ?? '' }
234
+ defaultValue={ defaultValueArr?.[0] }
235
+ onValueChange={ handleRadixValueChange }
236
+ open={ isOpen }
237
+ onOpenChange={ handleOpenChange }
238
+ disabled={ disabled || readOnly }
239
+ name={ name }
240
+ required={ required }
241
+ >
242
+ <div
243
+ ref={ ref }
244
+ className={ cn('relative inline-flex', className) }
245
+ style={ inlineStyle }
246
+ data-invalid={ invalid || undefined }
247
+ data-disabled={ disabled || undefined }
248
+ data-variant={ variant || undefined }
249
+ data-size={ size || undefined }
250
+ >
251
+ { children }
252
+ </div>
253
+ </RadixSelect.Root>
254
+ </SelectInternalContext.Provider>
255
+ );
256
+ },
257
+ );
258
+
259
+ // ---------------------------------------------------------------------------
260
+ // SelectControl
261
+ // ---------------------------------------------------------------------------
262
+
263
+ export interface SelectControlProps {
264
+ children?: React.ReactNode;
265
+ noIndicator?: boolean;
266
+ triggerProps?: React.ComponentPropsWithoutRef<typeof RadixSelect.Trigger> & {
267
+ asChild?: boolean;
268
+ px?: string | number;
269
+ className?: string;
270
+ };
271
+ loading?: boolean;
272
+ defaultValue?: Array<string>;
273
+ className?: string;
274
+ style?: React.CSSProperties;
275
+ }
276
+
277
+ export const SelectControl = React.forwardRef<HTMLButtonElement, SelectControlProps>(
278
+ function SelectControl(props, ref) {
279
+ const { children, noIndicator, triggerProps, loading, defaultValue } = props;
280
+ const ctx = useSelectInternalContext();
281
+
282
+ const isDefaultValue = Array.isArray(defaultValue) ?
283
+ ctx.value.every((item) => defaultValue.includes(item)) :
284
+ false;
285
+
286
+ const { asChild, px: _px, className: triggerClassName, ...radixTriggerProps } = triggerProps ?? {};
287
+
288
+ const trigger = (
289
+ <RadixSelect.Trigger
290
+ ref={ ref }
291
+ asChild={ asChild }
292
+ className={ cn(
293
+ 'group peer inline-flex items-center gap-2 cursor-pointer',
294
+ 'rounded-lg text-sm transition-colors outline-none',
295
+ 'border border-[var(--color-input-border)] bg-[var(--color-input-bg)] text-[var(--color-input-fg)]',
296
+ 'hover:border-[var(--color-input-border-hover)]',
297
+ 'focus-visible:border-[var(--color-input-border-focus)]',
298
+ 'disabled:opacity-50 disabled:cursor-not-allowed',
299
+ ctx.variant === 'plain' && 'border-transparent bg-transparent px-1 py-0.5',
300
+ ctx.variant !== 'plain' && ctx.size === 'lg' && 'px-4 py-2.5 min-h-[52px]',
301
+ ctx.variant !== 'plain' && ctx.size !== 'lg' && 'px-3 py-1.5 min-h-[36px]',
302
+ triggerClassName,
303
+ ) }
304
+ data-default-value={ isDefaultValue || undefined }
305
+ { ...radixTriggerProps }
306
+ >
307
+ { asChild ? children : (
308
+ <>
309
+ { children }
310
+ { !noIndicator && (
311
+ <span className="ml-auto shrink-0 transition-transform data-[state=open]:rotate-180 text-[var(--color-icon-secondary)]">
312
+ <ArrowIcon className="h-5 w-5 -rotate-90"/>
313
+ </span>
314
+ ) }
315
+ </>
316
+ ) }
317
+ </RadixSelect.Trigger>
318
+ );
319
+
320
+ if (loading) {
321
+ return (
322
+ <Skeleton loading={ loading } asChild>
323
+ { trigger }
324
+ </Skeleton>
325
+ );
326
+ }
327
+
328
+ return trigger;
329
+ },
330
+ );
331
+
332
+ // ---------------------------------------------------------------------------
333
+ // SelectClearTrigger
334
+ // ---------------------------------------------------------------------------
335
+
336
+ export interface SelectClearTriggerProps {
337
+ className?: string;
338
+ }
339
+
340
+ export const SelectClearTrigger = React.forwardRef<HTMLButtonElement, SelectClearTriggerProps>(
341
+ function SelectClearTrigger(props, ref) {
342
+ const { className, ...rest } = props;
343
+ const ctx = useSelectInternalContext();
344
+
345
+ const handleClick = React.useCallback(() => {
346
+ ctx.onValueChange({ value: [], items: [] });
347
+ }, [ ctx ]);
348
+
349
+ return (
350
+ <button
351
+ ref={ ref }
352
+ type="button"
353
+ onClick={ handleClick }
354
+ className={ cn('pointer-events-auto', className) }
355
+ aria-label="Clear selection"
356
+ { ...rest }
357
+ >
358
+ <svg className="h-5 w-5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
359
+ <path d="M18 6L6 18M6 6l12 12" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
360
+ </svg>
361
+ </button>
362
+ );
363
+ },
364
+ );
365
+
366
+ // ---------------------------------------------------------------------------
367
+ // SelectContent
368
+ // ---------------------------------------------------------------------------
369
+
370
+ export interface SelectContentProps {
371
+ children?: React.ReactNode;
372
+ portalled?: boolean;
373
+ portalRef?: React.RefObject<HTMLElement>;
374
+ className?: string;
375
+ style?: React.CSSProperties;
376
+ }
377
+
378
+ export const SelectContent = React.forwardRef<HTMLDivElement, SelectContentProps>(
379
+ function SelectContent(props, ref) {
380
+ const { portalled = true, portalRef, children, className, ...rest } = props;
381
+
382
+ const content = (
383
+ <RadixSelect.Content
384
+ ref={ ref }
385
+ position="popper"
386
+ sideOffset={ 4 }
387
+ className={ cn(
388
+ 'z-50 min-w-[8rem] overflow-hidden rounded-lg',
389
+ 'bg-[var(--color-popover-bg)] shadow-[var(--shadow-popover)]',
390
+ 'border border-[var(--color-border-divider)]',
391
+ 'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
392
+ 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
393
+ className,
394
+ ) }
395
+ { ...rest }
396
+ >
397
+ <RadixSelect.Viewport className="p-1">
398
+ { children }
399
+ </RadixSelect.Viewport>
400
+ </RadixSelect.Content>
401
+ );
402
+
403
+ if (portalled) {
404
+ return (
405
+ <RadixSelect.Portal container={ portalRef?.current ?? undefined }>
406
+ { content }
407
+ </RadixSelect.Portal>
408
+ );
409
+ }
410
+
411
+ return content;
412
+ },
413
+ );
414
+
415
+ // ---------------------------------------------------------------------------
416
+ // SelectItem
417
+ // ---------------------------------------------------------------------------
418
+
419
+ export interface SelectItemProps {
420
+ item: SelectOption;
421
+ children?: React.ReactNode;
422
+ className?: string;
423
+ }
424
+
425
+ export const SelectItem = React.forwardRef<HTMLDivElement, SelectItemProps>(
426
+ function SelectItem(props, ref) {
427
+ const { item, children, className, ...rest } = props;
428
+
429
+ return (
430
+ <RadixSelect.Item
431
+ ref={ ref }
432
+ value={ item.value }
433
+ textValue={ item.label }
434
+ className={ cn(
435
+ 'relative flex cursor-pointer select-none items-center gap-2',
436
+ 'rounded-md px-3 py-2 text-sm outline-none',
437
+ 'text-[var(--color-text-primary)]',
438
+ 'data-[highlighted]:bg-[var(--color-selected-control-bg)]',
439
+ 'data-[state=checked]:font-medium',
440
+ 'data-[disabled]:opacity-50 data-[disabled]:pointer-events-none',
441
+ className,
442
+ ) }
443
+ { ...rest }
444
+ >
445
+ { item.icon }
446
+ <RadixSelect.ItemText>
447
+ { children }
448
+ </RadixSelect.ItemText>
449
+ <RadixSelect.ItemIndicator className="ml-auto shrink-0">
450
+ <CheckIcon className="h-5 w-5"/>
451
+ </RadixSelect.ItemIndicator>
452
+ </RadixSelect.Item>
453
+ );
454
+ },
455
+ );
456
+
457
+ // ---------------------------------------------------------------------------
458
+ // SelectValueText
459
+ // ---------------------------------------------------------------------------
460
+
461
+ interface SelectValueTextProps {
462
+ children?: (items: Array<SelectOption>) => React.ReactNode;
463
+ placeholder?: string;
464
+ size?: SelectRootProps['size'];
465
+ required?: boolean;
466
+ invalid?: boolean;
467
+ errorText?: string;
468
+ mode?: ViewMode;
469
+ className?: string;
470
+ style?: React.CSSProperties;
471
+ }
472
+
473
+ export const SelectValueText = React.forwardRef<HTMLSpanElement, SelectValueTextProps>(
474
+ function SelectValueText(props, ref) {
475
+ const { children, size, required, invalid, errorText, mode, className, style, placeholder: placeholderProp, ...rest } = props;
476
+ const ctx = useSelectInternalContext();
477
+
478
+ const placeholderText = `${ placeholderProp ?? '' }${ required ? '*' : '' }${ invalid && errorText ? ` - ${ errorText }` : '' }`;
479
+
480
+ const content = (() => {
481
+ const items = ctx.selectedItems;
482
+
483
+ if (items.length === 0) return null;
484
+
485
+ if (children) return children(items);
486
+
487
+ if (items.length === 1) {
488
+ const item = items[0] as SelectOption;
489
+
490
+ if (!item) return null;
491
+
492
+ const label = size === 'lg' ? (
493
+ <span
494
+ className={ cn(
495
+ 'text-xs block',
496
+ invalid ? 'text-[var(--color-text-error)]' : 'text-[var(--color-input-placeholder)]',
497
+ ) }
498
+ style={{ display: '-webkit-box' }}
499
+ >
500
+ { placeholderText }
501
+ </span>
502
+ ) : null;
503
+
504
+ return (
505
+ <>
506
+ { label }
507
+ <span className="inline-flex items-center flex-nowrap gap-1">
508
+ { item.icon }
509
+ { mode !== 'compact' && (
510
+ <span
511
+ style={{
512
+ WebkitLineClamp: 1,
513
+ WebkitBoxOrient: 'vertical',
514
+ display: '-webkit-box',
515
+ overflow: 'hidden',
516
+ }}
517
+ >
518
+ { item.renderLabel ? item.renderLabel('value-text') : item.label }
519
+ </span>
520
+ ) }
521
+ </span>
522
+ </>
523
+ );
524
+ }
525
+
526
+ return `${ items.length } selected`;
527
+ })();
528
+
529
+ // Radix SelectValue renders the selected value or placeholder.
530
+ // We override with our custom content.
531
+ return (
532
+ <RadixSelect.Value
533
+ ref={ ref }
534
+ placeholder={ placeholderText }
535
+ className={ cn('flex flex-col justify-center min-w-0 truncate', className) }
536
+ { ...rest }
537
+ >
538
+ { content }
539
+ </RadixSelect.Value>
540
+ );
541
+ },
542
+ );
543
+
544
+ // ---------------------------------------------------------------------------
545
+ // SelectItemGroup
546
+ // ---------------------------------------------------------------------------
547
+
548
+ interface SelectItemGroupProps {
549
+ children?: React.ReactNode;
550
+ label: React.ReactNode;
551
+ className?: string;
552
+ }
553
+
554
+ export const SelectItemGroup = React.forwardRef<HTMLDivElement, SelectItemGroupProps>(
555
+ function SelectItemGroup(props, ref) {
556
+ const { children, label, className, ...rest } = props;
557
+ return (
558
+ <RadixSelect.Group ref={ ref } className={ cn('py-1', className) } { ...rest }>
559
+ <RadixSelect.Label className="px-3 py-1.5 text-xs font-medium text-[var(--color-text-secondary)]">
560
+ { label }
561
+ </RadixSelect.Label>
562
+ { children }
563
+ </RadixSelect.Group>
564
+ );
565
+ },
566
+ );
567
+
568
+ // ---------------------------------------------------------------------------
569
+ // SelectLabel / SelectItemText
570
+ // ---------------------------------------------------------------------------
571
+
572
+ export const SelectLabel = RadixSelect.Label;
573
+ export const SelectItemText = RadixSelect.ItemText;
574
+
575
+ // ---------------------------------------------------------------------------
576
+ // Select (composite)
577
+ // ---------------------------------------------------------------------------
578
+
579
+ export interface SelectProps extends SelectRootProps {
580
+ collection: ListCollection<SelectOption>;
581
+ placeholder: string;
582
+ portalled?: boolean;
583
+ loading?: boolean;
584
+ errorText?: string;
585
+ contentProps?: SelectContentProps;
586
+ contentHeader?: React.ReactNode;
587
+ itemFilter?: (item: SelectOption) => boolean;
588
+ mode?: ViewMode;
589
+ }
590
+
591
+ export const Select = React.forwardRef<HTMLDivElement, SelectProps>((props, ref) => {
592
+ const { collection, placeholder, portalled = true, loading, errorText, contentProps, contentHeader, itemFilter, mode, ...rest } = props;
593
+ return (
594
+ <SelectRoot
595
+ ref={ ref }
596
+ collection={ collection }
597
+ { ...rest }
598
+ >
599
+ <SelectControl loading={ loading }>
600
+ <SelectValueText
601
+ placeholder={ placeholder }
602
+ size={ props.size }
603
+ required={ props.required }
604
+ invalid={ props.invalid }
605
+ errorText={ errorText }
606
+ mode={ mode }
607
+ />
608
+ </SelectControl>
609
+ <SelectContent portalled={ portalled } { ...contentProps }>
610
+ { contentHeader }
611
+ { collection.items
612
+ .filter(itemFilter ?? (() => true))
613
+ .map((item: SelectOption) => (
614
+ <React.Fragment key={ item.value }>
615
+ <SelectItem item={ item }>
616
+ { item.renderLabel ? item.renderLabel('item') : item.label }
617
+ </SelectItem>
618
+ { item.afterElement }
619
+ </React.Fragment>
620
+ )) }
621
+ </SelectContent>
622
+ </SelectRoot>
623
+ );
624
+ });
625
+
626
+ // ---------------------------------------------------------------------------
627
+ // SelectAsync
628
+ // ---------------------------------------------------------------------------
629
+
630
+ export interface SelectAsyncProps extends Omit<SelectProps, 'collection'> {
631
+ placeholder: string;
632
+ portalled?: boolean;
633
+ loading?: boolean;
634
+ loadOptions: (input: string, currentValue: Array<string>) => Promise<ListCollection<SelectOption>>;
635
+ extraControls?: React.ReactNode;
636
+ mode?: ViewMode;
637
+ }
638
+
639
+ export const SelectAsync = React.forwardRef<HTMLDivElement, SelectAsyncProps>((props, ref) => {
640
+ const { placeholder, portalled = true, loading, loadOptions, extraControls, onValueChange, errorText, mode, contentHeader, ...rest } = props;
641
+
642
+ const [ collection, setCollection ] = React.useState<ListCollection<SelectOption>>(createListCollection<SelectOption>({ items: [] }));
643
+ const [ inputValue, setInputValue ] = React.useState('');
644
+ const [ value, setValue ] = React.useState<Array<string>>([]);
645
+
646
+ const debouncedInputValue = useDebounce(inputValue, 300);
647
+
648
+ React.useEffect(() => {
649
+ loadOptions(debouncedInputValue, value).then(setCollection);
650
+ }, [ debouncedInputValue, loadOptions, value ]);
651
+
652
+ const handleFilterChange = React.useCallback((val: string) => {
653
+ setInputValue(val);
654
+ }, []);
655
+
656
+ const handleValueChange = React.useCallback(({ value: v, items }: { value: Array<string>; items: Array<SelectOption> }) => {
657
+ setValue(v);
658
+ onValueChange?.({ value: v, items });
659
+ }, [ onValueChange ]);
660
+
661
+ return (
662
+ <SelectRoot
663
+ ref={ ref }
664
+ collection={ collection }
665
+ onValueChange={ handleValueChange }
666
+ { ...rest }
667
+ >
668
+ <SelectControl loading={ loading }>
669
+ <SelectValueText
670
+ placeholder={ placeholder }
671
+ size={ props.size }
672
+ required={ props.required }
673
+ invalid={ props.invalid }
674
+ errorText={ errorText }
675
+ mode={ mode }
676
+ />
677
+ </SelectControl>
678
+ <SelectContent portalled={ portalled }>
679
+ <div className="px-4">
680
+ <FilterInput
681
+ placeholder="Search"
682
+ initialValue={ inputValue }
683
+ onChange={ handleFilterChange }
684
+ />
685
+ { extraControls }
686
+ </div>
687
+ { contentHeader }
688
+ { collection.items.map((item) => (
689
+ <SelectItem item={ item } key={ item.value }>
690
+ { item.renderLabel ? item.renderLabel('item') : item.label }
691
+ </SelectItem>
692
+ )) }
693
+ </SelectContent>
694
+ </SelectRoot>
695
+ );
696
+ });