@addsign/moje-agenda-shared-lib 2.0.49 → 2.0.50
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/datatable/DataTableServer.d.ts +2 -1
- package/dist/components/datatable/DataTableServer.js +3 -1
- package/dist/components/datatable/DataTableServer.js.map +1 -1
- package/dist/components/datatable/Resizable.d.ts +2 -1
- package/dist/components/datatable/Resizable.js +11 -4
- package/dist/components/datatable/Resizable.js.map +1 -1
- package/dist/components/ui/multi-select.js +2 -2
- package/dist/components/ui/multi-select.js.map +1 -1
- package/lib/components/datatable/DataTableServer.tsx +3 -0
- package/lib/components/datatable/Resizable.tsx +11 -3
- package/lib/components/ui/multi-select.tsx +3 -2
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ interface IResizableProps {
|
|
|
3
3
|
colKey: string;
|
|
4
4
|
children: any;
|
|
5
5
|
defaultWidth: string;
|
|
6
|
+
setMinWidth?: boolean;
|
|
6
7
|
}
|
|
7
|
-
export declare const Resizable: ({ tableId, colKey, defaultWidth, children, }: IResizableProps) => any;
|
|
8
|
+
export declare const Resizable: ({ tableId, colKey, defaultWidth, children, setMinWidth, }: IResizableProps) => any;
|
|
8
9
|
export {};
|
|
@@ -3,7 +3,8 @@ const Resizable = ({
|
|
|
3
3
|
tableId,
|
|
4
4
|
colKey,
|
|
5
5
|
defaultWidth,
|
|
6
|
-
children
|
|
6
|
+
children,
|
|
7
|
+
setMinWidth = false
|
|
7
8
|
}) => {
|
|
8
9
|
const [node, setNode] = React__default.useState(null);
|
|
9
10
|
const [width, setWidth] = useState(() => {
|
|
@@ -41,7 +42,9 @@ const Resizable = ({
|
|
|
41
42
|
const dx = e2.clientX - startPos.x;
|
|
42
43
|
const newWidth = w + dx + "px";
|
|
43
44
|
parent == null ? void 0 : parent.style.setProperty("width", newWidth);
|
|
44
|
-
|
|
45
|
+
if (setMinWidth) {
|
|
46
|
+
parent == null ? void 0 : parent.style.setProperty("min-width", newWidth);
|
|
47
|
+
}
|
|
45
48
|
setWidth(newWidth);
|
|
46
49
|
};
|
|
47
50
|
const handleMouseUp = () => {
|
|
@@ -61,10 +64,14 @@ const Resizable = ({
|
|
|
61
64
|
const parent = node.parentElement;
|
|
62
65
|
if (node.parentNode !== ((_b = (_a = node.parentNode) == null ? void 0 : _a.parentNode) == null ? void 0 : _b.lastChild)) {
|
|
63
66
|
parent == null ? void 0 : parent.style.setProperty("width", `${width}`);
|
|
64
|
-
|
|
67
|
+
if (setMinWidth) {
|
|
68
|
+
parent == null ? void 0 : parent.style.setProperty("min-width", `${width}`);
|
|
69
|
+
}
|
|
65
70
|
} else {
|
|
66
71
|
parent == null ? void 0 : parent.style.setProperty("width", `auto`);
|
|
67
|
-
|
|
72
|
+
if (setMinWidth) {
|
|
73
|
+
parent == null ? void 0 : parent.style.setProperty("min-width", `auto`);
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
node.addEventListener("mousedown", handleMouseDown);
|
|
70
77
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resizable.js","sources":["../../../lib/components/datatable/Resizable.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\r\n\r\ninterface IResizableProps {\r\n tableId: string;\r\n colKey: string;\r\n children: any;\r\n defaultWidth: string;\r\n}\r\n\r\nexport const Resizable = ({\r\n tableId,\r\n colKey,\r\n defaultWidth,\r\n children,\r\n}: IResizableProps) => {\r\n const [node, setNode] = React.useState<HTMLElement | null>(null);\r\n\r\n const [width, setWidth] = useState(() => {\r\n const storageKey = `datatable:${tableId}`;\r\n const storedData = localStorage.getItem(storageKey);\r\n const data = storedData ? JSON.parse(storedData) : {};\r\n\r\n const columnWidths = data.columnWidths || {};\r\n const storedWidth = columnWidths[colKey];\r\n return storedWidth ? storedWidth : defaultWidth;\r\n });\r\n\r\n //storing sizes\r\n useEffect(() => {\r\n const storageKey = `datatable:${tableId}`;\r\n const storedData = localStorage.getItem(storageKey);\r\n const data = storedData ? JSON.parse(storedData) : {};\r\n\r\n data.columnWidths = data.columnWidths || {};\r\n data.columnWidths[colKey] = width;\r\n\r\n localStorage.setItem(storageKey, JSON.stringify(data));\r\n }, [width, tableId, colKey, defaultWidth]);\r\n\r\n const ref = React.useCallback((nodeEle: HTMLElement) => {\r\n setNode(nodeEle);\r\n }, []);\r\n\r\n const handleMouseDown = React.useCallback(\r\n (e: MouseEvent) => {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n const parent = node.parentElement;\r\n const startPos = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n // const styles = window.getComputedStyle(parent);\r\n const styles = parent ? window.getComputedStyle(parent) : null;\r\n\r\n const w = parseInt(styles?.width || \"0\", 10);\r\n\r\n const handleMouseMove = (e: MouseEvent) => {\r\n const dx = e.clientX - startPos.x;\r\n const newWidth = w + dx + \"px\";\r\n\r\n parent?.style.setProperty(\"width\", newWidth);\r\n parent?.style.setProperty(\"min-width\", newWidth);\r\n setWidth(newWidth);\r\n };\r\n\r\n const handleMouseUp = () => {\r\n document.removeEventListener(\"mousemove\", handleMouseMove);\r\n document.removeEventListener(\"mouseup\", handleMouseUp);\r\n };\r\n\r\n document.addEventListener(\"mousemove\", handleMouseMove);\r\n document.addEventListener(\"mouseup\", handleMouseUp);\r\n },\r\n [node]\r\n );\r\n\r\n React.useEffect(() => {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n const parent = node.parentElement;\r\n if (node.parentNode !== node.parentNode?.parentNode?.lastChild) {\r\n parent?.style.setProperty(\"width\", `${width}`);\r\n parent?.style.setProperty(\"min-width\", `${width}`);\r\n } else {\r\n parent?.style.setProperty(\"width\", `auto`);\r\n parent?.style.setProperty(\"min-width\", `auto`);\r\n }\r\n\r\n node.addEventListener(\"mousedown\", handleMouseDown);\r\n\r\n return () => {\r\n node.removeEventListener(\"mousedown\", handleMouseDown);\r\n };\r\n }, [node, handleMouseDown, tableId]);\r\n\r\n return children({ ref });\r\n};\r\n"],"names":["React","e"],"mappings":";
|
|
1
|
+
{"version":3,"file":"Resizable.js","sources":["../../../lib/components/datatable/Resizable.tsx"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\r\n\r\ninterface IResizableProps {\r\n tableId: string;\r\n colKey: string;\r\n children: any;\r\n defaultWidth: string;\r\n setMinWidth?: boolean;\r\n}\r\n\r\nexport const Resizable = ({\r\n tableId,\r\n colKey,\r\n defaultWidth,\r\n children,\r\n setMinWidth = false,\r\n}: IResizableProps) => {\r\n const [node, setNode] = React.useState<HTMLElement | null>(null);\r\n\r\n const [width, setWidth] = useState(() => {\r\n const storageKey = `datatable:${tableId}`;\r\n const storedData = localStorage.getItem(storageKey);\r\n const data = storedData ? JSON.parse(storedData) : {};\r\n\r\n const columnWidths = data.columnWidths || {};\r\n const storedWidth = columnWidths[colKey];\r\n return storedWidth ? storedWidth : defaultWidth;\r\n });\r\n\r\n //storing sizes\r\n useEffect(() => {\r\n const storageKey = `datatable:${tableId}`;\r\n const storedData = localStorage.getItem(storageKey);\r\n const data = storedData ? JSON.parse(storedData) : {};\r\n\r\n data.columnWidths = data.columnWidths || {};\r\n data.columnWidths[colKey] = width;\r\n\r\n localStorage.setItem(storageKey, JSON.stringify(data));\r\n }, [width, tableId, colKey, defaultWidth]);\r\n\r\n const ref = React.useCallback((nodeEle: HTMLElement) => {\r\n setNode(nodeEle);\r\n }, []);\r\n\r\n const handleMouseDown = React.useCallback(\r\n (e: MouseEvent) => {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n const parent = node.parentElement;\r\n const startPos = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n // const styles = window.getComputedStyle(parent);\r\n const styles = parent ? window.getComputedStyle(parent) : null;\r\n\r\n const w = parseInt(styles?.width || \"0\", 10);\r\n\r\n const handleMouseMove = (e: MouseEvent) => {\r\n const dx = e.clientX - startPos.x;\r\n const newWidth = w + dx + \"px\";\r\n\r\n parent?.style.setProperty(\"width\", newWidth);\r\n if (setMinWidth) {\r\n parent?.style.setProperty(\"min-width\", newWidth);\r\n }\r\n setWidth(newWidth);\r\n };\r\n\r\n const handleMouseUp = () => {\r\n document.removeEventListener(\"mousemove\", handleMouseMove);\r\n document.removeEventListener(\"mouseup\", handleMouseUp);\r\n };\r\n\r\n document.addEventListener(\"mousemove\", handleMouseMove);\r\n document.addEventListener(\"mouseup\", handleMouseUp);\r\n },\r\n [node]\r\n );\r\n\r\n React.useEffect(() => {\r\n if (!node) {\r\n return;\r\n }\r\n\r\n const parent = node.parentElement;\r\n if (node.parentNode !== node.parentNode?.parentNode?.lastChild) {\r\n parent?.style.setProperty(\"width\", `${width}`);\r\n if (setMinWidth) {\r\n parent?.style.setProperty(\"min-width\", `${width}`);\r\n }\r\n } else {\r\n parent?.style.setProperty(\"width\", `auto`);\r\n if (setMinWidth) {\r\n parent?.style.setProperty(\"min-width\", `auto`);\r\n }\r\n }\r\n\r\n node.addEventListener(\"mousedown\", handleMouseDown);\r\n\r\n return () => {\r\n node.removeEventListener(\"mousedown\", handleMouseDown);\r\n };\r\n }, [node, handleMouseDown, tableId]);\r\n\r\n return children({ ref });\r\n};\r\n"],"names":["React","e"],"mappings":";AAUO,MAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAChB,MAAuB;AACrB,QAAM,CAAC,MAAM,OAAO,IAAIA,eAAM,SAA6B,IAAI;AAE/D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,MAAM;AACjC,UAAA,aAAa,aAAa,OAAO;AACjC,UAAA,aAAa,aAAa,QAAQ,UAAU;AAClD,UAAM,OAAO,aAAa,KAAK,MAAM,UAAU,IAAI;AAE7C,UAAA,eAAe,KAAK,gBAAgB;AACpC,UAAA,cAAc,aAAa,MAAM;AACvC,WAAO,cAAc,cAAc;AAAA,EAAA,CACpC;AAGD,YAAU,MAAM;AACR,UAAA,aAAa,aAAa,OAAO;AACjC,UAAA,aAAa,aAAa,QAAQ,UAAU;AAClD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,YAAY,SAAS,GAAG,KAAK;AAC3C,UAAI,aAAa;AACf,yCAAQ,MAAM,YAAY,aAAa,GAAG,KAAK;AAAA,MACjD;AAAA,IAAA,OACK;AACG,uCAAA,MAAM,YAAY,SAAS;AACnC,UAAI,aAAa;AACP,yCAAA,MAAM,YAAY,aAAa;AAAA,MACzC;AAAA,IACF;AAEK,SAAA,iBAAiB,aAAa,eAAe;AAElD,WAAO,MAAM;AACN,WAAA,oBAAoB,aAAa,eAAe;AAAA,IAAA;AAAA,EAEtD,GAAA,CAAC,MAAM,iBAAiB,OAAO,CAAC;AAE5B,SAAA,SAAS,EAAE,IAAA,CAAK;AACzB;"}
|
|
@@ -218,7 +218,7 @@ const MultiSelect = React.forwardRef(
|
|
|
218
218
|
{
|
|
219
219
|
className: cn(
|
|
220
220
|
"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
|
|
221
|
-
selectedValues.length === options.length ? "bg-primary text-primary-foreground" : "opacity-50 [&_svg]:invisible"
|
|
221
|
+
selectedValues && selectedValues.length === options.length ? "bg-primary text-primary-foreground" : "opacity-50 [&_svg]:invisible"
|
|
222
222
|
),
|
|
223
223
|
children: /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" })
|
|
224
224
|
}
|
|
@@ -230,7 +230,7 @@ const MultiSelect = React.forwardRef(
|
|
|
230
230
|
),
|
|
231
231
|
options.map((option) => {
|
|
232
232
|
const optionStr = String(option.value);
|
|
233
|
-
const isSelected = selectedValues.includes(optionStr);
|
|
233
|
+
const isSelected = (selectedValues == null ? void 0 : selectedValues.includes(optionStr)) || false;
|
|
234
234
|
return /* @__PURE__ */ jsxs(
|
|
235
235
|
CommandItem,
|
|
236
236
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-select.js","sources":["../../../node_modules/lucide-react/dist/esm/icons/circle-x.js","../../../lib/components/ui/multi-select.tsx"],"sourcesContent":["/**\n * @license lucide-react v0.456.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst CircleX = createLucideIcon(\"CircleX\", [\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"10\", key: \"1mglay\" }],\n [\"path\", { d: \"m15 9-6 6\", key: \"1uzhvr\" }],\n [\"path\", { d: \"m9 9 6 6\", key: \"z0biqf\" }]\n]);\n\nexport { CircleX as default };\n//# sourceMappingURL=circle-x.js.map\n","// src/components/multi-select.tsx\r\n\r\nimport * as React from \"react\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { CheckIcon, XCircle, ChevronDown, XIcon } from \"lucide-react\";\r\n\r\nimport { cn } from \"../../utils/utils\";\r\nimport { Separator } from \"./separator\";\r\nimport { Button } from \"./button\";\r\nimport { Badge } from \"./badge\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\r\nimport {\r\n Command,\r\n CommandEmpty,\r\n CommandGroup,\r\n CommandInput,\r\n CommandItem,\r\n CommandList,\r\n CommandSeparator,\r\n} from \"./command\";\r\nimport { IOptionItem } from \"../../types\";\r\n\r\n/**\r\n * Variants for the multi-select component to handle different styles.\r\n * Uses class-variance-authority (cva) to define different styles based on \"variant\" prop.\r\n */\r\nconst multiSelectVariants = cva(\"m-1 transition ease-in-out delay-150 \", {\r\n variants: {\r\n variant: {\r\n default:\r\n \"border-foreground/10 text-foreground bg-card hover:bg-card/80 font-normal\",\r\n secondary:\r\n \"border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80 font-normal\",\r\n destructive:\r\n \"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80 font-normal\",\r\n inverted: \"inverted\",\r\n },\r\n },\r\n defaultVariants: {\r\n variant: \"default\",\r\n },\r\n});\r\n\r\n/**\r\n * Props for MultiSelect component\r\n */\r\ninterface MultiSelectProps\r\n extends Omit<\r\n React.ButtonHTMLAttributes<HTMLButtonElement>,\r\n \"onChange\" | \"value\"\r\n >,\r\n VariantProps<typeof multiSelectVariants> {\r\n /**\r\n * An array of option objects to be displayed in the multi-select component.\r\n * Each option object has a label, value, and an optional icon.\r\n */\r\n options: IOptionItem[];\r\n\r\n /**\r\n * Callback function triggered when the selected values change.\r\n * Receives an array of the new selected values.\r\n */\r\n onChange: (value: string[]) => void;\r\n\r\n /** The controlled value of the component */\r\n value?: string[];\r\n\r\n /** The default selected values when the component mounts (uncontrolled mode) */\r\n defaultValue?: string[];\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholderSearch?: string;\r\n\r\n /**\r\n * Maximum number of items to display. Extra selected items will be summarized.\r\n * Optional, defaults to 3.\r\n */\r\n maxCount?: number;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional, defaults to false.\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * If true, renders the multi-select component as a child of another component.\r\n * Optional, defaults to false.\r\n */\r\n asChild?: boolean;\r\n\r\n /**\r\n * Additional class names to apply custom styles to the multi-select component.\r\n * Optional, can be used to add custom styles.\r\n */\r\n className?: string;\r\n\r\n /**\r\n * If true, the multi-select component will be disabled.\r\n * Optional, defaults to false.\r\n */\r\n disabled?: boolean;\r\n\r\n /**\r\n * value?: string;\r\n onChange?: (value: string | undefined) => void;\r\n */\r\n}\r\n\r\nexport const MultiSelect = React.forwardRef<\r\n HTMLButtonElement,\r\n MultiSelectProps\r\n>(\r\n (\r\n {\r\n options,\r\n onChange,\r\n value: propValue,\r\n variant,\r\n defaultValue = [],\r\n placeholder = \"Vyberte možnosti\",\r\n placeholderSearch = \"Vyhledejte\",\r\n maxCount = 3,\r\n modalPopover = false,\r\n asChild = false,\r\n className,\r\n ...props\r\n },\r\n ref\r\n ) => {\r\n const [selectedValues, setSelectedValues] = React.useState<string[]>(\r\n propValue ?? defaultValue\r\n );\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n\r\n // Update internal state when controlled value changes\r\n React.useEffect(() => {\r\n if (propValue !== undefined) {\r\n setSelectedValues(propValue);\r\n }\r\n }, [propValue]);\r\n\r\n const handleValueChange = (newValues: string[]) => {\r\n setSelectedValues(newValues);\r\n onChange(newValues);\r\n };\r\n\r\n const handleTogglePopover = () => {\r\n setIsPopoverOpen((prev) => !prev);\r\n };\r\n\r\n const toggleOption = (option: string | number | null) => {\r\n if (option === null) return;\r\n const optionStr = String(option);\r\n const newSelectedValues = selectedValues.includes(optionStr)\r\n ? selectedValues.filter((value) => value !== optionStr)\r\n : [...selectedValues, optionStr];\r\n handleValueChange(newSelectedValues);\r\n };\r\n\r\n const handleClear = () => {\r\n handleValueChange([]);\r\n };\r\n\r\n const clearExtraOptions = () => {\r\n const newSelectedValues = selectedValues.slice(0, maxCount);\r\n handleValueChange(newSelectedValues);\r\n };\r\n\r\n const toggleAll = () => {\r\n if (selectedValues.length === options.length) {\r\n handleClear();\r\n } else {\r\n const allValues = options.map((option) => option.value as string);\r\n handleValueChange(allValues);\r\n }\r\n };\r\n\r\n return (\r\n <Popover\r\n open={isPopoverOpen}\r\n onOpenChange={setIsPopoverOpen}\r\n modal={modalPopover}\r\n >\r\n <PopoverTrigger asChild>\r\n <Button\r\n ref={ref}\r\n {...props}\r\n onClick={handleTogglePopover}\r\n className={cn(\r\n \"flex w-full p-1 rounded-md border min-h-10 h-auto items-center justify-between hover:bg-inherit [&_svg]:pointer-events-auto font-normal bg-background text-muted-foreground\",\r\n className\r\n )}\r\n >\r\n {selectedValues.length > 0 ? (\r\n <div className=\"flex justify-between items-center w-full\">\r\n <div className=\"flex flex-wrap items-center\">\r\n {maxCount === 0 && selectedValues.length == 1 && (\r\n <span className=\"px-2\">\r\n {\r\n options.find((o) => o.value === selectedValues[0])\r\n ?.label\r\n }\r\n </span>\r\n )}\r\n {maxCount === 0 && selectedValues.length > 1 && (\r\n <span className=\"px-2\">\r\n {`Více (${selectedValues.length})`}\r\n </span>\r\n )}\r\n {maxCount > 0 &&\r\n selectedValues.slice(0, maxCount).map((value) => {\r\n const option = options.find((o) => o.value === value);\r\n return (\r\n <Badge\r\n key={value}\r\n className={cn(multiSelectVariants({ variant }))}\r\n >\r\n {option?.label}\r\n <XCircle\r\n className=\"ml-2 h-4 w-4 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n toggleOption(value);\r\n }}\r\n />\r\n </Badge>\r\n );\r\n })}\r\n\r\n {maxCount > 0 && selectedValues.length > maxCount && (\r\n <Badge\r\n className={cn(\r\n \"bg-transparent text-foreground border-foreground/1 hover:bg-transparent\",\r\n multiSelectVariants({ variant })\r\n )}\r\n >\r\n {`Více (${selectedValues.length - maxCount})`}\r\n <XCircle\r\n className=\"ml-2 h-4 w-4 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n clearExtraOptions();\r\n }}\r\n />\r\n </Badge>\r\n )}\r\n </div>\r\n <div className=\"flex items-center justify-between\">\r\n <XIcon\r\n className=\"h-4 mx-2 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n handleClear();\r\n }}\r\n />\r\n <Separator\r\n orientation=\"vertical\"\r\n className=\"flex min-h-6 h-full\"\r\n />\r\n <ChevronDown className=\"h-4 mx-2 cursor-pointer text-muted-foreground\" />\r\n </div>\r\n </div>\r\n ) : (\r\n <div className=\"flex items-center justify-between w-full mx-auto\">\r\n <span className=\"text-sm text-muted-foreground mx-3\">\r\n {placeholder}\r\n </span>\r\n <ChevronDown className=\"h-4 cursor-pointer text-muted-foreground mx-2\" />\r\n </div>\r\n )}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent\r\n className=\"w-auto p-0\"\r\n align=\"start\"\r\n onEscapeKeyDown={() => setIsPopoverOpen(false)}\r\n >\r\n <Command>\r\n <CommandInput\r\n placeholder={placeholderSearch}\r\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (e.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (e.key === \"Backspace\" && !e.currentTarget.value) {\r\n const newSelectedValues = [...selectedValues];\r\n newSelectedValues.pop();\r\n handleValueChange(newSelectedValues);\r\n }\r\n }}\r\n />\r\n <CommandList>\r\n <CommandEmpty>No results found.</CommandEmpty>\r\n <CommandGroup>\r\n <CommandItem\r\n key=\"all\"\r\n onSelect={toggleAll}\r\n className=\"cursor-pointer\"\r\n >\r\n <div\r\n className={cn(\r\n \"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary\",\r\n selectedValues.length === options.length\r\n ? \"bg-primary text-primary-foreground\"\r\n : \"opacity-50 [&_svg]:invisible\"\r\n )}\r\n >\r\n <CheckIcon className=\"h-4 w-4\" />\r\n </div>\r\n <span>(Vyberte vše)</span>\r\n </CommandItem>\r\n {options.map((option) => {\r\n const optionStr = String(option.value);\r\n const isSelected = selectedValues.includes(optionStr);\r\n return (\r\n <CommandItem\r\n key={optionStr}\r\n onSelect={() => toggleOption(option.value)}\r\n className=\"cursor-pointer\"\r\n >\r\n <div\r\n className={cn(\r\n \"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary\",\r\n isSelected\r\n ? \"bg-primary text-primary-foreground\"\r\n : \"opacity-50 [&_svg]:invisible\"\r\n )}\r\n >\r\n <CheckIcon className=\"h-4 w-4\" />\r\n </div>\r\n\r\n <span>{option.label}</span>\r\n </CommandItem>\r\n );\r\n })}\r\n </CommandGroup>\r\n <CommandSeparator />\r\n <CommandGroup>\r\n <div className=\"flex items-center justify-between\">\r\n {selectedValues.length > 0 && (\r\n <>\r\n <CommandItem\r\n onSelect={handleClear}\r\n className=\"flex-1 justify-center cursor-pointer\"\r\n >\r\n Odebrat vše\r\n </CommandItem>\r\n <Separator\r\n orientation=\"vertical\"\r\n className=\"flex min-h-6 h-full\"\r\n />\r\n </>\r\n )}\r\n <CommandItem\r\n onSelect={() => setIsPopoverOpen(false)}\r\n className=\"flex-1 justify-center cursor-pointer max-w-full\"\r\n >\r\n Zavřít\r\n </CommandItem>\r\n </div>\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n }\r\n);\r\n\r\nMultiSelect.displayName = \"MultiSelect\";\r\n"],"names":["XCircle","XIcon","CheckIcon"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAM,UAAU,iBAAiB,WAAW;AAAA,EAC1C,CAAC,UAAU,EAAE,IAAI,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,UAAU;AAAA,EACzD,CAAC,QAAQ,EAAE,GAAG,aAAa,KAAK,SAAQ,CAAE;AAAA,EAC1C,CAAC,QAAQ,EAAE,GAAG,YAAY,KAAK,SAAQ,CAAE;AAC3C,CAAC;ACaD,MAAM,sBAAsB,IAAI,yCAAyC;AAAA,EACvE,UAAU;AAAA,IACR,SAAS;AAAA,MACP,SACE;AAAA,MACF,WACE;AAAA,MACF,aACE;AAAA,MACF,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,SAAS;AAAA,EACX;AACF,CAAC;AA8EM,MAAM,cAAc,MAAM;AAAA,EAI/B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,eAAe,CAAC;AAAA,IAChB,cAAc;AAAA,IACd,oBAAoB;AAAA,IACpB,WAAW;AAAA,IACX,eAAe;AAAA,IACf,UAAU;AAAA,IACV;AAAA,IACA,GAAG;AAAA,KAEL,QACG;;AACH,UAAM,CAAC,gBAAgB,iBAAiB,IAAI,MAAM;AAAA,MAChD,aAAa;AAAA,IAAA;AAEf,UAAM,CAAC,eAAe,gBAAgB,IAAI,MAAM,SAAS,KAAK;AAG9D,UAAM,UAAU,MAAM;AACpB,UAAI,cAAc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AA;AAAA,sBACZ;AAAA,oBAAA,GACF;AAAA,oBAEF;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,UAAU,MAAM,iBAAiB,KAAK;AAAA,wBACtC,WAAU;AAAA,wBACX,UAAA;AAAA,sBAAA;AAAA,oBAED;AAAA,kBAAA,EAAA,CACF,EACF,CAAA;AAAA,gBAAA,GACF;AAAA,cAAA,GACF;AAAA,YAAA;AAAA,UACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,YAAY,cAAc;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"multi-select.js","sources":["../../../node_modules/lucide-react/dist/esm/icons/circle-x.js","../../../lib/components/ui/multi-select.tsx"],"sourcesContent":["/**\n * @license lucide-react v0.456.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst CircleX = createLucideIcon(\"CircleX\", [\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"10\", key: \"1mglay\" }],\n [\"path\", { d: \"m15 9-6 6\", key: \"1uzhvr\" }],\n [\"path\", { d: \"m9 9 6 6\", key: \"z0biqf\" }]\n]);\n\nexport { CircleX as default };\n//# sourceMappingURL=circle-x.js.map\n","// src/components/multi-select.tsx\r\n\r\nimport * as React from \"react\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { CheckIcon, XCircle, ChevronDown, XIcon } from \"lucide-react\";\r\n\r\nimport { cn } from \"../../utils/utils\";\r\nimport { Separator } from \"./separator\";\r\nimport { Button } from \"./button\";\r\nimport { Badge } from \"./badge\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\r\nimport {\r\n Command,\r\n CommandEmpty,\r\n CommandGroup,\r\n CommandInput,\r\n CommandItem,\r\n CommandList,\r\n CommandSeparator,\r\n} from \"./command\";\r\nimport { IOptionItem } from \"../../types\";\r\n\r\n/**\r\n * Variants for the multi-select component to handle different styles.\r\n * Uses class-variance-authority (cva) to define different styles based on \"variant\" prop.\r\n */\r\nconst multiSelectVariants = cva(\"m-1 transition ease-in-out delay-150 \", {\r\n variants: {\r\n variant: {\r\n default:\r\n \"border-foreground/10 text-foreground bg-card hover:bg-card/80 font-normal\",\r\n secondary:\r\n \"border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80 font-normal\",\r\n destructive:\r\n \"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80 font-normal\",\r\n inverted: \"inverted\",\r\n },\r\n },\r\n defaultVariants: {\r\n variant: \"default\",\r\n },\r\n});\r\n\r\n/**\r\n * Props for MultiSelect component\r\n */\r\ninterface MultiSelectProps\r\n extends Omit<\r\n React.ButtonHTMLAttributes<HTMLButtonElement>,\r\n \"onChange\" | \"value\"\r\n >,\r\n VariantProps<typeof multiSelectVariants> {\r\n /**\r\n * An array of option objects to be displayed in the multi-select component.\r\n * Each option object has a label, value, and an optional icon.\r\n */\r\n options: IOptionItem[];\r\n\r\n /**\r\n * Callback function triggered when the selected values change.\r\n * Receives an array of the new selected values.\r\n */\r\n onChange: (value: string[]) => void;\r\n\r\n /** The controlled value of the component */\r\n value?: string[];\r\n\r\n /** The default selected values when the component mounts (uncontrolled mode) */\r\n defaultValue?: string[];\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholderSearch?: string;\r\n\r\n /**\r\n * Maximum number of items to display. Extra selected items will be summarized.\r\n * Optional, defaults to 3.\r\n */\r\n maxCount?: number;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional, defaults to false.\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * If true, renders the multi-select component as a child of another component.\r\n * Optional, defaults to false.\r\n */\r\n asChild?: boolean;\r\n\r\n /**\r\n * Additional class names to apply custom styles to the multi-select component.\r\n * Optional, can be used to add custom styles.\r\n */\r\n className?: string;\r\n\r\n /**\r\n * If true, the multi-select component will be disabled.\r\n * Optional, defaults to false.\r\n */\r\n disabled?: boolean;\r\n\r\n /**\r\n * value?: string;\r\n onChange?: (value: string | undefined) => void;\r\n */\r\n}\r\n\r\nexport const MultiSelect = React.forwardRef<\r\n HTMLButtonElement,\r\n MultiSelectProps\r\n>(\r\n (\r\n {\r\n options,\r\n onChange,\r\n value: propValue,\r\n variant,\r\n defaultValue = [],\r\n placeholder = \"Vyberte možnosti\",\r\n placeholderSearch = \"Vyhledejte\",\r\n maxCount = 3,\r\n modalPopover = false,\r\n asChild = false,\r\n className,\r\n ...props\r\n },\r\n ref\r\n ) => {\r\n const [selectedValues, setSelectedValues] = React.useState<string[]>(\r\n propValue ?? defaultValue\r\n );\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n\r\n // Update internal state when controlled value changes\r\n React.useEffect(() => {\r\n if (propValue !== undefined) {\r\n setSelectedValues(propValue);\r\n }\r\n }, [propValue]);\r\n\r\n const handleValueChange = (newValues: string[]) => {\r\n setSelectedValues(newValues);\r\n onChange(newValues);\r\n };\r\n\r\n const handleTogglePopover = () => {\r\n setIsPopoverOpen((prev) => !prev);\r\n };\r\n\r\n const toggleOption = (option: string | number | null) => {\r\n if (option === null) return;\r\n const optionStr = String(option);\r\n const newSelectedValues = selectedValues.includes(optionStr)\r\n ? selectedValues.filter((value) => value !== optionStr)\r\n : [...selectedValues, optionStr];\r\n handleValueChange(newSelectedValues);\r\n };\r\n\r\n const handleClear = () => {\r\n handleValueChange([]);\r\n };\r\n\r\n const clearExtraOptions = () => {\r\n const newSelectedValues = selectedValues.slice(0, maxCount);\r\n handleValueChange(newSelectedValues);\r\n };\r\n\r\n const toggleAll = () => {\r\n if (selectedValues.length === options.length) {\r\n handleClear();\r\n } else {\r\n const allValues = options.map((option) => option.value as string);\r\n handleValueChange(allValues);\r\n }\r\n };\r\n\r\n return (\r\n <Popover\r\n open={isPopoverOpen}\r\n onOpenChange={setIsPopoverOpen}\r\n modal={modalPopover}\r\n >\r\n <PopoverTrigger asChild>\r\n <Button\r\n ref={ref}\r\n {...props}\r\n onClick={handleTogglePopover}\r\n className={cn(\r\n \"flex w-full p-1 rounded-md border min-h-10 h-auto items-center justify-between hover:bg-inherit [&_svg]:pointer-events-auto font-normal bg-background text-muted-foreground\",\r\n className\r\n )}\r\n >\r\n {selectedValues.length > 0 ? (\r\n <div className=\"flex justify-between items-center w-full\">\r\n <div className=\"flex flex-wrap items-center\">\r\n {maxCount === 0 && selectedValues.length == 1 && (\r\n <span className=\"px-2\">\r\n {\r\n options.find((o) => o.value === selectedValues[0])\r\n ?.label\r\n }\r\n </span>\r\n )}\r\n {maxCount === 0 && selectedValues.length > 1 && (\r\n <span className=\"px-2\">\r\n {`Více (${selectedValues.length})`}\r\n </span>\r\n )}\r\n {maxCount > 0 &&\r\n selectedValues.slice(0, maxCount).map((value) => {\r\n const option = options.find((o) => o.value === value);\r\n return (\r\n <Badge\r\n key={value}\r\n className={cn(multiSelectVariants({ variant }))}\r\n >\r\n {option?.label}\r\n <XCircle\r\n className=\"ml-2 h-4 w-4 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n toggleOption(value);\r\n }}\r\n />\r\n </Badge>\r\n );\r\n })}\r\n\r\n {maxCount > 0 && selectedValues.length > maxCount && (\r\n <Badge\r\n className={cn(\r\n \"bg-transparent text-foreground border-foreground/1 hover:bg-transparent\",\r\n multiSelectVariants({ variant })\r\n )}\r\n >\r\n {`Více (${selectedValues.length - maxCount})`}\r\n <XCircle\r\n className=\"ml-2 h-4 w-4 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n clearExtraOptions();\r\n }}\r\n />\r\n </Badge>\r\n )}\r\n </div>\r\n <div className=\"flex items-center justify-between\">\r\n <XIcon\r\n className=\"h-4 mx-2 cursor-pointer text-muted-foreground\"\r\n onClick={(event) => {\r\n event.stopPropagation();\r\n handleClear();\r\n }}\r\n />\r\n <Separator\r\n orientation=\"vertical\"\r\n className=\"flex min-h-6 h-full\"\r\n />\r\n <ChevronDown className=\"h-4 mx-2 cursor-pointer text-muted-foreground\" />\r\n </div>\r\n </div>\r\n ) : (\r\n <div className=\"flex items-center justify-between w-full mx-auto\">\r\n <span className=\"text-sm text-muted-foreground mx-3\">\r\n {placeholder}\r\n </span>\r\n <ChevronDown className=\"h-4 cursor-pointer text-muted-foreground mx-2\" />\r\n </div>\r\n )}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent\r\n className=\"w-auto p-0\"\r\n align=\"start\"\r\n onEscapeKeyDown={() => setIsPopoverOpen(false)}\r\n >\r\n <Command>\r\n <CommandInput\r\n placeholder={placeholderSearch}\r\n onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (e.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (e.key === \"Backspace\" && !e.currentTarget.value) {\r\n const newSelectedValues = [...selectedValues];\r\n newSelectedValues.pop();\r\n handleValueChange(newSelectedValues);\r\n }\r\n }}\r\n />\r\n <CommandList>\r\n <CommandEmpty>No results found.</CommandEmpty>\r\n <CommandGroup>\r\n <CommandItem\r\n key=\"all\"\r\n onSelect={toggleAll}\r\n className=\"cursor-pointer\"\r\n >\r\n <div\r\n className={cn(\r\n \"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary\",\r\n selectedValues && selectedValues.length === options.length\r\n ? \"bg-primary text-primary-foreground\"\r\n : \"opacity-50 [&_svg]:invisible\"\r\n )}\r\n >\r\n <CheckIcon className=\"h-4 w-4\" />\r\n </div>\r\n <span>(Vyberte vše)</span>\r\n </CommandItem>\r\n {options.map((option) => {\r\n const optionStr = String(option.value);\r\n const isSelected =\r\n selectedValues?.includes(optionStr) || false;\r\n return (\r\n <CommandItem\r\n key={optionStr}\r\n onSelect={() => toggleOption(option.value)}\r\n className=\"cursor-pointer\"\r\n >\r\n <div\r\n className={cn(\r\n \"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary\",\r\n isSelected\r\n ? \"bg-primary text-primary-foreground\"\r\n : \"opacity-50 [&_svg]:invisible\"\r\n )}\r\n >\r\n <CheckIcon className=\"h-4 w-4\" />\r\n </div>\r\n\r\n <span>{option.label}</span>\r\n </CommandItem>\r\n );\r\n })}\r\n </CommandGroup>\r\n <CommandSeparator />\r\n <CommandGroup>\r\n <div className=\"flex items-center justify-between\">\r\n {selectedValues.length > 0 && (\r\n <>\r\n <CommandItem\r\n onSelect={handleClear}\r\n className=\"flex-1 justify-center cursor-pointer\"\r\n >\r\n Odebrat vše\r\n </CommandItem>\r\n <Separator\r\n orientation=\"vertical\"\r\n className=\"flex min-h-6 h-full\"\r\n />\r\n </>\r\n )}\r\n <CommandItem\r\n onSelect={() => setIsPopoverOpen(false)}\r\n className=\"flex-1 justify-center cursor-pointer max-w-full\"\r\n >\r\n Zavřít\r\n </CommandItem>\r\n </div>\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n }\r\n);\r\n\r\nMultiSelect.displayName = \"MultiSelect\";\r\n"],"names":["XCircle","XIcon","CheckIcon"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAM,UAAU,iBAAiB,WAAW;AAAA,EAC1C,CAAC,UAAU,EAAE,IAAI,MAAM,IAAI,MAAM,GAAG,MAAM,KAAK,UAAU;AAAA,EACzD,CAAC,QAAQ,EAAE,GAAG,aAAa,KAAK,SAAQ,CAAE;AAAA,EAC1C,CAAC,QAAQ,EAAE,GAAG,YAAY,KAAK,SAAQ,CAAE;AAC3C,CAAC;ACaD,MAAM,sBAAsB,IAAI,yCAAyC;AAAA,EACvE,UAAU;AAAA,IACR,SAAS;AAAA,MACP,SACE;AAAA,MACF,WACE;AAAA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CAAA;AAAA,8BAAA;AAAA,4BACjC;AAAA,4BAEA,oBAAC,QAAM,EAAA,UAAA,OAAO,MAAM,CAAA;AAAA,0BAAA;AAAA,wBAAA;AAAA,wBAff;AAAA,sBAAA;AAAA,oBAgBP,CAEH;AAAA,kBAAA,GACH;AAAA,sCACC,kBAAiB,EAAA;AAAA,kBACjB,oBAAA,cAAA,EACC,UAAC,qBAAA,OAAA,EAAI,WAAU,qCACZ,UAAA;AAAA,oBAAe,eAAA,SAAS,KAErB,qBAAA,UAAA,EAAA,UAAA;AAAA,sBAAA;AAAA,wBAAC;AAAA,wBAAA;AAAA,0BACC,UAAU;AAAA,0BACV,WAAU;AAAA,0BACX,UAAA;AAAA,wBAAA;AAAA,sBAED;AAAA,sBACA;AAAA,wBAAC;AAAA,wBAAA;AAAA,0BACC,aAAY;AAAA,0BACZ,WAAU;AAAA,wBAAA;AAAA,sBACZ;AAAA,oBAAA,GACF;AAAA,oBAEF;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,UAAU,MAAM,iBAAiB,KAAK;AAAA,wBACtC,WAAU;AAAA,wBACX,UAAA;AAAA,sBAAA;AAAA,oBAED;AAAA,kBAAA,EAAA,CACF,EACF,CAAA;AAAA,gBAAA,GACF;AAAA,cAAA,GACF;AAAA,YAAA;AAAA,UACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,YAAY,cAAc;","x_google_ignoreList":[0]}
|
|
@@ -54,6 +54,7 @@ interface DataTableServerProps<T> {
|
|
|
54
54
|
filters?: object;
|
|
55
55
|
selectedItemKey?: string;
|
|
56
56
|
itemsPerPageOptions?: IOptionItem[];
|
|
57
|
+
setMinWidth?: boolean;
|
|
57
58
|
}
|
|
58
59
|
const defaultItemsPerPageOptions: IOptionItem[] = [
|
|
59
60
|
{ value: 10, label: "10" },
|
|
@@ -112,6 +113,7 @@ function DataTableServer<T extends DataTableInternalItems>({
|
|
|
112
113
|
filters,
|
|
113
114
|
selectedItemKey = "id",
|
|
114
115
|
itemsPerPageOptions = defaultItemsPerPageOptions,
|
|
116
|
+
setMinWidth = false,
|
|
115
117
|
}: DataTableServerProps<T>) {
|
|
116
118
|
const abortControllerRef = useRef<AbortController | null>(null);
|
|
117
119
|
const [itemsPerPageLocal, setItemsPerPageLocal] = useState<number>();
|
|
@@ -749,6 +751,7 @@ function DataTableServer<T extends DataTableInternalItems>({
|
|
|
749
751
|
tableId={id}
|
|
750
752
|
colKey={String(key)}
|
|
751
753
|
defaultWidth={width || "auto"}
|
|
754
|
+
setMinWidth={setMinWidth}
|
|
752
755
|
>
|
|
753
756
|
{({ ref }: { ref: any }) => (
|
|
754
757
|
<th
|
|
@@ -5,6 +5,7 @@ interface IResizableProps {
|
|
|
5
5
|
colKey: string;
|
|
6
6
|
children: any;
|
|
7
7
|
defaultWidth: string;
|
|
8
|
+
setMinWidth?: boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const Resizable = ({
|
|
@@ -12,6 +13,7 @@ export const Resizable = ({
|
|
|
12
13
|
colKey,
|
|
13
14
|
defaultWidth,
|
|
14
15
|
children,
|
|
16
|
+
setMinWidth = false,
|
|
15
17
|
}: IResizableProps) => {
|
|
16
18
|
const [node, setNode] = React.useState<HTMLElement | null>(null);
|
|
17
19
|
|
|
@@ -62,7 +64,9 @@ export const Resizable = ({
|
|
|
62
64
|
const newWidth = w + dx + "px";
|
|
63
65
|
|
|
64
66
|
parent?.style.setProperty("width", newWidth);
|
|
65
|
-
|
|
67
|
+
if (setMinWidth) {
|
|
68
|
+
parent?.style.setProperty("min-width", newWidth);
|
|
69
|
+
}
|
|
66
70
|
setWidth(newWidth);
|
|
67
71
|
};
|
|
68
72
|
|
|
@@ -85,10 +89,14 @@ export const Resizable = ({
|
|
|
85
89
|
const parent = node.parentElement;
|
|
86
90
|
if (node.parentNode !== node.parentNode?.parentNode?.lastChild) {
|
|
87
91
|
parent?.style.setProperty("width", `${width}`);
|
|
88
|
-
|
|
92
|
+
if (setMinWidth) {
|
|
93
|
+
parent?.style.setProperty("min-width", `${width}`);
|
|
94
|
+
}
|
|
89
95
|
} else {
|
|
90
96
|
parent?.style.setProperty("width", `auto`);
|
|
91
|
-
|
|
97
|
+
if (setMinWidth) {
|
|
98
|
+
parent?.style.setProperty("min-width", `auto`);
|
|
99
|
+
}
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
node.addEventListener("mousedown", handleMouseDown);
|
|
@@ -310,7 +310,7 @@ export const MultiSelect = React.forwardRef<
|
|
|
310
310
|
<div
|
|
311
311
|
className={cn(
|
|
312
312
|
"mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
|
|
313
|
-
selectedValues.length === options.length
|
|
313
|
+
selectedValues && selectedValues.length === options.length
|
|
314
314
|
? "bg-primary text-primary-foreground"
|
|
315
315
|
: "opacity-50 [&_svg]:invisible"
|
|
316
316
|
)}
|
|
@@ -321,7 +321,8 @@ export const MultiSelect = React.forwardRef<
|
|
|
321
321
|
</CommandItem>
|
|
322
322
|
{options.map((option) => {
|
|
323
323
|
const optionStr = String(option.value);
|
|
324
|
-
const isSelected =
|
|
324
|
+
const isSelected =
|
|
325
|
+
selectedValues?.includes(optionStr) || false;
|
|
325
326
|
return (
|
|
326
327
|
<CommandItem
|
|
327
328
|
key={optionStr}
|