@bioturing/components 0.38.0 → 0.39.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/dist/components/cmdk/index.d.ts +2 -2
- package/dist/components/combobox/component.js.map +1 -1
- package/dist/components/data-table/component.js +7 -7
- package/dist/components/data-table/component.js.map +1 -1
- package/dist/components/data-table/hooks.d.ts.map +1 -1
- package/dist/components/data-table/hooks.js +73 -61
- package/dist/components/data-table/hooks.js.map +1 -1
- package/dist/components/dropdown-menu/component.js +1 -1
- package/dist/components/dropdown-menu/component.js.map +1 -1
- package/dist/components/popup-panel/component.d.ts +13 -1
- package/dist/components/popup-panel/component.d.ts.map +1 -1
- package/dist/components/popup-panel/component.js +102 -95
- package/dist/components/popup-panel/component.js.map +1 -1
- package/dist/components/toast/function.d.ts +8 -8
- package/dist/components/toast/function.d.ts.map +1 -1
- package/dist/components/toast/function.js.map +1 -1
- package/dist/components/tree/components.d.ts.map +1 -1
- package/dist/components/tree/components.js +50 -40
- package/dist/components/tree/components.js.map +1 -1
- package/dist/components/tree/style.css +1 -1
- package/dist/components/tree/types.d.ts +4 -0
- package/dist/components/tree/types.d.ts.map +1 -1
- package/dist/components/tree/useTreeCommon.d.ts +1 -0
- package/dist/components/tree/useTreeCommon.d.ts.map +1 -1
- package/dist/components/tree/useTreeCommon.js +21 -19
- package/dist/components/tree/useTreeCommon.js.map +1 -1
- package/dist/stats.html +1 -1
- package/package.json +3 -3
|
@@ -182,7 +182,7 @@ declare const List: React.ForwardRefExoticComponent<Children & Omit<React.Detail
|
|
|
182
182
|
/**
|
|
183
183
|
* Renders the command menu in a Radix Dialog.
|
|
184
184
|
*/
|
|
185
|
-
declare const Dialog: React.ForwardRefExoticComponent<RadixDialog.Root.Props & Children & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
185
|
+
declare const Dialog: React.ForwardRefExoticComponent<RadixDialog.Root.Props<unknown> & Children & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
186
186
|
render?: import("@base-ui-components/react").useRender.RenderProp<Record<string, unknown>>;
|
|
187
187
|
as?: "div";
|
|
188
188
|
state?: Record<string, unknown>;
|
|
@@ -353,7 +353,7 @@ declare const pkg: React.ForwardRefExoticComponent<Children & Omit<React.Detaile
|
|
|
353
353
|
/** Whether this separator should always be rendered. Useful if you disable automatic filtering. */
|
|
354
354
|
alwaysRender?: boolean;
|
|
355
355
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
356
|
-
Dialog: React.ForwardRefExoticComponent<RadixDialog.Root.Props & Children & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
356
|
+
Dialog: React.ForwardRefExoticComponent<RadixDialog.Root.Props<unknown> & Children & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
357
357
|
render?: import("@base-ui-components/react").useRender.RenderProp<Record<string, unknown>>;
|
|
358
358
|
as?: "div";
|
|
359
359
|
state?: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/combobox/component.tsx"],"sourcesContent":["\"use client\";\nimport { Combobox as BaseCombobox } from \"@base-ui-components/react/combobox\";\nimport DisabledContext from \"antd/es/config-provider/DisabledContext\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\nimport { ValidateStatus } from \"antd/es/form/FormItem\";\nimport type { PopoverProps } from \"antd/es/popover\";\nimport React, {\n ForwardedRef,\n forwardRef,\n useCallback,\n useContext,\n useMemo,\n useRef,\n} from \"react\";\nimport { BaseMenuItem } from \"../base-menu\";\nimport { useControlledState } from \"../hooks\";\nimport { SelectTrigger } from \"../select-trigger\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\n\nimport { XIcon } from \"@bioturing/assets\";\nimport { BaseMenu } from \"../base-menu\";\nimport { Empty } from \"../empty\";\nimport \"./style.css\";\n\nexport type ComboboxOption<\n T extends React.Key,\n O extends Record<string, unknown> = {}\n> = {\n value: T;\n label: React.ReactNode;\n disabled?: boolean;\n icon?: React.ReactNode;\n} & O;\n\nexport interface ComboboxProps<\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n> {\n /** Array of options to be displayed in the combobox */\n options?: ComboboxOption<T, O>[];\n /** Current value of the combobox */\n value?: M extends true ? T[] : T;\n /** Default value when uncontrolled */\n defaultValue?: M extends true ? T[] : T;\n /** Callback when value changes */\n onChange?: (value: M extends true ? T[] : T) => void;\n /** Placeholder text for the input */\n placeholder?: string;\n /** Whether the combobox is disabled */\n disabled?: boolean;\n /** Validation status */\n status?: ValidateStatus;\n /** Whether to allow clearing the selection */\n allowClear?: boolean;\n /** Whether to allow multiple selections */\n multiple?: M;\n /** Maximum number of tags to show */\n maxTagCount?: number;\n /** Whether to show search functionality */\n showSearch?: boolean;\n /** Controlled open state */\n open?: boolean;\n /** Callback when open state changes */\n onOpenChange?: (open: boolean) => void;\n /** Placement of the dropdown */\n placement?: PopoverProps[\"placement\"];\n /** Custom className for the component */\n className?: string;\n /** Custom class names for different parts */\n classNames?: {\n trigger?: string;\n input?: string;\n option?: string;\n optionIcon?: string;\n optionText?: string;\n list?: string;\n portal?: string;\n };\n /** Size of the combobox */\n size?: \"small\" | \"middle\" | \"large\";\n /** Loading state */\n loading?: boolean;\n /** Custom render for options */\n optionRender?: (\n option: ComboboxOption<T, O>,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /** Filter function for search */\n filterOption?:\n | boolean\n | ((input: string, option: ComboboxOption<T, O>) => boolean);\n /** Callback when search input changes */\n onSearch?: (value: string) => void;\n /** Custom dropdown render */\n dropdownRender?: (menu: React.ReactElement) => React.ReactElement;\n /** Custom clear icon */\n clearIcon?: React.ReactNode;\n /** Custom suffix icon */\n suffixIcon?: React.ReactNode;\n // /**\n // * Show selection summary instead of individual tags when multiple\n // * @default false\n // */\n // showSelectionSummary?: boolean;\n // /**\n // * Render function for the selection summary in multiple case\n // * @default (selectedValues) => `${selectedValues.length} items selected`\n // */\n // selectionSummaryRender?: (selectedValues: T[]) => React.ReactNode;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n /**\n * Render function for the select all option\n */\n selectAllRender?: (props: {\n onSelectAll: () => void;\n onDeselectAll: () => void;\n checked: boolean;\n indeterminate: boolean;\n }) => React.ReactNode;\n /**\n * Function to extract keywords from the item for search filtering\n * @default (option) => [String(option.key), reactNodeToString(option.label)]\n */\n getOptionKeywords?: (option: ComboboxOption<T, O>) => string[];\n /**\n * Render function for the option label\n */\n optionLabelRender?: (\n option: ComboboxOption<T, O>,\n props?: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n}\n\nconst ComboboxInner = <\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n>(\n {\n options = [],\n value: controlledValue,\n defaultValue,\n onChange,\n placeholder = \"Select...\",\n disabled: disabledProp = false,\n status: statusProp,\n allowClear = false,\n multiple = false as M,\n showSearch: _showSearch = true,\n open: controlledOpen,\n onOpenChange,\n className,\n classNames,\n size = \"middle\",\n optionRender,\n onSearch,\n clearIcon,\n suffixIcon,\n // showSelectionSummary: _showSelectionSummary = false,\n // selectionSummaryRender,\n showSelectAll = false,\n optionLabelRender,\n getOptionKeywords: _getOptionKeywords = (option: ComboboxOption<T, O>) => [\n String(option.value),\n reactNodeToString(option.label),\n ],\n ...rest\n }: ComboboxProps<T, M, O>,\n ref: React.ForwardedRef<HTMLDivElement>\n) => {\n const [value, setValue] = useControlledState(\n controlledValue,\n onChange,\n defaultValue !== undefined\n ? defaultValue\n : multiple\n ? ([] as T[])\n : undefined\n );\n\n const [open, setOpen] = useControlledState(\n controlledOpen,\n onOpenChange,\n false\n );\n\n const cls = useCls();\n const inputContainerRef = useRef<HTMLDivElement>(null);\n\n // Get form context values\n const { status: contextStatus } = useContext(FormItemInputContext);\n const contextDisabled = useContext(DisabledContext);\n\n // Merge context values with props\n const mergedStatus = statusProp || contextStatus;\n const disabled = disabledProp || contextDisabled;\n\n const handleValueChange = useCallback(\n (newValue: M extends true ? T[] : T) => {\n setValue(newValue);\n onChange?.(newValue);\n },\n [setValue, onChange]\n );\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = options.map((option) => option.value);\n (handleValueChange as (v: T[]) => void)(allValues);\n }\n }, [multiple, options, handleValueChange]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)([]);\n }\n }, [multiple, handleValueChange]);\n\n const handleClear = useCallback(() => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)([]);\n } else {\n (handleValueChange as (v: T) => void)(undefined as T);\n }\n }, [multiple, handleValueChange]);\n\n // Prepare selected values\n const selectedValues = useMemo(() => {\n return Array.isArray(value) ? value : value ? [value] : [];\n }, [value]);\n\n // Select all option logic\n const selectAllOption = useMemo(() => {\n if (!showSelectAll || !multiple || options.length === 0) {\n return null;\n }\n\n const selectedFromFiltered = selectedValues.filter((val) =>\n options.some((opt) => opt.value === val)\n );\n const checked =\n selectedFromFiltered.length === options.length && options.length > 0;\n const indeterminate =\n selectedFromFiltered.length > 0 &&\n selectedFromFiltered.length < options.length;\n\n return {\n checked,\n indeterminate,\n onToggle: () => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n },\n };\n }, [\n showSelectAll,\n multiple,\n options,\n selectedValues,\n handleDeselectAll,\n handleSelectAll,\n ]);\n\n // Convert options to Base UI format\n const baseUIItems = useMemo(() => options.map((opt) => opt.value), [options]);\n\n // Get display value for SelectTrigger\n const displayValue = useMemo(() => {\n if (multiple) {\n return selectedValues.length > 0\n ? `${selectedValues.length} item${\n selectedValues.length === 1 ? \"\" : \"s\"\n } selected`\n : null;\n } else {\n const selectedOption = options.find(\n (opt) => opt.value === selectedValues[0]\n );\n return selectedOption?.label || null;\n }\n }, [multiple, selectedValues, options]);\n\n const inputClassName = clsx(\n cls(\"combobox-input\"),\n cls(`combobox-input-${size}`),\n mergedStatus && cls(`combobox-input-${mergedStatus}`),\n classNames?.input\n );\n\n return (\n <div ref={ref} className={clsx(cls(\"combobox\"), className)} {...rest}>\n <BaseCombobox.Root<T, T, M>\n value={\n (multiple\n ? selectedValues\n : selectedValues[0] ?? null) as M extends true ? T[] : T | null\n }\n onValueChange={(newValue) => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)(\n Array.isArray(newValue) ? (newValue as T[]) : []\n );\n } else {\n (handleValueChange as (v: T) => void)(newValue as T);\n }\n }}\n open={open}\n onOpenChange={setOpen}\n multiple={multiple}\n disabled={disabled}\n items={baseUIItems}\n itemToStringLabel={(itemValue) => {\n const option = options.find((opt) => opt.value === itemValue);\n return reactNodeToString(option?.label || String(itemValue));\n }}\n >\n {/* Single Selection Layout using SelectTrigger compound components */}\n {!multiple ? (\n <SelectTrigger.Root\n ref={inputContainerRef}\n as=\"div\"\n size={size}\n disabled={disabled}\n open={open}\n status={mergedStatus}\n placeholder={placeholder}\n displayValue={displayValue}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n onClear={handleClear}\n onOpenChange={setOpen}\n className={clsx(\n classNames?.trigger,\n cls(\"combobox-trigger-single\")\n )}\n >\n <SelectTrigger.Content\n contentRender={({ className, children, ...rest }) => (\n <BaseCombobox.Input\n placeholder={placeholder}\n className={clsx(className, inputClassName)}\n disabled={disabled}\n onChange={(event) => {\n onSearch?.(event.target.value);\n }}\n {...rest}\n />\n )}\n />\n <SelectTrigger.Clear\n render={(props) => (\n <BaseCombobox.Clear {...props}></BaseCombobox.Clear>\n )}\n />\n <SelectTrigger.Arrow\n render={(props, { icon }) => (\n <BaseCombobox.Trigger {...props}>\n <BaseCombobox.Icon>{icon}</BaseCombobox.Icon>\n </BaseCombobox.Trigger>\n )}\n />\n </SelectTrigger.Root>\n ) : (\n /* Multiple Selection Layout using SelectTrigger compound components */\n <SelectTrigger.Root\n ref={inputContainerRef}\n size={size}\n disabled={disabled}\n open={open}\n status={mergedStatus}\n placeholder={placeholder}\n displayValue={displayValue}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n onClear={handleClear}\n onOpenChange={setOpen}\n className={clsx(\n classNames?.trigger,\n cls(\"combobox-trigger-multiple\")\n )}\n as=\"div\"\n >\n <SelectTrigger.Content\n contentRender={({ className, children, ...rest }) => (\n <BaseCombobox.Chips\n className={clsx(cls(\"combobox-chips\"), className)}\n {...rest}\n >\n <BaseCombobox.Value>\n {(selectedItems) => (\n <>\n {selectedItems.map((item: T) => {\n const option = options.find(\n (opt) => opt.value === item\n );\n return (\n <BaseCombobox.Chip\n key={item}\n className={clsx(cls(\"combobox-chip\"))}\n >\n {option?.icon && (\n <span\n className={clsx(cls(\"combobox-chip-icon\"))}\n >\n {option.icon}\n </span>\n )}\n <span className={clsx(cls(\"combobox-chip-text\"))}>\n {option\n ? optionLabelRender\n ? optionLabelRender(option)\n : option.label\n : item}\n </span>\n <BaseCombobox.ChipRemove\n className={clsx(cls(\"combobox-chip-remove\"))}\n >\n <XIcon />\n </BaseCombobox.ChipRemove>\n </BaseCombobox.Chip>\n );\n })}\n\n <BaseCombobox.Input\n placeholder={\n selectedItems.length > 0 ? \"\" : placeholder\n }\n className={inputClassName}\n disabled={disabled}\n onChange={(event) => {\n onSearch?.(event.target.value);\n }}\n />\n </>\n )}\n </BaseCombobox.Value>\n </BaseCombobox.Chips>\n )}\n />\n <SelectTrigger.Clear\n render={(props) => (\n <BaseCombobox.Clear {...props}></BaseCombobox.Clear>\n )}\n />\n <SelectTrigger.Arrow\n render={(props, { icon }) => (\n <BaseCombobox.Trigger {...props}>\n <BaseCombobox.Icon>{icon}</BaseCombobox.Icon>\n </BaseCombobox.Trigger>\n )}\n />\n </SelectTrigger.Root>\n )}\n\n <BaseCombobox.Portal>\n <BaseCombobox.Positioner\n anchor={inputContainerRef.current}\n sideOffset={4}\n render={(props) => <BaseMenu.Root {...props}></BaseMenu.Root>}\n >\n <BaseCombobox.Popup\n className={clsx(cls(\"combobox-popup\"), classNames?.portal)}\n render={(props) => <BaseMenu.Popup {...props}></BaseMenu.Popup>}\n >\n {/* Select All Option */}\n {selectAllOption && (\n <>\n <BaseMenuItem\n as=\"button\"\n type=\"button\"\n className={clsx(cls(\"combobox-select-all\"))}\n selected={selectAllOption.checked}\n onClick={selectAllOption.onToggle}\n indeterminate={selectAllOption.indeterminate}\n showCheckbox\n >\n Select All\n </BaseMenuItem>\n <BaseCombobox.Separator\n render={(props) => <BaseMenu.Divider {...props} />}\n />\n </>\n )}\n <BaseCombobox.List\n className={clsx(cls(\"combobox-list\"), classNames?.list)}\n render={(props) => <BaseMenu.List {...props}></BaseMenu.List>}\n >\n {(item: T) => {\n const option = options.find((opt) => opt.value === item);\n const isSelected = (selectedValues as T[]).includes(item);\n return optionRender ? (\n optionRender(option, {})\n ) : (\n <BaseMenuItem\n key={option.value}\n disabled={option.disabled}\n selected={isSelected}\n showCheckbox={multiple}\n icon={option.icon}\n classNames={{\n root: clsx(classNames?.option),\n icon: classNames?.optionIcon,\n text: classNames?.optionText,\n }}\n labelRender={\n optionLabelRender\n ? (props: React.HTMLAttributes<HTMLElement>) =>\n optionLabelRender(option, props)\n : undefined\n }\n render={(props: React.HTMLAttributes<HTMLElement>) => (\n <BaseCombobox.Item\n value={item as T}\n disabled={option.disabled}\n {...props}\n data-disabled={option.disabled}\n data-selected={isSelected}\n />\n )}\n >\n {option.label}\n </BaseMenuItem>\n );\n }}\n </BaseCombobox.List>\n\n <BaseCombobox.Empty className={clsx(cls(\"combobox-empty\"))}>\n <Empty description=\"No options found\" />\n </BaseCombobox.Empty>\n </BaseCombobox.Popup>\n </BaseCombobox.Positioner>\n </BaseCombobox.Portal>\n </BaseCombobox.Root>\n </div>\n );\n};\n\nconst MainCombobox = forwardRef(ComboboxInner) as <\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n>(\n props: ComboboxProps<T, M, O> & { ref?: ForwardedRef<HTMLDivElement> }\n) => ReturnType<typeof ComboboxInner>;\n\nexport const Combobox = Object.assign(MainCombobox, {\n // Add any sub components here if needed\n});\n\nexport default Combobox;\n"],"names":["ComboboxInner","options","controlledValue","defaultValue","onChange","placeholder","disabledProp","statusProp","allowClear","multiple","_showSearch","controlledOpen","onOpenChange","className","classNames","size","optionRender","onSearch","clearIcon","suffixIcon","showSelectAll","optionLabelRender","_getOptionKeywords","option","reactNodeToString","rest","ref","value","setValue","useControlledState","open","setOpen","cls","useCls","inputContainerRef","useRef","contextStatus","useContext","FormItemInputContext","contextDisabled","DisabledContext","mergedStatus","disabled","handleValueChange","useCallback","newValue","handleSelectAll","allValues","handleDeselectAll","handleClear","selectedValues","useMemo","selectAllOption","selectedFromFiltered","val","opt","checked","indeterminate","baseUIItems","displayValue","inputClassName","clsx","jsx","jsxs","BaseCombobox","itemValue","SelectTrigger","children","selectedItems","Fragment","item","XIcon","event","props","icon","BaseMenu","BaseMenuItem","isSelected","Empty","MainCombobox","forwardRef","Combobox"],"mappings":";;;;;;;;;;;;;;;;AA0IA,MAAMA,KAAgB,CAKpB;AAAA,EACE,SAAAC,IAAU,CAAA;AAAA,EACV,OAAOC;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAe;AAAA,EACzB,QAAQC;AAAA,EACR,YAAAC,IAAa;AAAA,EACb,UAAAC,IAAW;AAAA,EACX,YAAYC,KAAc;AAAA,EAC1B,MAAMC;AAAA,EACN,cAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA;AAAA;AAAA,EAGA,eAAAC,IAAgB;AAAA,EAChB,mBAAAC;AAAA,EACA,mBAAmBC,K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gBAAgB,CAAC,GACvD,UAAA,gBAAA8B,EAACgB,IAAA,EAAM,aAAY,oBAAmB,EAAA,CACxC;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACF;AAAA,QAAA,EACF,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAEJ;AAEJ,GAEMC,KAAeC,GAAWhF,EAAa,GAQhCiF,KAAW,OAAO,OAAOF,IAAc;AAAA;AAEpD,CAAC;"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/combobox/component.tsx"],"sourcesContent":["\"use client\";\nimport { Combobox as BaseCombobox } from \"@base-ui-components/react/combobox\";\nimport DisabledContext from \"antd/es/config-provider/DisabledContext\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\nimport { ValidateStatus } from \"antd/es/form/FormItem\";\nimport type { PopoverProps } from \"antd/es/popover\";\nimport React, {\n ForwardedRef,\n forwardRef,\n useCallback,\n useContext,\n useMemo,\n useRef,\n} from \"react\";\nimport { BaseMenuItem } from \"../base-menu\";\nimport { useControlledState } from \"../hooks\";\nimport { SelectTrigger } from \"../select-trigger\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\n\nimport { XIcon } from \"@bioturing/assets\";\nimport { BaseMenu } from \"../base-menu\";\nimport { Empty } from \"../empty\";\nimport \"./style.css\";\n\nexport type ComboboxOption<\n T extends React.Key,\n O extends Record<string, unknown> = {}\n> = {\n value: T;\n label: React.ReactNode;\n disabled?: boolean;\n icon?: React.ReactNode;\n} & O;\n\nexport interface ComboboxProps<\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n> {\n /** Array of options to be displayed in the combobox */\n options?: ComboboxOption<T, O>[];\n /** Current value of the combobox */\n value?: M extends true ? T[] : T;\n /** Default value when uncontrolled */\n defaultValue?: M extends true ? T[] : T;\n /** Callback when value changes */\n onChange?: (value: M extends true ? T[] : T) => void;\n /** Placeholder text for the input */\n placeholder?: string;\n /** Whether the combobox is disabled */\n disabled?: boolean;\n /** Validation status */\n status?: ValidateStatus;\n /** Whether to allow clearing the selection */\n allowClear?: boolean;\n /** Whether to allow multiple selections */\n multiple?: M;\n /** Maximum number of tags to show */\n maxTagCount?: number;\n /** Whether to show search functionality */\n showSearch?: boolean;\n /** Controlled open state */\n open?: boolean;\n /** Callback when open state changes */\n onOpenChange?: (open: boolean) => void;\n /** Placement of the dropdown */\n placement?: PopoverProps[\"placement\"];\n /** Custom className for the component */\n className?: string;\n /** Custom class names for different parts */\n classNames?: {\n trigger?: string;\n input?: string;\n option?: string;\n optionIcon?: string;\n optionText?: string;\n list?: string;\n portal?: string;\n };\n /** Size of the combobox */\n size?: \"small\" | \"middle\" | \"large\";\n /** Loading state */\n loading?: boolean;\n /** Custom render for options */\n optionRender?: (\n option: ComboboxOption<T, O>,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /** Filter function for search */\n filterOption?:\n | boolean\n | ((input: string, option: ComboboxOption<T, O>) => boolean);\n /** Callback when search input changes */\n onSearch?: (value: string) => void;\n /** Custom dropdown render */\n dropdownRender?: (menu: React.ReactElement) => React.ReactElement;\n /** Custom clear icon */\n clearIcon?: React.ReactNode;\n /** Custom suffix icon */\n suffixIcon?: React.ReactNode;\n // /**\n // * Show selection summary instead of individual tags when multiple\n // * @default false\n // */\n // showSelectionSummary?: boolean;\n // /**\n // * Render function for the selection summary in multiple case\n // * @default (selectedValues) => `${selectedValues.length} items selected`\n // */\n // selectionSummaryRender?: (selectedValues: T[]) => React.ReactNode;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n /**\n * Render function for the select all option\n */\n selectAllRender?: (props: {\n onSelectAll: () => void;\n onDeselectAll: () => void;\n checked: boolean;\n indeterminate: boolean;\n }) => React.ReactNode;\n /**\n * Function to extract keywords from the item for search filtering\n * @default (option) => [String(option.key), reactNodeToString(option.label)]\n */\n getOptionKeywords?: (option: ComboboxOption<T, O>) => string[];\n /**\n * Render function for the option label\n */\n optionLabelRender?: (\n option: ComboboxOption<T, O>,\n props?: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n}\n\nconst ComboboxInner = <\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n>(\n {\n options = [],\n value: controlledValue,\n defaultValue,\n onChange,\n placeholder = \"Select...\",\n disabled: disabledProp = false,\n status: statusProp,\n allowClear = false,\n multiple = false as M,\n showSearch: _showSearch = true,\n open: controlledOpen,\n onOpenChange,\n className,\n classNames,\n size = \"middle\",\n optionRender,\n onSearch,\n clearIcon,\n suffixIcon,\n // showSelectionSummary: _showSelectionSummary = false,\n // selectionSummaryRender,\n showSelectAll = false,\n optionLabelRender,\n getOptionKeywords: _getOptionKeywords = (option: ComboboxOption<T, O>) => [\n String(option.value),\n reactNodeToString(option.label),\n ],\n ...rest\n }: ComboboxProps<T, M, O>,\n ref: React.ForwardedRef<HTMLDivElement>\n) => {\n const [value, setValue] = useControlledState(\n controlledValue,\n onChange,\n defaultValue !== undefined\n ? defaultValue\n : multiple\n ? ([] as T[])\n : undefined\n );\n\n const [open, setOpen] = useControlledState(\n controlledOpen,\n onOpenChange,\n false\n );\n\n const cls = useCls();\n const inputContainerRef = useRef<HTMLDivElement>(null);\n\n // Get form context values\n const { status: contextStatus } = useContext(FormItemInputContext);\n const contextDisabled = useContext(DisabledContext);\n\n // Merge context values with props\n const mergedStatus = statusProp || contextStatus;\n const disabled = disabledProp || contextDisabled;\n\n const handleValueChange = useCallback(\n (newValue: M extends true ? T[] : T) => {\n setValue(newValue);\n onChange?.(newValue);\n },\n [setValue, onChange]\n );\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = options.map((option) => option.value);\n (handleValueChange as (v: T[]) => void)(allValues);\n }\n }, [multiple, options, handleValueChange]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)([]);\n }\n }, [multiple, handleValueChange]);\n\n const handleClear = useCallback(() => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)([]);\n } else {\n (handleValueChange as (v: T) => void)(undefined as T);\n }\n }, [multiple, handleValueChange]);\n\n // Prepare selected values\n const selectedValues = useMemo(() => {\n return Array.isArray(value) ? value : value ? [value] : [];\n }, [value]);\n\n // Select all option logic\n const selectAllOption = useMemo(() => {\n if (!showSelectAll || !multiple || options.length === 0) {\n return null;\n }\n\n const selectedFromFiltered = selectedValues.filter((val) =>\n options.some((opt) => opt.value === val)\n );\n const checked =\n selectedFromFiltered.length === options.length && options.length > 0;\n const indeterminate =\n selectedFromFiltered.length > 0 &&\n selectedFromFiltered.length < options.length;\n\n return {\n checked,\n indeterminate,\n onToggle: () => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n },\n };\n }, [\n showSelectAll,\n multiple,\n options,\n selectedValues,\n handleDeselectAll,\n handleSelectAll,\n ]);\n\n // Convert options to Base UI format\n const baseUIItems = useMemo(() => options.map((opt) => opt.value), [options]);\n\n // Get display value for SelectTrigger\n const displayValue = useMemo(() => {\n if (multiple) {\n return selectedValues.length > 0\n ? `${selectedValues.length} item${\n selectedValues.length === 1 ? \"\" : \"s\"\n } selected`\n : null;\n } else {\n const selectedOption = options.find(\n (opt) => opt.value === selectedValues[0]\n );\n return selectedOption?.label || null;\n }\n }, [multiple, selectedValues, options]);\n\n const inputClassName = clsx(\n cls(\"combobox-input\"),\n cls(`combobox-input-${size}`),\n mergedStatus && cls(`combobox-input-${mergedStatus}`),\n classNames?.input\n );\n\n return (\n <div ref={ref} className={clsx(cls(\"combobox\"), className)} {...rest}>\n <BaseCombobox.Root<T, M>\n value={\n (multiple\n ? selectedValues\n : selectedValues[0] ?? null) as M extends true ? T[] : T | null\n }\n onValueChange={(newValue) => {\n if (multiple) {\n (handleValueChange as (v: T[]) => void)(\n Array.isArray(newValue) ? (newValue as T[]) : []\n );\n } else {\n (handleValueChange as (v: T) => void)(newValue as T);\n }\n }}\n open={open}\n onOpenChange={setOpen}\n multiple={multiple}\n disabled={disabled}\n items={baseUIItems}\n itemToStringLabel={(itemValue) => {\n const option = options.find((opt) => opt.value === itemValue);\n return reactNodeToString(option?.label || String(itemValue));\n }}\n >\n {/* Single Selection Layout using SelectTrigger compound components */}\n {!multiple ? (\n <SelectTrigger.Root\n ref={inputContainerRef}\n as=\"div\"\n size={size}\n disabled={disabled}\n open={open}\n status={mergedStatus}\n placeholder={placeholder}\n displayValue={displayValue}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n onClear={handleClear}\n onOpenChange={setOpen}\n className={clsx(\n classNames?.trigger,\n cls(\"combobox-trigger-single\")\n )}\n >\n <SelectTrigger.Content\n contentRender={({ className, children, ...rest }) => (\n <BaseCombobox.Input\n placeholder={placeholder}\n className={clsx(className, inputClassName)}\n disabled={disabled}\n onChange={(event) => {\n onSearch?.(event.target.value);\n }}\n {...rest}\n />\n )}\n />\n <SelectTrigger.Clear\n render={(props) => (\n <BaseCombobox.Clear {...props}></BaseCombobox.Clear>\n )}\n />\n <SelectTrigger.Arrow\n render={(props, { icon }) => (\n <BaseCombobox.Trigger {...props}>\n <BaseCombobox.Icon>{icon}</BaseCombobox.Icon>\n </BaseCombobox.Trigger>\n )}\n />\n </SelectTrigger.Root>\n ) : (\n /* Multiple Selection Layout using SelectTrigger compound components */\n <SelectTrigger.Root\n ref={inputContainerRef}\n size={size}\n disabled={disabled}\n open={open}\n status={mergedStatus}\n placeholder={placeholder}\n displayValue={displayValue}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n onClear={handleClear}\n onOpenChange={setOpen}\n className={clsx(\n classNames?.trigger,\n cls(\"combobox-trigger-multiple\")\n )}\n as=\"div\"\n >\n <SelectTrigger.Content\n contentRender={({ className, children, ...rest }) => (\n <BaseCombobox.Chips\n className={clsx(cls(\"combobox-chips\"), className)}\n {...rest}\n >\n <BaseCombobox.Value>\n {(selectedItems) => (\n <>\n {selectedItems.map((item: T) => {\n const option = options.find(\n (opt) => opt.value === item\n );\n return (\n <BaseCombobox.Chip\n key={item}\n className={clsx(cls(\"combobox-chip\"))}\n >\n {option?.icon && (\n <span\n className={clsx(cls(\"combobox-chip-icon\"))}\n >\n {option.icon}\n </span>\n )}\n <span className={clsx(cls(\"combobox-chip-text\"))}>\n {option\n ? optionLabelRender\n ? optionLabelRender(option)\n : option.label\n : item}\n </span>\n <BaseCombobox.ChipRemove\n className={clsx(cls(\"combobox-chip-remove\"))}\n >\n <XIcon />\n </BaseCombobox.ChipRemove>\n </BaseCombobox.Chip>\n );\n })}\n\n <BaseCombobox.Input\n placeholder={\n selectedItems.length > 0 ? \"\" : placeholder\n }\n className={inputClassName}\n disabled={disabled}\n onChange={(event) => {\n onSearch?.(event.target.value);\n }}\n />\n </>\n )}\n </BaseCombobox.Value>\n </BaseCombobox.Chips>\n )}\n />\n <SelectTrigger.Clear\n render={(props) => (\n <BaseCombobox.Clear {...props}></BaseCombobox.Clear>\n )}\n />\n <SelectTrigger.Arrow\n render={(props, { icon }) => (\n <BaseCombobox.Trigger {...props}>\n <BaseCombobox.Icon>{icon}</BaseCombobox.Icon>\n </BaseCombobox.Trigger>\n )}\n />\n </SelectTrigger.Root>\n )}\n\n <BaseCombobox.Portal>\n <BaseCombobox.Positioner\n anchor={inputContainerRef.current}\n sideOffset={4}\n render={(props) => <BaseMenu.Root {...props}></BaseMenu.Root>}\n >\n <BaseCombobox.Popup\n className={clsx(cls(\"combobox-popup\"), classNames?.portal)}\n render={(props) => <BaseMenu.Popup {...props}></BaseMenu.Popup>}\n >\n {/* Select All Option */}\n {selectAllOption && (\n <>\n <BaseMenuItem\n as=\"button\"\n type=\"button\"\n className={clsx(cls(\"combobox-select-all\"))}\n selected={selectAllOption.checked}\n onClick={selectAllOption.onToggle}\n indeterminate={selectAllOption.indeterminate}\n showCheckbox\n >\n Select All\n </BaseMenuItem>\n <BaseCombobox.Separator\n render={(props) => <BaseMenu.Divider {...props} />}\n />\n </>\n )}\n <BaseCombobox.List\n className={clsx(cls(\"combobox-list\"), classNames?.list)}\n render={(props) => <BaseMenu.List {...props}></BaseMenu.List>}\n >\n {(item: T) => {\n const option = options.find((opt) => opt.value === item);\n const isSelected = (selectedValues as T[]).includes(item);\n return optionRender ? (\n optionRender(option, {})\n ) : (\n <BaseMenuItem\n key={option.value}\n disabled={option.disabled}\n selected={isSelected}\n showCheckbox={multiple}\n icon={option.icon}\n classNames={{\n root: clsx(classNames?.option),\n icon: classNames?.optionIcon,\n text: classNames?.optionText,\n }}\n labelRender={\n optionLabelRender\n ? (props: React.HTMLAttributes<HTMLElement>) =>\n optionLabelRender(option, props)\n : undefined\n }\n render={(props: React.HTMLAttributes<HTMLElement>) => (\n <BaseCombobox.Item\n value={item as T}\n disabled={option.disabled}\n {...props}\n data-disabled={option.disabled}\n data-selected={isSelected}\n />\n )}\n >\n {option.label}\n </BaseMenuItem>\n );\n }}\n </BaseCombobox.List>\n\n <BaseCombobox.Empty className={clsx(cls(\"combobox-empty\"))}>\n <Empty description=\"No options found\" />\n </BaseCombobox.Empty>\n </BaseCombobox.Popup>\n </BaseCombobox.Positioner>\n </BaseCombobox.Portal>\n </BaseCombobox.Root>\n </div>\n );\n};\n\nconst MainCombobox = forwardRef(ComboboxInner) as <\n T extends React.Key,\n M extends boolean,\n O extends Record<string, unknown> = {}\n>(\n props: ComboboxProps<T, M, O> & { ref?: ForwardedRef<HTMLDivElement> }\n) => ReturnType<typeof ComboboxInner>;\n\nexport const Combobox = Object.assign(MainCombobox, {\n // Add any sub components here if needed\n});\n\nexport default Combobox;\n"],"names":["ComboboxInner","options","controlledValue","defaultValue","onChange","placeholder","disabledProp","statusProp","allowClear","multiple","_showSearch","controlledOpen","onOpenChange","className","classNames","size","optionRender","onSearch","clearIcon","suffixIcon","showSelectAll","optionLabelRender","_getOptionKeywords","option","reactNodeToString","rest","ref","value","setValue","useControlledState","open","setOpen","cls","useCls","inputContainerRef","useRef","contextStatus","useContext","FormItemInputContext","contextDisabled","DisabledContext","mergedStatus","disabled","handleValueChange","useCallback","newValue","handleSelectAll","allValues","handleDeselectAll","handleClear","selectedValues","useMemo","selectAllOption","selectedFromFiltered","val","opt","checked","indeterminate","baseUIItems","displayValue","inputClassName","clsx","jsx","jsxs","BaseCombobox","itemValue","SelectTrigger","children","selectedItems","Fragment","item","XIcon","event","props","icon","BaseMenu","BaseMenuItem","isSelected","Empty","MainCombobox","forwardRef","Combobox"],"mappings":";;;;;;;;;;;;;;;;AA0IA,MAAMA,KAAgB,CAKpB;AAAA,EACE,SAAAC,IAAU,CAAA;AAAA,EACV,OAAOC;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAe;AAAA,EACzB,QAAQC;AAAA,EACR,YAAAC,IAAa;AAAA,EACb,UAAAC,IAAW;AAAA,EACX,YAAYC,KAAc;AAAA,EAC1B,MAAMC;AAAA,EACN,cAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA;AAAA;AAAA,EAGA,eAAAC,IAAgB;AAAA,EAChB,mBAAAC;AAAA,EACA,mBAAmBC,KAAqB,CAACC,MAAiC;AAAA,IACxE,OAAOA,EAAO,KAAK;AAAA,IACnBC,EAAkBD,EAAO,KAAK;AAAA,EAAA;AAAA,EAEhC,GAAGE;AACL,GACAC,OACG;AACH,QAAM,CAACC,GAAOC,CAAQ,IAAIC;AAAA,IACxB3B;AAAA,IACAE;AAAA,IACAD,MAAiB,SACbA,IACAM,IACC,CAAA,IACD;AAAA,EAAA,GAGA,CAACqB,GAAMC,CAAO,IAAIF;AAAA,IACtBlB;AAAA,IACAC;AAAA,IACA;AAAA,EAAA,GAGIoB,IAAMC,GAAA,GACNC,IAAoBC,GAAuB,IAAI,GAG/C,EAAE,QAAQC,OAAkBC,EAAWC,EAAoB,GAC3DC,KAAkBF,EAAWG,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AOtD,IACLA,EAAaO,GAAQ,CAAA,CAAE,IAEvB,gBAAAuC;AAAA,0BAACc;AAAA,0BAAA;AAAA,4BAEC,UAAUrD,EAAO;AAAA,4BACjB,UAAUsD;AAAA,4BACV,cAAcpE;AAAA,4BACd,MAAMc,EAAO;AAAA,4BACb,YAAY;AAAA,8BACV,MAAMsC,EAAK/C,GAAY,MAAM;AAAA,8BAC7B,MAAMA,GAAY;AAAA,8BAClB,MAAMA,GAAY;AAAA,4BAAA;AAAA,4BAEpB,aACEO,IACI,CAACoD,MACCpD,EAAkBE,GAAQkD,CAAK,IACjC;AAAA,4BAEN,QAAQ,CAACA,MACP,gBAAAX;AAAA,8BAACE,EAAa;AAAA,8BAAb;AAAA,gCACC,OAAOM;AAAA,gCACP,UAAU/C,EAAO;AAAA,gCAChB,GAAGkD;AAAA,gCACJ,iBAAelD,EAAO;AAAA,gCACtB,iBAAesD;AAAA,8BAAA;AAAA,4BAAA;AAAA,4BAIlB,UAAAtD,EAAO;AAAA,0BAAA;AAAA,0BA1BHA,EAAO;AAAA,wBAAA;AAAA,sBA6BlB;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAGF,gBAAAuC,EAACE,EAAa,OAAb,EAAmB,WAAWH,EAAK7B,EAAI,gBAAgB,CAAC,GACvD,UAAA,gBAAA8B,EAACgB,IAAA,EAAM,aAAY,oBAAmB,EAAA,CACxC;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACF;AAAA,QAAA,EACF,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,GAEJ;AAEJ,GAEMC,KAAeC,GAAWhF,EAAa,GAQhCiF,KAAW,OAAO,OAAOF,IAAc;AAAA;AAEpD,CAAC;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as t, jsxs as p } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef as y, useRef as
|
|
3
|
+
import { forwardRef as y, useRef as u, useState as H, useEffect as N } from "react";
|
|
4
4
|
import { Spin as W } from "../spin/component.js";
|
|
5
5
|
import { useDataTable as P } from "./hooks.js";
|
|
6
6
|
import { convertSelectionToAntFormat as k } from "./utils.js";
|
|
@@ -9,7 +9,7 @@ import { TableHeader as I } from "./components/TableHeader.js";
|
|
|
9
9
|
import { TableBody as j } from "./components/TableBody.js";
|
|
10
10
|
import { TablePagination as A } from "./components/TablePagination.js";
|
|
11
11
|
import { useCls as E, useAntdCssVarClassname as F } from "../utils/antdUtils.js";
|
|
12
|
-
import { clsx as
|
|
12
|
+
import { clsx as h } from "../utils/cn.js";
|
|
13
13
|
const $ = (s, G) => {
|
|
14
14
|
const {
|
|
15
15
|
dataSource: i = [],
|
|
@@ -18,7 +18,7 @@ const $ = (s, G) => {
|
|
|
18
18
|
variant: S = "default",
|
|
19
19
|
emptyDescription: w,
|
|
20
20
|
rowKey: c
|
|
21
|
-
} = s, e = E(), v =
|
|
21
|
+
} = s, e = E(), v = u(null), {
|
|
22
22
|
table: a,
|
|
23
23
|
isLoading: C,
|
|
24
24
|
spinProps: R,
|
|
@@ -40,7 +40,7 @@ const $ = (s, G) => {
|
|
|
40
40
|
new Event("click")
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
|
-
}, D = F(), o =
|
|
43
|
+
}, D = F(), o = u(null), [f, x] = H({
|
|
44
44
|
vertical: !1,
|
|
45
45
|
horizontal: !1
|
|
46
46
|
});
|
|
@@ -49,11 +49,11 @@ const $ = (s, G) => {
|
|
|
49
49
|
vertical: o.current.scrollHeight > o.current.clientHeight,
|
|
50
50
|
horizontal: o.current.scrollWidth > o.current.clientWidth
|
|
51
51
|
});
|
|
52
|
-
}, [i
|
|
52
|
+
}, [i]), /* @__PURE__ */ t(
|
|
53
53
|
"div",
|
|
54
54
|
{
|
|
55
55
|
ref: v,
|
|
56
|
-
className:
|
|
56
|
+
className: h(
|
|
57
57
|
e("table-wrapper", "data-table"),
|
|
58
58
|
e(`table-${g}`),
|
|
59
59
|
S === "zebra" ? e("table-zebra") : "",
|
|
@@ -64,7 +64,7 @@ const $ = (s, G) => {
|
|
|
64
64
|
b
|
|
65
65
|
),
|
|
66
66
|
children: /* @__PURE__ */ p(W, { spinning: C, ...R, children: [
|
|
67
|
-
/* @__PURE__ */ t("div", { className:
|
|
67
|
+
/* @__PURE__ */ t("div", { className: h(e("table")), children: /* @__PURE__ */ t("div", { className: e("table-container"), ref: o, children: /* @__PURE__ */ t("div", { className: e("table-content"), children: /* @__PURE__ */ p("table", { children: [
|
|
68
68
|
/* @__PURE__ */ t("colgroup", { children: a.getHeaderGroups()[0]?.headers.map((l) => {
|
|
69
69
|
let r;
|
|
70
70
|
if (l.id === "select")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/data-table/component.tsx"],"sourcesContent":["\"use client\";\nimport React, {\n forwardRef,\n useEffect,\n useRef,\n useState,\n type Ref,\n} from \"react\";\nimport { type Row } from \"@tanstack/react-table\";\nimport { clsx, useAntdCssVarClassname, useCls } from \"../utils\";\nimport { Spin } from \"../spin/component\";\nimport { TableHeader, TableBody, TablePagination } from \"./components\";\nimport { useDataTable } from \"./hooks\";\nimport { convertSelectionToAntFormat } from \"./utils\";\nimport { type DataTableProps, type DataTableRef } from \"./types\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useToken } from \"../hooks\";\n\n// Extended meta type for column definitions\ninterface ExtendedColumnMeta {\n align?: \"left\" | \"center\" | \"right\";\n width?: string | number;\n fixed?: \"left\" | \"right\" | boolean;\n ellipsis?: boolean;\n}\n\nconst InnerDataTable = <\n RecordType extends Record<string, any> = Record<string, unknown>\n>(\n props: DataTableProps<RecordType>,\n ref: Ref<DataTableRef>\n) => {\n const {\n dataSource = [],\n className,\n size = \"large\",\n variant = \"default\",\n emptyDescription,\n rowKey,\n } = props;\n\n const cls = useCls();\n const tableWrapperRef = useRef<HTMLDivElement>(null);\n\n // Use the custom hook for table logic\n const {\n table,\n isLoading,\n spinProps,\n hasRowSelection,\n hasPagination,\n paginationConfig,\n rowSelectionConfig,\n } = useDataTable(props);\n\n // Handle row click for selection\n const handleRowClick = (row: Row<RecordType>) => {\n if (hasRowSelection) {\n row.toggleSelected();\n if (rowSelectionConfig?.onSelect) {\n const { selectedRowKeys, selectedRows } = convertSelectionToAntFormat(\n table.getState().rowSelection,\n dataSource,\n rowKey\n );\n rowSelectionConfig.onSelect(\n row.original,\n !row.getIsSelected(),\n selectedRows,\n new Event(\"click\")\n );\n }\n }\n };\n\n // cls(\"table-scroll-horizontal\"))\n\n const antdClass = useAntdCssVarClassname();\n\n const tableContainerRef = useRef<HTMLDivElement>(null);\n\n const [hasScroll, setHasScroll] = useState({\n vertical: false,\n horizontal: false,\n });\n\n useEffect(() => {\n if (tableContainerRef.current) {\n setHasScroll({\n vertical:\n tableContainerRef.current.scrollHeight >\n tableContainerRef.current.clientHeight,\n horizontal:\n tableContainerRef.current.scrollWidth >\n tableContainerRef.current.clientWidth,\n });\n }\n }, [dataSource
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/data-table/component.tsx"],"sourcesContent":["\"use client\";\nimport React, {\n forwardRef,\n useEffect,\n useRef,\n useState,\n type Ref,\n} from \"react\";\nimport { type Row } from \"@tanstack/react-table\";\nimport { clsx, useAntdCssVarClassname, useCls } from \"../utils\";\nimport { Spin } from \"../spin/component\";\nimport { TableHeader, TableBody, TablePagination } from \"./components\";\nimport { useDataTable } from \"./hooks\";\nimport { convertSelectionToAntFormat } from \"./utils\";\nimport { type DataTableProps, type DataTableRef } from \"./types\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useToken } from \"../hooks\";\n\n// Extended meta type for column definitions\ninterface ExtendedColumnMeta {\n align?: \"left\" | \"center\" | \"right\";\n width?: string | number;\n fixed?: \"left\" | \"right\" | boolean;\n ellipsis?: boolean;\n}\n\nconst InnerDataTable = <\n RecordType extends Record<string, any> = Record<string, unknown>\n>(\n props: DataTableProps<RecordType>,\n ref: Ref<DataTableRef>\n) => {\n const {\n dataSource = [],\n className,\n size = \"large\",\n variant = \"default\",\n emptyDescription,\n rowKey,\n } = props;\n\n const cls = useCls();\n const tableWrapperRef = useRef<HTMLDivElement>(null);\n\n // Use the custom hook for table logic\n const {\n table,\n isLoading,\n spinProps,\n hasRowSelection,\n hasPagination,\n paginationConfig,\n rowSelectionConfig,\n } = useDataTable(props);\n\n // Handle row click for selection\n const handleRowClick = (row: Row<RecordType>) => {\n if (hasRowSelection) {\n row.toggleSelected();\n if (rowSelectionConfig?.onSelect) {\n const { selectedRowKeys, selectedRows } = convertSelectionToAntFormat(\n table.getState().rowSelection,\n dataSource,\n rowKey\n );\n rowSelectionConfig.onSelect(\n row.original,\n !row.getIsSelected(),\n selectedRows,\n new Event(\"click\")\n );\n }\n }\n };\n\n // cls(\"table-scroll-horizontal\"))\n\n const antdClass = useAntdCssVarClassname();\n\n const tableContainerRef = useRef<HTMLDivElement>(null);\n\n const [hasScroll, setHasScroll] = useState({\n vertical: false,\n horizontal: false,\n });\n\n useEffect(() => {\n if (tableContainerRef.current) {\n setHasScroll({\n vertical:\n tableContainerRef.current.scrollHeight >\n tableContainerRef.current.clientHeight,\n horizontal:\n tableContainerRef.current.scrollWidth >\n tableContainerRef.current.clientWidth,\n });\n }\n }, [dataSource]);\n\n return (\n <div\n ref={tableWrapperRef}\n className={clsx(\n cls(\"table-wrapper\", \"data-table\"),\n cls(`table-${size}`),\n variant === \"zebra\" ? cls(\"table-zebra\") : \"\",\n hasPagination ? cls(\"table-has-pagination\") : \"\",\n hasScroll.vertical ? cls(\"table-scroll-vertical\") : \"\",\n hasScroll.horizontal ? cls(\"table-scroll-horizontal\") : \"\",\n antdClass,\n className\n )}\n >\n <Spin spinning={isLoading} {...spinProps}>\n <div className={clsx(cls(\"table\"))}>\n <div className={cls(\"table-container\")} ref={tableContainerRef}>\n <div className={cls(\"table-content\")}>\n <table>\n <colgroup>\n {table.getHeaderGroups()[0]?.headers.map((header) => {\n let columnWidth: string | number | undefined;\n\n if (header.id === \"select\") {\n columnWidth = rowSelectionConfig?.columnWidth || 32;\n } else {\n // Try to get the current size from TanStack, fallback to meta width\n try {\n columnWidth = `${header.getSize()}px`;\n } catch (error) {\n // Fallback to static width from column meta\n columnWidth = (\n header.column.columnDef.meta as ExtendedColumnMeta\n )?.width;\n }\n }\n\n return (\n <col key={header.id} style={{ width: columnWidth }} />\n );\n })}\n </colgroup>\n\n <TableHeader\n table={table}\n rowSelectionConfig={rowSelectionConfig}\n dataSource={dataSource}\n rowKey={rowKey}\n />\n\n <TableBody\n table={table}\n dataSource={dataSource}\n emptyDescription={emptyDescription}\n hasRowSelection={hasRowSelection}\n onRowClick={handleRowClick}\n rowSelectionConfig={rowSelectionConfig}\n rowKey={rowKey}\n />\n </table>\n </div>\n </div>\n </div>\n\n {hasPagination && (\n <TablePagination\n table={table}\n paginationConfig={paginationConfig}\n totalCount={table.getPreFilteredRowModel().rows.length}\n />\n )}\n </Spin>\n </div>\n );\n};\n\nconst InternalDataTable = forwardRef(InnerDataTable) as <\n RecordType extends Record<string, any> = Record<string, unknown>\n>(\n props: DataTableProps<RecordType> & { ref?: Ref<DataTableRef> }\n) => ReturnType<typeof InnerDataTable>;\n\nexport const DataTable = InternalDataTable;\n"],"names":["InnerDataTable","props","ref","dataSource","className","size","variant","emptyDescription","rowKey","cls","useCls","tableWrapperRef","useRef","table","isLoading","spinProps","hasRowSelection","hasPagination","paginationConfig","rowSelectionConfig","useDataTable","handleRowClick","row","selectedRows","convertSelectionToAntFormat","antdClass","useAntdCssVarClassname","tableContainerRef","hasScroll","setHasScroll","useState","useEffect","jsx","clsx","jsxs","Spin","header","columnWidth","TableHeader","TableBody","TablePagination","InternalDataTable","forwardRef","DataTable"],"mappings":";;;;;;;;;;;;AA4BA,MAAMA,IAAiB,CAGrBC,GACAC,MACG;AACH,QAAM;AAAA,IACJ,YAAAC,IAAa,CAAA;AAAA,IACb,WAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,SAAAC,IAA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ACF,GACF,EAAA,CACF,GACF,GACF;AAAA,QAECS,KACC,gBAAAe;AAAA,UAACQ;AAAA,UAAA;AAAA,YACC,OAAA3B;AAAA,YACA,kBAAAK;AAAA,YACA,YAAYL,EAAM,uBAAA,EAAyB,KAAK;AAAA,UAAA;AAAA,QAAA;AAAA,MAClD,EAAA,CAEJ;AAAA,IAAA;AAAA,EAAA;AAGN,GAEM4B,IAAoBC,EAAW1C,CAAc,GAMtC2C,IAAYF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/data-table/hooks.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,SAAS,CAAC;AAOnE;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,KAAK,EAAE,cAAc,CAAC,UAAU,CAAC;;;;;;;;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/data-table/hooks.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,SAAS,CAAC;AAOnE;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,KAAK,EAAE,cAAc,CAAC,UAAU,CAAC;;;;;;;;EAkNlC"}
|
|
@@ -1,52 +1,64 @@
|
|
|
1
|
-
import { useState as y, useMemo as
|
|
2
|
-
import { useReactTable as
|
|
3
|
-
import { convertColumnsToTanStack as
|
|
4
|
-
function
|
|
1
|
+
import { useState as y, useMemo as M, useEffect as x } from "react";
|
|
2
|
+
import { useReactTable as P, getPaginationRowModel as F, getFilteredRowModel as I, getSortedRowModel as E, getCoreRowModel as T } from "@tanstack/react-table";
|
|
3
|
+
import { convertColumnsToTanStack as v, getRowKey as L, convertSelectionToAntFormat as W } from "./utils.js";
|
|
4
|
+
function A(d) {
|
|
5
5
|
const {
|
|
6
|
-
dataSource:
|
|
7
|
-
columns:
|
|
8
|
-
rowSelection:
|
|
9
|
-
pagination:
|
|
10
|
-
loading:
|
|
11
|
-
enableSorting:
|
|
12
|
-
enableFiltering:
|
|
13
|
-
onSortingChange:
|
|
14
|
-
onFilteringChange:
|
|
15
|
-
rowKey:
|
|
16
|
-
enableColumnResizing:
|
|
17
|
-
columnResizeMode:
|
|
18
|
-
columnResizeDirection:
|
|
19
|
-
onColumnSizingChange:
|
|
20
|
-
} = d, [t,
|
|
6
|
+
dataSource: g = [],
|
|
7
|
+
columns: r = [],
|
|
8
|
+
rowSelection: i,
|
|
9
|
+
pagination: a,
|
|
10
|
+
loading: s,
|
|
11
|
+
enableSorting: f = !0,
|
|
12
|
+
enableFiltering: u = !1,
|
|
13
|
+
onSortingChange: p,
|
|
14
|
+
onFilteringChange: C,
|
|
15
|
+
rowKey: S,
|
|
16
|
+
enableColumnResizing: c = !1,
|
|
17
|
+
columnResizeMode: w = "onChange",
|
|
18
|
+
columnResizeDirection: h = "ltr",
|
|
19
|
+
onColumnSizingChange: z
|
|
20
|
+
} = d, [t, l] = y({
|
|
21
21
|
sorting: [],
|
|
22
22
|
filtering: [],
|
|
23
23
|
pagination: {
|
|
24
24
|
pageIndex: 0,
|
|
25
|
-
pageSize:
|
|
25
|
+
pageSize: a ? a?.defaultPageSize || a?.pageSize || 10 : g.length
|
|
26
26
|
},
|
|
27
27
|
rowSelection: {},
|
|
28
28
|
columnSizing: {}
|
|
29
|
-
}),
|
|
30
|
-
let e =
|
|
31
|
-
return
|
|
29
|
+
}), R = M(() => {
|
|
30
|
+
let e = v(r);
|
|
31
|
+
return i && (e = [{
|
|
32
32
|
id: "select",
|
|
33
|
-
header: ({ table:
|
|
34
|
-
cell: ({ row:
|
|
35
|
-
size: typeof
|
|
33
|
+
header: ({ table: o }) => i.type === "radio" ? i.columnTitle || null : "SELECTION_HEADER",
|
|
34
|
+
cell: ({ row: o }) => "SELECTION_CELL",
|
|
35
|
+
size: typeof i.columnWidth == "number" ? i.columnWidth : typeof i.columnWidth == "string" && parseFloat(i.columnWidth) || 32,
|
|
36
36
|
enableSorting: !1,
|
|
37
37
|
enableHiding: !1,
|
|
38
38
|
meta: {
|
|
39
|
-
fixed:
|
|
39
|
+
fixed: i.fixed,
|
|
40
40
|
isSelectionColumn: !0
|
|
41
41
|
}
|
|
42
42
|
}, ...e]), e;
|
|
43
|
-
}, [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
}, [r, i]);
|
|
44
|
+
x(() => {
|
|
45
|
+
if (a === !1) return;
|
|
46
|
+
const e = t.pagination.pageSize, n = Math.max(0, Math.ceil(g.length / e) - 1);
|
|
47
|
+
t.pagination.pageIndex > n && l((o) => ({
|
|
48
|
+
...o,
|
|
49
|
+
pagination: {
|
|
50
|
+
...o.pagination,
|
|
51
|
+
pageIndex: 0
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
}, [g, a, t.pagination.pageSize, t.pagination.pageIndex]);
|
|
55
|
+
const m = P({
|
|
56
|
+
data: g,
|
|
57
|
+
columns: R,
|
|
58
|
+
getCoreRowModel: T(),
|
|
59
|
+
getSortedRowModel: f ? E() : void 0,
|
|
60
|
+
getFilteredRowModel: u ? I() : void 0,
|
|
61
|
+
getPaginationRowModel: a !== !1 ? F() : void 0,
|
|
50
62
|
// Default column configuration for sizing
|
|
51
63
|
defaultColumn: {
|
|
52
64
|
size: 150,
|
|
@@ -59,62 +71,62 @@ function k(d) {
|
|
|
59
71
|
columnFilters: t.filtering,
|
|
60
72
|
pagination: t.pagination,
|
|
61
73
|
rowSelection: t.rowSelection,
|
|
62
|
-
columnSizing:
|
|
74
|
+
columnSizing: c ? t.columnSizing : void 0
|
|
63
75
|
},
|
|
64
76
|
// State update handlers
|
|
65
77
|
onSortingChange: (e) => {
|
|
66
78
|
const n = typeof e == "function" ? e(t.sorting) : e;
|
|
67
|
-
|
|
79
|
+
l((o) => ({ ...o, sorting: n })), p?.(n);
|
|
68
80
|
},
|
|
69
81
|
onColumnFiltersChange: (e) => {
|
|
70
82
|
const n = typeof e == "function" ? e(t.filtering) : e;
|
|
71
|
-
|
|
83
|
+
l((o) => ({ ...o, filtering: n })), C?.(n);
|
|
72
84
|
},
|
|
73
85
|
onPaginationChange: (e) => {
|
|
74
|
-
if (
|
|
86
|
+
if (a === !1) return;
|
|
75
87
|
const n = typeof e == "function" ? e(t.pagination) : e;
|
|
76
|
-
|
|
88
|
+
l((o) => ({ ...o, pagination: n }));
|
|
77
89
|
},
|
|
78
90
|
onRowSelectionChange: (e) => {
|
|
79
91
|
const n = typeof e == "function" ? e(t.rowSelection) : e;
|
|
80
|
-
if (
|
|
81
|
-
const { selectedRowKeys:
|
|
92
|
+
if (l((o) => ({ ...o, rowSelection: n })), i?.onChange) {
|
|
93
|
+
const { selectedRowKeys: o, selectedRows: b } = W(
|
|
82
94
|
n,
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
g,
|
|
96
|
+
S
|
|
85
97
|
);
|
|
86
|
-
|
|
98
|
+
i.onChange(o, b);
|
|
87
99
|
}
|
|
88
100
|
},
|
|
89
|
-
onColumnSizingChange:
|
|
101
|
+
onColumnSizingChange: c ? (e) => {
|
|
90
102
|
const n = typeof e == "function" ? e(t.columnSizing) : e;
|
|
91
|
-
|
|
92
|
-
...
|
|
103
|
+
l((o) => ({
|
|
104
|
+
...o,
|
|
93
105
|
columnSizing: n
|
|
94
|
-
})),
|
|
106
|
+
})), z?.(n);
|
|
95
107
|
} : void 0,
|
|
96
108
|
// Feature enables
|
|
97
|
-
enableSorting:
|
|
98
|
-
enableFilters:
|
|
99
|
-
enableRowSelection: !!
|
|
100
|
-
enableColumnResizing:
|
|
109
|
+
enableSorting: f,
|
|
110
|
+
enableFilters: u,
|
|
111
|
+
enableRowSelection: !!i,
|
|
112
|
+
enableColumnResizing: c,
|
|
101
113
|
// Column resizing configuration
|
|
102
|
-
columnResizeMode:
|
|
103
|
-
columnResizeDirection:
|
|
114
|
+
columnResizeMode: w,
|
|
115
|
+
columnResizeDirection: h,
|
|
104
116
|
// Row identification
|
|
105
|
-
getRowId: (e, n) => String(
|
|
117
|
+
getRowId: (e, n) => String(L(e, n, S))
|
|
106
118
|
});
|
|
107
119
|
return {
|
|
108
120
|
table: m,
|
|
109
|
-
isLoading: typeof
|
|
110
|
-
spinProps: typeof
|
|
111
|
-
hasRowSelection: !!
|
|
121
|
+
isLoading: typeof s == "boolean" ? s : typeof s == "object",
|
|
122
|
+
spinProps: typeof s == "object" ? s : {},
|
|
123
|
+
hasRowSelection: !!i,
|
|
112
124
|
hasPagination: m.getPageCount() > 1,
|
|
113
|
-
paginationConfig:
|
|
114
|
-
rowSelectionConfig:
|
|
125
|
+
paginationConfig: a === !1 ? void 0 : a,
|
|
126
|
+
rowSelectionConfig: i
|
|
115
127
|
};
|
|
116
128
|
}
|
|
117
129
|
export {
|
|
118
|
-
|
|
130
|
+
A as useDataTable
|
|
119
131
|
};
|
|
120
132
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../src/components/data-table/hooks.ts"],"sourcesContent":["import { useState, useMemo } from \"react\";\nimport {\n useReactTable,\n getCoreRowModel,\n getSortedRowModel,\n getFilteredRowModel,\n getPaginationRowModel,\n type ColumnDef,\n} from \"@tanstack/react-table\";\nimport { type DataTableProps, type DataTableState } from \"./types\";\nimport {\n convertColumnsToTanStack,\n convertSelectionToAntFormat,\n getRowKey,\n} from \"./utils\";\n\n/**\n * Hook to manage DataTable state and TanStack Table integration\n */\nexport function useDataTable<\n RecordType extends Record<string, any> = Record<string, unknown>\n>(props: DataTableProps<RecordType>) {\n const {\n dataSource = [],\n columns = [],\n rowSelection,\n pagination,\n loading,\n enableSorting = true,\n enableFiltering = false,\n onSortingChange,\n onFilteringChange,\n rowKey,\n enableColumnResizing = false,\n columnResizeMode = \"onChange\",\n columnResizeDirection = \"ltr\",\n onColumnSizingChange,\n } = props;\n\n // Internal state for uncontrolled mode\n const [internalState, setInternalState] = useState<DataTableState>({\n sorting: [],\n filtering: [],\n pagination: {\n pageIndex: 0,\n pageSize: !pagination\n ? dataSource.length\n : pagination?.defaultPageSize || pagination?.pageSize || 10,\n },\n rowSelection: {},\n columnSizing: {},\n });\n\n // Convert Ant Design columns to TanStack format\n const tanStackColumns = useMemo(() => {\n let processedColumns = convertColumnsToTanStack(columns);\n\n // Add selection column if needed\n if (rowSelection) {\n const selectionColumn: ColumnDef<RecordType> = {\n id: \"select\",\n header: ({ table: _table }) => {\n if (rowSelection.type === \"radio\")\n return rowSelection.columnTitle || null;\n // Return a marker that will be handled by the TableHeader component\n return \"SELECTION_HEADER\";\n },\n cell: ({ row: _row }) => {\n // Return a marker that will be handled by the TableBody component\n return \"SELECTION_CELL\";\n },\n size:\n typeof rowSelection.columnWidth === \"number\"\n ? rowSelection.columnWidth\n : typeof rowSelection.columnWidth === \"string\"\n ? parseFloat(rowSelection.columnWidth) || 32\n : 32,\n enableSorting: false,\n enableHiding: false,\n meta: {\n fixed: rowSelection.fixed,\n isSelectionColumn: true,\n },\n };\n\n processedColumns = [selectionColumn, ...processedColumns];\n }\n\n return processedColumns;\n }, [columns, rowSelection]);\n\n // Initialize TanStack Table\n const table = useReactTable<RecordType>({\n data: dataSource,\n columns: tanStackColumns,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: enableSorting ? getSortedRowModel() : undefined,\n getFilteredRowModel: enableFiltering ? getFilteredRowModel() : undefined,\n getPaginationRowModel:\n pagination !== false ? getPaginationRowModel() : undefined,\n\n // Default column configuration for sizing\n defaultColumn: {\n size: 150,\n minSize: 50,\n maxSize: 500,\n },\n\n // State management\n state: {\n sorting: internalState.sorting,\n columnFilters: internalState.filtering,\n pagination: internalState.pagination,\n rowSelection: internalState.rowSelection,\n columnSizing: enableColumnResizing\n ? internalState.columnSizing\n : undefined,\n },\n\n // State update handlers\n onSortingChange: (updater) => {\n const newSorting =\n typeof updater === \"function\"\n ? updater(internalState.sorting)\n : updater;\n setInternalState((prev) => ({ ...prev, sorting: newSorting }));\n onSortingChange?.(newSorting);\n },\n\n onColumnFiltersChange: (updater) => {\n const newFiltering =\n typeof updater === \"function\"\n ? updater(internalState.filtering)\n : updater;\n setInternalState((prev) => ({ ...prev, filtering: newFiltering }));\n onFilteringChange?.(newFiltering);\n },\n\n onPaginationChange: (updater) => {\n if (pagination === false) return;\n\n const newPagination =\n typeof updater === \"function\"\n ? updater(internalState.pagination)\n : updater;\n setInternalState((prev) => ({ ...prev, pagination: newPagination }));\n },\n\n onRowSelectionChange: (updater) => {\n const newSelection =\n typeof updater === \"function\"\n ? updater(internalState.rowSelection)\n : updater;\n setInternalState((prev) => ({ ...prev, rowSelection: newSelection }));\n\n // Convert to Ant Design format and call onChange\n if (rowSelection?.onChange) {\n const { selectedRowKeys, selectedRows } = convertSelectionToAntFormat(\n newSelection,\n dataSource,\n rowKey\n );\n rowSelection.onChange(selectedRowKeys, selectedRows);\n }\n },\n\n onColumnSizingChange: enableColumnResizing\n ? (updater) => {\n const newColumnSizing =\n typeof updater === \"function\"\n ? updater(internalState.columnSizing)\n : updater;\n setInternalState((prev) => ({\n ...prev,\n columnSizing: newColumnSizing,\n }));\n onColumnSizingChange?.(newColumnSizing);\n }\n : undefined,\n\n // Feature enables\n enableSorting,\n enableFilters: enableFiltering,\n enableRowSelection: !!rowSelection,\n enableColumnResizing,\n\n // Column resizing configuration\n columnResizeMode,\n columnResizeDirection,\n\n // Row identification\n getRowId: (row, index) => String(getRowKey(row, index, rowKey)),\n });\n\n // Loading state processing\n const isLoading =\n typeof loading === \"boolean\"\n ? loading\n : typeof loading === \"object\"\n ? true\n : false;\n const spinProps = typeof loading === \"object\" ? loading : {};\n\n return {\n table,\n isLoading,\n spinProps,\n hasRowSelection: !!rowSelection,\n hasPagination: table.getPageCount() > 1,\n paginationConfig: pagination === false ? undefined : pagination,\n rowSelectionConfig: rowSelection,\n };\n}\n"],"names":["useDataTable","props","dataSource","columns","rowSelection","pagination","loading","enableSorting","enableFiltering","onSortingChange","onFilteringChange","rowKey","enableColumnResizing","columnResizeMode","columnResizeDirection","onColumnSizingChange","internalState","setInternalState","useState","tanStackColumns","useMemo","processedColumns","convertColumnsToTanStack","_table","_row","table","useReactTable","getCoreRowModel","getSortedRowModel","getFilteredRowModel","getPaginationRowModel","updater","newSorting","prev","newFiltering","newPagination","newSelection","selectedRowKeys","selectedRows","convertSelectionToAntFormat","newColumnSizing","row","index","getRowKey"],"mappings":";;;AAmBO,SAASA,EAEdC,GAAmC;AACnC,QAAM;AAAA,IACJ,YAAAC,IAAa,CAAA;AAAA,IACb,SAAAC,IAAU,CAAA;AAAA,IACV,cAAAC;AAAA,IACA,YAAAC;AAAA,IACA,SAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,iBAAAC,IAAkB;AAAA,IAClB,iBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,sBAAAC,IAAuB;AAAA,IACvB,kBAAAC,IAAmB;AAAA,IACnB,uBAAAC,IAAwB;AAAA,IACxB,sBAAAC;AAAA,EAAA,IACEd,GAGE,CAACe,GAAeC,CAAgB,IAAIC,EAAyB;AAAA,IACjE,SAAS,CAAA;AAAA,IACT,WAAW,CAAA;AAAA,IACX,YAAY;AAAA,MACV,WAAW;AAAA,MACX,UAAWb,IAEPA,GAAY,mBAAmBA,GAAY,YAAY,KADvDH,EAAW;AAAA,IAC4C;AAAA,IAE7D,cAAc,CAAA;AAAA,IACd,cAAc,CAAA;AAAA,EAAC,CAChB,GAGKiB,IAAkBC,EAAQ,MAAM;AACpC,QAAIC,IAAmBC,EAAyBnB,CAAO;AAGvD,WAAIC,MA2BFiB,IAAmB,CA1B4B;AAAA,MAC7C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A,KAAY;AAAA,IAQvB,WALgB,OAAOA,KAAY,WAAWA,IAAU,CAAA;AAAA,IAMxD,iBAAiB,CAAC,CAACF;AAAA,IACnB,eAAeqB,EAAM,aAAA,IAAiB;AAAA,IACtC,kBAAkBpB,MAAe,KAAQ,SAAYA;AAAA,IACrD,oBAAoBD;AAAA,EAAA;AAExB;"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../src/components/data-table/hooks.ts"],"sourcesContent":["import { useState, useMemo, useEffect } from \"react\";\nimport {\n useReactTable,\n getCoreRowModel,\n getSortedRowModel,\n getFilteredRowModel,\n getPaginationRowModel,\n type ColumnDef,\n} from \"@tanstack/react-table\";\nimport { type DataTableProps, type DataTableState } from \"./types\";\nimport {\n convertColumnsToTanStack,\n convertSelectionToAntFormat,\n getRowKey,\n} from \"./utils\";\n\n/**\n * Hook to manage DataTable state and TanStack Table integration\n */\nexport function useDataTable<\n RecordType extends Record<string, any> = Record<string, unknown>\n>(props: DataTableProps<RecordType>) {\n const {\n dataSource = [],\n columns = [],\n rowSelection,\n pagination,\n loading,\n enableSorting = true,\n enableFiltering = false,\n onSortingChange,\n onFilteringChange,\n rowKey,\n enableColumnResizing = false,\n columnResizeMode = \"onChange\",\n columnResizeDirection = \"ltr\",\n onColumnSizingChange,\n } = props;\n\n // Internal state for uncontrolled mode\n const [internalState, setInternalState] = useState<DataTableState>({\n sorting: [],\n filtering: [],\n pagination: {\n pageIndex: 0,\n pageSize: !pagination\n ? dataSource.length\n : pagination?.defaultPageSize || pagination?.pageSize || 10,\n },\n rowSelection: {},\n columnSizing: {},\n });\n\n // Convert Ant Design columns to TanStack format\n const tanStackColumns = useMemo(() => {\n let processedColumns = convertColumnsToTanStack(columns);\n\n // Add selection column if needed\n if (rowSelection) {\n const selectionColumn: ColumnDef<RecordType> = {\n id: \"select\",\n header: ({ table: _table }) => {\n if (rowSelection.type === \"radio\")\n return rowSelection.columnTitle || null;\n // Return a marker that will be handled by the TableHeader component\n return \"SELECTION_HEADER\";\n },\n cell: ({ row: _row }) => {\n // Return a marker that will be handled by the TableBody component\n return \"SELECTION_CELL\";\n },\n size:\n typeof rowSelection.columnWidth === \"number\"\n ? rowSelection.columnWidth\n : typeof rowSelection.columnWidth === \"string\"\n ? parseFloat(rowSelection.columnWidth) || 32\n : 32,\n enableSorting: false,\n enableHiding: false,\n meta: {\n fixed: rowSelection.fixed,\n isSelectionColumn: true,\n },\n };\n\n processedColumns = [selectionColumn, ...processedColumns];\n }\n\n return processedColumns;\n }, [columns, rowSelection]);\n\n // Reset pagination when dataSource changes\n useEffect(() => {\n if (pagination === false) return;\n\n const currentPageSize = internalState.pagination.pageSize;\n const maxPageIndex = Math.max(0, Math.ceil(dataSource.length / currentPageSize) - 1);\n\n // Only reset if current page is out of bounds\n if (internalState.pagination.pageIndex > maxPageIndex) {\n setInternalState((prev) => ({\n ...prev,\n pagination: {\n ...prev.pagination,\n pageIndex: 0,\n },\n }));\n }\n }, [dataSource, pagination, internalState.pagination.pageSize, internalState.pagination.pageIndex]);\n\n // Initialize TanStack Table\n const table = useReactTable<RecordType>({\n data: dataSource,\n columns: tanStackColumns,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: enableSorting ? getSortedRowModel() : undefined,\n getFilteredRowModel: enableFiltering ? getFilteredRowModel() : undefined,\n getPaginationRowModel:\n pagination !== false ? getPaginationRowModel() : undefined,\n\n // Default column configuration for sizing\n defaultColumn: {\n size: 150,\n minSize: 50,\n maxSize: 500,\n },\n\n // State management\n state: {\n sorting: internalState.sorting,\n columnFilters: internalState.filtering,\n pagination: internalState.pagination,\n rowSelection: internalState.rowSelection,\n columnSizing: enableColumnResizing\n ? internalState.columnSizing\n : undefined,\n },\n\n // State update handlers\n onSortingChange: (updater) => {\n const newSorting =\n typeof updater === \"function\"\n ? updater(internalState.sorting)\n : updater;\n setInternalState((prev) => ({ ...prev, sorting: newSorting }));\n onSortingChange?.(newSorting);\n },\n\n onColumnFiltersChange: (updater) => {\n const newFiltering =\n typeof updater === \"function\"\n ? updater(internalState.filtering)\n : updater;\n setInternalState((prev) => ({ ...prev, filtering: newFiltering }));\n onFilteringChange?.(newFiltering);\n },\n\n onPaginationChange: (updater) => {\n if (pagination === false) return;\n\n const newPagination =\n typeof updater === \"function\"\n ? updater(internalState.pagination)\n : updater;\n setInternalState((prev) => ({ ...prev, pagination: newPagination }));\n },\n\n onRowSelectionChange: (updater) => {\n const newSelection =\n typeof updater === \"function\"\n ? updater(internalState.rowSelection)\n : updater;\n setInternalState((prev) => ({ ...prev, rowSelection: newSelection }));\n\n // Convert to Ant Design format and call onChange\n if (rowSelection?.onChange) {\n const { selectedRowKeys, selectedRows } = convertSelectionToAntFormat(\n newSelection,\n dataSource,\n rowKey\n );\n rowSelection.onChange(selectedRowKeys, selectedRows);\n }\n },\n\n onColumnSizingChange: enableColumnResizing\n ? (updater) => {\n const newColumnSizing =\n typeof updater === \"function\"\n ? updater(internalState.columnSizing)\n : updater;\n setInternalState((prev) => ({\n ...prev,\n columnSizing: newColumnSizing,\n }));\n onColumnSizingChange?.(newColumnSizing);\n }\n : undefined,\n\n // Feature enables\n enableSorting,\n enableFilters: enableFiltering,\n enableRowSelection: !!rowSelection,\n enableColumnResizing,\n\n // Column resizing configuration\n columnResizeMode,\n columnResizeDirection,\n\n // Row identification\n getRowId: (row, index) => String(getRowKey(row, index, rowKey)),\n });\n\n // Loading state processing\n const isLoading =\n typeof loading === \"boolean\"\n ? loading\n : typeof loading === \"object\"\n ? true\n : false;\n const spinProps = typeof loading === \"object\" ? loading : {};\n\n return {\n table,\n isLoading,\n spinProps,\n hasRowSelection: !!rowSelection,\n hasPagination: table.getPageCount() > 1,\n paginationConfig: pagination === false ? undefined : pagination,\n rowSelectionConfig: rowSelection,\n };\n}\n"],"names":["useDataTable","props","dataSource","columns","rowSelection","pagination","loading","enableSorting","enableFiltering","onSortingChange","onFilteringChange","rowKey","enableColumnResizing","columnResizeMode","columnResizeDirection","onColumnSizingChange","internalState","setInternalState","useState","tanStackColumns","useMemo","processedColumns","convertColumnsToTanStack","_table","_row","useEffect","currentPageSize","maxPageIndex","prev","table","useReactTable","getCoreRowModel","getSortedRowModel","getFilteredRowModel","getPaginationRowModel","updater","newSorting","newFiltering","newPagination","newSelection","selectedRowKeys","selectedRows","convertSelectionToAntFormat","newColumnSizing","row","index","getRowKey"],"mappings":";;;AAmBO,SAASA,EAEdC,GAAmC;AACnC,QAAM;AAAA,IACJ,YAAAC,IAAa,CAAA;AAAA,IACb,SAAAC,IAAU,CAAA;AAAA,IACV,cAAAC;AAAA,IACA,YAAAC;AAAA,IACA,SAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,iBAAAC,IAAkB;AAAA,IAClB,iBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,sBAAAC,IAAuB;AAAA,IACvB,kBAAAC,IAAmB;AAAA,IACnB,uBAAAC,IAAwB;AAAA,IACxB,sBAAAC;AAAA,EAAA,IACEd,GAGE,CAACe,GAAeC,CAAgB,IAAIC,EAAyB;AAAA,IACjE,SAAS,CAAA;AAAA,IACT,WAAW,CAAA;AAAA,IACX,YAAY;AAAA,MACV,WAAW;AAAA,MACX,UAAWb,IAEPA,GAAY,mBAAmBA,GAAY,YAAY,KADvDH,EAAW;AAAA,IAC4C;AAAA,IAE7D,cAAc,CAAA;AAAA,IACd,cAAc,CAAA;AAAA,EAAC,CAChB,GAGKiB,IAAkBC,EAAQ,MAAM;AACpC,QAAIC,IAAmBC,EAAyBnB,CAAO;AAGvD,WAAIC,MA2BFiB,IAAmB,CA1B4B;AAAA,MAC7C,IAAI;AAAA,MACJ,QAAQ,CAAC,EAAE,OAAOE,QACZnB,EAAa,SAAS,UACjBA,EAAa,eAAe,OAE9B;AAAA,MAET,MAAM,CAAC,EAAE,KAAKoB,QAEL;AAAA,MAET,MACE,OAAOpB,EAAa,eAAgB,WAChCA,EAAa,cACb,OAAOA,EAAa,eAAgB,YACpC,WAAWA,EAAa,WAAW,KAA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ACA,uBAAAC;AAAA;AAAA,IAGA,UAAU,CAAC8B,GAAKC,MAAU,OAAOC,EAAUF,GAAKC,GAAOlC,CAAM,CAAC;AAAA,EAAA,CAC/D;AAWD,SAAO;AAAA,IACL,OAAAkB;AAAA,IACA,WATA,OAAOvB,KAAY,YACfA,IACA,OAAOA,KAAY;AAAA,IAQvB,WALgB,OAAOA,KAAY,WAAWA,IAAU,CAAA;AAAA,IAMxD,iBAAiB,CAAC,CAACF;AAAA,IACnB,eAAeyB,EAAM,aAAA,IAAiB;AAAA,IACtC,kBAAkBxB,MAAe,KAAQ,SAAYA;AAAA,IACrD,oBAAoBD;AAAA,EAAA;AAExB;"}
|
|
@@ -115,7 +115,6 @@ const ve = ({
|
|
|
115
115
|
return /* @__PURE__ */ m(
|
|
116
116
|
t.Root,
|
|
117
117
|
{
|
|
118
|
-
openOnHover: A,
|
|
119
118
|
open: _,
|
|
120
119
|
onOpenChange: v,
|
|
121
120
|
children: [
|
|
@@ -125,6 +124,7 @@ const ve = ({
|
|
|
125
124
|
render: b,
|
|
126
125
|
ref: z,
|
|
127
126
|
nativeButton: !1,
|
|
127
|
+
openOnHover: A,
|
|
128
128
|
className: s(
|
|
129
129
|
r("dropdown-menu-trigger"),
|
|
130
130
|
o?.trigger,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\n\nimport { DropdownMenuItemType } from \"./types\";\nimport { useDropdownMenu, UseDropdownMenuProps } from \"./useDropdownMenu\";\nimport { useControlledState } from \"../hooks\";\n\nimport { useTheme } from \"../theme-provider\";\nimport { BaseMenu } from \"../base-menu\";\n\nexport interface DropdownMenuProps\n extends Omit<UseDropdownMenuProps, \"classNames\"> {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Default open state of the dropdown\n */\n defaultOpen?: boolean;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n itemIcon?: string;\n itemText?: string;\n positioner?: string;\n } & UseDropdownMenuProps[\"classNames\"];\n\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n * Whether to match the width of the popup with the trigger\n * @default false\n */\n popupMatchTriggerWidth?: boolean;\n /**\n * Content to display before the list\n */\n beforeList?: React.ReactNode;\n /**\n * Content to display after the list\n */\n afterList?: React.ReactNode;\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n defaultOpen = false,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n inCombobox: inComboboxProp,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n getItemKeywords,\n showCheckbox,\n itemLabelRender,\n}: DropdownMenuProps) => {\n const inCombobox =\n typeof inComboboxProp === \"boolean\" ? inComboboxProp : showSearch;\n const [open, onOpenChange] = useControlledState(\n outsideOpen,\n outsideOnOpenChange,\n defaultOpen\n );\n const cls = useCls();\n const { className: themeClassName } = useTheme();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const { itemGroups, renderGroup } = useDropdownMenu({\n items,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n getItemKeywords,\n itemLabelRender,\n itemRender,\n inCombobox,\n onOpenChange,\n classNames: {\n item: classNames?.item,\n itemIcon: classNames?.itemIcon,\n itemSuffix: classNames?.itemSuffix,\n group: classNames?.group,\n groupLabel: classNames?.groupLabel,\n divider: classNames?.divider,\n },\n });\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command\n className={cls(\"dropdown-menu-container\")}\n disablePointerSelection={showSearch}\n defaultValue={\n highlightedItemKey ? String(highlightedItemKey) : undefined\n }\n // filter={(value, search, keywords) => {\n // console.log({ value, search, keywords });\n // const extendValue = value + \" \" + keywords.join(\" \");\n // if (extendValue.toLowerCase().includes(search.toLowerCase()))\n // return 1;\n // return 0;\n // }}\n >\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroup)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea fadeEdges>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n afterList,\n renderGroup,\n ]\n );\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n openOnHover={openOnHover}\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n nativeButton={false}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n themeClassName\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={baseUIPlacement.side}\n align={baseUIPlacement.align}\n sideOffset={4}\n className={clsx(\n cls(\"dropdown-menu-root\"),\n themeClassName,\n classNames?.root\n )}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n render={(props) => <BaseMenu.Root {...props} />}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\n \"dropdown-menu\",\n showCheckbox && \"dropdown-menu-show-checkbox\",\n popupMatchTriggerWidth && \"dropdown-menu-match-trigger-width\"\n ),\n className,\n classNames?.popup\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n render={(props) => <BaseMenu.Popup {...props} />}\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","defaultOpen","className","itemRender","classNames","size","showSearch","inComboboxProp","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","getItemKeywords","showCheckbox","itemLabelRender","inCombobox","open","onOpenChange","useControlledState","cls","useCls","themeClassName","useTheme","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","renderGroup","useDropdownMenu","renderMenuInner","useCallback","jsxs","Command","jsx","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","Menu","clsx","DROPDOWN_COLLISION_AVOIDANCE","props","BaseMenu","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;;AAuGO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,aAAAC,IAAc;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EAAA;AAAA,EAEf,wBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,cAAAC;AAAA,EACA,iBAAAC;AACF,MAAyB;AACvB,QAAMC,IACJ,OAAOX,KAAmB,YAAYA,IAAiBD,GACnD,CAACa,GAAMC,CAAY,IAAIC;AAAA,IAC3BtB;AAAA,IACAC;AAAA,IACAC;AAAA,EAAA,GAEIqB,IAAMC,EAAA,GACN,EAAE,WAAWC,EAAA,IAAmBC,GAAA,GAChCC,IAAkBC,EAAmB9B,CAAS,GAC9C+B,IAAYC,EAA0B,IAAI,GAC1C,EAAE,YAAAC,GAAY,aAAAC,EAAA,IAAgBC,EAAgB;AAAA,IAClD,OAAApC;AAAA,IACA,kBAAAgB;AAAA,IAEA,kBAAAE;AAAA,IACA,cAAAE;AAAA,IACA,iBAAAD;AAAA,IACA,iBAAAE;AAAA,IACA,YAAAd;AAAA,IACA,YAAAe;AAAA,IACA,cAAAE;AAAA,IACA,YAAY;AAAA,MACV,MAAM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;AAAA,gBAE7C,UAAAd,EAAA;AAAA,cAAgB;AAAA,YAAA;AAAA,UACnB;AAAA,QAAA,EACF,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\n\nimport { DropdownMenuItemType } from \"./types\";\nimport { useDropdownMenu, UseDropdownMenuProps } from \"./useDropdownMenu\";\nimport { useControlledState } from \"../hooks\";\n\nimport { useTheme } from \"../theme-provider\";\nimport { BaseMenu } from \"../base-menu\";\n\nexport interface DropdownMenuProps\n extends Omit<UseDropdownMenuProps, \"classNames\"> {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Default open state of the dropdown\n */\n defaultOpen?: boolean;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n itemIcon?: string;\n itemText?: string;\n positioner?: string;\n } & UseDropdownMenuProps[\"classNames\"];\n\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n * Whether to match the width of the popup with the trigger\n * @default false\n */\n popupMatchTriggerWidth?: boolean;\n /**\n * Content to display before the list\n */\n beforeList?: React.ReactNode;\n /**\n * Content to display after the list\n */\n afterList?: React.ReactNode;\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n defaultOpen = false,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n inCombobox: inComboboxProp,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n getItemKeywords,\n showCheckbox,\n itemLabelRender,\n}: DropdownMenuProps) => {\n const inCombobox =\n typeof inComboboxProp === \"boolean\" ? inComboboxProp : showSearch;\n const [open, onOpenChange] = useControlledState(\n outsideOpen,\n outsideOnOpenChange,\n defaultOpen\n );\n const cls = useCls();\n const { className: themeClassName } = useTheme();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const { itemGroups, renderGroup } = useDropdownMenu({\n items,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n getItemKeywords,\n itemLabelRender,\n itemRender,\n inCombobox,\n onOpenChange,\n classNames: {\n item: classNames?.item,\n itemIcon: classNames?.itemIcon,\n itemSuffix: classNames?.itemSuffix,\n group: classNames?.group,\n groupLabel: classNames?.groupLabel,\n divider: classNames?.divider,\n },\n });\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command\n className={cls(\"dropdown-menu-container\")}\n disablePointerSelection={showSearch}\n defaultValue={\n highlightedItemKey ? String(highlightedItemKey) : undefined\n }\n // filter={(value, search, keywords) => {\n // console.log({ value, search, keywords });\n // const extendValue = value + \" \" + keywords.join(\" \");\n // if (extendValue.toLowerCase().includes(search.toLowerCase()))\n // return 1;\n // return 0;\n // }}\n >\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroup)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea fadeEdges>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n afterList,\n renderGroup,\n ]\n );\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n nativeButton={false}\n openOnHover={openOnHover}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n themeClassName\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={baseUIPlacement.side}\n align={baseUIPlacement.align}\n sideOffset={4}\n className={clsx(\n cls(\"dropdown-menu-root\"),\n themeClassName,\n classNames?.root\n )}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n render={(props) => <BaseMenu.Root {...props} />}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\n \"dropdown-menu\",\n showCheckbox && \"dropdown-menu-show-checkbox\",\n popupMatchTriggerWidth && \"dropdown-menu-match-trigger-width\"\n ),\n className,\n classNames?.popup\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n render={(props) => <BaseMenu.Popup {...props} />}\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","defaultOpen","className","itemRender","classNames","size","showSearch","inComboboxProp","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","getItemKeywords","showCheckbox","itemLabelRender","inCombobox","open","onOpenChange","useControlledState","cls","useCls","themeClassName","useTheme","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","renderGroup","useDropdownMenu","renderMenuInner","useCallback","jsxs","Command","jsx","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","Menu","clsx","DROPDOWN_COLLISION_AVOIDANCE","props","BaseMenu","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;;AAuGO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,aAAAC,IAAc;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EAAA;AAAA,EAEf,wBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,iBAAAC;AAAA,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