@smilodon/react 1.2.4 → 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 +14 -0
- package/dist/index.cjs +24 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -6
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +10 -0
- package/dist/types/Select.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1072,6 +1072,20 @@ This component is built with accessibility in mind:
|
|
|
1072
1072
|
- ✅ 44px minimum touch targets (WCAG 2.5.5)
|
|
1073
1073
|
- ✅ WCAG 2.1 AAA compliant
|
|
1074
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
|
+
|
|
1075
1089
|
## Performance
|
|
1076
1090
|
|
|
1077
1091
|
- Virtual scrolling for large datasets (1000+ items)
|
package/dist/index.cjs
CHANGED
|
@@ -58,17 +58,31 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
58
58
|
onLoadMore,
|
|
59
59
|
loading = false,
|
|
60
60
|
creatable = false,
|
|
61
|
-
onCreate
|
|
61
|
+
onCreate,
|
|
62
|
+
classMap
|
|
62
63
|
} = props;
|
|
63
64
|
const elementRef = React.useRef(null);
|
|
64
65
|
const [isControlled] = React.useState(value !== void 0);
|
|
65
66
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
66
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]);
|
|
67
74
|
const resolvedOptionRenderer = React.useMemo(() => {
|
|
68
|
-
if (optionRenderer)
|
|
69
|
-
|
|
70
|
-
|
|
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;
|
|
71
83
|
return (item, index, _helpers) => {
|
|
84
|
+
const renderer = customRendererRef.current;
|
|
85
|
+
if (!renderer) return document.createElement("div");
|
|
72
86
|
let entry = reactRendererCache.current.get(index);
|
|
73
87
|
if (!entry) {
|
|
74
88
|
const container = document.createElement("div");
|
|
@@ -79,7 +93,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
79
93
|
entry.root.render(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderer(item, index) }));
|
|
80
94
|
return entry.container;
|
|
81
95
|
};
|
|
82
|
-
}, [optionRenderer, customRenderer
|
|
96
|
+
}, [!!optionRenderer, !!(customRenderer ?? renderItem)]);
|
|
83
97
|
React.useEffect(() => {
|
|
84
98
|
return () => {
|
|
85
99
|
reactRendererCache.current.forEach(({ root }) => root.unmount());
|
|
@@ -143,6 +157,11 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
143
157
|
creatable
|
|
144
158
|
};
|
|
145
159
|
element.updateConfig(config);
|
|
160
|
+
if (classMap) {
|
|
161
|
+
element.classMap = classMap;
|
|
162
|
+
} else {
|
|
163
|
+
element.classMap = void 0;
|
|
164
|
+
}
|
|
146
165
|
const currentValue = isControlled ? value : internalValue;
|
|
147
166
|
if (currentValue !== void 0) {
|
|
148
167
|
const values = Array.isArray(currentValue) ? currentValue : [currentValue];
|
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, 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 // 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 } = 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 const resolvedOptionRenderer = useMemo(() => {\n if (optionRenderer) return optionRenderer;\n const renderer = customRenderer ?? renderItem;\n if (!renderer) return undefined;\n\n return (item: SelectItem, index: number, _helpers: RendererHelpers) => {\n let entry = reactRendererCache.current.get(index);\n if (!entry) {\n const container = document.createElement('div');\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 }, [optionRenderer, customRenderer, renderItem]);\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 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","useMemo","createRoot","jsx","Fragment","useEffect","module","value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B,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;;"}
|
|
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,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,IACA;AAAA,IACF;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,aAAaC,MAAAA,OAAY,IAAI;AACnC,QAAM,CAAC,YAAY,IAAIC,eAAS,UAAU,MAAS;AACnD,QAAM,CAAC,eAAe,gBAAgB,IAAIA,MAAAA,SAAS,YAAY;AAC/D,QAAM,qBAAqBD,MAAAA,OAAO,oBAAI,KAAqD;AAG3F,QAAM,oBAAoBA,MAAAA,OAAO,kBAAkB,UAAU;AAC7D,QAAM,oBAAoBA,MAAAA,OAAO,cAAc;AAG/CE,QAAAA,UAAU,MAAM;AACd,sBAAkB,UAAU,kBAAkB;AAC9C,sBAAkB,UAAU;AAAA,EAC9B,GAAG,CAAC,gBAAgB,YAAY,cAAc,CAAC;AAE/C,QAAM,yBAAyBC,MAAAA,QAAQ,MAAM;AAK3C,QAAI,CAAC,CAAC,gBAAgB;A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AAA,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;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import React, { forwardRef, useRef, useState,
|
|
2
|
+
import React, { forwardRef, useRef, useState, useEffect, useMemo, useImperativeHandle } from "react";
|
|
3
3
|
import { createRoot } from "react-dom/client";
|
|
4
4
|
const Select = forwardRef((props, ref) => {
|
|
5
5
|
const {
|
|
@@ -34,17 +34,31 @@ const Select = forwardRef((props, ref) => {
|
|
|
34
34
|
onLoadMore,
|
|
35
35
|
loading = false,
|
|
36
36
|
creatable = false,
|
|
37
|
-
onCreate
|
|
37
|
+
onCreate,
|
|
38
|
+
classMap
|
|
38
39
|
} = props;
|
|
39
40
|
const elementRef = useRef(null);
|
|
40
41
|
const [isControlled] = useState(value !== void 0);
|
|
41
42
|
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
42
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]);
|
|
43
50
|
const resolvedOptionRenderer = useMemo(() => {
|
|
44
|
-
if (optionRenderer)
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
59
|
return (item, index, _helpers) => {
|
|
60
|
+
const renderer = customRendererRef.current;
|
|
61
|
+
if (!renderer) return document.createElement("div");
|
|
48
62
|
let entry = reactRendererCache.current.get(index);
|
|
49
63
|
if (!entry) {
|
|
50
64
|
const container = document.createElement("div");
|
|
@@ -55,7 +69,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
55
69
|
entry.root.render(/* @__PURE__ */ jsx(Fragment, { children: renderer(item, index) }));
|
|
56
70
|
return entry.container;
|
|
57
71
|
};
|
|
58
|
-
}, [optionRenderer, customRenderer
|
|
72
|
+
}, [!!optionRenderer, !!(customRenderer ?? renderItem)]);
|
|
59
73
|
useEffect(() => {
|
|
60
74
|
return () => {
|
|
61
75
|
reactRendererCache.current.forEach(({ root }) => root.unmount());
|
|
@@ -119,6 +133,11 @@ const Select = forwardRef((props, ref) => {
|
|
|
119
133
|
creatable
|
|
120
134
|
};
|
|
121
135
|
element.updateConfig(config);
|
|
136
|
+
if (classMap) {
|
|
137
|
+
element.classMap = classMap;
|
|
138
|
+
} else {
|
|
139
|
+
element.classMap = void 0;
|
|
140
|
+
}
|
|
122
141
|
const currentValue = isControlled ? value : internalValue;
|
|
123
142
|
if (currentValue !== void 0) {
|
|
124
143
|
const values = Array.isArray(currentValue) ? currentValue : [currentValue];
|
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, 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 // 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 } = 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 const resolvedOptionRenderer = useMemo(() => {\n if (optionRenderer) return optionRenderer;\n const renderer = customRenderer ?? renderItem;\n if (!renderer) return undefined;\n\n return (item: SelectItem, index: number, _helpers: RendererHelpers) => {\n let entry = reactRendererCache.current.get(index);\n if (!entry) {\n const container = document.createElement('div');\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 }, [optionRenderer, customRenderer, renderItem]);\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 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":";;;AAqMO,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,WAAW;AAAA,IACX,cAAc;AAAA,IACd,sBAAsB;AAAA,IACtB;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACF;AAAA,IACE;AAAA,IACA;AAAA,I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;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;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,IACA;AAAA,IACF;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM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,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;"}
|
package/dist/types/Select.d.ts
CHANGED
|
@@ -59,6 +59,16 @@ export interface SelectProps {
|
|
|
59
59
|
optionRenderer?: (item: SelectItem, index: number, helpers: RendererHelpers) => HTMLElement;
|
|
60
60
|
/** Custom selected value renderer */
|
|
61
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
|
+
};
|
|
62
72
|
/** Called when selection changes */
|
|
63
73
|
onChange?: (value: string | number | Array<string | number>, items: SelectItem[]) => void;
|
|
64
74
|
/** Called when an item is selected */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/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