@smilodon/react 1.2.2 → 1.4.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/README.md +42 -0
- package/dist/index.cjs +58 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -5
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +156 -0
- package/dist/types/Select.d.ts.map +1 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -466,6 +466,34 @@ function LargeDatasetExample() {
|
|
|
466
466
|
|
|
467
467
|
Now also supports the native `optionRenderer` hook (Option B) that returns an `HTMLElement` for maximum control (e.g., non-React DOM fragments). Pass `optionRenderer={(item, index, helpers) => { const el = document.createElement('div'); el.textContent = item.label; return el; }}` to mirror the Web Component API.
|
|
468
468
|
|
|
469
|
+
#### Advanced scenarios (React)
|
|
470
|
+
- **A11y-first**: provide `aria-labelledby`/`aria-describedby` on the wrapper, and announce changes:
|
|
471
|
+
```tsx
|
|
472
|
+
<label id="user-label" htmlFor="user-picker">Pick a user</label>
|
|
473
|
+
<Select id="user-picker" aria-labelledby="user-label" onChange={(v, items) => {
|
|
474
|
+
console.log('Selected', items);
|
|
475
|
+
}}/>
|
|
476
|
+
```
|
|
477
|
+
- **Server-side lookup**: debounce and push items into the web component:
|
|
478
|
+
```tsx
|
|
479
|
+
const fetchUsers = useMemo(() => debounce(async (q) => {
|
|
480
|
+
const res = await fetch(`/api/users?q=${encodeURIComponent(q)}`);
|
|
481
|
+
const items = await res.json();
|
|
482
|
+
selectRef.current?.setItems(items);
|
|
483
|
+
}, 200), []);
|
|
484
|
+
|
|
485
|
+
<Select
|
|
486
|
+
searchable
|
|
487
|
+
onSearch={(q) => fetchUsers(q)}
|
|
488
|
+
ref={selectRef}
|
|
489
|
+
/>
|
|
490
|
+
```
|
|
491
|
+
- **Heavy lists (100k+)**: rely on virtualization with an accurate height:
|
|
492
|
+
```tsx
|
|
493
|
+
const big = useMemo(() => Array.from({ length: 100_000 }, (_, i) => ({ value: i, label: `Row ${i}` })), []);
|
|
494
|
+
<Select items={big} virtualized estimatedItemHeight={44} />
|
|
495
|
+
```
|
|
496
|
+
|
|
469
497
|
**Use when**: You need rich, interactive option content with custom React components.
|
|
470
498
|
|
|
471
499
|
**Advantages**:
|
|
@@ -1044,6 +1072,20 @@ This component is built with accessibility in mind:
|
|
|
1044
1072
|
- ✅ 44px minimum touch targets (WCAG 2.5.5)
|
|
1045
1073
|
- ✅ WCAG 2.1 AAA compliant
|
|
1046
1074
|
|
|
1075
|
+
### Important: Passing inline functions as renderers
|
|
1076
|
+
|
|
1077
|
+
If you define `optionRenderer` or `customRenderer` inline (like arrow function inside template/JSX), it may cause unnecessary re-creation in some frameworks.
|
|
1078
|
+
|
|
1079
|
+
**Highly recommended:** For best performance and to avoid potential issues, always use memoization:
|
|
1080
|
+
|
|
1081
|
+
```tsx
|
|
1082
|
+
const myRenderer = useCallback((item, index, helpers) => {
|
|
1083
|
+
return document.createElement('div');
|
|
1084
|
+
}, []);
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
Adapters are designed to not loop even without memoization, but memoization still improves performance.
|
|
1088
|
+
|
|
1047
1089
|
## Performance
|
|
1048
1090
|
|
|
1049
1091
|
- Virtual scrolling for large datasets (1000+ items)
|
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
25
26
|
const React = require("react");
|
|
27
|
+
const client = require("react-dom/client");
|
|
26
28
|
const Select = React.forwardRef((props, ref) => {
|
|
27
29
|
const {
|
|
28
30
|
items = [],
|
|
@@ -45,6 +47,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
45
47
|
className,
|
|
46
48
|
style,
|
|
47
49
|
renderItem,
|
|
50
|
+
customRenderer,
|
|
48
51
|
renderValue,
|
|
49
52
|
optionRenderer,
|
|
50
53
|
onChange,
|
|
@@ -55,11 +58,57 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
55
58
|
onLoadMore,
|
|
56
59
|
loading = false,
|
|
57
60
|
creatable = false,
|
|
58
|
-
onCreate
|
|
61
|
+
onCreate,
|
|
62
|
+
classMap
|
|
59
63
|
} = props;
|
|
60
64
|
const elementRef = React.useRef(null);
|
|
61
65
|
const [isControlled] = React.useState(value !== void 0);
|
|
62
66
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
67
|
+
const reactRendererCache = React.useRef(/* @__PURE__ */ new Map());
|
|
68
|
+
const customRendererRef = React.useRef(customRenderer ?? renderItem);
|
|
69
|
+
const optionRendererRef = React.useRef(optionRenderer);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
customRendererRef.current = customRenderer ?? renderItem;
|
|
72
|
+
optionRendererRef.current = optionRenderer;
|
|
73
|
+
}, [customRenderer, renderItem, optionRenderer]);
|
|
74
|
+
const resolvedOptionRenderer = React.useMemo(() => {
|
|
75
|
+
if (!!optionRenderer) {
|
|
76
|
+
return (item, index, helpers) => {
|
|
77
|
+
var _a;
|
|
78
|
+
return ((_a = optionRendererRef.current) == null ? void 0 : _a.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const hasReactRenderer = !!(customRenderer ?? renderItem);
|
|
82
|
+
if (!hasReactRenderer) return void 0;
|
|
83
|
+
return (item, index, _helpers) => {
|
|
84
|
+
const renderer = customRendererRef.current;
|
|
85
|
+
if (!renderer) return document.createElement("div");
|
|
86
|
+
let entry = reactRendererCache.current.get(index);
|
|
87
|
+
if (!entry) {
|
|
88
|
+
const container = document.createElement("div");
|
|
89
|
+
const root = client.createRoot(container);
|
|
90
|
+
entry = { container, root };
|
|
91
|
+
reactRendererCache.current.set(index, entry);
|
|
92
|
+
}
|
|
93
|
+
entry.root.render(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderer(item, index) }));
|
|
94
|
+
return entry.container;
|
|
95
|
+
};
|
|
96
|
+
}, [!!optionRenderer, !!(customRenderer ?? renderItem)]);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
return () => {
|
|
99
|
+
reactRendererCache.current.forEach(({ root }) => root.unmount());
|
|
100
|
+
reactRendererCache.current.clear();
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
React.useEffect(() => {
|
|
104
|
+
const totalItems = groupedItems ? groupedItems.reduce((count, group) => count + group.options.length, 0) : items.length;
|
|
105
|
+
reactRendererCache.current.forEach((entry, index) => {
|
|
106
|
+
if (index >= totalItems) {
|
|
107
|
+
entry.root.unmount();
|
|
108
|
+
reactRendererCache.current.delete(index);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}, [items, groupedItems]);
|
|
63
112
|
const [isElementReady, setIsElementReady] = React.useState(false);
|
|
64
113
|
React.useEffect(() => {
|
|
65
114
|
if (typeof window !== "undefined") {
|
|
@@ -87,8 +136,8 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
87
136
|
} else if (items.length > 0) {
|
|
88
137
|
element.setItems(items);
|
|
89
138
|
}
|
|
90
|
-
if (
|
|
91
|
-
element.optionRenderer =
|
|
139
|
+
if (resolvedOptionRenderer) {
|
|
140
|
+
element.optionRenderer = resolvedOptionRenderer;
|
|
92
141
|
}
|
|
93
142
|
const config = {
|
|
94
143
|
searchable,
|
|
@@ -108,6 +157,11 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
108
157
|
creatable
|
|
109
158
|
};
|
|
110
159
|
element.updateConfig(config);
|
|
160
|
+
if (classMap) {
|
|
161
|
+
element.classMap = classMap;
|
|
162
|
+
} else {
|
|
163
|
+
element.classMap = void 0;
|
|
164
|
+
}
|
|
111
165
|
const currentValue = isControlled ? value : internalValue;
|
|
112
166
|
if (currentValue !== void 0) {
|
|
113
167
|
const values = Array.isArray(currentValue) ? currentValue : [currentValue];
|
|
@@ -121,7 +175,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
121
175
|
if (required) {
|
|
122
176
|
element.setRequired(true);
|
|
123
177
|
}
|
|
124
|
-
}, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled,
|
|
178
|
+
}, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, resolvedOptionRenderer]);
|
|
125
179
|
React.useEffect(() => {
|
|
126
180
|
const element = elementRef.current;
|
|
127
181
|
if (!element || !isElementReady || !element.setItems) return;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/Select.tsx"],"sourcesContent":["import React, { useEffect, useRef, useCallback, forwardRef, useImperativeHandle, useState } from 'react';\nimport type {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n RendererHelpers,\n} from '@smilodon/core';\n\n/**\n * Item type for the select component\n */\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Props for the Select component\n */\nexport interface SelectProps {\n /** Array of items to display in the dropdown */\n items?: SelectItem[];\n \n /** Grouped items (alternative to flat items array) */\n groupedItems?: GroupedItem[];\n \n /** Currently selected value(s) */\n value?: string | number | Array<string | number>;\n \n /** Default value(s) for uncontrolled mode */\n defaultValue?: string | number | Array<string | number>;\n \n /** Enable multi-select mode */\n multiple?: boolean;\n \n /** Enable search/filter functionality */\n searchable?: boolean;\n \n /** Placeholder text */\n placeholder?: string;\n \n /** Disable the select */\n disabled?: boolean;\n \n /** Required field */\n required?: boolean;\n \n /** Error state */\n error?: boolean;\n \n /** Error message to display */\n errorMessage?: string;\n \n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n \n /** Page size for infinite scroll */\n pageSize?: number;\n \n /** Enable virtual scrolling for large lists */\n virtualized?: boolean;\n \n /** Estimated height of each item (for virtualization) */\n estimatedItemHeight?: number;\n \n /** Maximum number of selections (for multiple mode) */\n maxSelections?: number;\n \n /** Dropdown placement */\n placement?: 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n \n /** Custom CSS class name */\n className?: string;\n \n /** Inline styles */\n style?: React.CSSProperties;\n \n /** Custom item renderer */\n renderItem?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom option renderer (DOM). Returns an HTMLElement for full control. */\n optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;\n \n /** Custom selected value renderer */\n renderValue?: (selectedItems: SelectItem[]) => React.ReactNode;\n \n // Event Handlers\n /** Called when selection changes */\n onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;\n \n /** Called when an item is selected */\n onSelect?: (item: SelectItem, index: number) => void;\n \n /** Called when dropdown opens */\n onOpen?: () => void;\n \n /** Called when dropdown closes */\n onClose?: () => void;\n \n /** Called when search query changes */\n onSearch?: (query: string, results?: SelectItem[], count?: number) => void;\n \n /** Called when more items are needed (infinite scroll) */\n onLoadMore?: (page: number) => void | Promise<void>;\n \n /** Loading state for async operations */\n loading?: boolean;\n \n /** Enable creatable mode (allow creating new options) */\n creatable?: boolean;\n \n /** Called when a new option is created */\n onCreate?: (label: string) => void;\n}\n\n/**\n * Imperative handle for the Select component\n */\nexport interface SelectHandle {\n /** Focus the select input */\n focus: () => void;\n \n /** Open the dropdown */\n open: () => void;\n \n /** Close the dropdown */\n close: () => void;\n \n /** Get currently selected items */\n getSelectedItems: () => SelectItem[];\n \n /** Get currently selected values */\n getSelectedValues: () => Array<string | number>;\n \n /** Programmatically set items */\n setItems: (items: SelectItem[]) => void;\n \n /** Programmatically set grouped items */\n setGroupedItems: (groups: GroupedItem[]) => void;\n \n /** Clear the selection */\n clear: () => void;\n}\n\n/**\n * Smilodon Select Component for React\n * \n * A production-ready, accessible select component with advanced features:\n * - Single and multi-select modes\n * - Searchable with client or server-side filtering\n * - Infinite scroll and virtual scrolling for large datasets\n * - Grouped options\n * - Custom rendering\n * - Full keyboard navigation\n * - WCAG 2.1 AAA compliant\n * \n * @example\n * ```tsx\n * // Simple usage\n * <Select\n * items={[\n * { value: 'apple', label: 'Apple' },\n * { value: 'banana', label: 'Banana' }\n * ]}\n * value=\"apple\"\n * onChange={(value) => console.log(value)}\n * />\n * \n * // Multi-select with search\n * <Select\n * items={items}\n * multiple\n * searchable\n * value={selectedValues}\n * onChange={(values) => setSelectedValues(values)}\n * />\n * \n * // With grouped items\n * <Select\n * groupedItems={[\n * { label: 'Fruits', options: [...] },\n * { label: 'Vegetables', options: [...] }\n * ]}\n * onChange={(value) => console.log(value)}\n * />\n * ```\n */\nexport const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {\n const {\n items = [],\n groupedItems,\n value,\n defaultValue,\n multiple = false,\n searchable = false,\n placeholder = 'Select an option...',\n disabled = false,\n required = false,\n error = false,\n errorMessage,\n infiniteScroll = false,\n pageSize = 20,\n virtualized = false,\n estimatedItemHeight = 48,\n maxSelections,\n placement = 'bottom-start',\n className,\n style,\n renderItem,\n renderValue,\n optionRenderer,\n onChange,\n onSelect,\n onOpen,\n onClose,\n onSearch,\n onLoadMore,\n loading = false,\n creatable = false,\n onCreate,\n } = props;\n\n const elementRef = useRef<any>(null);\n const [isControlled] = useState(value !== undefined);\n const [internalValue, setInternalValue] = useState(defaultValue);\n\n // Register custom element if not already registered\n const [isElementReady, setIsElementReady] = useState(false);\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n if (customElements.get('enhanced-select')) {\n setIsElementReady(true);\n } else {\n import('@smilodon/core').then((module) => {\n if (!customElements.get('enhanced-select')) {\n customElements.define('enhanced-select', module.EnhancedSelect);\n }\n setIsElementReady(true);\n });\n }\n }\n }, []);\n\n // Initialize component\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n // Wait for the element to be fully upgraded\n if (!element.setItems) {\n console.warn('Enhanced select element not fully initialized yet');\n return;\n }\n\n // Set initial items\n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else if (items.length > 0) {\n element.setItems(items);\n }\n\n if (optionRenderer) {\n element.optionRenderer = optionRenderer;\n }\n\n // Configure component\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n scrollToSelected: {\n enabled: true,\n },\n creatable: creatable,\n };\n\n element.updateConfig(config);\n\n // Set initial value\n const currentValue = isControlled ? value : internalValue;\n if (currentValue !== undefined) {\n const values = Array.isArray(currentValue) ? currentValue : [currentValue];\n element.setSelectedValues(values);\n }\n\n // Set error state\n if (error) {\n element.setError(errorMessage || 'Invalid selection');\n } else {\n element.clearError();\n }\n\n // Set required state\n if (required) {\n element.setRequired(true);\n }\n }, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, optionRenderer]);\n\n // Update items when they change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setItems) return;\n \n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else {\n element.setItems(items);\n }\n }, [items, groupedItems, isElementReady]);\n\n // Update selected value when it changes (controlled mode)\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isControlled || !isElementReady || !element.setSelectedValues) return;\n \n if (value !== undefined) {\n const values = Array.isArray(value) ? value : [value];\n element.setSelectedValues(values);\n }\n }, [value, isControlled, isElementReady]);\n\n // Update config when props change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.updateConfig) return;\n\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n };\n\n element.updateConfig(config);\n }, [searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, isElementReady]);\n\n // Update error state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n if (error) {\n if (element.setError) element.setError(errorMessage || 'Invalid selection');\n } else {\n if (element.clearError) element.clearError();\n }\n }, [error, errorMessage, isElementReady]);\n\n // Update required state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setRequired) return;\n element.setRequired(required);\n }, [required, isElementReady]);\n\n // Event handlers\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handleSelect = (e: CustomEvent<SelectEventDetail>) => {\n const { item, index } = e.detail;\n onSelect?.(item as SelectItem, index);\n };\n\n const handleChange = (e: CustomEvent<ChangeEventDetail>) => {\n const { selectedItems, selectedValues } = e.detail;\n \n // Cast selectedValues to proper type\n const values = selectedValues as (string | number)[];\n \n // Update internal value in uncontrolled mode\n if (!isControlled) {\n setInternalValue(multiple ? values : values[0]);\n }\n\n // Call onChange callback\n if (onChange) {\n const value = multiple ? values : values[0];\n onChange(value, selectedItems as SelectItem[]);\n }\n };\n\n const handleOpen = (e: CustomEvent<OpenEventDetail>) => {\n onOpen?.();\n };\n\n const handleClose = (e: CustomEvent<CloseEventDetail>) => {\n onClose?.();\n };\n\n const handleSearch = (e: CustomEvent<SearchEventDetail>) => {\n const { query, results, count } = e.detail;\n onSearch?.(query, results as SelectItem[] | undefined, count);\n };\n\n const handleLoadMore = (e: CustomEvent<LoadMoreEventDetail>) => {\n const { page } = e.detail;\n onLoadMore?.(page);\n };\n\n element.addEventListener('select', handleSelect);\n element.addEventListener('change', handleChange);\n element.addEventListener('open', handleOpen);\n element.addEventListener('close', handleClose);\n element.addEventListener('search', handleSearch);\n element.addEventListener('loadMore', handleLoadMore);\n\n return () => {\n element.removeEventListener('select', handleSelect);\n element.removeEventListener('change', handleChange);\n element.removeEventListener('open', handleOpen);\n element.removeEventListener('close', handleClose);\n element.removeEventListener('search', handleSearch);\n element.removeEventListener('loadMore', handleLoadMore);\n };\n }, [onSelect, onChange, onOpen, onClose, onSearch, onLoadMore, isControlled, multiple]);\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n focus: () => {\n elementRef.current?.focus();\n },\n open: () => {\n elementRef.current?.open();\n },\n close: () => {\n elementRef.current?.close();\n },\n getSelectedItems: () => {\n return elementRef.current?.getSelectedItems() || [];\n },\n getSelectedValues: () => {\n return elementRef.current?.getSelectedValues() || [];\n },\n setItems: (items: SelectItem[]) => {\n elementRef.current?.setItems(items);\n },\n setGroupedItems: (groups: GroupedItem[]) => {\n elementRef.current?.setGroupedItems(groups);\n },\n clear: () => {\n elementRef.current?.setSelectedValues([]);\n if (!isControlled) {\n setInternalValue(multiple ? [] : undefined);\n }\n onChange?.(multiple ? [] : '', []);\n },\n }));\n\n return React.createElement('enhanced-select', {\n ref: elementRef,\n className,\n style,\n });\n});\n\nSelect.displayName = 'Select';\n"],"names":["forwardRef","useRef","useState","useEffect","module","value","useImperativeHandle","items"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiMO,MAAM,SAASA,MAAAA,WAAsC,CAAC,OAAO,QAAQ;AAC1E,QAAM;AAAA,IACJ,QAAQ,CAAA;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IACb,cAAc;AAAA,IACd,WAAW;AAAA,IACX,WAAW;AAAA,IACX,QAAQ;AAAA,IACR;AAAA,IACA,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX,cAAc;AAAA,IACd,sBAAsB;AAAA,IACtB;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACF;AAAA,IACE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A,IACA,UAAU,CAACC,WAAwB;;AACjC,uBAAW,YAAX,mBAAoB,SAASA;AAAAA,IAC/B;AAAA,IACA,iBAAiB,CAAC,WAA0B;;AAC1C,uBAAW,YAAX,mBAAoB,gBAAgB;AAAA,IACtC;AAAA,IACA,OAAO,MAAM;;AACX,uBAAW,YAAX,mBAAoB,kBAAkB;AACtC,UAAI,CAAC,cAAc;AACjB,yBAAiB,WAAW,CAAA,IAAK,MAAS;AAAA,MAC5C;AACA,2CAAW,WAAW,KAAK,IAAI,CAAA;AAAA,IACjC;AAAA,EAAA,EACA;AAEF,SAAO,MAAM,cAAc,mBAAmB;AAAA,IAC5C,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EAAA,CACD;AACH,CAAC;AAED,OAAO,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/Select.tsx"],"sourcesContent":["import React, { useEffect, useRef, useCallback, forwardRef, useImperativeHandle, useState, useMemo } from 'react';\nimport { createRoot, type Root } from 'react-dom/client';\nimport type {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n RendererHelpers,\n} from '@smilodon/core';\n\n/**\n * Item type for the select component\n */\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Props for the Select component\n */\nexport interface SelectProps {\n /** Array of items to display in the dropdown */\n items?: SelectItem[];\n \n /** Grouped items (alternative to flat items array) */\n groupedItems?: GroupedItem[];\n \n /** Currently selected value(s) */\n value?: string | number | Array<string | number>;\n \n /** Default value(s) for uncontrolled mode */\n defaultValue?: string | number | Array<string | number>;\n \n /** Enable multi-select mode */\n multiple?: boolean;\n \n /** Enable search/filter functionality */\n searchable?: boolean;\n \n /** Placeholder text */\n placeholder?: string;\n \n /** Disable the select */\n disabled?: boolean;\n \n /** Required field */\n required?: boolean;\n \n /** Error state */\n error?: boolean;\n \n /** Error message to display */\n errorMessage?: string;\n \n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n \n /** Page size for infinite scroll */\n pageSize?: number;\n \n /** Enable virtual scrolling for large lists */\n virtualized?: boolean;\n \n /** Estimated height of each item (for virtualization) */\n estimatedItemHeight?: number;\n \n /** Maximum number of selections (for multiple mode) */\n maxSelections?: number;\n \n /** Dropdown placement */\n placement?: 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n \n /** Custom CSS class name */\n className?: string;\n \n /** Inline styles */\n style?: React.CSSProperties;\n \n /** Custom item renderer */\n renderItem?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom React renderer for option content */\n customRenderer?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom option renderer (DOM). Returns an HTMLElement for full control. */\n optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;\n \n /** Custom selected value renderer */\n renderValue?: (selectedItems: SelectItem[]) => React.ReactNode;\n \n /**\n * Class map for overriding internal state classes.\n * Useful for Tailwind or other utility-first CSS frameworks.\n */\n classMap?: {\n selected?: string;\n active?: string;\n disabled?: string;\n [key: string]: string | undefined;\n };\n\n // Event Handlers\n /** Called when selection changes */\n onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;\n \n /** Called when an item is selected */\n onSelect?: (item: SelectItem, index: number) => void;\n \n /** Called when dropdown opens */\n onOpen?: () => void;\n \n /** Called when dropdown closes */\n onClose?: () => void;\n \n /** Called when search query changes */\n onSearch?: (query: string, results?: SelectItem[], count?: number) => void;\n \n /** Called when more items are needed (infinite scroll) */\n onLoadMore?: (page: number) => void | Promise<void>;\n \n /** Loading state for async operations */\n loading?: boolean;\n \n /** Enable creatable mode (allow creating new options) */\n creatable?: boolean;\n \n /** Called when a new option is created */\n onCreate?: (label: string) => void;\n}\n\n/**\n * Imperative handle for the Select component\n */\nexport interface SelectHandle {\n /** Focus the select input */\n focus: () => void;\n \n /** Open the dropdown */\n open: () => void;\n \n /** Close the dropdown */\n close: () => void;\n \n /** Get currently selected items */\n getSelectedItems: () => SelectItem[];\n \n /** Get currently selected values */\n getSelectedValues: () => Array<string | number>;\n \n /** Programmatically set items */\n setItems: (items: SelectItem[]) => void;\n \n /** Programmatically set grouped items */\n setGroupedItems: (groups: GroupedItem[]) => void;\n \n /** Clear the selection */\n clear: () => void;\n}\n\n/**\n * Smilodon Select Component for React\n * \n * A production-ready, accessible select component with advanced features:\n * - Single and multi-select modes\n * - Searchable with client or server-side filtering\n * - Infinite scroll and virtual scrolling for large datasets\n * - Grouped options\n * - Custom rendering\n * - Full keyboard navigation\n * - WCAG 2.1 AAA compliant\n * \n * @example\n * ```tsx\n * // Simple usage\n * <Select\n * items={[\n * { value: 'apple', label: 'Apple' },\n * { value: 'banana', label: 'Banana' }\n * ]}\n * value=\"apple\"\n * onChange={(value) => console.log(value)}\n * />\n * \n * // Multi-select with search\n * <Select\n * items={items}\n * multiple\n * searchable\n * value={selectedValues}\n * onChange={(values) => setSelectedValues(values)}\n * />\n * \n * // With grouped items\n * <Select\n * groupedItems={[\n * { label: 'Fruits', options: [...] },\n * { label: 'Vegetables', options: [...] }\n * ]}\n * onChange={(value) => console.log(value)}\n * />\n * ```\n */\nexport const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {\n const {\n items = [],\n groupedItems,\n value,\n defaultValue,\n multiple = false,\n searchable = false,\n placeholder = 'Select an option...',\n disabled = false,\n required = false,\n error = false,\n errorMessage,\n infiniteScroll = false,\n pageSize = 20,\n virtualized = false,\n estimatedItemHeight = 48,\n maxSelections,\n placement = 'bottom-start',\n className,\n style,\n renderItem,\n customRenderer,\n renderValue,\n optionRenderer,\n onChange,\n onSelect,\n onOpen,\n onClose,\n onSearch,\n onLoadMore,\n loading = false,\n creatable = false,\n onCreate,\n classMap,\n } = props;\n\n const elementRef = useRef<any>(null);\n const [isControlled] = useState(value !== undefined);\n const [internalValue, setInternalValue] = useState(defaultValue);\n const reactRendererCache = useRef(new Map<number, { container: HTMLElement; root: Root }>());\n\n // Use refs for renderers to avoid reconstructing the wrapper function on every render\n const customRendererRef = useRef(customRenderer ?? renderItem);\n const optionRendererRef = useRef(optionRenderer);\n \n // Update ref when props change\n useEffect(() => {\n customRendererRef.current = customRenderer ?? renderItem;\n optionRendererRef.current = optionRenderer;\n }, [customRenderer, renderItem, optionRenderer]);\n\n const resolvedOptionRenderer = useMemo(() => {\n // If a direct DOM renderer is provided, use it (assumed stable or controlled by user)\n // Wait, if optionRenderer is provided as inline function, it changes every render.\n // We should wrap it too IF it is provided.\n \n if (!!optionRenderer) {\n return (item: SelectItem, index: number, helpers: RendererHelpers) => {\n return optionRendererRef.current?.(item, index, helpers) || document.createElement('div');\n };\n }\n \n // We only want to reconstruct the wrapper if the existence of a renderer changes,\n // NOT if the identity of the function changes (to avoid infinite loops with inline functions).\n const hasReactRenderer = !!(customRenderer ?? renderItem);\n \n if (!hasReactRenderer) return undefined;\n\n return (item: SelectItem, index: number, _helpers: RendererHelpers) => {\n const renderer = customRendererRef.current;\n if (!renderer) return document.createElement('div'); \n\n let entry = reactRendererCache.current.get(index);\n if (!entry) {\n const container = document.createElement('div');\n // Note: createRoot should be reused.\n const root = createRoot(container);\n entry = { container, root };\n reactRendererCache.current.set(index, entry);\n }\n\n entry.root.render(<>{renderer(item, index)}</>);\n return entry.container;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [!!optionRenderer, !!(customRenderer ?? renderItem)]); // Only reconstruct if presence changes\n\n\n\n\n useEffect(() => {\n return () => {\n reactRendererCache.current.forEach(({ root }) => root.unmount());\n reactRendererCache.current.clear();\n };\n }, []);\n\n useEffect(() => {\n const totalItems = groupedItems\n ? groupedItems.reduce((count, group) => count + group.options.length, 0)\n : items.length;\n\n reactRendererCache.current.forEach((entry, index) => {\n if (index >= totalItems) {\n entry.root.unmount();\n reactRendererCache.current.delete(index);\n }\n });\n }, [items, groupedItems]);\n\n // Register custom element if not already registered\n const [isElementReady, setIsElementReady] = useState(false);\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n if (customElements.get('enhanced-select')) {\n setIsElementReady(true);\n } else {\n import('@smilodon/core').then((module) => {\n if (!customElements.get('enhanced-select')) {\n customElements.define('enhanced-select', module.EnhancedSelect);\n }\n setIsElementReady(true);\n });\n }\n }\n }, []);\n\n // Initialize component\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n // Wait for the element to be fully upgraded\n if (!element.setItems) {\n console.warn('Enhanced select element not fully initialized yet');\n return;\n }\n\n // Set initial items\n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else if (items.length > 0) {\n element.setItems(items);\n }\n\n if (resolvedOptionRenderer) {\n element.optionRenderer = resolvedOptionRenderer;\n }\n\n // Configure component\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n scrollToSelected: {\n enabled: true,\n },\n creatable: creatable,\n };\n\n element.updateConfig(config);\n\n // Set classMap if provided\n if (classMap) {\n element.classMap = classMap;\n } else {\n element.classMap = undefined;\n }\n\n // Set initial value\n const currentValue = isControlled ? value : internalValue;\n if (currentValue !== undefined) {\n const values = Array.isArray(currentValue) ? currentValue : [currentValue];\n element.setSelectedValues(values);\n }\n\n // Set error state\n if (error) {\n element.setError(errorMessage || 'Invalid selection');\n } else {\n element.clearError();\n }\n\n // Set required state\n if (required) {\n element.setRequired(true);\n }\n }, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, resolvedOptionRenderer]);\n\n // Update items when they change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setItems) return;\n \n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else {\n element.setItems(items);\n }\n }, [items, groupedItems, isElementReady]);\n\n // Update selected value when it changes (controlled mode)\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isControlled || !isElementReady || !element.setSelectedValues) return;\n \n if (value !== undefined) {\n const values = Array.isArray(value) ? value : [value];\n element.setSelectedValues(values);\n }\n }, [value, isControlled, isElementReady]);\n\n // Update config when props change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.updateConfig) return;\n\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n };\n\n element.updateConfig(config);\n }, [searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, isElementReady]);\n\n // Update error state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n if (error) {\n if (element.setError) element.setError(errorMessage || 'Invalid selection');\n } else {\n if (element.clearError) element.clearError();\n }\n }, [error, errorMessage, isElementReady]);\n\n // Update required state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setRequired) return;\n element.setRequired(required);\n }, [required, isElementReady]);\n\n // Event handlers\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handleSelect = (e: CustomEvent<SelectEventDetail>) => {\n const { item, index } = e.detail;\n onSelect?.(item as SelectItem, index);\n };\n\n const handleChange = (e: CustomEvent<ChangeEventDetail>) => {\n const { selectedItems, selectedValues } = e.detail;\n \n // Cast selectedValues to proper type\n const values = selectedValues as (string | number)[];\n \n // Update internal value in uncontrolled mode\n if (!isControlled) {\n setInternalValue(multiple ? values : values[0]);\n }\n\n // Call onChange callback\n if (onChange) {\n const value = multiple ? values : values[0];\n onChange(value, selectedItems as SelectItem[]);\n }\n };\n\n const handleOpen = (e: CustomEvent<OpenEventDetail>) => {\n onOpen?.();\n };\n\n const handleClose = (e: CustomEvent<CloseEventDetail>) => {\n onClose?.();\n };\n\n const handleSearch = (e: CustomEvent<SearchEventDetail>) => {\n const { query, results, count } = e.detail;\n onSearch?.(query, results as SelectItem[] | undefined, count);\n };\n\n const handleLoadMore = (e: CustomEvent<LoadMoreEventDetail>) => {\n const { page } = e.detail;\n onLoadMore?.(page);\n };\n\n element.addEventListener('select', handleSelect);\n element.addEventListener('change', handleChange);\n element.addEventListener('open', handleOpen);\n element.addEventListener('close', handleClose);\n element.addEventListener('search', handleSearch);\n element.addEventListener('loadMore', handleLoadMore);\n\n return () => {\n element.removeEventListener('select', handleSelect);\n element.removeEventListener('change', handleChange);\n element.removeEventListener('open', handleOpen);\n element.removeEventListener('close', handleClose);\n element.removeEventListener('search', handleSearch);\n element.removeEventListener('loadMore', handleLoadMore);\n };\n }, [onSelect, onChange, onOpen, onClose, onSearch, onLoadMore, isControlled, multiple]);\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n focus: () => {\n elementRef.current?.focus();\n },\n open: () => {\n elementRef.current?.open();\n },\n close: () => {\n elementRef.current?.close();\n },\n getSelectedItems: () => {\n return elementRef.current?.getSelectedItems() || [];\n },\n getSelectedValues: () => {\n return elementRef.current?.getSelectedValues() || [];\n },\n setItems: (items: SelectItem[]) => {\n elementRef.current?.setItems(items);\n },\n setGroupedItems: (groups: GroupedItem[]) => {\n elementRef.current?.setGroupedItems(groups);\n },\n clear: () => {\n elementRef.current?.setSelectedValues([]);\n if (!isControlled) {\n setInternalValue(multiple ? [] : undefined);\n }\n onChange?.(multiple ? [] : '', []);\n },\n }));\n\n return React.createElement('enhanced-select', {\n ref: elementRef,\n className,\n style,\n });\n});\n\nSelect.displayName = 'Select';\n"],"names":["forwardRef","useRef","useState","useEffect","useMemo","createRoot","jsx","Fragment","module","value","useImperativeHandle","items"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgNO,MAAM,SAASA,MAAAA,WAAsC,CAAC,OAAO,QAAQ;AAC1E,QAAM;AAAA,IACJ,QAAQ,CAAA;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IAC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,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { forwardRef, useRef, useState, useEffect, useMemo, useImperativeHandle } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
2
4
|
const Select = forwardRef((props, ref) => {
|
|
3
5
|
const {
|
|
4
6
|
items = [],
|
|
@@ -21,6 +23,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
21
23
|
className,
|
|
22
24
|
style,
|
|
23
25
|
renderItem,
|
|
26
|
+
customRenderer,
|
|
24
27
|
renderValue,
|
|
25
28
|
optionRenderer,
|
|
26
29
|
onChange,
|
|
@@ -31,11 +34,57 @@ const Select = forwardRef((props, ref) => {
|
|
|
31
34
|
onLoadMore,
|
|
32
35
|
loading = false,
|
|
33
36
|
creatable = false,
|
|
34
|
-
onCreate
|
|
37
|
+
onCreate,
|
|
38
|
+
classMap
|
|
35
39
|
} = props;
|
|
36
40
|
const elementRef = useRef(null);
|
|
37
41
|
const [isControlled] = useState(value !== void 0);
|
|
38
42
|
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
43
|
+
const reactRendererCache = useRef(/* @__PURE__ */ new Map());
|
|
44
|
+
const customRendererRef = useRef(customRenderer ?? renderItem);
|
|
45
|
+
const optionRendererRef = useRef(optionRenderer);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
customRendererRef.current = customRenderer ?? renderItem;
|
|
48
|
+
optionRendererRef.current = optionRenderer;
|
|
49
|
+
}, [customRenderer, renderItem, optionRenderer]);
|
|
50
|
+
const resolvedOptionRenderer = useMemo(() => {
|
|
51
|
+
if (!!optionRenderer) {
|
|
52
|
+
return (item, index, helpers) => {
|
|
53
|
+
var _a;
|
|
54
|
+
return ((_a = optionRendererRef.current) == null ? void 0 : _a.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const hasReactRenderer = !!(customRenderer ?? renderItem);
|
|
58
|
+
if (!hasReactRenderer) return void 0;
|
|
59
|
+
return (item, index, _helpers) => {
|
|
60
|
+
const renderer = customRendererRef.current;
|
|
61
|
+
if (!renderer) return document.createElement("div");
|
|
62
|
+
let entry = reactRendererCache.current.get(index);
|
|
63
|
+
if (!entry) {
|
|
64
|
+
const container = document.createElement("div");
|
|
65
|
+
const root = createRoot(container);
|
|
66
|
+
entry = { container, root };
|
|
67
|
+
reactRendererCache.current.set(index, entry);
|
|
68
|
+
}
|
|
69
|
+
entry.root.render(/* @__PURE__ */ jsx(Fragment, { children: renderer(item, index) }));
|
|
70
|
+
return entry.container;
|
|
71
|
+
};
|
|
72
|
+
}, [!!optionRenderer, !!(customRenderer ?? renderItem)]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
return () => {
|
|
75
|
+
reactRendererCache.current.forEach(({ root }) => root.unmount());
|
|
76
|
+
reactRendererCache.current.clear();
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const totalItems = groupedItems ? groupedItems.reduce((count, group) => count + group.options.length, 0) : items.length;
|
|
81
|
+
reactRendererCache.current.forEach((entry, index) => {
|
|
82
|
+
if (index >= totalItems) {
|
|
83
|
+
entry.root.unmount();
|
|
84
|
+
reactRendererCache.current.delete(index);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, [items, groupedItems]);
|
|
39
88
|
const [isElementReady, setIsElementReady] = useState(false);
|
|
40
89
|
useEffect(() => {
|
|
41
90
|
if (typeof window !== "undefined") {
|
|
@@ -63,8 +112,8 @@ const Select = forwardRef((props, ref) => {
|
|
|
63
112
|
} else if (items.length > 0) {
|
|
64
113
|
element.setItems(items);
|
|
65
114
|
}
|
|
66
|
-
if (
|
|
67
|
-
element.optionRenderer =
|
|
115
|
+
if (resolvedOptionRenderer) {
|
|
116
|
+
element.optionRenderer = resolvedOptionRenderer;
|
|
68
117
|
}
|
|
69
118
|
const config = {
|
|
70
119
|
searchable,
|
|
@@ -84,6 +133,11 @@ const Select = forwardRef((props, ref) => {
|
|
|
84
133
|
creatable
|
|
85
134
|
};
|
|
86
135
|
element.updateConfig(config);
|
|
136
|
+
if (classMap) {
|
|
137
|
+
element.classMap = classMap;
|
|
138
|
+
} else {
|
|
139
|
+
element.classMap = void 0;
|
|
140
|
+
}
|
|
87
141
|
const currentValue = isControlled ? value : internalValue;
|
|
88
142
|
if (currentValue !== void 0) {
|
|
89
143
|
const values = Array.isArray(currentValue) ? currentValue : [currentValue];
|
|
@@ -97,7 +151,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
97
151
|
if (required) {
|
|
98
152
|
element.setRequired(true);
|
|
99
153
|
}
|
|
100
|
-
}, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled,
|
|
154
|
+
}, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, resolvedOptionRenderer]);
|
|
101
155
|
useEffect(() => {
|
|
102
156
|
const element = elementRef.current;
|
|
103
157
|
if (!element || !isElementReady || !element.setItems) return;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/Select.tsx"],"sourcesContent":["import React, { useEffect, useRef, useCallback, forwardRef, useImperativeHandle, useState } from 'react';\nimport type {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n RendererHelpers,\n} from '@smilodon/core';\n\n/**\n * Item type for the select component\n */\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Props for the Select component\n */\nexport interface SelectProps {\n /** Array of items to display in the dropdown */\n items?: SelectItem[];\n \n /** Grouped items (alternative to flat items array) */\n groupedItems?: GroupedItem[];\n \n /** Currently selected value(s) */\n value?: string | number | Array<string | number>;\n \n /** Default value(s) for uncontrolled mode */\n defaultValue?: string | number | Array<string | number>;\n \n /** Enable multi-select mode */\n multiple?: boolean;\n \n /** Enable search/filter functionality */\n searchable?: boolean;\n \n /** Placeholder text */\n placeholder?: string;\n \n /** Disable the select */\n disabled?: boolean;\n \n /** Required field */\n required?: boolean;\n \n /** Error state */\n error?: boolean;\n \n /** Error message to display */\n errorMessage?: string;\n \n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n \n /** Page size for infinite scroll */\n pageSize?: number;\n \n /** Enable virtual scrolling for large lists */\n virtualized?: boolean;\n \n /** Estimated height of each item (for virtualization) */\n estimatedItemHeight?: number;\n \n /** Maximum number of selections (for multiple mode) */\n maxSelections?: number;\n \n /** Dropdown placement */\n placement?: 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n \n /** Custom CSS class name */\n className?: string;\n \n /** Inline styles */\n style?: React.CSSProperties;\n \n /** Custom item renderer */\n renderItem?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom option renderer (DOM). Returns an HTMLElement for full control. */\n optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;\n \n /** Custom selected value renderer */\n renderValue?: (selectedItems: SelectItem[]) => React.ReactNode;\n \n // Event Handlers\n /** Called when selection changes */\n onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;\n \n /** Called when an item is selected */\n onSelect?: (item: SelectItem, index: number) => void;\n \n /** Called when dropdown opens */\n onOpen?: () => void;\n \n /** Called when dropdown closes */\n onClose?: () => void;\n \n /** Called when search query changes */\n onSearch?: (query: string, results?: SelectItem[], count?: number) => void;\n \n /** Called when more items are needed (infinite scroll) */\n onLoadMore?: (page: number) => void | Promise<void>;\n \n /** Loading state for async operations */\n loading?: boolean;\n \n /** Enable creatable mode (allow creating new options) */\n creatable?: boolean;\n \n /** Called when a new option is created */\n onCreate?: (label: string) => void;\n}\n\n/**\n * Imperative handle for the Select component\n */\nexport interface SelectHandle {\n /** Focus the select input */\n focus: () => void;\n \n /** Open the dropdown */\n open: () => void;\n \n /** Close the dropdown */\n close: () => void;\n \n /** Get currently selected items */\n getSelectedItems: () => SelectItem[];\n \n /** Get currently selected values */\n getSelectedValues: () => Array<string | number>;\n \n /** Programmatically set items */\n setItems: (items: SelectItem[]) => void;\n \n /** Programmatically set grouped items */\n setGroupedItems: (groups: GroupedItem[]) => void;\n \n /** Clear the selection */\n clear: () => void;\n}\n\n/**\n * Smilodon Select Component for React\n * \n * A production-ready, accessible select component with advanced features:\n * - Single and multi-select modes\n * - Searchable with client or server-side filtering\n * - Infinite scroll and virtual scrolling for large datasets\n * - Grouped options\n * - Custom rendering\n * - Full keyboard navigation\n * - WCAG 2.1 AAA compliant\n * \n * @example\n * ```tsx\n * // Simple usage\n * <Select\n * items={[\n * { value: 'apple', label: 'Apple' },\n * { value: 'banana', label: 'Banana' }\n * ]}\n * value=\"apple\"\n * onChange={(value) => console.log(value)}\n * />\n * \n * // Multi-select with search\n * <Select\n * items={items}\n * multiple\n * searchable\n * value={selectedValues}\n * onChange={(values) => setSelectedValues(values)}\n * />\n * \n * // With grouped items\n * <Select\n * groupedItems={[\n * { label: 'Fruits', options: [...] },\n * { label: 'Vegetables', options: [...] }\n * ]}\n * onChange={(value) => console.log(value)}\n * />\n * ```\n */\nexport const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {\n const {\n items = [],\n groupedItems,\n value,\n defaultValue,\n multiple = false,\n searchable = false,\n placeholder = 'Select an option...',\n disabled = false,\n required = false,\n error = false,\n errorMessage,\n infiniteScroll = false,\n pageSize = 20,\n virtualized = false,\n estimatedItemHeight = 48,\n maxSelections,\n placement = 'bottom-start',\n className,\n style,\n renderItem,\n renderValue,\n optionRenderer,\n onChange,\n onSelect,\n onOpen,\n onClose,\n onSearch,\n onLoadMore,\n loading = false,\n creatable = false,\n onCreate,\n } = props;\n\n const elementRef = useRef<any>(null);\n const [isControlled] = useState(value !== undefined);\n const [internalValue, setInternalValue] = useState(defaultValue);\n\n // Register custom element if not already registered\n const [isElementReady, setIsElementReady] = useState(false);\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n if (customElements.get('enhanced-select')) {\n setIsElementReady(true);\n } else {\n import('@smilodon/core').then((module) => {\n if (!customElements.get('enhanced-select')) {\n customElements.define('enhanced-select', module.EnhancedSelect);\n }\n setIsElementReady(true);\n });\n }\n }\n }, []);\n\n // Initialize component\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n // Wait for the element to be fully upgraded\n if (!element.setItems) {\n console.warn('Enhanced select element not fully initialized yet');\n return;\n }\n\n // Set initial items\n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else if (items.length > 0) {\n element.setItems(items);\n }\n\n if (optionRenderer) {\n element.optionRenderer = optionRenderer;\n }\n\n // Configure component\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n scrollToSelected: {\n enabled: true,\n },\n creatable: creatable,\n };\n\n element.updateConfig(config);\n\n // Set initial value\n const currentValue = isControlled ? value : internalValue;\n if (currentValue !== undefined) {\n const values = Array.isArray(currentValue) ? currentValue : [currentValue];\n element.setSelectedValues(values);\n }\n\n // Set error state\n if (error) {\n element.setError(errorMessage || 'Invalid selection');\n } else {\n element.clearError();\n }\n\n // Set required state\n if (required) {\n element.setRequired(true);\n }\n }, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, optionRenderer]);\n\n // Update items when they change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setItems) return;\n \n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else {\n element.setItems(items);\n }\n }, [items, groupedItems, isElementReady]);\n\n // Update selected value when it changes (controlled mode)\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isControlled || !isElementReady || !element.setSelectedValues) return;\n \n if (value !== undefined) {\n const values = Array.isArray(value) ? value : [value];\n element.setSelectedValues(values);\n }\n }, [value, isControlled, isElementReady]);\n\n // Update config when props change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.updateConfig) return;\n\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n };\n\n element.updateConfig(config);\n }, [searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, isElementReady]);\n\n // Update error state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n if (error) {\n if (element.setError) element.setError(errorMessage || 'Invalid selection');\n } else {\n if (element.clearError) element.clearError();\n }\n }, [error, errorMessage, isElementReady]);\n\n // Update required state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setRequired) return;\n element.setRequired(required);\n }, [required, isElementReady]);\n\n // Event handlers\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handleSelect = (e: CustomEvent<SelectEventDetail>) => {\n const { item, index } = e.detail;\n onSelect?.(item as SelectItem, index);\n };\n\n const handleChange = (e: CustomEvent<ChangeEventDetail>) => {\n const { selectedItems, selectedValues } = e.detail;\n \n // Cast selectedValues to proper type\n const values = selectedValues as (string | number)[];\n \n // Update internal value in uncontrolled mode\n if (!isControlled) {\n setInternalValue(multiple ? values : values[0]);\n }\n\n // Call onChange callback\n if (onChange) {\n const value = multiple ? values : values[0];\n onChange(value, selectedItems as SelectItem[]);\n }\n };\n\n const handleOpen = (e: CustomEvent<OpenEventDetail>) => {\n onOpen?.();\n };\n\n const handleClose = (e: CustomEvent<CloseEventDetail>) => {\n onClose?.();\n };\n\n const handleSearch = (e: CustomEvent<SearchEventDetail>) => {\n const { query, results, count } = e.detail;\n onSearch?.(query, results as SelectItem[] | undefined, count);\n };\n\n const handleLoadMore = (e: CustomEvent<LoadMoreEventDetail>) => {\n const { page } = e.detail;\n onLoadMore?.(page);\n };\n\n element.addEventListener('select', handleSelect);\n element.addEventListener('change', handleChange);\n element.addEventListener('open', handleOpen);\n element.addEventListener('close', handleClose);\n element.addEventListener('search', handleSearch);\n element.addEventListener('loadMore', handleLoadMore);\n\n return () => {\n element.removeEventListener('select', handleSelect);\n element.removeEventListener('change', handleChange);\n element.removeEventListener('open', handleOpen);\n element.removeEventListener('close', handleClose);\n element.removeEventListener('search', handleSearch);\n element.removeEventListener('loadMore', handleLoadMore);\n };\n }, [onSelect, onChange, onOpen, onClose, onSearch, onLoadMore, isControlled, multiple]);\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n focus: () => {\n elementRef.current?.focus();\n },\n open: () => {\n elementRef.current?.open();\n },\n close: () => {\n elementRef.current?.close();\n },\n getSelectedItems: () => {\n return elementRef.current?.getSelectedItems() || [];\n },\n getSelectedValues: () => {\n return elementRef.current?.getSelectedValues() || [];\n },\n setItems: (items: SelectItem[]) => {\n elementRef.current?.setItems(items);\n },\n setGroupedItems: (groups: GroupedItem[]) => {\n elementRef.current?.setGroupedItems(groups);\n },\n clear: () => {\n elementRef.current?.setSelectedValues([]);\n if (!isControlled) {\n setInternalValue(multiple ? [] : undefined);\n }\n onChange?.(multiple ? [] : '', []);\n },\n }));\n\n return React.createElement('enhanced-select', {\n ref: elementRef,\n className,\n style,\n });\n});\n\nSelect.displayName = 'Select';\n"],"names":["value","items"],"mappings":";AAiMO,MAAM,SAAS,WAAsC,CAAC,OAAO,QAAQ;AAC1E,QAAM;AAAA,IACJ,QAAQ,CAAA;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IACb,cAAc;AAAA,IACd,WAAW;AAAA,IACX,WAAW;AAAA,IACX,QAAQ;AAAA,IACR;AAAA,IACA,iBAAiB;AAAA,IACjB,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oB,wBAAuB,CAAA;AAAA,IACpD;AAAA,IACA,UAAU,CAACC,WAAwB;;AACjC,uBAAW,YAAX,mBAAoB,SAASA;AAAAA,IAC/B;AAAA,IACA,iBAAiB,CAAC,WAA0B;;AAC1C,uBAAW,YAAX,mBAAoB,gBAAgB;AAAA,IACtC;AAAA,IACA,OAAO,MAAM;;AACX,uBAAW,YAAX,mBAAoB,kBAAkB;AACtC,UAAI,CAAC,cAAc;AACjB,yBAAiB,WAAW,CAAA,IAAK,MAAS;AAAA,MAC5C;AACA,2CAAW,WAAW,KAAK,IAAI,CAAA;AAAA,IACjC;AAAA,EAAA,EACA;AAEF,SAAO,MAAM,cAAc,mBAAmB;AAAA,IAC5C,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EAAA,CACD;AACH,CAAC;AAED,OAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Select.tsx"],"sourcesContent":["import React, { useEffect, useRef, useCallback, forwardRef, useImperativeHandle, useState, useMemo } from 'react';\nimport { createRoot, type Root } from 'react-dom/client';\nimport type {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n RendererHelpers,\n} from '@smilodon/core';\n\n/**\n * Item type for the select component\n */\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Props for the Select component\n */\nexport interface SelectProps {\n /** Array of items to display in the dropdown */\n items?: SelectItem[];\n \n /** Grouped items (alternative to flat items array) */\n groupedItems?: GroupedItem[];\n \n /** Currently selected value(s) */\n value?: string | number | Array<string | number>;\n \n /** Default value(s) for uncontrolled mode */\n defaultValue?: string | number | Array<string | number>;\n \n /** Enable multi-select mode */\n multiple?: boolean;\n \n /** Enable search/filter functionality */\n searchable?: boolean;\n \n /** Placeholder text */\n placeholder?: string;\n \n /** Disable the select */\n disabled?: boolean;\n \n /** Required field */\n required?: boolean;\n \n /** Error state */\n error?: boolean;\n \n /** Error message to display */\n errorMessage?: string;\n \n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n \n /** Page size for infinite scroll */\n pageSize?: number;\n \n /** Enable virtual scrolling for large lists */\n virtualized?: boolean;\n \n /** Estimated height of each item (for virtualization) */\n estimatedItemHeight?: number;\n \n /** Maximum number of selections (for multiple mode) */\n maxSelections?: number;\n \n /** Dropdown placement */\n placement?: 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n \n /** Custom CSS class name */\n className?: string;\n \n /** Inline styles */\n style?: React.CSSProperties;\n \n /** Custom item renderer */\n renderItem?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom React renderer for option content */\n customRenderer?: (item: SelectItem, index: number) => React.ReactNode;\n\n /** Custom option renderer (DOM). Returns an HTMLElement for full control. */\n optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;\n \n /** Custom selected value renderer */\n renderValue?: (selectedItems: SelectItem[]) => React.ReactNode;\n \n /**\n * Class map for overriding internal state classes.\n * Useful for Tailwind or other utility-first CSS frameworks.\n */\n classMap?: {\n selected?: string;\n active?: string;\n disabled?: string;\n [key: string]: string | undefined;\n };\n\n // Event Handlers\n /** Called when selection changes */\n onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;\n \n /** Called when an item is selected */\n onSelect?: (item: SelectItem, index: number) => void;\n \n /** Called when dropdown opens */\n onOpen?: () => void;\n \n /** Called when dropdown closes */\n onClose?: () => void;\n \n /** Called when search query changes */\n onSearch?: (query: string, results?: SelectItem[], count?: number) => void;\n \n /** Called when more items are needed (infinite scroll) */\n onLoadMore?: (page: number) => void | Promise<void>;\n \n /** Loading state for async operations */\n loading?: boolean;\n \n /** Enable creatable mode (allow creating new options) */\n creatable?: boolean;\n \n /** Called when a new option is created */\n onCreate?: (label: string) => void;\n}\n\n/**\n * Imperative handle for the Select component\n */\nexport interface SelectHandle {\n /** Focus the select input */\n focus: () => void;\n \n /** Open the dropdown */\n open: () => void;\n \n /** Close the dropdown */\n close: () => void;\n \n /** Get currently selected items */\n getSelectedItems: () => SelectItem[];\n \n /** Get currently selected values */\n getSelectedValues: () => Array<string | number>;\n \n /** Programmatically set items */\n setItems: (items: SelectItem[]) => void;\n \n /** Programmatically set grouped items */\n setGroupedItems: (groups: GroupedItem[]) => void;\n \n /** Clear the selection */\n clear: () => void;\n}\n\n/**\n * Smilodon Select Component for React\n * \n * A production-ready, accessible select component with advanced features:\n * - Single and multi-select modes\n * - Searchable with client or server-side filtering\n * - Infinite scroll and virtual scrolling for large datasets\n * - Grouped options\n * - Custom rendering\n * - Full keyboard navigation\n * - WCAG 2.1 AAA compliant\n * \n * @example\n * ```tsx\n * // Simple usage\n * <Select\n * items={[\n * { value: 'apple', label: 'Apple' },\n * { value: 'banana', label: 'Banana' }\n * ]}\n * value=\"apple\"\n * onChange={(value) => console.log(value)}\n * />\n * \n * // Multi-select with search\n * <Select\n * items={items}\n * multiple\n * searchable\n * value={selectedValues}\n * onChange={(values) => setSelectedValues(values)}\n * />\n * \n * // With grouped items\n * <Select\n * groupedItems={[\n * { label: 'Fruits', options: [...] },\n * { label: 'Vegetables', options: [...] }\n * ]}\n * onChange={(value) => console.log(value)}\n * />\n * ```\n */\nexport const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {\n const {\n items = [],\n groupedItems,\n value,\n defaultValue,\n multiple = false,\n searchable = false,\n placeholder = 'Select an option...',\n disabled = false,\n required = false,\n error = false,\n errorMessage,\n infiniteScroll = false,\n pageSize = 20,\n virtualized = false,\n estimatedItemHeight = 48,\n maxSelections,\n placement = 'bottom-start',\n className,\n style,\n renderItem,\n customRenderer,\n renderValue,\n optionRenderer,\n onChange,\n onSelect,\n onOpen,\n onClose,\n onSearch,\n onLoadMore,\n loading = false,\n creatable = false,\n onCreate,\n classMap,\n } = props;\n\n const elementRef = useRef<any>(null);\n const [isControlled] = useState(value !== undefined);\n const [internalValue, setInternalValue] = useState(defaultValue);\n const reactRendererCache = useRef(new Map<number, { container: HTMLElement; root: Root }>());\n\n // Use refs for renderers to avoid reconstructing the wrapper function on every render\n const customRendererRef = useRef(customRenderer ?? renderItem);\n const optionRendererRef = useRef(optionRenderer);\n \n // Update ref when props change\n useEffect(() => {\n customRendererRef.current = customRenderer ?? renderItem;\n optionRendererRef.current = optionRenderer;\n }, [customRenderer, renderItem, optionRenderer]);\n\n const resolvedOptionRenderer = useMemo(() => {\n // If a direct DOM renderer is provided, use it (assumed stable or controlled by user)\n // Wait, if optionRenderer is provided as inline function, it changes every render.\n // We should wrap it too IF it is provided.\n \n if (!!optionRenderer) {\n return (item: SelectItem, index: number, helpers: RendererHelpers) => {\n return optionRendererRef.current?.(item, index, helpers) || document.createElement('div');\n };\n }\n \n // We only want to reconstruct the wrapper if the existence of a renderer changes,\n // NOT if the identity of the function changes (to avoid infinite loops with inline functions).\n const hasReactRenderer = !!(customRenderer ?? renderItem);\n \n if (!hasReactRenderer) return undefined;\n\n return (item: SelectItem, index: number, _helpers: RendererHelpers) => {\n const renderer = customRendererRef.current;\n if (!renderer) return document.createElement('div'); \n\n let entry = reactRendererCache.current.get(index);\n if (!entry) {\n const container = document.createElement('div');\n // Note: createRoot should be reused.\n const root = createRoot(container);\n entry = { container, root };\n reactRendererCache.current.set(index, entry);\n }\n\n entry.root.render(<>{renderer(item, index)}</>);\n return entry.container;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [!!optionRenderer, !!(customRenderer ?? renderItem)]); // Only reconstruct if presence changes\n\n\n\n\n useEffect(() => {\n return () => {\n reactRendererCache.current.forEach(({ root }) => root.unmount());\n reactRendererCache.current.clear();\n };\n }, []);\n\n useEffect(() => {\n const totalItems = groupedItems\n ? groupedItems.reduce((count, group) => count + group.options.length, 0)\n : items.length;\n\n reactRendererCache.current.forEach((entry, index) => {\n if (index >= totalItems) {\n entry.root.unmount();\n reactRendererCache.current.delete(index);\n }\n });\n }, [items, groupedItems]);\n\n // Register custom element if not already registered\n const [isElementReady, setIsElementReady] = useState(false);\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n if (customElements.get('enhanced-select')) {\n setIsElementReady(true);\n } else {\n import('@smilodon/core').then((module) => {\n if (!customElements.get('enhanced-select')) {\n customElements.define('enhanced-select', module.EnhancedSelect);\n }\n setIsElementReady(true);\n });\n }\n }\n }, []);\n\n // Initialize component\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n // Wait for the element to be fully upgraded\n if (!element.setItems) {\n console.warn('Enhanced select element not fully initialized yet');\n return;\n }\n\n // Set initial items\n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else if (items.length > 0) {\n element.setItems(items);\n }\n\n if (resolvedOptionRenderer) {\n element.optionRenderer = resolvedOptionRenderer;\n }\n\n // Configure component\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n scrollToSelected: {\n enabled: true,\n },\n creatable: creatable,\n };\n\n element.updateConfig(config);\n\n // Set classMap if provided\n if (classMap) {\n element.classMap = classMap;\n } else {\n element.classMap = undefined;\n }\n\n // Set initial value\n const currentValue = isControlled ? value : internalValue;\n if (currentValue !== undefined) {\n const values = Array.isArray(currentValue) ? currentValue : [currentValue];\n element.setSelectedValues(values);\n }\n\n // Set error state\n if (error) {\n element.setError(errorMessage || 'Invalid selection');\n } else {\n element.clearError();\n }\n\n // Set required state\n if (required) {\n element.setRequired(true);\n }\n }, [isElementReady, items, groupedItems, searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, creatable, error, errorMessage, required, value, internalValue, isControlled, resolvedOptionRenderer]);\n\n // Update items when they change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setItems) return;\n \n if (groupedItems) {\n element.setGroupedItems(groupedItems);\n } else {\n element.setItems(items);\n }\n }, [items, groupedItems, isElementReady]);\n\n // Update selected value when it changes (controlled mode)\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isControlled || !isElementReady || !element.setSelectedValues) return;\n \n if (value !== undefined) {\n const values = Array.isArray(value) ? value : [value];\n element.setSelectedValues(values);\n }\n }, [value, isControlled, isElementReady]);\n\n // Update config when props change\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.updateConfig) return;\n\n const config = {\n searchable,\n placeholder,\n enabled: !disabled,\n selection: {\n mode: multiple ? 'multi' : 'single',\n maxSelections: maxSelections,\n },\n infiniteScroll: {\n enabled: infiniteScroll,\n pageSize: pageSize,\n },\n };\n\n element.updateConfig(config);\n }, [searchable, placeholder, disabled, multiple, maxSelections, infiniteScroll, pageSize, isElementReady]);\n\n // Update error state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady) return;\n\n if (error) {\n if (element.setError) element.setError(errorMessage || 'Invalid selection');\n } else {\n if (element.clearError) element.clearError();\n }\n }, [error, errorMessage, isElementReady]);\n\n // Update required state\n useEffect(() => {\n const element = elementRef.current;\n if (!element || !isElementReady || !element.setRequired) return;\n element.setRequired(required);\n }, [required, isElementReady]);\n\n // Event handlers\n useEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n\n const handleSelect = (e: CustomEvent<SelectEventDetail>) => {\n const { item, index } = e.detail;\n onSelect?.(item as SelectItem, index);\n };\n\n const handleChange = (e: CustomEvent<ChangeEventDetail>) => {\n const { selectedItems, selectedValues } = e.detail;\n \n // Cast selectedValues to proper type\n const values = selectedValues as (string | number)[];\n \n // Update internal value in uncontrolled mode\n if (!isControlled) {\n setInternalValue(multiple ? values : values[0]);\n }\n\n // Call onChange callback\n if (onChange) {\n const value = multiple ? values : values[0];\n onChange(value, selectedItems as SelectItem[]);\n }\n };\n\n const handleOpen = (e: CustomEvent<OpenEventDetail>) => {\n onOpen?.();\n };\n\n const handleClose = (e: CustomEvent<CloseEventDetail>) => {\n onClose?.();\n };\n\n const handleSearch = (e: CustomEvent<SearchEventDetail>) => {\n const { query, results, count } = e.detail;\n onSearch?.(query, results as SelectItem[] | undefined, count);\n };\n\n const handleLoadMore = (e: CustomEvent<LoadMoreEventDetail>) => {\n const { page } = e.detail;\n onLoadMore?.(page);\n };\n\n element.addEventListener('select', handleSelect);\n element.addEventListener('change', handleChange);\n element.addEventListener('open', handleOpen);\n element.addEventListener('close', handleClose);\n element.addEventListener('search', handleSearch);\n element.addEventListener('loadMore', handleLoadMore);\n\n return () => {\n element.removeEventListener('select', handleSelect);\n element.removeEventListener('change', handleChange);\n element.removeEventListener('open', handleOpen);\n element.removeEventListener('close', handleClose);\n element.removeEventListener('search', handleSearch);\n element.removeEventListener('loadMore', handleLoadMore);\n };\n }, [onSelect, onChange, onOpen, onClose, onSearch, onLoadMore, isControlled, multiple]);\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n focus: () => {\n elementRef.current?.focus();\n },\n open: () => {\n elementRef.current?.open();\n },\n close: () => {\n elementRef.current?.close();\n },\n getSelectedItems: () => {\n return elementRef.current?.getSelectedItems() || [];\n },\n getSelectedValues: () => {\n return elementRef.current?.getSelectedValues() || [];\n },\n setItems: (items: SelectItem[]) => {\n elementRef.current?.setItems(items);\n },\n setGroupedItems: (groups: GroupedItem[]) => {\n elementRef.current?.setGroupedItems(groups);\n },\n clear: () => {\n elementRef.current?.setSelectedValues([]);\n if (!isControlled) {\n setInternalValue(multiple ? [] : undefined);\n }\n onChange?.(multiple ? [] : '', []);\n },\n }));\n\n return React.createElement('enhanced-select', {\n ref: elementRef,\n className,\n style,\n });\n});\n\nSelect.displayName = 'Select';\n"],"names":["value","items"],"mappings":";;;AAgNO,MAAM,SAAS,WAAsC,CAAC,OAAO,QAAQ;AAC1E,QAAM;AAAA,IACJ,QAAQ,CAAA;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IACb,cAAc;AAAA,IACd,WAAW;AAAA,IACX,WAAW;AAAA,IACX,QAAQ;AAA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F,GAAG,CAAC,UAAU,UAAU,QAAQ,SAAS,UAAU,YAAY,cAAc,QAAQ,CAAC;AAGtF,sBAAoB,KAAK,OAAO;AAAA,IAC9B,OAAO,MAAM;;AACX,uBAAW,YAAX,mBAAoB;AAAA,IACtB;AAAA,IACA,MAAM,MAAM;;AACV,uBAAW,YAAX,mBAAoB;AAAA,IACtB;AAAA,IACA,OAAO,MAAM;;AACX,uBAAW,YAAX,mBAAoB;AAAA,IACtB;AAAA,IACA,kBAAkB,MAAM;;AACtB,eAAO,gBAAW,YAAX,mBAAoB,uBAAsB,CAAA;AAAA,IACnD;AAAA,IACA,mBAAmB,MAAM;;AACvB,eAAO,gBAAW,YAAX,mBAAoB,wBAAuB,CAAA;AAAA,IACpD;AAAA,IACA,UAAU,CAACC,WAAwB;;AACjC,uBAAW,YAAX,mBAAoB,SAASA;AAAAA,IAC/B;AAAA,IACA,iBAAiB,CAAC,WAA0B;;AAC1C,uBAAW,YAAX,mBAAoB,gBAAgB;AAAA,IACtC;AAAA,IACA,OAAO,MAAM;;AACX,uBAAW,YAAX,mBAAoB,kBAAkB;AACtC,UAAI,CAAC,cAAc;AACjB,yBAAiB,WAAW,CAAA,IAAK,MAAS;AAAA,MAC5C;AACA,2CAAW,WAAW,KAAK,IAAI,CAAA;AAAA,IACjC;AAAA,EAAA,EACA;AAEF,SAAO,MAAM,cAAc,mBAAmB;AAAA,IAC5C,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EAAA,CACD;AACH,CAAC;AAED,OAAO,cAAc;"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GroupedItem, RendererHelpers } from '@smilodon/core';
|
|
3
|
+
/**
|
|
4
|
+
* Item type for the select component
|
|
5
|
+
*/
|
|
6
|
+
export interface SelectItem {
|
|
7
|
+
value: string | number;
|
|
8
|
+
label: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Props for the Select component
|
|
14
|
+
*/
|
|
15
|
+
export interface SelectProps {
|
|
16
|
+
/** Array of items to display in the dropdown */
|
|
17
|
+
items?: SelectItem[];
|
|
18
|
+
/** Grouped items (alternative to flat items array) */
|
|
19
|
+
groupedItems?: GroupedItem[];
|
|
20
|
+
/** Currently selected value(s) */
|
|
21
|
+
value?: string | number | Array<string | number>;
|
|
22
|
+
/** Default value(s) for uncontrolled mode */
|
|
23
|
+
defaultValue?: string | number | Array<string | number>;
|
|
24
|
+
/** Enable multi-select mode */
|
|
25
|
+
multiple?: boolean;
|
|
26
|
+
/** Enable search/filter functionality */
|
|
27
|
+
searchable?: boolean;
|
|
28
|
+
/** Placeholder text */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
/** Disable the select */
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** Required field */
|
|
33
|
+
required?: boolean;
|
|
34
|
+
/** Error state */
|
|
35
|
+
error?: boolean;
|
|
36
|
+
/** Error message to display */
|
|
37
|
+
errorMessage?: string;
|
|
38
|
+
/** Enable infinite scroll */
|
|
39
|
+
infiniteScroll?: boolean;
|
|
40
|
+
/** Page size for infinite scroll */
|
|
41
|
+
pageSize?: number;
|
|
42
|
+
/** Enable virtual scrolling for large lists */
|
|
43
|
+
virtualized?: boolean;
|
|
44
|
+
/** Estimated height of each item (for virtualization) */
|
|
45
|
+
estimatedItemHeight?: number;
|
|
46
|
+
/** Maximum number of selections (for multiple mode) */
|
|
47
|
+
maxSelections?: number;
|
|
48
|
+
/** Dropdown placement */
|
|
49
|
+
placement?: 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';
|
|
50
|
+
/** Custom CSS class name */
|
|
51
|
+
className?: string;
|
|
52
|
+
/** Inline styles */
|
|
53
|
+
style?: React.CSSProperties;
|
|
54
|
+
/** Custom item renderer */
|
|
55
|
+
renderItem?: (item: SelectItem, index: number) => React.ReactNode;
|
|
56
|
+
/** Custom React renderer for option content */
|
|
57
|
+
customRenderer?: (item: SelectItem, index: number) => React.ReactNode;
|
|
58
|
+
/** Custom option renderer (DOM). Returns an HTMLElement for full control. */
|
|
59
|
+
optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;
|
|
60
|
+
/** Custom selected value renderer */
|
|
61
|
+
renderValue?: (selectedItems: SelectItem[]) => React.ReactNode;
|
|
62
|
+
/**
|
|
63
|
+
* Class map for overriding internal state classes.
|
|
64
|
+
* Useful for Tailwind or other utility-first CSS frameworks.
|
|
65
|
+
*/
|
|
66
|
+
classMap?: {
|
|
67
|
+
selected?: string;
|
|
68
|
+
active?: string;
|
|
69
|
+
disabled?: string;
|
|
70
|
+
[key: string]: string | undefined;
|
|
71
|
+
};
|
|
72
|
+
/** Called when selection changes */
|
|
73
|
+
onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;
|
|
74
|
+
/** Called when an item is selected */
|
|
75
|
+
onSelect?: (item: SelectItem, index: number) => void;
|
|
76
|
+
/** Called when dropdown opens */
|
|
77
|
+
onOpen?: () => void;
|
|
78
|
+
/** Called when dropdown closes */
|
|
79
|
+
onClose?: () => void;
|
|
80
|
+
/** Called when search query changes */
|
|
81
|
+
onSearch?: (query: string, results?: SelectItem[], count?: number) => void;
|
|
82
|
+
/** Called when more items are needed (infinite scroll) */
|
|
83
|
+
onLoadMore?: (page: number) => void | Promise<void>;
|
|
84
|
+
/** Loading state for async operations */
|
|
85
|
+
loading?: boolean;
|
|
86
|
+
/** Enable creatable mode (allow creating new options) */
|
|
87
|
+
creatable?: boolean;
|
|
88
|
+
/** Called when a new option is created */
|
|
89
|
+
onCreate?: (label: string) => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Imperative handle for the Select component
|
|
93
|
+
*/
|
|
94
|
+
export interface SelectHandle {
|
|
95
|
+
/** Focus the select input */
|
|
96
|
+
focus: () => void;
|
|
97
|
+
/** Open the dropdown */
|
|
98
|
+
open: () => void;
|
|
99
|
+
/** Close the dropdown */
|
|
100
|
+
close: () => void;
|
|
101
|
+
/** Get currently selected items */
|
|
102
|
+
getSelectedItems: () => SelectItem[];
|
|
103
|
+
/** Get currently selected values */
|
|
104
|
+
getSelectedValues: () => Array<string | number>;
|
|
105
|
+
/** Programmatically set items */
|
|
106
|
+
setItems: (items: SelectItem[]) => void;
|
|
107
|
+
/** Programmatically set grouped items */
|
|
108
|
+
setGroupedItems: (groups: GroupedItem[]) => void;
|
|
109
|
+
/** Clear the selection */
|
|
110
|
+
clear: () => void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Smilodon Select Component for React
|
|
114
|
+
*
|
|
115
|
+
* A production-ready, accessible select component with advanced features:
|
|
116
|
+
* - Single and multi-select modes
|
|
117
|
+
* - Searchable with client or server-side filtering
|
|
118
|
+
* - Infinite scroll and virtual scrolling for large datasets
|
|
119
|
+
* - Grouped options
|
|
120
|
+
* - Custom rendering
|
|
121
|
+
* - Full keyboard navigation
|
|
122
|
+
* - WCAG 2.1 AAA compliant
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* // Simple usage
|
|
127
|
+
* <Select
|
|
128
|
+
* items={[
|
|
129
|
+
* { value: 'apple', label: 'Apple' },
|
|
130
|
+
* { value: 'banana', label: 'Banana' }
|
|
131
|
+
* ]}
|
|
132
|
+
* value="apple"
|
|
133
|
+
* onChange={(value) => console.log(value)}
|
|
134
|
+
* />
|
|
135
|
+
*
|
|
136
|
+
* // Multi-select with search
|
|
137
|
+
* <Select
|
|
138
|
+
* items={items}
|
|
139
|
+
* multiple
|
|
140
|
+
* searchable
|
|
141
|
+
* value={selectedValues}
|
|
142
|
+
* onChange={(values) => setSelectedValues(values)}
|
|
143
|
+
* />
|
|
144
|
+
*
|
|
145
|
+
* // With grouped items
|
|
146
|
+
* <Select
|
|
147
|
+
* groupedItems={[
|
|
148
|
+
* { label: 'Fruits', options: [...] },
|
|
149
|
+
* { label: 'Vegetables', options: [...] }
|
|
150
|
+
* ]}
|
|
151
|
+
* onChange={(value) => console.log(value)}
|
|
152
|
+
* />
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare const Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<SelectHandle>>;
|
|
156
|
+
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6F,MAAM,OAAO,CAAC;AAElH,OAAO,KAAK,EAOV,WAAW,EACX,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IAErB,sDAAsD;IACtD,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAE7B,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjD,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAExD,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,yCAAyC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO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AC;IAEhD,iCAAiC;IACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IAExC,yCAAyC;IACzC,eAAe,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAEjD,0BAA0B;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,MAAM,kFA2WjB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @smilodon/react
|
|
3
|
+
*
|
|
4
|
+
* React adapter for Smilodon Select Component
|
|
5
|
+
*
|
|
6
|
+
* A production-ready, accessible select component for React applications.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Select } from '@smilodon/react';
|
|
11
|
+
*
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* const [value, setValue] = useState('');
|
|
14
|
+
*
|
|
15
|
+
* return (
|
|
16
|
+
* <Select
|
|
17
|
+
* items={[
|
|
18
|
+
* { value: '1', label: 'Option 1' },
|
|
19
|
+
* { value: '2', label: 'Option 2' },
|
|
20
|
+
* ]}
|
|
21
|
+
* value={value}
|
|
22
|
+
* onChange={(newValue) => setValue(newValue as string)}
|
|
23
|
+
* searchable
|
|
24
|
+
* placeholder="Select an option..."
|
|
25
|
+
* />
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @packageDocumentation
|
|
31
|
+
*/
|
|
32
|
+
export { Select } from './Select';
|
|
33
|
+
export type { SelectProps, SelectItem, SelectHandle } from './Select';
|
|
34
|
+
export type { SelectEventDetail, OpenEventDetail, CloseEventDetail, SearchEventDetail, ChangeEventDetail, LoadMoreEventDetail, GroupedItem, } from '@smilodon/core';
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGtE,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smilodon/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "React adapter for @smilodon/core - Production-ready accessible select component (React, Vue, Svelte, Vanilla JS)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,18 +18,21 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc --declaration --emitDeclarationOnly --outDir dist/types &&
|
|
21
|
+
"build": "vite build && tsc --declaration --emitDeclarationOnly --outDir dist/types && node scripts/cleanup-types.js",
|
|
22
22
|
"size": "gzip -c dist/index.js | wc -c",
|
|
23
23
|
"prepublishOnly": "npm run build"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@smilodon/core": "^1.0.0",
|
|
27
|
-
"react": ">=16.8.0"
|
|
27
|
+
"react": ">=16.8.0",
|
|
28
|
+
"react-dom": ">=16.8.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/react": "^18.2.0",
|
|
32
|
+
"@types/react-dom": "^18.2.0",
|
|
31
33
|
"@vitejs/plugin-react": "^4.7.0",
|
|
32
34
|
"react": "^18.2.0",
|
|
35
|
+
"react-dom": "^18.2.0",
|
|
33
36
|
"typescript": "^5.6.2",
|
|
34
37
|
"vite": "^5.4.21"
|
|
35
38
|
},
|