periplo-ui 4.16.0 → 4.16.1
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/feedback/Dialog/Dialog.js +1 -1
- package/dist/components/feedback/Dialog/Dialog.js.map +1 -1
- package/dist/components/feedback/Skeleton/Skeleton.js +1 -1
- package/dist/components/feedback/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/inputs/Button/Button.js +1 -1
- package/dist/components/inputs/Button/Button.js.map +1 -1
- package/dist/components/inputs/Combobox/Combobox.js +2 -1
- package/dist/components/inputs/Combobox/Combobox.js.map +1 -1
- package/dist/components/inputs/Combobox/StaticComboboxList.js +1 -2
- package/dist/components/inputs/Combobox/StaticComboboxList.js.map +1 -1
- package/dist/components/inputs/Combobox/VirtualizedComboboxList.js +1 -2
- package/dist/components/inputs/Combobox/VirtualizedComboboxList.js.map +1 -1
- package/dist/components/inputs/InlineMultiSelect/InlineMultiSelect.js +12 -13
- package/dist/components/inputs/InlineMultiSelect/InlineMultiSelect.js.map +1 -1
- package/dist/components/inputs/LazyDatePicker/LazyDatePicker.js +1 -1
- package/dist/components/inputs/LazyDatePicker/LazyDatePicker.js.map +1 -1
- package/dist/components/inputs/MultiSelect/MultiSelect.js +12 -13
- package/dist/components/inputs/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/components/inputs/PhoneInput/PhoneInput.js +2 -1
- package/dist/components/inputs/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/components/inputs/Select/Select.js +6 -5
- package/dist/components/inputs/Select/Select.js.map +1 -1
- package/dist/components/inputs/Toggle/Toggle.js +1 -1
- package/dist/components/inputs/Toggle/Toggle.js.map +1 -1
- package/dist/components/navigation/DropdownMenu/DropdownMenu.js +7 -6
- package/dist/components/navigation/DropdownMenu/DropdownMenu.js.map +1 -1
- package/dist/components/navigation/Sheet/Sheet.js +1 -1
- package/dist/components/navigation/Sheet/Sheet.js.map +1 -1
- package/dist/components/navigation/Sidebar/SidebarMenu.js +2 -2
- package/dist/components/navigation/Sidebar/SidebarMenu.js.map +1 -1
- package/dist/components/navigation/Sidebar/SidebarUser.js +1 -1
- package/dist/components/navigation/Sidebar/SidebarUser.js.map +1 -1
- package/dist/components/navigation/Sidebar/styles.d.ts +1 -1
- package/dist/components/navigation/Sidebar/styles.js +3 -1
- package/dist/components/navigation/Sidebar/styles.js.map +1 -1
- package/dist/components/utils/Command/Command.js +8 -7
- package/dist/components/utils/Command/Command.js.map +1 -1
- package/dist/components/utils/Popover/Popover.js +2 -1
- package/dist/components/utils/Popover/Popover.js.map +1 -1
- package/dist/lib/surface.d.ts +5 -0
- package/dist/lib/surface.js +10 -0
- package/dist/lib/surface.js.map +1 -0
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var DialogPortal = DialogPrimitive.Portal;
|
|
|
10
10
|
var DialogClose = DialogPrimitive.Close;
|
|
11
11
|
var DialogOverlay = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(DialogPrimitive.Overlay, {
|
|
12
12
|
ref,
|
|
13
|
-
className: cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-
|
|
13
|
+
className: cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-neutral-950/32", className),
|
|
14
14
|
...props
|
|
15
15
|
}));
|
|
16
16
|
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","names":["React"],"sources":["../../../../src/components/feedback/Dialog/Dialog.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport * as DialogPrimitive from '@radix-ui/react-dialog'\nimport * as React from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype DialogContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {\n closable?: boolean\n container?: HTMLElement | null\n}\n\nconst Dialog = DialogPrimitive.Root\n\nconst DialogTrigger = DialogPrimitive.Trigger\n\nconst DialogPortal = DialogPrimitive.Portal\n\nconst DialogClose = DialogPrimitive.Close\n\nconst DialogOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={cn(\n 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-
|
|
1
|
+
{"version":3,"file":"Dialog.js","names":["React"],"sources":["../../../../src/components/feedback/Dialog/Dialog.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport * as DialogPrimitive from '@radix-ui/react-dialog'\nimport * as React from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype DialogContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {\n closable?: boolean\n container?: HTMLElement | null\n}\n\nconst Dialog = DialogPrimitive.Root\n\nconst DialogTrigger = DialogPrimitive.Trigger\n\nconst DialogPortal = DialogPrimitive.Portal\n\nconst DialogClose = DialogPrimitive.Close\n\nconst DialogOverlay = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Overlay>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Overlay\n ref={ref}\n className={cn(\n 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-neutral-950/32',\n className,\n )}\n {...props}\n />\n))\nDialogOverlay.displayName = DialogPrimitive.Overlay.displayName\n\nconst DialogContent = React.forwardRef<React.ComponentRef<typeof DialogPrimitive.Content>, DialogContentProps>(\n ({ className, children, closable = true, container, ...props }, ref) => (\n <DialogPortal container={container}>\n <DialogOverlay />\n <DialogPrimitive.Content\n ref={ref}\n className={cn(\n 'bg-background-100 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg duration-200 sm:rounded-lg',\n className,\n )}\n onPointerDownOutside={(event) => {\n if (!closable) {\n event.preventDefault()\n }\n }}\n onEscapeKeyDown={(event) => {\n if (!closable) {\n event.preventDefault()\n }\n }}\n {...props}\n >\n {children}\n {closable ? (\n <DialogPrimitive.Close className=\"data-[state=open]:text-muted-foreground ring-offset-background focus:ring-ring data-[state=open]:bg-accent absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none\">\n <XIcon size={24} weight=\"bold\" />\n <span className=\"sr-only\">Close</span>\n </DialogPrimitive.Close>\n ) : null}\n </DialogPrimitive.Content>\n </DialogPortal>\n ),\n)\nDialogContent.displayName = DialogPrimitive.Content.displayName\n\nconst DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />\n)\nDialogHeader.displayName = 'DialogHeader'\n\nconst DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (\n <div className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)} {...props} />\n)\nDialogFooter.displayName = 'DialogFooter'\n\nconst DialogTitle = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Title>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Title\n ref={ref}\n className={cn('text-lg leading-none font-semibold tracking-tight', className)}\n {...props}\n />\n))\nDialogTitle.displayName = DialogPrimitive.Title.displayName\n\nconst DialogDescription = React.forwardRef<\n React.ComponentRef<typeof DialogPrimitive.Description>,\n React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>\n>(({ className, ...props }, ref) => (\n <DialogPrimitive.Description ref={ref} className={cn('text-muted-foreground text-sm', className)} {...props} />\n))\nDialogDescription.displayName = DialogPrimitive.Description.displayName\n\nexport {\n Dialog,\n DialogPortal,\n DialogOverlay,\n DialogTrigger,\n DialogClose,\n DialogContent,\n DialogHeader,\n DialogFooter,\n DialogTitle,\n DialogDescription,\n}\n"],"mappings":";;;;;;AAWA,IAAM,SAAS,gBAAgB;AAE/B,IAAM,gBAAgB,gBAAgB;AAEtC,IAAM,eAAe,gBAAgB;AAErC,IAAM,cAAc,gBAAgB;AAEpC,IAAM,gBAAgBA,QAAM,YAGzB,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,SAAjB;CACO;CACL,WAAW,GACT,gKACA,SACF;CACA,GAAI;AACL,CAAA,CACF;AACD,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,IAAM,gBAAgBA,QAAM,YACzB,EAAE,WAAW,UAAU,WAAW,MAAM,WAAW,GAAG,SAAS,QAC9D,qBAAC,cAAD;CAAyB;CAAzB,UAAA,CACE,oBAAC,eAAD,CAAgB,CAAA,GAChB,qBAAC,gBAAgB,SAAjB;EACO;EACL,WAAW,GACT,2VACA,SACF;EACA,uBAAuB,UAAU;GAC/B,IAAI,CAAC,UACH,MAAM,eAAe;EAEzB;EACA,kBAAkB,UAAU;GAC1B,IAAI,CAAC,UACH,MAAM,eAAe;EAEzB;EACA,GAAI;EAhBN,UAAA,CAkBG,UACA,WACC,qBAAC,gBAAgB,OAAjB;GAAuB,WAAU;GAAjC,UAAA,CACE,oBAAC,OAAD;IAAO,MAAM;IAAI,QAAO;GAAQ,CAAA,GAChC,oBAAC,QAAD;IAAM,WAAU;IAAU,UAAA;GAAW,CAAA,CAChB;EACrB,CAAA,IAAA,IACmB;CACb,CAAA,CAAA;AAElB,CAAA,CAAA;AACA,cAAc,cAAc,gBAAgB,QAAQ;AAEpD,IAAM,gBAAgB,EAAE,WAAW,GAAG,YACpC,oBAAC,OAAD;CAAK,WAAW,GAAG,sDAAsD,SAAS;CAAG,GAAI;AAAQ,CAAA;AAEnG,aAAa,cAAc;AAE3B,IAAM,gBAAgB,EAAE,WAAW,GAAG,YACpC,oBAAC,OAAD;CAAK,WAAW,GAAG,iEAAiE,SAAS;CAAG,GAAI;AAAQ,CAAA;AAE9G,aAAa,cAAc;AAE3B,IAAM,cAAcA,QAAM,YAGvB,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,OAAjB;CACO;CACL,WAAW,GAAG,qDAAqD,SAAS;CAC5E,GAAI;AACL,CAAA,CACF;AACD,YAAY,cAAc,gBAAgB,MAAM;AAEhD,IAAM,oBAAoBA,QAAM,YAG7B,EAAE,WAAW,GAAG,SAAS,QAC1B,oBAAC,gBAAgB,aAAjB;CAAkC;CAAK,WAAW,GAAG,iCAAiC,SAAS;CAAG,GAAI;AAAQ,CAAA,CAC/G;AACD,kBAAkB,cAAc,gBAAgB,YAAY"}
|
|
@@ -4,7 +4,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
function Skeleton({ className, ...props }) {
|
|
5
5
|
return /* @__PURE__ */ jsx("div", {
|
|
6
6
|
"data-testid": "skeleton",
|
|
7
|
-
className: cn("animate-pulse rounded-
|
|
7
|
+
className: cn("animate-pulse rounded-lg bg-neutral-100", className),
|
|
8
8
|
...props
|
|
9
9
|
});
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Skeleton.js","names":[],"sources":["../../../../src/components/feedback/Skeleton/Skeleton.tsx"],"sourcesContent":["import { cn } from '@/lib/utils'\n\nfunction Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {\n return <div data-testid=\"skeleton\" className={cn('animate-pulse rounded-
|
|
1
|
+
{"version":3,"file":"Skeleton.js","names":[],"sources":["../../../../src/components/feedback/Skeleton/Skeleton.tsx"],"sourcesContent":["import { cn } from '@/lib/utils'\n\nfunction Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {\n return <div data-testid=\"skeleton\" className={cn('animate-pulse rounded-lg bg-neutral-100', className)} {...props} />\n}\n\nexport { Skeleton }\n"],"mappings":";;;AAEA,SAAS,SAAS,EAAE,WAAW,GAAG,SAA+C;CAC/E,OAAO,oBAAC,OAAD;EAAK,eAAY;EAAW,WAAW,GAAG,2CAA2C,SAAS;EAAG,GAAI;CAAQ,CAAA;AACtH"}
|
|
@@ -5,7 +5,7 @@ import { cva } from "class-variance-authority";
|
|
|
5
5
|
import * as React$1 from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
//#region src/components/inputs/Button/Button.tsx
|
|
8
|
-
var buttonVariants = cva("inline-flex items-center justify-center gap-2 rounded-
|
|
8
|
+
var buttonVariants = cva("inline-flex items-center justify-center gap-2 rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", {
|
|
9
9
|
variants: {
|
|
10
10
|
/**
|
|
11
11
|
* Defines the visual style of the button
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","names":["React"],"sources":["../../../../src/components/inputs/Button/Button.tsx"],"sourcesContent":["import type { Icon, IconWeight, IconProps } from '@phosphor-icons/react'\nimport { SpinnerGapIcon } from '@phosphor-icons/react/dist/ssr/SpinnerGap'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport * as React from 'react'\n\nimport { cn } from '../../../lib/utils'\nimport { typographyVariants } from '../../data-display/Typography'\n\nconst buttonVariants = cva(\n 'inline-flex items-center justify-center gap-2 rounded-
|
|
1
|
+
{"version":3,"file":"Button.js","names":["React"],"sources":["../../../../src/components/inputs/Button/Button.tsx"],"sourcesContent":["import type { Icon, IconWeight, IconProps } from '@phosphor-icons/react'\nimport { SpinnerGapIcon } from '@phosphor-icons/react/dist/ssr/SpinnerGap'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport * as React from 'react'\n\nimport { cn } from '../../../lib/utils'\nimport { typographyVariants } from '../../data-display/Typography'\n\nconst buttonVariants = cva(\n 'inline-flex items-center justify-center gap-2 rounded-lg font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',\n {\n variants: {\n /**\n * Defines the visual style of the button\n */\n variant: {\n primary:\n 'bg-primary-500 text-primary-foreground hover:bg-primary-700 active:bg-primary-900 disabled:bg-background-200',\n secondary:\n 'bg-neutral-950 text-neutral-foreground hover:bg-neutral-800 active:bg-neutral-700 disabled:bg-neutral-200 disabled:text-neutral-600',\n ghost:\n 'border border-neutral-500 text-primary-foreground hover:bg-neutral-100/50 active:bg-neutral-200/50 disabled:border-neutral-500 disabled:text-neutral-500',\n 'inverse-ghost':\n 'border border-neutral-50 text-neutral-50 hover:bg-neutral/50 hover:border-neutral-50 active:bg-neutral-600/50 disabled:border-neutral-300 disabled:text-neutral-300',\n text: 'hover:bg-neutral-50 active:bg-neutral-100 text-primary-foreground disabled:text-neutral-500',\n error:\n 'bg-error text-white hover:bg-error-800 active:bg-error-900 disabled:bg-error-200 disabled:text-neutral-600',\n success:\n 'bg-success text-white hover:bg-success-800 active:bg-success-900 disabled:bg-success-200 disabled:text-neutral-600',\n input:\n 'border border-neutral-200 bg-white text-neutral-950 hover:bg-neutral-50 active:bg-neutral-100 focus-visible:border-neutral-950 disabled:bg-neutral-50 focus-visible:ring-0',\n },\n /**\n * Controls the size and padding of the button\n */\n size: {\n sm: 'h-8 px-3 text-sm',\n md: 'h-10 px-4 text-sm',\n lg: 'h-12 px-6 text-base',\n },\n },\n compoundVariants: [\n {\n variant: 'input',\n size: ['sm', 'md', 'lg'],\n className: typographyVariants({ variant: 'body-lg' }),\n },\n ],\n defaultVariants: {\n variant: 'primary',\n size: 'md',\n },\n },\n)\n\nexport type ButtonProps = {\n /**\n * The visual style of the button.\n * @default primary\n */\n variant?: 'primary' | 'secondary' | 'ghost' | 'inverse-ghost' | 'text' | 'error' | 'success'\n\n /**\n * The size of the button, affecting height, padding, and font size.\n * @default md\n */\n size?: 'sm' | 'md' | 'lg'\n\n /**\n * Icon component to display at the start of the button content.\n * Use Phosphor icons for consistent styling.\n * @example <Button StartIcon={House}>Home</Button>\n */\n StartIcon?: Icon\n\n /**\n * Icon component to display at the end of the button content.\n * Use Phosphor icons for consistent styling.\n * @example <Button EndIcon={ArrowRight}>Next</Button>\n */\n EndIcon?: Icon\n\n /**\n * When true, displays a loading spinner and disables the button.\n * The spinner replaces the StartIcon if present.\n * @default false\n */\n loading?: boolean\n\n /**\n * When true, creates a circular button with only the StartIcon visible.\n * @default false\n */\n iconOnly?: boolean\n\n /**\n * The content to display inside the button.\n * Not displayed when iconOnly is true.\n */\n children?: React.ReactNode\n\n /**\n * Custom props to pass to the icons (StartIcon, EndIcon, SpinnerGap).\n * Allows overriding size, weight, color, etc.\n */\n iconProps?: Partial<IconProps>\n} & React.ButtonHTMLAttributes<HTMLButtonElement> &\n VariantProps<typeof buttonVariants>\n\n/**\n * A versatile button component that supports multiple variants, sizes, and icon placements.\n *\n * @example\n * // Basic usage\n * <Button>Click me</Button>\n *\n * // With icon\n * <Button StartIcon={House}>Home</Button>\n *\n * // Icon only button\n * <Button StartIcon={Plus} iconOnly aria-label=\"Add item\" />\n *\n * // Loading state\n * <Button loading>Processing...</Button>\n */\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n { className, variant = 'primary', size = 'md', StartIcon, EndIcon, loading, iconOnly, iconProps = {}, ...props },\n ref,\n ) => {\n const defaultIconProps = (): { size: number; weight: IconWeight } => {\n switch (size) {\n case 'sm':\n return { size: 16, weight: 'regular' }\n case 'lg':\n return { size: 20, weight: 'regular' }\n default:\n return { size: 18, weight: 'regular' }\n }\n }\n const mergedIconProps = { ...defaultIconProps(), ...iconProps }\n const getIconOnlyClasses = () => {\n switch (size) {\n case 'sm':\n return 'h-8 w-8'\n case 'lg':\n return 'h-12 w-12'\n default:\n return 'h-10 w-10'\n }\n }\n\n return (\n <button\n className={cn(\n buttonVariants({ variant, size, className }),\n iconOnly && 'rounded-full p-0',\n iconOnly && getIconOnlyClasses(),\n className,\n )}\n ref={ref}\n disabled={loading}\n {...props}\n >\n {loading && <SpinnerGapIcon {...defaultIconProps()} className=\"animate-spin\" aria-label=\"Loading\" />}\n {StartIcon && !loading && <StartIcon {...mergedIconProps} className=\"shrink-0\" />}\n {iconOnly ? <span className=\"sr-only\">{props.children}</span> : props.children}\n {EndIcon && !iconOnly && <EndIcon {...mergedIconProps} className=\"shrink-0\" />}\n </button>\n )\n },\n)\nButton.displayName = 'Button'\n\nexport { Button, buttonVariants }\n"],"mappings":";;;;;;;AAQA,IAAM,iBAAiB,IACrB,+OACA;CACE,UAAU;;;;EAIR,SAAS;GACP,SACE;GACF,WACE;GACF,OACE;GACF,iBACE;GACF,MAAM;GACN,OACE;GACF,SACE;GACF,OACE;EACJ;;;;EAIA,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;CACF;CACA,kBAAkB,CAChB;EACE,SAAS;EACT,MAAM;GAAC;GAAM;GAAM;EAAI;EACvB,WAAW,mBAAmB,EAAE,SAAS,UAAU,CAAC;CACtD,CACF;CACA,iBAAiB;EACf,SAAS;EACT,MAAM;CACR;AACF,CACF;;;;;;;;;;;;;;;;;AAwEA,IAAM,SAASA,QAAM,YAEjB,EAAE,WAAW,UAAU,WAAW,OAAO,MAAM,WAAW,SAAS,SAAS,UAAU,YAAY,CAAC,GAAG,GAAG,SACzG,QACG;CACH,MAAM,yBAA+D;EACnE,QAAQ,MAAR;GACE,KAAK,MACH,OAAO;IAAE,MAAM;IAAI,QAAQ;GAAU;GACvC,KAAK,MACH,OAAO;IAAE,MAAM;IAAI,QAAQ;GAAU;GACvC,SACE,OAAO;IAAE,MAAM;IAAI,QAAQ;GAAU;EACzC;CACF;CACA,MAAM,kBAAkB;EAAE,GAAG,iBAAiB;EAAG,GAAG;CAAU;CAC9D,MAAM,2BAA2B;EAC/B,QAAQ,MAAR;GACE,KAAK,MACH,OAAO;GACT,KAAK,MACH,OAAO;GACT,SACE,OAAO;EACX;CACF;CAEA,OACE,qBAAC,UAAD;EACE,WAAW,GACT,eAAe;GAAE;GAAS;GAAM;EAAU,CAAC,GAC3C,YAAY,oBACZ,YAAY,mBAAmB,GAC/B,SACF;EACK;EACL,UAAU;EACV,GAAI;EATN,UAAA;GAWG,WAAW,oBAAC,gBAAD;IAAgB,GAAI,iBAAiB;IAAG,WAAU;IAAe,cAAW;GAAW,CAAA;GAClG,aAAa,CAAC,WAAW,oBAAC,WAAD;IAAW,GAAI;IAAiB,WAAU;GAAY,CAAA;GAC/E,WAAW,oBAAC,QAAD;IAAM,WAAU;IAAW,UAAA,MAAM;GAAe,CAAA,IAAI,MAAM;GACrE,WAAW,CAAC,YAAY,oBAAC,SAAD;IAAS,GAAI;IAAiB,WAAU;GAAY,CAAA;EACvE;;AAEZ,CACF;AACA,OAAO,cAAc"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from "../../../lib/utils.js";
|
|
2
|
+
import { SURFACE_LIST } from "../../../lib/surface.js";
|
|
2
3
|
import { useListScroll } from "../../../lib/useListScroll.js";
|
|
3
4
|
import { Command, CommandInput } from "../../utils/Command/Command.js";
|
|
4
5
|
import { PopoverContent, PopoverRoot, PopoverTrigger } from "../../utils/Popover/Popover.js";
|
|
@@ -85,7 +86,7 @@ var Combobox = (props) => {
|
|
|
85
86
|
onClick: handleClear
|
|
86
87
|
})]
|
|
87
88
|
}), /* @__PURE__ */ jsx(PopoverContent, {
|
|
88
|
-
className: cn("overflow-hidden p-0", contentClassName),
|
|
89
|
+
className: cn(SURFACE_LIST, "overflow-hidden p-0", contentClassName),
|
|
89
90
|
container,
|
|
90
91
|
side: "bottom",
|
|
91
92
|
align,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","names":[],"sources":["../../../../src/components/inputs/Combobox/Combobox.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport { useEffect, useRef } from 'react'\n\nimport { useListScroll } from '../../../lib/useListScroll'\nimport { cn } from '../../../lib/utils'\nimport { Command, CommandInput } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\n\nimport { ComboboxTrigger } from './ComboboxTrigger'\nimport { StaticComboboxList } from './StaticComboboxList'\nimport { useCombobox } from './useCombobox'\nimport { VirtualizedComboboxList } from './VirtualizedComboboxList'\n\ntype ComboboxBaseProps<T> = {\n /** Unique identifier for the combobox */\n id?: string\n /** Array of options to display in the combobox (static mode). */\n options?: Array<T>\n /** Function to get the unique identifier from an option. */\n getOptionValue: (option: T) => string\n /** Function to get the display text from an option. */\n getOptionLabel: (option: T) => string\n /** Custom render function for options. If not provided, defaults to showing a checkmark and label */\n renderOption?: (option: T, isSelected: boolean) => React.ReactNode\n /** Placeholder text shown when no option is selected */\n placeholder?: React.ReactNode\n /** Placeholder text for the search input field */\n searchPlaceholder?: string\n /** Message shown when no options match the search query */\n emptyMessage?: string\n /** Additional CSS classes to apply to the combobox trigger */\n className?: string\n /** Additional CSS classes to apply to the popover content */\n contentClassName?: string\n /** Whether the combobox is disabled */\n disabled?: boolean\n /** Maximum height of the options list. Can be any valid CSS height value */\n maxHeight?: string | number\n /** Whether to close the dropdown when an option is selected. Defaults to `true` for single select and `false` for multi-select. */\n closeOnSelect?: boolean\n /** Whether the combobox is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the combobox has an error */\n error?: boolean | string\n /** Custom function to filter options based on search term (static mode only) */\n filterOptions?: (options: Array<T>, searchTerm: string) => Array<T>\n /** Callback function executed when the clear button is clicked. When provided, an X button will appear on hover to clear the selection. */\n onClear?: boolean | (() => void)\n /** Whether the selection can be cleared */\n clearable?: boolean\n /** Whether the combobox is inside a modal */\n modal?: boolean\n /** Placeholder text for the selected multiple options */\n selectedMultiplePlaceholder?: string\n /** Placeholder text for the multiple options */\n multipleOptionsPlaceholder?: string\n /** Pinned above a separator. Selecting one switches multi-select to single-select. */\n specialOptions?: Array<T>\n /** Heading for the special options group */\n specialOptionsTitle?: string\n /** Container element to position the combobox relative to. */\n container?: HTMLElement\n /** Alignment of the dropdown relative to the trigger. Defaults to 'center'. */\n align?: 'start' | 'center' | 'end'\n /** Auto-focus the search input when the dropdown opens. */\n onOpenAutoFocus?: boolean\n /** Defaults to `!!error`. */\n 'aria-invalid'?: boolean\n 'aria-describedby'?: string\n}\n\nexport type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {\n virtualized?: false\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n}\n\nexport type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {\n virtualized?: false\n multiple: true\n value?: Array<string>\n onChange: (value: Array<string>) => void\n /** Custom render function for the selected value(s) display. */\n renderLabel?: (selectedOptions: Array<T>, onRemove: (value: string) => void) => React.ReactNode\n}\n\ntype ComboboxRemoteVirtualizedProps<T> = {\n /** The accumulated, flattened list of loaded items. */\n items: Array<T>\n /** Whether more pages can be loaded. */\n hasNextPage: boolean\n /** Whether the next page is currently being fetched. */\n isFetchingNextPage: boolean\n /** Request the next page (triggered near the end of the list). */\n onLoadMore: () => void\n /** Emitted (debounced) when the search term changes. The consumer refetches. */\n onSearchChange: (search: string) => void\n}\n\n/** Pass none of `ComboboxRemoteVirtualizedProps`'s fields to virtualize the local `options`\n * list instead (filtered the same way static mode is). */\ntype ComboboxLocalVirtualizedProps = {\n items?: undefined\n hasNextPage?: undefined\n isFetchingNextPage?: undefined\n onLoadMore?: undefined\n onSearchChange?: undefined\n}\n\nexport type ComboboxVirtualizedProps<T> = ComboboxBaseProps<T> & {\n virtualized: true\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n /** The resolved selected item, fetched independently of the list. Used for the trigger label. */\n selectedItem?: T\n /** Estimated row height (px), default: 40. */\n estimateSize?: number\n} & (ComboboxRemoteVirtualizedProps<T> | ComboboxLocalVirtualizedProps)\n\nexport type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T> | ComboboxVirtualizedProps<T>\n\n/**\n * A searchable combobox component with support for custom rendering, keyboard navigation, and search filtering.\n *\n * @example Basic usage\n * ```tsx\n * <Combobox<User>\n * options={users}\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * />\n * ```\n */\nexport const Combobox = <T extends object>(props: ComboboxProps<T>) => {\n const {\n id,\n options = [],\n getOptionValue,\n getOptionLabel,\n searchPlaceholder = 'Search...',\n emptyMessage = 'No results found.',\n className = 'w-60',\n contentClassName,\n disabled = false,\n maxHeight = '300px',\n renderOption,\n loading = false,\n loadingPlaceholder = 'Cargando...',\n error = false,\n multiple,\n onClear,\n modal = false,\n selectedMultiplePlaceholder = 'Selected',\n multipleOptionsPlaceholder = 'Options',\n specialOptionsTitle,\n container,\n align,\n onOpenAutoFocus = false,\n 'aria-invalid': ariaInvalid,\n 'aria-describedby': ariaDescribedBy,\n } = props\n\n const searchInputRef = useRef<HTMLInputElement>(null)\n const normalizedMaxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight\n const boundedListMaxHeight = `min(${normalizedMaxHeight}, max(120px, calc(var(--radix-popover-content-available-height, 100dvh) - 68px)))`\n\n const {\n open,\n setOpen,\n searchTerm,\n setSearchTerm,\n setIsHovered,\n hasNextPage,\n loadingMore,\n isVirtualized,\n filteredOptions,\n filteredSpecialOptions,\n displayValue,\n hasValue,\n showClearButton,\n handleSelect,\n handleClear,\n loadNextPage,\n } = useCombobox(props)\n\n const singleValue = typeof props.value === 'string' && props.value ? props.value : undefined\n\n useEffect(() => {\n if (!open || !onOpenAutoFocus) return\n const timeoutId = globalThis.setTimeout(() => searchInputRef.current?.focus(), 0)\n return () => globalThis.clearTimeout(timeoutId)\n }, [open, onOpenAutoFocus])\n\n const listRef = useListScroll({\n open,\n searchTerm,\n selectedValue: isVirtualized ? undefined : singleValue,\n })\n\n const hasMultipleRenderLabel = !!(multiple && 'renderLabel' in props && props.renderLabel)\n\n return (\n <div className=\"flex w-full flex-col gap-1\">\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <div\n className={cn('relative', className)}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <PopoverTrigger\n asChild\n onPointerDown={(event) => {\n event.stopPropagation()\n if (open) {\n setOpen(false)\n event.preventDefault()\n } else {\n setOpen(true)\n }\n }}\n onClick={(event) => {\n if (event.detail === 0) return\n event.preventDefault()\n event.stopPropagation()\n }}\n >\n <ComboboxTrigger\n id={id}\n disabled={disabled}\n open={open}\n error={error}\n hasValue={hasValue}\n showClearButton={showClearButton}\n isMultilineLabel={hasMultipleRenderLabel}\n displayValue={displayValue}\n className={cn('w-full', className)}\n aria-invalid={ariaInvalid ?? (!!error || undefined)}\n aria-describedby={ariaDescribedBy}\n />\n </PopoverTrigger>\n {!!onClear && hasValue && (\n <XIcon\n data-testid=\"clear-button\"\n className={cn(\n 'absolute top-1/2 right-4 z-10 h-4 w-4 -translate-y-1/2 cursor-pointer transition-opacity duration-150',\n showClearButton ? 'opacity-100 hover:opacity-70' : 'opacity-0',\n )}\n onPointerDown={(event) => event.stopPropagation()}\n onClick={handleClear}\n />\n )}\n </div>\n <PopoverContent\n className={cn('overflow-hidden p-0', contentClassName)}\n container={container}\n side=\"bottom\"\n align={align}\n onOpenAutoFocus={onOpenAutoFocus ? (event) => event.preventDefault() : undefined}\n >\n <Command shouldFilter={false} defaultValue={singleValue}>\n <CommandInput\n ref={searchInputRef}\n placeholder={searchPlaceholder}\n value={searchTerm}\n onValueChange={setSearchTerm}\n />\n {isVirtualized ? (\n <VirtualizedComboboxList\n listRef={listRef}\n localOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n value={props.value as string}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n hasNextPage={hasNextPage}\n loadingMore={loadingMore}\n onLoadMore={loadNextPage}\n estimateSize={'estimateSize' in props ? props.estimateSize : undefined}\n specialOptions={filteredSpecialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n ) : (\n <StaticComboboxList\n listRef={listRef}\n filteredOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n multiple={!!multiple}\n value={props.value}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n selectedMultiplePlaceholder={selectedMultiplePlaceholder}\n multipleOptionsPlaceholder={multipleOptionsPlaceholder}\n options={options}\n specialOptions={filteredSpecialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n )}\n </Command>\n </PopoverContent>\n </PopoverRoot>\n {typeof error === 'string' && <span className=\"text-error-500 text-sm\">{error}</span>}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+IA,IAAa,YAA8B,UAA4B;CACrE,MAAM,EACJ,IACA,UAAU,CAAC,GACX,gBACA,gBACA,oBAAoB,aACpB,eAAe,qBACf,YAAY,QACZ,kBACA,WAAW,OACX,YAAY,SACZ,cACA,UAAU,OACV,qBAAqB,eACrB,QAAQ,OACR,UACA,SACA,QAAQ,OACR,8BAA8B,YAC9B,6BAA6B,WAC7B,qBACA,WACA,OACA,kBAAkB,OAClB,gBAAgB,aAChB,oBAAoB,oBAClB;CAEJ,MAAM,iB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ACnB,CAAA;IACa,CAAA,GACf,CAAC,CAAC,WAAW,YACZ,oBAAC,OAAD;KACE,eAAY;KACZ,WAAW,GACT,yGACA,kBAAkB,iCAAiC,WACrD;KACA,gBAAgB,UAAU,MAAM,gBAAgB;KAChD,SAAS;IACV,CAAA,CAEA;GACL,CAAA,GAAA,oBAAC,gBAAD;IACE,WAAW,GAAG,uBAAuB,gBAAgB;IAC1C;IACX,MAAK;IACE;IACP,iBAAiB,mBAAmB,UAAU,MAAM,eAAe,IAAI,KAAA;IAEvE,UAAA,qBAAC,SAAD;KAAS,cAAc;KAAO,cAAc;KAA5C,UAAA,CACE,oBAAC,cAAD;MACE,KAAK;MACL,aAAa;MACb,OAAO;MACP,eAAe;KAChB,CAAA,GACA,gBACC,oBAAC,yBAAD;MACW;MACT,cAAc;MACL;MACW;MACN;MACd,OAAO,MAAM;MACG;MACA;MACF;MACA;MACd,WAAW;MACE;MACA;MACb,YAAY;MACZ,cAAc,kBAAkB,QAAQ,MAAM,eAAe,KAAA;MAC7D,gBAAgB;MACK;KACtB,CAAA,IAED,oBAAC,oBAAD;MACW;MACQ;MACR;MACW;MACN;MACd,UAAU,CAAC,CAAC;MACZ,OAAO,MAAM;MACG;MACA;MACF;MACA;MACd,WAAW;MACkB;MACD;MACnB;MACT,gBAAgB;MACK;KACtB,CAAA,CAEI;;GACK,CAAA,CACL;EACZ,CAAA,GAAA,OAAO,UAAU,YAAY,oBAAC,QAAD;GAAM,WAAU;GAA0B,UAAA;EAAY,CAAA,CACjF;;AAET"}
|
|
1
|
+
{"version":3,"file":"Combobox.js","names":[],"sources":["../../../../src/components/inputs/Combobox/Combobox.tsx"],"sourcesContent":["import { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport { useEffect, useRef } from 'react'\n\nimport { SURFACE_LIST } from '../../../lib/surface'\nimport { useListScroll } from '../../../lib/useListScroll'\nimport { cn } from '../../../lib/utils'\nimport { Command, CommandInput } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\n\nimport { ComboboxTrigger } from './ComboboxTrigger'\nimport { StaticComboboxList } from './StaticComboboxList'\nimport { useCombobox } from './useCombobox'\nimport { VirtualizedComboboxList } from './VirtualizedComboboxList'\n\ntype ComboboxBaseProps<T> = {\n /** Unique identifier for the combobox */\n id?: string\n /** Array of options to display in the combobox (static mode). */\n options?: Array<T>\n /** Function to get the unique identifier from an option. */\n getOptionValue: (option: T) => string\n /** Function to get the display text from an option. */\n getOptionLabel: (option: T) => string\n /** Custom render function for options. If not provided, defaults to showing a checkmark and label */\n renderOption?: (option: T, isSelected: boolean) => React.ReactNode\n /** Placeholder text shown when no option is selected */\n placeholder?: React.ReactNode\n /** Placeholder text for the search input field */\n searchPlaceholder?: string\n /** Message shown when no options match the search query */\n emptyMessage?: string\n /** Additional CSS classes to apply to the combobox trigger */\n className?: string\n /** Additional CSS classes to apply to the popover content */\n contentClassName?: string\n /** Whether the combobox is disabled */\n disabled?: boolean\n /** Maximum height of the options list. Can be any valid CSS height value */\n maxHeight?: string | number\n /** Whether to close the dropdown when an option is selected. Defaults to `true` for single select and `false` for multi-select. */\n closeOnSelect?: boolean\n /** Whether the combobox is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the combobox has an error */\n error?: boolean | string\n /** Custom function to filter options based on search term (static mode only) */\n filterOptions?: (options: Array<T>, searchTerm: string) => Array<T>\n /** Callback function executed when the clear button is clicked. When provided, an X button will appear on hover to clear the selection. */\n onClear?: boolean | (() => void)\n /** Whether the selection can be cleared */\n clearable?: boolean\n /** Whether the combobox is inside a modal */\n modal?: boolean\n /** Placeholder text for the selected multiple options */\n selectedMultiplePlaceholder?: string\n /** Placeholder text for the multiple options */\n multipleOptionsPlaceholder?: string\n /** Pinned above a separator. Selecting one switches multi-select to single-select. */\n specialOptions?: Array<T>\n /** Heading for the special options group */\n specialOptionsTitle?: string\n /** Container element to position the combobox relative to. */\n container?: HTMLElement\n /** Alignment of the dropdown relative to the trigger. Defaults to 'center'. */\n align?: 'start' | 'center' | 'end'\n /** Auto-focus the search input when the dropdown opens. */\n onOpenAutoFocus?: boolean\n /** Defaults to `!!error`. */\n 'aria-invalid'?: boolean\n 'aria-describedby'?: string\n}\n\nexport type ComboboxSingleProps<T> = ComboboxBaseProps<T> & {\n virtualized?: false\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n}\n\nexport type ComboboxMultipleProps<T> = ComboboxBaseProps<T> & {\n virtualized?: false\n multiple: true\n value?: Array<string>\n onChange: (value: Array<string>) => void\n /** Custom render function for the selected value(s) display. */\n renderLabel?: (selectedOptions: Array<T>, onRemove: (value: string) => void) => React.ReactNode\n}\n\ntype ComboboxRemoteVirtualizedProps<T> = {\n /** The accumulated, flattened list of loaded items. */\n items: Array<T>\n /** Whether more pages can be loaded. */\n hasNextPage: boolean\n /** Whether the next page is currently being fetched. */\n isFetchingNextPage: boolean\n /** Request the next page (triggered near the end of the list). */\n onLoadMore: () => void\n /** Emitted (debounced) when the search term changes. The consumer refetches. */\n onSearchChange: (search: string) => void\n}\n\n/** Pass none of `ComboboxRemoteVirtualizedProps`'s fields to virtualize the local `options`\n * list instead (filtered the same way static mode is). */\ntype ComboboxLocalVirtualizedProps = {\n items?: undefined\n hasNextPage?: undefined\n isFetchingNextPage?: undefined\n onLoadMore?: undefined\n onSearchChange?: undefined\n}\n\nexport type ComboboxVirtualizedProps<T> = ComboboxBaseProps<T> & {\n virtualized: true\n multiple?: false\n value?: string\n onChange: (value: string) => void\n /** Custom render function for the selected value display. */\n renderLabel?: (selectedOption: T) => React.ReactNode\n /** The resolved selected item, fetched independently of the list. Used for the trigger label. */\n selectedItem?: T\n /** Estimated row height (px), default: 40. */\n estimateSize?: number\n} & (ComboboxRemoteVirtualizedProps<T> | ComboboxLocalVirtualizedProps)\n\nexport type ComboboxProps<T> = ComboboxSingleProps<T> | ComboboxMultipleProps<T> | ComboboxVirtualizedProps<T>\n\n/**\n * A searchable combobox component with support for custom rendering, keyboard navigation, and search filtering.\n *\n * @example Basic usage\n * ```tsx\n * <Combobox<User>\n * options={users}\n * value={selectedUserId}\n * onChange={setSelectedUserId}\n * getOptionValue={(user) => user.id}\n * getOptionLabel={(user) => user.name}\n * />\n * ```\n */\nexport const Combobox = <T extends object>(props: ComboboxProps<T>) => {\n const {\n id,\n options = [],\n getOptionValue,\n getOptionLabel,\n searchPlaceholder = 'Search...',\n emptyMessage = 'No results found.',\n className = 'w-60',\n contentClassName,\n disabled = false,\n maxHeight = '300px',\n renderOption,\n loading = false,\n loadingPlaceholder = 'Cargando...',\n error = false,\n multiple,\n onClear,\n modal = false,\n selectedMultiplePlaceholder = 'Selected',\n multipleOptionsPlaceholder = 'Options',\n specialOptionsTitle,\n container,\n align,\n onOpenAutoFocus = false,\n 'aria-invalid': ariaInvalid,\n 'aria-describedby': ariaDescribedBy,\n } = props\n\n const searchInputRef = useRef<HTMLInputElement>(null)\n const normalizedMaxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight\n const boundedListMaxHeight = `min(${normalizedMaxHeight}, max(120px, calc(var(--radix-popover-content-available-height, 100dvh) - 68px)))`\n\n const {\n open,\n setOpen,\n searchTerm,\n setSearchTerm,\n setIsHovered,\n hasNextPage,\n loadingMore,\n isVirtualized,\n filteredOptions,\n filteredSpecialOptions,\n displayValue,\n hasValue,\n showClearButton,\n handleSelect,\n handleClear,\n loadNextPage,\n } = useCombobox(props)\n\n const singleValue = typeof props.value === 'string' && props.value ? props.value : undefined\n\n useEffect(() => {\n if (!open || !onOpenAutoFocus) return\n const timeoutId = globalThis.setTimeout(() => searchInputRef.current?.focus(), 0)\n return () => globalThis.clearTimeout(timeoutId)\n }, [open, onOpenAutoFocus])\n\n const listRef = useListScroll({\n open,\n searchTerm,\n selectedValue: isVirtualized ? undefined : singleValue,\n })\n\n const hasMultipleRenderLabel = !!(multiple && 'renderLabel' in props && props.renderLabel)\n\n return (\n <div className=\"flex w-full flex-col gap-1\">\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <div\n className={cn('relative', className)}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <PopoverTrigger\n asChild\n onPointerDown={(event) => {\n event.stopPropagation()\n if (open) {\n setOpen(false)\n event.preventDefault()\n } else {\n setOpen(true)\n }\n }}\n onClick={(event) => {\n if (event.detail === 0) return\n event.preventDefault()\n event.stopPropagation()\n }}\n >\n <ComboboxTrigger\n id={id}\n disabled={disabled}\n open={open}\n error={error}\n hasValue={hasValue}\n showClearButton={showClearButton}\n isMultilineLabel={hasMultipleRenderLabel}\n displayValue={displayValue}\n className={cn('w-full', className)}\n aria-invalid={ariaInvalid ?? (!!error || undefined)}\n aria-describedby={ariaDescribedBy}\n />\n </PopoverTrigger>\n {!!onClear && hasValue && (\n <XIcon\n data-testid=\"clear-button\"\n className={cn(\n 'absolute top-1/2 right-4 z-10 h-4 w-4 -translate-y-1/2 cursor-pointer transition-opacity duration-150',\n showClearButton ? 'opacity-100 hover:opacity-70' : 'opacity-0',\n )}\n onPointerDown={(event) => event.stopPropagation()}\n onClick={handleClear}\n />\n )}\n </div>\n <PopoverContent\n className={cn(SURFACE_LIST, 'overflow-hidden p-0', contentClassName)}\n container={container}\n side=\"bottom\"\n align={align}\n onOpenAutoFocus={onOpenAutoFocus ? (event) => event.preventDefault() : undefined}\n >\n <Command shouldFilter={false} defaultValue={singleValue}>\n <CommandInput\n ref={searchInputRef}\n placeholder={searchPlaceholder}\n value={searchTerm}\n onValueChange={setSearchTerm}\n />\n {isVirtualized ? (\n <VirtualizedComboboxList\n listRef={listRef}\n localOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n value={props.value as string}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n hasNextPage={hasNextPage}\n loadingMore={loadingMore}\n onLoadMore={loadNextPage}\n estimateSize={'estimateSize' in props ? props.estimateSize : undefined}\n specialOptions={filteredSpecialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n ) : (\n <StaticComboboxList\n listRef={listRef}\n filteredOptions={filteredOptions}\n loading={loading}\n loadingPlaceholder={loadingPlaceholder}\n emptyMessage={emptyMessage}\n multiple={!!multiple}\n value={props.value}\n getOptionValue={getOptionValue}\n getOptionLabel={getOptionLabel}\n handleSelect={handleSelect}\n renderOption={renderOption}\n maxHeight={boundedListMaxHeight}\n selectedMultiplePlaceholder={selectedMultiplePlaceholder}\n multipleOptionsPlaceholder={multipleOptionsPlaceholder}\n options={options}\n specialOptions={filteredSpecialOptions}\n specialOptionsTitle={specialOptionsTitle}\n />\n )}\n </Command>\n </PopoverContent>\n </PopoverRoot>\n {typeof error === 'string' && <span className=\"text-error-500 text-sm\">{error}</span>}\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJA,IAAa,YAA8B,UAA4B;CACrE,MAAM,EACJ,IACA,UAAU,CAAC,GACX,gBACA,gBACA,oBAAoB,aACpB,eAAe,qBACf,YAAY,QACZ,kBACA,WAAW,OACX,YAAY,SACZ,cACA,UAAU,OACV,qBAAqB,eACrB,QAAQ,OACR,UACA,SACA,QAAQ,OACR,8BAA8B,YAC9B,6BAA6B,WAC7B,qBACA,WACA,OACA,kBAAkB,OAClB,gBAAgB,aAChB,oBAAoB,oBAClB;CAEJ,MAAM,iBAAiB,OAAyB,IAAI;CAEpD,MAAM,uBAAuB,OADD,OAAO,cAAc,WAAW,GAAG,UAAU,MAAM,UACvB;CAExD,MAAM,EACJ,MACA,SACA,YACA,eACA,cACA,aACA,aACA,eACA,iBACA,wBACA,cACA,UACA,iBACA,cACA,aACA,iBACE,YAAY,KAAK;CAErB,MAAM,cAAc,OAAO,MAAM,UAAU,YAAY,MAAM,QAAQ,MAAM,QAAQ,KA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IACE;IACP,iBAAiB,mBAAmB,UAAU,MAAM,eAAe,IAAI,KAAA;IAEvE,UAAA,qBAAC,SAAD;KAAS,cAAc;KAAO,cAAc;KAA5C,UAAA,CACE,oBAAC,cAAD;MACE,KAAK;MACL,aAAa;MACb,OAAO;MACP,eAAe;KAChB,CAAA,GACA,gBACC,oBAAC,yBAAD;MACW;MACT,cAAc;MACL;MACW;MACN;MACd,OAAO,MAAM;MACG;MACA;MACF;MACA;MACd,WAAW;MACE;MACA;MACb,YAAY;MACZ,cAAc,kBAAkB,QAAQ,MAAM,eAAe,KAAA;MAC7D,gBAAgB;MACK;KACtB,CAAA,IAED,oBAAC,oBAAD;MACW;MACQ;MACR;MACW;MACN;MACd,UAAU,CAAC,CAAC;MACZ,OAAO,MAAM;MACG;MACA;MACF;MACA;MACd,WAAW;MACkB;MACD;MACnB;MACT,gBAAgB;MACK;KACtB,CAAA,CAEI;;GACK,CAAA,CACL;EACZ,CAAA,GAAA,OAAO,UAAU,YAAY,oBAAC,QAAD;GAAM,WAAU;GAA0B,UAAA;EAAY,CAAA,CACjF;;AAET"}
|
|
@@ -66,14 +66,13 @@ var StaticComboboxList = ({ filteredOptions, loading, loadingPlaceholder, emptyM
|
|
|
66
66
|
return /* @__PURE__ */ jsx(CommandItem, {
|
|
67
67
|
value: optionValue,
|
|
68
68
|
onSelect: handleSelect,
|
|
69
|
-
className: "px-3",
|
|
70
69
|
children: renderOption ? renderOption(option, selected) : /* @__PURE__ */ jsxs(Fragment, { children: [renderSelectionIndicator(), /* @__PURE__ */ jsx(ComboboxOptionWithTooltip, { label: getOptionLabel(option) })] })
|
|
71
70
|
}, optionValue);
|
|
72
71
|
};
|
|
73
72
|
return /* @__PURE__ */ jsx(CommandList, {
|
|
74
73
|
ref: listRef,
|
|
75
74
|
style: { maxHeight },
|
|
76
|
-
className: "overflow-auto overscroll-contain
|
|
75
|
+
className: "overflow-auto overscroll-contain",
|
|
77
76
|
onWheel: (event) => event.stopPropagation(),
|
|
78
77
|
children: loading ? /* @__PURE__ */ jsx("div", {
|
|
79
78
|
className: "flex items-center justify-center py-6 text-sm text-neutral-400",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticComboboxList.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/Combobox/StaticComboboxList.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useMemo } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../../utils/Command'\nimport { Checkbox } from '../Checkbox'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { StaticComboboxListProps } from './types'\n\nexport const StaticComboboxList = <T extends object>({\n filteredOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n multiple,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n selectedMultiplePlaceholder,\n multipleOptionsPlaceholder,\n options,\n specialOptions,\n specialOptionsTitle,\n listRef,\n}: StaticComboboxListProps<T>) => {\n const isArrayValue = Array.isArray(value)\n const selectedValues = useMemo(() => (multiple && isArrayValue ? value : []), [multiple, isArrayValue, value])\n\n const isOptionSelected = (optionValue: string) =>\n multiple ? selectedValues.includes(optionValue) : value === optionValue\n\n const regularOptions = useMemo(() => {\n return filteredOptions.filter(\n (option) => !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [filteredOptions, specialOptions, getOptionValue])\n\n const regularSelectedOptions = useMemo(() => {\n if (!multiple || !isArrayValue) return []\n\n return options.filter(\n (option) =>\n selectedValues.includes(getOptionValue(option)) &&\n !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [options, selectedValues, specialOptions, getOptionValue, multiple, isArrayValue])\n\n const optionsToShow = useMemo(() => {\n if (specialOptions) return regularOptions\n\n if (!multiple || !isArrayValue) return regularOptions\n\n return regularOptions.filter((option) => !selectedValues.includes(getOptionValue(option)))\n }, [regularOptions, specialOptions, selectedValues, getOptionValue, multiple, isArrayValue])\n\n const groupHeading = !specialOptions && multiple ? multipleOptionsPlaceholder : undefined\n\n const renderListOption = (option: T) => {\n const optionValue = getOptionValue(option)\n const selected = isOptionSelected(optionValue)\n\n const renderSelectionIndicator = () => {\n if (multiple) {\n return <Checkbox checked={selected} tabIndex={-1} aria-hidden className=\"pointer-events-none mr-2 shrink-0\" />\n }\n\n return (\n <span aria-hidden className=\"mr-1 flex h-6! w-6! shrink-0 items-center justify-end\">\n {selected && <CheckIcon weight=\"bold\" className=\"h-4! w-4!\" />}\n </span>\n )\n }\n\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}
|
|
1
|
+
{"version":3,"file":"StaticComboboxList.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/Combobox/StaticComboboxList.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useMemo } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../../utils/Command'\nimport { Checkbox } from '../Checkbox'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { StaticComboboxListProps } from './types'\n\nexport const StaticComboboxList = <T extends object>({\n filteredOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n multiple,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n selectedMultiplePlaceholder,\n multipleOptionsPlaceholder,\n options,\n specialOptions,\n specialOptionsTitle,\n listRef,\n}: StaticComboboxListProps<T>) => {\n const isArrayValue = Array.isArray(value)\n const selectedValues = useMemo(() => (multiple && isArrayValue ? value : []), [multiple, isArrayValue, value])\n\n const isOptionSelected = (optionValue: string) =>\n multiple ? selectedValues.includes(optionValue) : value === optionValue\n\n const regularOptions = useMemo(() => {\n return filteredOptions.filter(\n (option) => !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [filteredOptions, specialOptions, getOptionValue])\n\n const regularSelectedOptions = useMemo(() => {\n if (!multiple || !isArrayValue) return []\n\n return options.filter(\n (option) =>\n selectedValues.includes(getOptionValue(option)) &&\n !specialOptions?.some((special) => getOptionValue(special) === getOptionValue(option)),\n )\n }, [options, selectedValues, specialOptions, getOptionValue, multiple, isArrayValue])\n\n const optionsToShow = useMemo(() => {\n if (specialOptions) return regularOptions\n\n if (!multiple || !isArrayValue) return regularOptions\n\n return regularOptions.filter((option) => !selectedValues.includes(getOptionValue(option)))\n }, [regularOptions, specialOptions, selectedValues, getOptionValue, multiple, isArrayValue])\n\n const groupHeading = !specialOptions && multiple ? multipleOptionsPlaceholder : undefined\n\n const renderListOption = (option: T) => {\n const optionValue = getOptionValue(option)\n const selected = isOptionSelected(optionValue)\n\n const renderSelectionIndicator = () => {\n if (multiple) {\n return <Checkbox checked={selected} tabIndex={-1} aria-hidden className=\"pointer-events-none mr-2 shrink-0\" />\n }\n\n return (\n <span aria-hidden className=\"mr-1 flex h-6! w-6! shrink-0 items-center justify-end\">\n {selected && <CheckIcon weight=\"bold\" className=\"h-4! w-4!\" />}\n </span>\n )\n }\n\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, selected)\n ) : (\n <>\n {renderSelectionIndicator()}\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n )\n }\n\n return (\n <CommandList\n ref={listRef}\n style={{ maxHeight }}\n className=\"overflow-auto overscroll-contain\"\n onWheel={(event) => event.stopPropagation()}\n >\n {loading ? (\n <div className=\"flex items-center justify-center py-6 text-sm text-neutral-400\">{loadingPlaceholder}</div>\n ) : (\n <>\n {filteredOptions.length === 0 &&\n regularOptions.length === 0 &&\n (!specialOptions || specialOptions.length === 0) && <CommandEmpty>{emptyMessage}</CommandEmpty>}\n\n {specialOptions?.length ? (\n <>\n <CommandGroup heading={specialOptionsTitle}>{specialOptions.map(renderListOption)}</CommandGroup>\n\n {optionsToShow.length > 0 && <CommandSeparator className=\"mx-1\" />}\n </>\n ) : null}\n\n {!specialOptions && multiple && isArrayValue && regularSelectedOptions.length > 0 && (\n <CommandGroup heading={selectedMultiplePlaceholder}>\n {regularSelectedOptions.map(renderListOption)}\n </CommandGroup>\n )}\n\n {optionsToShow.length > 0 && (\n <CommandGroup heading={groupHeading}>{optionsToShow.map(renderListOption)}</CommandGroup>\n )}\n </>\n )}\n </CommandList>\n )\n}\n"],"mappings":";;;;;;;AASA,IAAa,sBAAwC,EACnD,iBACA,SACA,oBACA,cACA,UACA,OACA,gBACA,gBACA,cACA,cACA,WACA,6BACA,4BACA,SACA,gBACA,qBACA,cACgC;CAChC,MAAM,eAAe,MAAM,QAAQ,KAAK;CACxC,MAAM,iBAAiB,cAAe,YAAY,eAAe,QAAQ,CAAC,GAAI;EAAC;EAAU;EAAc;CAAK,CAAC;CAE7G,MAAM,oBAAoB,gBACxB,WAAW,eAAe,SAAS,WAAW,IAAI,UAAU;CAE9D,MAAM,iBAAiB,cAAc;EACnC,OAAO,gBAAgB,QACpB,WAAW,CAAC,gBAAgB,MAAM,YAAY,eAAe,OAAO,MAAM,eAAe,MAAM,CAAC,CACnG;CACF,GAAG;EAAC;EAAiB;EAAgB;CAAc,CAAC;CAEpD,MAAM,yBAAyB,cAAc;EAC3C,IAAI,CAAC,YAAY,CAAC,cAAc,OAAO,CAAC;EAExC,OAAO,QAAQ,QACZ,WACC,eAAe,SAAS,eAAe,MAAM,CAAC,KAC9C,CAAC,gBAAgB,MAAM,YAAY,eAAe,OAAO,MAAM,eAAe,MAAM,CAAC,CACzF;CACF,GAAG;EAAC;EAAS;EAAgB;EAAgB;EAAgB;EAAU;CAAY,CAAC;CAEpF,MAAM,gBAAgB,cAAc;EAClC,IAAI,gBAAgB,OAAO;EAE3B,IAAI,CAAC,YAAY,CAAC,cAAc,OAAO;EAEvC,OAAO,eAAe,QAAQ,WAAW,CAAC,eAAe,SAAS,eAAe,MAAM,CAAC,CAAC;CAC3F,GAAG;EAAC;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B,YAAY,gBAAgB,uBAAuB,SAAS,KAC9E,oBAAC,cAAD;IAAc,SAAS;IACpB,UAAA,uBAAuB,IAAI,gBAAgB;GAChC,CAAA;GAGf,cAAc,SAAS,KACtB,oBAAC,cAAD;IAAc,SAAS;IAAe,UAAA,cAAc,IAAI,gBAAgB;GAAgB,CAAA;EAE1F,EAAA,CAAA;CAEO,CAAA;AAEjB"}
|
|
@@ -69,13 +69,12 @@ var VirtualizedComboboxList = ({ localOptions, loading, loadingPlaceholder, empt
|
|
|
69
69
|
return /* @__PURE__ */ jsx(CommandItem, {
|
|
70
70
|
value: optionValue,
|
|
71
71
|
onSelect: handleSelect,
|
|
72
|
-
className: "px-3",
|
|
73
72
|
children: renderOption ? renderOption(option, isSelected) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CheckIcon, { className: `mr-2 h-4 w-4 ${isSelected ? "opacity-100" : "opacity-0"}` }), /* @__PURE__ */ jsx(ComboboxOptionWithTooltip, { label: getOptionLabel(option) })] })
|
|
74
73
|
}, optionValue);
|
|
75
74
|
};
|
|
76
75
|
return /* @__PURE__ */ jsxs(CommandList, {
|
|
77
76
|
ref: parentRef,
|
|
78
|
-
className: "overflow-auto overscroll-contain
|
|
77
|
+
className: "overflow-auto overscroll-contain",
|
|
79
78
|
style: { maxHeight },
|
|
80
79
|
onWheel: (event) => event.stopPropagation(),
|
|
81
80
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedComboboxList.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/Combobox/VirtualizedComboboxList.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport { useRef, useEffect, useState } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../../utils/Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { VirtualizedComboboxListProps } from './types'\n\nconst DEFAULT_ESTIMATED_ROW_HEIGHT = 40\n\nexport const VirtualizedComboboxList = <T extends object>({\n localOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n hasNextPage = false,\n loadingMore = false,\n onLoadMore = () => {},\n estimateSize = DEFAULT_ESTIMATED_ROW_HEIGHT,\n listRef,\n specialOptions,\n specialOptionsTitle,\n}: VirtualizedComboboxListProps<T>) => {\n const ownRef = useRef<HTMLDivElement>(null)\n const parentRef = listRef ?? ownRef\n const hasTriggeredRef = useRef(false)\n\n const totalCount = localOptions.length\n const PREFETCH_THRESHOLD = 25\n\n // scrollMargin accounts for the special group's height so scrollToIndex still centers correctly.\n const specialGroupRef = useRef<HTMLDivElement>(null)\n const [specialGroupHeight, setSpecialGroupHeight] = useState(0)\n useEffect(() => {\n setSpecialGroupHeight(specialGroupRef.current?.offsetHeight ?? 0)\n }, [specialOptions])\n\n const rowVirtualizer = useVirtualizer({\n count: totalCount,\n getScrollElement: () => parentRef.current,\n estimateSize: () => estimateSize,\n overscan: 10,\n useAnimationFrameWithResizeObserver: true,\n scrollMargin: specialGroupHeight,\n })\n\n useEffect(() => {\n hasTriggeredRef.current = false\n }, [totalCount, loadingMore])\n\n const hasCenteredRef = useRef(false)\n useEffect(() => {\n if (hasCenteredRef.current || !value) return\n const index = localOptions.findIndex((option) => getOptionValue(option) === value)\n if (index === -1) return\n hasCenteredRef.current = true\n if (!parentRef.current?.scrollTop) rowVirtualizer.scrollToIndex(index, { align: 'center' })\n }, [value, localOptions, getOptionValue, rowVirtualizer, parentRef])\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n\n useEffect(() => {\n if (virtualItems.length === 0 || !hasNextPage || loadingMore || loading || hasTriggeredRef.current) {\n return\n }\n\n const lastVisibleItem = virtualItems.at(-1)\n const itemsFromEnd = totalCount - (lastVisibleItem?.index ?? 0)\n\n if (itemsFromEnd <= PREFETCH_THRESHOLD) {\n hasTriggeredRef.current = true\n onLoadMore()\n }\n }, [virtualItems, totalCount, hasNextPage, loadingMore, loading, onLoadMore])\n\n if (loading && localOptions.length === 0) {\n return <div className=\"flex items-center justify-center py-6 text-sm text-neutral-400\">{loadingPlaceholder}</div>\n }\n\n if (localOptions.length === 0 && !specialOptions?.length && !loading && !loadingMore) {\n return <CommandEmpty>{emptyMessage}</CommandEmpty>\n }\n\n const renderOptionRow = (option: T) => {\n const optionValue = getOptionValue(option)\n const isSelected = value === optionValue\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}
|
|
1
|
+
{"version":3,"file":"VirtualizedComboboxList.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/Combobox/VirtualizedComboboxList.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport { useRef, useEffect, useState } from 'react'\n\nimport { CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator } from '../../utils/Command'\n\nimport { ComboboxOptionWithTooltip } from './ComboboxOptionWithTooltip'\nimport type { VirtualizedComboboxListProps } from './types'\n\nconst DEFAULT_ESTIMATED_ROW_HEIGHT = 40\n\nexport const VirtualizedComboboxList = <T extends object>({\n localOptions,\n loading,\n loadingPlaceholder,\n emptyMessage,\n value,\n getOptionValue,\n getOptionLabel,\n handleSelect,\n renderOption,\n maxHeight,\n hasNextPage = false,\n loadingMore = false,\n onLoadMore = () => {},\n estimateSize = DEFAULT_ESTIMATED_ROW_HEIGHT,\n listRef,\n specialOptions,\n specialOptionsTitle,\n}: VirtualizedComboboxListProps<T>) => {\n const ownRef = useRef<HTMLDivElement>(null)\n const parentRef = listRef ?? ownRef\n const hasTriggeredRef = useRef(false)\n\n const totalCount = localOptions.length\n const PREFETCH_THRESHOLD = 25\n\n // scrollMargin accounts for the special group's height so scrollToIndex still centers correctly.\n const specialGroupRef = useRef<HTMLDivElement>(null)\n const [specialGroupHeight, setSpecialGroupHeight] = useState(0)\n useEffect(() => {\n setSpecialGroupHeight(specialGroupRef.current?.offsetHeight ?? 0)\n }, [specialOptions])\n\n const rowVirtualizer = useVirtualizer({\n count: totalCount,\n getScrollElement: () => parentRef.current,\n estimateSize: () => estimateSize,\n overscan: 10,\n useAnimationFrameWithResizeObserver: true,\n scrollMargin: specialGroupHeight,\n })\n\n useEffect(() => {\n hasTriggeredRef.current = false\n }, [totalCount, loadingMore])\n\n const hasCenteredRef = useRef(false)\n useEffect(() => {\n if (hasCenteredRef.current || !value) return\n const index = localOptions.findIndex((option) => getOptionValue(option) === value)\n if (index === -1) return\n hasCenteredRef.current = true\n if (!parentRef.current?.scrollTop) rowVirtualizer.scrollToIndex(index, { align: 'center' })\n }, [value, localOptions, getOptionValue, rowVirtualizer, parentRef])\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n\n useEffect(() => {\n if (virtualItems.length === 0 || !hasNextPage || loadingMore || loading || hasTriggeredRef.current) {\n return\n }\n\n const lastVisibleItem = virtualItems.at(-1)\n const itemsFromEnd = totalCount - (lastVisibleItem?.index ?? 0)\n\n if (itemsFromEnd <= PREFETCH_THRESHOLD) {\n hasTriggeredRef.current = true\n onLoadMore()\n }\n }, [virtualItems, totalCount, hasNextPage, loadingMore, loading, onLoadMore])\n\n if (loading && localOptions.length === 0) {\n return <div className=\"flex items-center justify-center py-6 text-sm text-neutral-400\">{loadingPlaceholder}</div>\n }\n\n if (localOptions.length === 0 && !specialOptions?.length && !loading && !loadingMore) {\n return <CommandEmpty>{emptyMessage}</CommandEmpty>\n }\n\n const renderOptionRow = (option: T) => {\n const optionValue = getOptionValue(option)\n const isSelected = value === optionValue\n return (\n <CommandItem key={optionValue} value={optionValue} onSelect={handleSelect}>\n {renderOption ? (\n renderOption(option, isSelected)\n ) : (\n <>\n <CheckIcon className={`mr-2 h-4 w-4 ${isSelected ? 'opacity-100' : 'opacity-0'}`} />\n <ComboboxOptionWithTooltip label={getOptionLabel(option)} />\n </>\n )}\n </CommandItem>\n )\n }\n\n return (\n <CommandList\n ref={parentRef}\n className=\"overflow-auto overscroll-contain\"\n style={{ maxHeight }}\n onWheel={(event) => event.stopPropagation()}\n >\n <div style={{ height: `${specialGroupHeight + rowVirtualizer.getTotalSize()}px`, position: 'relative' }}>\n {specialOptions?.length ? (\n <div ref={specialGroupRef} data-testid=\"combobox-special-group\">\n <CommandGroup heading={specialOptionsTitle}>{specialOptions.map(renderOptionRow)}</CommandGroup>\n {localOptions.length > 0 && <CommandSeparator className=\"mx-1\" />}\n </div>\n ) : null}\n\n {rowVirtualizer.getVirtualItems().map((virtualRow) => (\n <div\n key={getOptionValue(localOptions[virtualRow.index])}\n data-index={virtualRow.index}\n ref={(el) => rowVirtualizer.measureElement(el)}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n transform: `translateY(${virtualRow.start}px)`,\n }}\n >\n {renderOptionRow(localOptions[virtualRow.index])}\n </div>\n ))}\n </div>\n {loadingMore && (\n <div className=\"flex items-center justify-center py-2 text-sm text-neutral-500\">{loadingPlaceholder}</div>\n )}\n </CommandList>\n )\n}\n"],"mappings":";;;;;;;AASA,IAAM,+BAA+B;AAErC,IAAa,2BAA6C,EACxD,cACA,SACA,oBACA,cACA,OACA,gBACA,gBACA,cACA,cACA,WACA,cAAc,OACd,cAAc,OACd,mBAAmB,CAAC,GACpB,eAAe,8BACf,SACA,gBACA,0BACqC;CACrC,MAAM,SAAS,OAAuB,IAAI;CAC1C,MAAM,YAAY,WAAW;CAC7B,MAAM,kBAAkB,OAAO,KAAK;CAEpC,MAAM,aAAa,aAAa;CAChC,MAAM,qBAAqB;CAG3B,MAAM,kBAAkB,OAAuB,IAAI;CACnD,MAAM,CAAC,oBAAoB,yBAAyB,SAAS,CAAC;CAC9D,gBAAgB;EACd,sBAAsB,gBAAgB,SAAS,gBAAgB,CAAC;CAClE,GAAG,CAAC,cAAc,CAAC;CAEnB,MAAM,iBAAiB,e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EAAW,WAAW,gBAAgB,aAAa,gBAAgB,cAAgB,CAAA,GACnF,oBAAC,2BAAD,EAA2B,OAAO,eAAe,MAAM,EAAI,CAAA,CAC3D,EAAA,CAAA;EAEO,GATK,WASL;CAEjB;CAEA,OACE,qBAAC,aAAD;EACE,KAAK;EACL,WAAU;EACV,OAAO,EAAE,UAAU;EACnB,UAAU,UAAU,MAAM,gBAAgB;EAJ5C,UAAA,CAME,qBAAC,OAAD;GAAK,OAAO;IAAE,QAAQ,GAAG,qBAAqB,eAAe,aAAa,EAAE;IAAK,UAAU;GAAW;GAAtG,UAAA,CACG,gBAAgB,SACf,qBAAC,OAAD;IAAK,KAAK;IAAiB,eAAY;IAAvC,UAAA,CACE,oBAAC,cAAD;KAAc,SAAS;KAAsB,UAAA,eAAe,IAAI,eAAe;IAAgB,CAAA,GAC9F,aAAa,SAAS,KAAK,oBAAC,kBAAD,EAAkB,WAAU,OAAQ,CAAA,CAC7D;GACH,CAAA,IAAA,MAEH,eAAe,gBAAgB,CAAC,CAAC,KAAK,eACrC,oBAAC,OAAD;IAEE,cAAY,WAAW;IACvB,MAAM,OAAO,eAAe,eAAe,EAAE;IAC7C,OAAO;KACL,UAAU;KACV,KAAK;KACL,MAAM;KACN,OAAO;KACP,WAAW,cAAc,WAAW,MAAM;IAC5C;IAEC,UAAA,gBAAgB,aAAa,WAAW,MAAM;GAC5C,GAZE,eAAe,aAAa,WAAW,MAAM,CAY/C,CACN,CACE;EACJ,CAAA,GAAA,eACC,oBAAC,OAAD;GAAK,WAAU;GAAkE,UAAA;EAAwB,CAAA,CAEhG;;AAEjB"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { cn } from "../../../lib/utils.js";
|
|
4
4
|
import { Button, buttonVariants } from "../Button/Button.js";
|
|
5
|
+
import { SURFACE_LIST } from "../../../lib/surface.js";
|
|
5
6
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../../utils/Command/Command.js";
|
|
6
7
|
import { PopoverContent, PopoverRoot, PopoverTrigger } from "../../utils/Popover/Popover.js";
|
|
7
8
|
import * as React$1 from "react";
|
|
@@ -57,12 +58,12 @@ var InlineMultiSelect = ({ options, value, onChange, defaultValue = [], placehol
|
|
|
57
58
|
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
58
59
|
asChild: true,
|
|
59
60
|
children: /* @__PURE__ */ jsxs(Button, {
|
|
60
|
-
variant: "
|
|
61
|
+
variant: "text",
|
|
61
62
|
"aria-expanded": open,
|
|
62
|
-
className: cn(
|
|
63
|
-
variant: "
|
|
63
|
+
className: cn(buttonVariants({
|
|
64
|
+
variant: "input",
|
|
64
65
|
size: "lg"
|
|
65
|
-
}), className),
|
|
66
|
+
}), "w-full justify-between", open && "border-neutral-950", fieldState?.invalid && "border-error-400 focus-visible:border-error-700", className),
|
|
66
67
|
children: [/* @__PURE__ */ jsx("div", {
|
|
67
68
|
ref: containerRef,
|
|
68
69
|
className: "flex flex-1 flex-wrap items-center gap-1 overflow-hidden pr-2",
|
|
@@ -94,7 +95,7 @@ var InlineMultiSelect = ({ options, value, onChange, defaultValue = [], placehol
|
|
|
94
95
|
}), /* @__PURE__ */ jsx(CaretUpDownIcon, { className: "h-4 w-4 opacity-50" })]
|
|
95
96
|
})
|
|
96
97
|
}), /* @__PURE__ */ jsxs(PopoverContent, {
|
|
97
|
-
className: "
|
|
98
|
+
className: cn(SURFACE_LIST, "p-0"),
|
|
98
99
|
children: [/* @__PURE__ */ jsx(CommandInput, {
|
|
99
100
|
placeholder: commandInputPlaceholder ?? "Search...",
|
|
100
101
|
disabled: loading,
|
|
@@ -105,7 +106,7 @@ var InlineMultiSelect = ({ options, value, onChange, defaultValue = [], placehol
|
|
|
105
106
|
children: loadingPlaceholder
|
|
106
107
|
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CommandEmpty, { children: notFoundText ?? "Options not found" }), open && /* @__PURE__ */ jsx(CommandGroup, { children: options.map((item) => {
|
|
107
108
|
const isSelected = selectedValues.includes(item.value);
|
|
108
|
-
return /* @__PURE__ */
|
|
109
|
+
return /* @__PURE__ */ jsxs(CommandItem, {
|
|
109
110
|
onMouseDown: (event) => {
|
|
110
111
|
event.preventDefault();
|
|
111
112
|
event.stopPropagation();
|
|
@@ -119,13 +120,11 @@ var InlineMultiSelect = ({ options, value, onChange, defaultValue = [], placehol
|
|
|
119
120
|
}
|
|
120
121
|
if (closeOnSelect) setOpen(false);
|
|
121
122
|
},
|
|
122
|
-
children: /* @__PURE__ */
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}), /* @__PURE__ */ jsx("div", { children: item.label })]
|
|
128
|
-
})
|
|
123
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
124
|
+
"aria-hidden": true,
|
|
125
|
+
className: "mr-1 flex size-6 shrink-0 items-center justify-end",
|
|
126
|
+
children: isSelected && /* @__PURE__ */ jsx(CheckIcon, { weight: "bold" })
|
|
127
|
+
}), item.label]
|
|
129
128
|
}, item.value);
|
|
130
129
|
}) })] }) })]
|
|
131
130
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineMultiSelect.js","names":["React","_Fragment"],"sources":["../../../../src/components/inputs/InlineMultiSelect/InlineMultiSelect.tsx"],"sourcesContent":["'use client'\n\nimport { CaretUpDownIcon } from '@phosphor-icons/react/dist/ssr/CaretUpDown'\nimport { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport * as React from 'react'\nimport { ControllerFieldState } from 'react-hook-form'\n\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\nimport { Button, buttonVariants } from '../Button'\n\nimport { cn } from '@/lib/utils'\n\n/** Represents a selectable option in the InlineMultiSelect */\ntype Option = { value: string; label: string }\n\n/** Props for the InlineMultiSelect component */\nexport type InlineMultiSelectProps = {\n /** Array of options to display in the select */\n options: Array<Option>\n /** Currently selected values (controlled) */\n value?: Array<string>\n /** Callback fired when selection changes */\n onChange?: (value: Array<string>) => void\n /** Form field state from react-hook-form */\n fieldState?: ControllerFieldState\n /** Default selected values (uncontrolled) */\n defaultValue?: Array<string>\n /** Placeholder text when no items are selected */\n placeholder?: string\n /** Text to show when no options match the search */\n notFoundText?: string\n /** Placeholder for the search input */\n commandInputPlaceholder?: string\n /** Maximum number of items that can be selected */\n max?: number\n /** Additional CSS classes */\n className?: string\n /** Whether the component is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the component is in a modal */\n modal?: boolean\n /** Whether to close the dropdown when an option is selected. Defaults to false for multi-select. */\n closeOnSelect?: boolean\n}\n\n/**\n * InlineMultiSelect Component\n *\n * A controlled multi-select component that displays selected items inline with search functionality.\n * Supports keyboard navigation, maximum selection limit, and custom styling.\n */\nexport const InlineMultiSelect = ({\n options,\n value,\n onChange,\n defaultValue = [],\n placeholder,\n notFoundText,\n commandInputPlaceholder,\n max,\n className,\n fieldState,\n loading = false,\n modal = false,\n loadingPlaceholder = 'Cargando...',\n closeOnSelect = false,\n}: InlineMultiSelectProps) => {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const containerRef = React.useRef<HTMLDivElement>(null)\n const [open, setOpen] = React.useState(false)\n const [inputValue, setInputValue] = React.useState('')\n\n const isControlled = value !== undefined\n\n const [internalSelected, setInternalSelected] = React.useState<Array<string>>(() => defaultValue)\n\n const selectedValues = isControlled ? value! : internalSelected\n const selected = React.useMemo(\n () => options.filter((option) => selectedValues.includes(option.value)),\n [options, selectedValues],\n )\n\n const maxVisibleItems = 2\n const visibleCount = Math.min(selected.length, maxVisibleItems)\n const visibleItems = React.useMemo(() => selected.slice(0, visibleCount), [selected, visibleCount])\n const hiddenCount = selected.length - visibleCount\n\n const handleSelectionChange = (newSelected: Array<string>) => {\n if (!isControlled) {\n setInternalSelected(newSelected)\n }\n onChange?.(newSelected)\n }\n\n const removeItem = (itemToRemove?: Option) => {\n const newValues = itemToRemove\n ? selectedValues.filter((val) => val !== itemToRemove.value)\n : selectedValues.slice(0, -1)\n handleSelectionChange(newValues)\n }\n\n const handleUnselect = (item: Option, event: React.MouseEvent | React.KeyboardEvent) => {\n event.stopPropagation()\n event.preventDefault()\n removeItem(item)\n }\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (input) {\n if ((event.key === 'Backspace' || event.key === 'Delete') && input.value === '') {\n removeItem()\n }\n if (event.key === 'Escape') {\n input.blur()\n }\n }\n }\n\n return (\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <Command onKeyDown={handleKeyDown}>\n <PopoverTrigger asChild>\n <Button\n variant=\"ghost\"\n aria-expanded={open}\n className={cn(\n 'w-full justify-between bg-[#fff] pr-2 pl-2',\n fieldState?.invalid ? 'border-error-400 focus-within:border-error-700' : '',\n buttonVariants({ variant: 'ghost', size: 'lg' }),\n className,\n )}\n >\n <div ref={containerRef} className=\"flex flex-1 flex-wrap items-center gap-1 overflow-hidden pr-2\">\n <div className=\"flex items-center whitespace-nowrap\">\n {selected.length > 0 ? (\n <>\n {visibleItems.map((item) => (\n <div key={item.value} className=\"bg-muted flex items-center gap-1 rounded px-1 py-0.5\">\n <span className=\"text-sm\">{item.label}</span>\n <span\n role=\"button\"\n tabIndex={0}\n onClick={(event) => handleUnselect(item, event)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n handleUnselect(item, event)\n }\n }}\n className=\"hover:bg-muted-foreground/20 flex h-4 w-4 items-center justify-center rounded-full\"\n >\n <XIcon className=\"text-muted-foreground h-3 w-3\" />\n </span>\n </div>\n ))}\n {hiddenCount > 0 && <span className=\"text-muted-foreground text-sm\">+{hiddenCount}</span>}\n </>\n ) : (\n <span className=\"text-muted-foreground\">{placeholder}</span>\n )}\n </div>\n </div>\n <CaretUpDownIcon className=\"h-4 w-4 opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"px-0 py-0\">\n <CommandInput\n placeholder={commandInputPlaceholder ?? 'Search...'}\n disabled={loading}\n value={inputValue}\n onValueChange={setInputValue}\n />\n <CommandList>\n {loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">\n {loadingPlaceholder}\n </div>\n ) : (\n <>\n <CommandEmpty>{notFoundText ?? 'Options not found'}</CommandEmpty>\n {open && (\n <CommandGroup>\n {options.map((item) => {\n const isSelected = selectedValues.includes(item.value)\n return (\n <CommandItem\n key={item.value}\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onSelect={() => {\n if (isSelected) {\n handleSelectionChange(selectedValues.filter((val) => val !== item.value))\n } else {\n if (max && selectedValues.length >= max) return\n handleSelectionChange([...selectedValues, item.value])\n setInputValue('')\n }\n\n if (closeOnSelect) {\n setOpen(false)\n }\n }}\n >\n <div className=\"flex items-center\">\n <div className=\"mr-2\">\n {isSelected ? <CheckIcon className=\"h-4 w-4\" /> : <div className=\"h-4 w-4\" />}\n </div>\n <div>{item.label}</div>\n </div>\n </CommandItem>\n )\n })}\n </CommandGroup>\n )}\n </>\n )}\n </CommandList>\n </PopoverContent>\n </Command>\n </PopoverRoot>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuDA,IAAA,qBAAA,EAAA,SAAA,OAAA,UAAA,eAAA,CAAA,GAAA,aAAA,cAAA,yBAAA,KAAA,WAAA,YAAA,UAAA,OAAA,QAAA,OAAA,qBAAA,eAAA,gBAAA,YAAA;CAgBE,MAAA,WAAA,QAAA,OAAA,IAAA;CACA,MAAA,eAAA,QAAA,OAAA,IAAA;CACA,MAAA,CAAA,MAAA,WAAA,QAAA,SAAA,KAAA;CACA,MAAA,CAAA,YAAA,iBAAA,QAAA,SAAA,EAAA;CAEA,MAAA,eAAA,UAAA,KAAA;CAEA,MAAA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,KAAA,CAAA;YAEO;QACL,IAAA,OAAA,eAAA,UAAA,KAAA;QACA,sBAAA,CAAA,GAAA,gBAAA,KAAA,KAAA,CAAA;QACA,cAAA,EAAA;OACF;OAEA,IAAA,eAAA,QAAA,KAAA;MAGF;MAEA,UAAA,qBAAA,OAAA;OAAK,WAAA;OAAL,UAAA,CAAA,oBAAA,OAAA;QACO,WAAA;QACF,UAAA,aAAA,oBAAA,WAAA,EAAA,WAAA,UAAA,CAAA,IAAA,oBAAA,OAAA,EAAA,WAAA,UAAA,CAAA;OACE,CAAA,GAAA,oBAAA,OAAA,EAAA,UAAA,KAAA,MAAA,CAAA,CAAA;;KAGI,GAAA,KAAA,KAAA;IAEjB,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA;GAOL,CAAA,CAAA;;CACE,CAAA;AAEjB"}
|
|
1
|
+
{"version":3,"file":"InlineMultiSelect.js","names":["React","_Fragment"],"sources":["../../../../src/components/inputs/InlineMultiSelect/InlineMultiSelect.tsx"],"sourcesContent":["'use client'\n\nimport { CaretUpDownIcon } from '@phosphor-icons/react/dist/ssr/CaretUpDown'\nimport { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { XIcon } from '@phosphor-icons/react/dist/ssr/X'\nimport * as React from 'react'\nimport { ControllerFieldState } from 'react-hook-form'\n\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\nimport { Button, buttonVariants } from '../Button'\n\nimport { SURFACE_LIST } from '@/lib/surface'\nimport { cn } from '@/lib/utils'\n\n/** Represents a selectable option in the InlineMultiSelect */\ntype Option = { value: string; label: string }\n\n/** Props for the InlineMultiSelect component */\nexport type InlineMultiSelectProps = {\n /** Array of options to display in the select */\n options: Array<Option>\n /** Currently selected values (controlled) */\n value?: Array<string>\n /** Callback fired when selection changes */\n onChange?: (value: Array<string>) => void\n /** Form field state from react-hook-form */\n fieldState?: ControllerFieldState\n /** Default selected values (uncontrolled) */\n defaultValue?: Array<string>\n /** Placeholder text when no items are selected */\n placeholder?: string\n /** Text to show when no options match the search */\n notFoundText?: string\n /** Placeholder for the search input */\n commandInputPlaceholder?: string\n /** Maximum number of items that can be selected */\n max?: number\n /** Additional CSS classes */\n className?: string\n /** Whether the component is in a loading state */\n loading?: boolean\n /** Message to show when in loading state */\n loadingPlaceholder?: string\n /** Whether the component is in a modal */\n modal?: boolean\n /** Whether to close the dropdown when an option is selected. Defaults to false for multi-select. */\n closeOnSelect?: boolean\n}\n\n/**\n * InlineMultiSelect Component\n *\n * A controlled multi-select component that displays selected items inline with search functionality.\n * Supports keyboard navigation, maximum selection limit, and custom styling.\n */\nexport const InlineMultiSelect = ({\n options,\n value,\n onChange,\n defaultValue = [],\n placeholder,\n notFoundText,\n commandInputPlaceholder,\n max,\n className,\n fieldState,\n loading = false,\n modal = false,\n loadingPlaceholder = 'Cargando...',\n closeOnSelect = false,\n}: InlineMultiSelectProps) => {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const containerRef = React.useRef<HTMLDivElement>(null)\n const [open, setOpen] = React.useState(false)\n const [inputValue, setInputValue] = React.useState('')\n\n const isControlled = value !== undefined\n\n const [internalSelected, setInternalSelected] = React.useState<Array<string>>(() => defaultValue)\n\n const selectedValues = isControlled ? value! : internalSelected\n const selected = React.useMemo(\n () => options.filter((option) => selectedValues.includes(option.value)),\n [options, selectedValues],\n )\n\n const maxVisibleItems = 2\n const visibleCount = Math.min(selected.length, maxVisibleItems)\n const visibleItems = React.useMemo(() => selected.slice(0, visibleCount), [selected, visibleCount])\n const hiddenCount = selected.length - visibleCount\n\n const handleSelectionChange = (newSelected: Array<string>) => {\n if (!isControlled) {\n setInternalSelected(newSelected)\n }\n onChange?.(newSelected)\n }\n\n const removeItem = (itemToRemove?: Option) => {\n const newValues = itemToRemove\n ? selectedValues.filter((val) => val !== itemToRemove.value)\n : selectedValues.slice(0, -1)\n handleSelectionChange(newValues)\n }\n\n const handleUnselect = (item: Option, event: React.MouseEvent | React.KeyboardEvent) => {\n event.stopPropagation()\n event.preventDefault()\n removeItem(item)\n }\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (input) {\n if ((event.key === 'Backspace' || event.key === 'Delete') && input.value === '') {\n removeItem()\n }\n if (event.key === 'Escape') {\n input.blur()\n }\n }\n }\n\n return (\n <PopoverRoot open={open} onOpenChange={setOpen} modal={modal}>\n <Command onKeyDown={handleKeyDown}>\n <PopoverTrigger asChild>\n <Button\n variant=\"text\"\n aria-expanded={open}\n className={cn(\n buttonVariants({ variant: 'input', size: 'lg' }),\n 'w-full justify-between',\n open && 'border-neutral-950',\n fieldState?.invalid && 'border-error-400 focus-visible:border-error-700',\n className,\n )}\n >\n <div ref={containerRef} className=\"flex flex-1 flex-wrap items-center gap-1 overflow-hidden pr-2\">\n <div className=\"flex items-center whitespace-nowrap\">\n {selected.length > 0 ? (\n <>\n {visibleItems.map((item) => (\n <div key={item.value} className=\"bg-muted flex items-center gap-1 rounded px-1 py-0.5\">\n <span className=\"text-sm\">{item.label}</span>\n <span\n role=\"button\"\n tabIndex={0}\n onClick={(event) => handleUnselect(item, event)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n handleUnselect(item, event)\n }\n }}\n className=\"hover:bg-muted-foreground/20 flex h-4 w-4 items-center justify-center rounded-full\"\n >\n <XIcon className=\"text-muted-foreground h-3 w-3\" />\n </span>\n </div>\n ))}\n {hiddenCount > 0 && <span className=\"text-muted-foreground text-sm\">+{hiddenCount}</span>}\n </>\n ) : (\n <span className=\"text-muted-foreground\">{placeholder}</span>\n )}\n </div>\n </div>\n <CaretUpDownIcon className=\"h-4 w-4 opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className={cn(SURFACE_LIST, 'p-0')}>\n <CommandInput\n placeholder={commandInputPlaceholder ?? 'Search...'}\n disabled={loading}\n value={inputValue}\n onValueChange={setInputValue}\n />\n <CommandList>\n {loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center py-6 text-sm\">\n {loadingPlaceholder}\n </div>\n ) : (\n <>\n <CommandEmpty>{notFoundText ?? 'Options not found'}</CommandEmpty>\n {open && (\n <CommandGroup>\n {options.map((item) => {\n const isSelected = selectedValues.includes(item.value)\n return (\n <CommandItem\n key={item.value}\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onSelect={() => {\n if (isSelected) {\n handleSelectionChange(selectedValues.filter((val) => val !== item.value))\n } else {\n if (max && selectedValues.length >= max) return\n handleSelectionChange([...selectedValues, item.value])\n setInputValue('')\n }\n\n if (closeOnSelect) {\n setOpen(false)\n }\n }}\n >\n <span aria-hidden className=\"mr-1 flex size-6 shrink-0 items-center justify-end\">\n {isSelected && <CheckIcon weight=\"bold\" />}\n </span>\n {item.label}\n </CommandItem>\n )\n })}\n </CommandGroup>\n )}\n </>\n )}\n </CommandList>\n </PopoverContent>\n </Command>\n </PopoverRoot>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwDA,IAAA,qBAAA,EAAA,SAAA,OAAA,UAAA,eAAA,CAAA,GAAA,aAAA,cAAA,yBAAA,KAAA,WAAA,YAAA,UAAA,OAAA,QAAA,OAAA,qBAAA,eAAA,gBAAA,YAAA;CAgBE,MAAA,WAAA,QAAA,OAAA,IAAA;CACA,MAAA,eAAA,QAAA,OAAA,IAAA;CACA,MAAA,CAAA,MAAA,WAAA,QAAA,SAAA,KAAA;CACA,MAAA,CAAA,YAAA,iBAAA,QAAA,SAAA,EAAA;CAEA,MAAA,eAAA,UAAA,KAAA;CAEA,MAAA,CAAA,kBAAA,uBAAA,QAAA,eAAA,YAAA;CAEA,MAAA,iBAAA,eAAA,QAAA;CACA,MAAA,WAAA,QAAA,cAAA,QAAA,QAAA,WAAA,eAAA,SAAA,OAAA,KAAA,CAAA,GAAA,CAAA,SAAA,cAAA,CAAA;CAMA,MAAA,eA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,UAAA,CAAA,oBAAA,QAAA;OAoBQ,eAAA;OAAY,WAAA;OACf,UAAA,cAAA,oBAAA,WAAA,EAAA,QAAA,OAAA,CAAA;MACG,CAAA,GAAA,KAAA,KAAA;KArBD,GAAA,KAAA,KAAA;IAyBX,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA;GAOL,CAAA,CAAA;;CACE,CAAA;AAEjB"}
|
|
@@ -17,7 +17,7 @@ function LazyDatePicker(props, initialValue, value, onChange) {
|
|
|
17
17
|
onMouseEnter: loadDatePicker,
|
|
18
18
|
onFocus: loadDatePicker,
|
|
19
19
|
onTouchStart: loadDatePicker,
|
|
20
|
-
className: cn("flex h-12 w-full items-center justify-center gap-2 rounded-
|
|
20
|
+
className: cn("flex h-12 w-full items-center justify-center gap-2 rounded-lg border border-neutral-200 bg-white px-6 text-neutral-950 hover:bg-neutral-50 focus-visible:border-neutral-950 focus-visible:ring-0", props.buttonClassName),
|
|
21
21
|
"aria-label": props.placeholder ?? "Open date picker",
|
|
22
22
|
children: [/* @__PURE__ */ jsx(CalendarBlankIcon, {
|
|
23
23
|
size: 16,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LazyDatePicker.js","names":[],"sources":["../../../../src/components/inputs/LazyDatePicker/LazyDatePicker.tsx"],"sourcesContent":["import { CalendarBlankIcon } from '@phosphor-icons/react/dist/ssr/CalendarBlank'\nimport type { ComponentType } from 'react'\nimport { useState } from 'react'\n\nimport { cn } from '../../../lib/utils'\nimport type { DatePickerInput, DatePickerOutput, DatePickerProps } from '../DatePicker/DatePicker'\n\nimport { ValueFormat } from '@/lib/dateUtils'\n\nfunction LazyDatePicker<V extends 'single' | 'range' = 'single', F extends ValueFormat = 'iso'>(\n props: DatePickerProps<V, F>,\n initialValue?: DatePickerInput<V>,\n value?: DatePickerInput<V>,\n onChange?: (value: DatePickerOutput<V, F>) => void,\n) {\n const [DatePickerComponent, setDatePickerComponent] = useState<ComponentType<DatePickerProps<V, F>> | null>(null)\n\n const loadDatePicker = async () => {\n if (!DatePickerComponent) {\n const { DatePicker } = await import('../DatePicker/DatePicker')\n setDatePickerComponent(() => DatePicker)\n }\n }\n\n const PlaceHolderButton = () => {\n return (\n <button\n type=\"button\"\n onMouseEnter={loadDatePicker}\n onFocus={loadDatePicker}\n onTouchStart={loadDatePicker}\n className={cn(\n 'flex h-12 w-full items-center justify-center gap-2 rounded-
|
|
1
|
+
{"version":3,"file":"LazyDatePicker.js","names":[],"sources":["../../../../src/components/inputs/LazyDatePicker/LazyDatePicker.tsx"],"sourcesContent":["import { CalendarBlankIcon } from '@phosphor-icons/react/dist/ssr/CalendarBlank'\nimport type { ComponentType } from 'react'\nimport { useState } from 'react'\n\nimport { cn } from '../../../lib/utils'\nimport type { DatePickerInput, DatePickerOutput, DatePickerProps } from '../DatePicker/DatePicker'\n\nimport { ValueFormat } from '@/lib/dateUtils'\n\nfunction LazyDatePicker<V extends 'single' | 'range' = 'single', F extends ValueFormat = 'iso'>(\n props: DatePickerProps<V, F>,\n initialValue?: DatePickerInput<V>,\n value?: DatePickerInput<V>,\n onChange?: (value: DatePickerOutput<V, F>) => void,\n) {\n const [DatePickerComponent, setDatePickerComponent] = useState<ComponentType<DatePickerProps<V, F>> | null>(null)\n\n const loadDatePicker = async () => {\n if (!DatePickerComponent) {\n const { DatePicker } = await import('../DatePicker/DatePicker')\n setDatePickerComponent(() => DatePicker)\n }\n }\n\n const PlaceHolderButton = () => {\n return (\n <button\n type=\"button\"\n onMouseEnter={loadDatePicker}\n onFocus={loadDatePicker}\n onTouchStart={loadDatePicker}\n className={cn(\n 'flex h-12 w-full items-center justify-center gap-2 rounded-lg border border-neutral-200 bg-white px-6 text-neutral-950 hover:bg-neutral-50 focus-visible:border-neutral-950 focus-visible:ring-0',\n props.buttonClassName,\n )}\n aria-label={props.placeholder ?? 'Open date picker'}\n >\n <CalendarBlankIcon size={16} aria-hidden=\"true\" className=\"h-4 w-4 shrink-0 transition-opacity duration-150\" />\n <span className=\"text-center tracking-[0.08px]\">{props.placeholder}</span>\n </button>\n )\n }\n\n return DatePickerComponent ? (\n <DatePickerComponent onChange={onChange} initialValue={initialValue} value={value} {...props} />\n ) : (\n <PlaceHolderButton />\n )\n}\n\nexport { LazyDatePicker }\n"],"mappings":";;;;;AASA,SAAS,eACP,OACA,cACA,OACA,UACA;CACA,MAAM,CAAC,qBAAqB,0BAA0B,SAAsD,IAAI;CAEhH,MAAM,iBAAiB,YAAY;EACjC,IAAI,CAAC,qBAAqB;GACxB,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,6BAA6B,UAAU;EACzC;CACF;CAEA,MAAM,0BAA0B;EAC9B,OACE,qBAAC,UAAD;GACE,MAAK;GACL,cAAc;GACd,SAAS;GACT,cAAc;GACd,WAAW,GACT,oMACA,MAAM,eACR;GACA,cAAY,MAAM,eAAe;GATnC,UAAA,CAWE,oBAAC,mBAAD;IAAmB,MAAM;IAAI,eAAY;IAAO,WAAU;GAAoD,CAAA,GAC9G,oBAAC,QAAD;IAAM,WAAU;IAAiC,UAAA,MAAM;GAAkB,CAAA,CACnE;;CAEZ;CAEA,OAAO,sBACL,oBAAC,qBAAD;EAA+B;EAAwB;EAAqB;EAAO,GAAI;CAAQ,CAAA,IAE/F,oBAAC,mBAAD,CAAoB,CAAA;AAExB"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { cn } from "../../../lib/utils.js";
|
|
4
4
|
import { Button, buttonVariants } from "../Button/Button.js";
|
|
5
|
+
import { SURFACE_LIST } from "../../../lib/surface.js";
|
|
5
6
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../../utils/Command/Command.js";
|
|
6
7
|
import { PopoverContent, PopoverRoot, PopoverTrigger } from "../../utils/Popover/Popover.js";
|
|
7
8
|
import { Chip } from "../../data-display/Chip/Chip.js";
|
|
@@ -75,18 +76,18 @@ var MultiSelect = React$1.forwardRef(({ options, onChange, chipProps, defaultVal
|
|
|
75
76
|
asChild: true,
|
|
76
77
|
children: /* @__PURE__ */ jsxs(Button, {
|
|
77
78
|
id,
|
|
78
|
-
variant: "
|
|
79
|
+
variant: "text",
|
|
79
80
|
role: "combobox",
|
|
80
81
|
"aria-expanded": open,
|
|
81
|
-
className: cn(
|
|
82
|
-
variant: "
|
|
82
|
+
className: cn(buttonVariants({
|
|
83
|
+
variant: "input",
|
|
83
84
|
size: "lg"
|
|
84
|
-
}), className),
|
|
85
|
+
}), "w-full justify-between", open && "border-neutral-950", fieldState?.invalid && "border-error-400 focus-visible:border-error-700", className),
|
|
85
86
|
children: [placeholder, /* @__PURE__ */ jsx(CaretUpDownIcon, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })]
|
|
86
87
|
})
|
|
87
88
|
}),
|
|
88
89
|
/* @__PURE__ */ jsxs(PopoverContent, {
|
|
89
|
-
className: "
|
|
90
|
+
className: cn(SURFACE_LIST, "p-0"),
|
|
90
91
|
children: [/* @__PURE__ */ jsx(CommandInput, {
|
|
91
92
|
placeholder: commandInputPlaceholder,
|
|
92
93
|
ref: inputRef,
|
|
@@ -102,7 +103,7 @@ var MultiSelect = React$1.forwardRef(({ options, onChange, chipProps, defaultVal
|
|
|
102
103
|
max
|
|
103
104
|
]
|
|
104
105
|
})
|
|
105
|
-
}), /* @__PURE__ */ jsxs(CommandList, { children: [/* @__PURE__ */ jsx(CommandEmpty, { children: notFoundText }), open && options.length > 0 && /* @__PURE__ */ jsx(CommandGroup, { children: options.map((item) => /* @__PURE__ */
|
|
106
|
+
}), /* @__PURE__ */ jsxs(CommandList, { children: [/* @__PURE__ */ jsx(CommandEmpty, { children: notFoundText }), open && options.length > 0 && /* @__PURE__ */ jsx(CommandGroup, { children: options.map((item) => /* @__PURE__ */ jsxs(CommandItem, {
|
|
106
107
|
onMouseDown: (event) => {
|
|
107
108
|
event.preventDefault();
|
|
108
109
|
event.stopPropagation();
|
|
@@ -115,13 +116,11 @@ var MultiSelect = React$1.forwardRef(({ options, onChange, chipProps, defaultVal
|
|
|
115
116
|
setSelected((prev) => [...prev, item]);
|
|
116
117
|
}
|
|
117
118
|
},
|
|
118
|
-
children: /* @__PURE__ */
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}), /* @__PURE__ */ jsx("div", { children: item.label })]
|
|
124
|
-
})
|
|
119
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
120
|
+
"aria-hidden": true,
|
|
121
|
+
className: "mr-1 flex size-6 shrink-0 items-center justify-end",
|
|
122
|
+
children: selected.some((selectedOption) => selectedOption.value === item.value) && /* @__PURE__ */ jsx(CheckIcon, { weight: "bold" })
|
|
123
|
+
}), item.label]
|
|
125
124
|
}, `item-${item.value}`)) })] })]
|
|
126
125
|
}),
|
|
127
126
|
selected.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiSelect.js","names":["React"],"sources":["../../../../src/components/inputs/MultiSelect/MultiSelect.tsx"],"sourcesContent":["'use client'\n\nimport { CaretUpDownIcon } from '@phosphor-icons/react/dist/ssr/CaretUpDown'\nimport { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport * as React from 'react'\nimport { ControllerFieldState } from 'react-hook-form'\n\nimport { Chip } from '../../data-display/Chip'\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\nimport { Button, buttonVariants } from '../Button'\n\nimport { cn } from '@/lib/utils'\n\n/**\n * Represents a selectable option in the MultiSelect component\n */\ntype Option = {\n /** Unique identifier for the option */\n value: string\n /** Display text for the option */\n label: string\n}\n\nexport type MultiSelectProps = {\n /**\n * Array of options to display in the select menu\n */\n options: Array<Option>\n\n /**\n * Props to be passed to the individual Chip components\n */\n chipProps?: React.ComponentProps<typeof Chip>\n\n /**\n * Callback fired when selected values change\n * @param value Array of selected option values\n */\n onChange?: (value: Array<string>) => void\n\n /**\n * Form field state from react-hook-form\n */\n fieldState?: ControllerFieldState\n\n /**\n * Initially selected option values\n */\n defaultValue?: Array<string>\n\n /**\n * Text shown in the select button when no option is selected\n * @default \"Select your options...\"\n */\n placeholder?: string\n\n /**\n * Text shown when no options match the search query\n * @default \"Options not found\"\n */\n notFoundText?: string\n\n /**\n * Placeholder text for the search input\n * @default \"Search...\"\n */\n commandInputPlaceholder?: string\n\n /**\n * Maximum number of items that can be selected\n * Shows a counter chip when specified\n */\n max?: number\n\n /**\n * Additional class names for the select button component\n */\n className?: string\n\n /**\n * Unique identifier for the select button component\n */\n id?: string\n}\n\n/**\n * A multi-select component with search functionality and chip display for selected items.\n * Supports keyboard navigation, search filtering, and maximum selection limit.\n *\n * @example\n * // Basic usage\n * <MultiSelect\n * options={[\n * { value: '1', label: 'Option 1' },\n * { value: '2', label: 'Option 2' }\n * ]}\n * onChange={(values) => console.log(values)}\n * />\n *\n * // With maximum selection limit\n * <MultiSelect\n * options={options}\n * max={3}\n * placeholder=\"Select up to 3 options\"\n * />\n *\n * // With custom chip styling\n * <MultiSelect\n * options={options}\n * chipProps={{ variant: 'primary' }}\n * />\n */\nexport const MultiSelect = React.forwardRef<HTMLInputElement, MultiSelectProps>(\n ({\n options,\n onChange,\n chipProps,\n defaultValue,\n placeholder = 'Select your options...',\n notFoundText = 'Options not found',\n fieldState,\n commandInputPlaceholder = 'Search...',\n max,\n className,\n id,\n }) => {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const [open, setOpen] = React.useState(false)\n const [selected, setSelected] = React.useState<MultiSelectProps['options']>(\n options.filter((option) => defaultValue?.includes(option.value) ?? []),\n )\n const [inputValue, setInputValue] = React.useState('')\n\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n })\n\n const handleUnselect = React.useCallback((item: Option) => {\n setSelected((prev) => prev.filter((selectedOption) => selectedOption.value !== item.value))\n }, [])\n\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (input) {\n if (event.key === 'Delete' || event.key === 'Backspace') {\n if (input.value === '') {\n setSelected((prev) => {\n const newSelected = [...prev]\n newSelected.pop()\n return newSelected\n })\n }\n }\n\n if (event.key === 'Escape') {\n input.blur()\n }\n }\n }, [])\n\n React.useEffect(() => {\n onChangeRef.current?.(selected.map((item) => item.value))\n }, [selected])\n\n return (\n <PopoverRoot open={open} onOpenChange={setOpen}>\n <Command onKeyDown={handleKeyDown}>\n <PopoverTrigger asChild>\n <Button\n id={id}\n variant=\"ghost\"\n role=\"combobox\"\n aria-expanded={open}\n className={cn(\n `w-full justify-between bg-white ${\n fieldState?.invalid ? 'border-error-400 focus-within:border-error-700' : ''\n }`,\n buttonVariants({ variant: 'ghost', size: 'lg' }),\n className,\n )}\n >\n {placeholder}\n <CaretUpDownIcon className=\"ml-2 h-4 w-4 shrink-0 opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"px-0 py-0\">\n <CommandInput\n placeholder={commandInputPlaceholder}\n ref={inputRef}\n value={inputValue}\n onValueChange={setInputValue}\n >\n {max && (\n <Chip\n variant={selected.length >= max ? 'primary' : 'default'}\n size=\"sm\"\n className=\"my-1 whitespace-nowrap\"\n >\n {selected.length} / {max}\n </Chip>\n )}\n </CommandInput>\n\n <CommandList>\n <CommandEmpty>{notFoundText}</CommandEmpty>\n {open && options.length > 0 && (\n <CommandGroup>\n {options.map((item) => (\n <CommandItem\n key={`item-${item.value}`}\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onSelect={(value) => {\n const isSelected = selected.find((selectedOption) => selectedOption.label === value)\n if (isSelected) {\n handleUnselect(isSelected)\n } else if (!max || selected.length < max) {\n setInputValue('')\n setSelected((prev) => [...prev, item])\n }\n }}\n >\n <div className=\"flex\">\n <div className=\"mr-2\">\n {selected.some((selectedOption) => selectedOption.value === item.value) ? (\n <CheckIcon className=\"h-4 w-4\" />\n ) : (\n <div className=\"h-4 w-4\" />\n )}\n </div>\n <div>{item.label}</div>\n </div>\n </CommandItem>\n ))}\n </CommandGroup>\n )}\n </CommandList>\n </PopoverContent>\n {selected.length > 0 && (\n <div className=\"flex flex-wrap gap-2 pt-2\">\n {selected.map((item) => (\n <Chip key={item.value} {...chipProps} className=\"gap-2 pr-1\" onRemove={() => handleUnselect(item)}>\n {item.label}\n </Chip>\n ))}\n </div>\n )}\n </Command>\n </PopoverRoot>\n )\n },\n)\n\nMultiSelect.displayName = 'MultiSelect'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,IAAA,cAAA,QAAA,YAAA,EAAA,SAAA,UAAA,WAAA,cAAA,cAAA,0BAAA,eAAA,qBAAA,YAAA,0BAAA,aAAA,KAAA,WAAA,SAAA;CAcI,MAAA,WAAA,QAAA,OAAA,IAAA;CACA,MAAA,CAAA,MAAA,WAAA,QAAA,SAAA,KAAA;CACA,MAAA,CAAA,UAAA,eAAA,QAAA,SAAA,QAAA,QAAA,WAAA,cAAA,SAAA,OAAA,KAAA,KAAA,CAAA,CAAA,CAAA;CAGA,MAAA,CAAA,YAAA,iBAAA,QAAA,SAAA,EAAA;CAEA,MAAA,cAAA,QAAA,OAAA,QAAA;CACA,QAAA,gBAAA;EACE,YAAA,UAAA;CACF,CAAA;CAEA,MAAA,iBAAA,QAAA,aAAA,SAAA;EACE,aAAA,SAAA,KAAA,QAAA,mBAAA,eAAA,UAAA,KAAA,KAAA,CAAA;CACF,GAAA,CAAA,CAAA;CAEA,MAAA,gBAAA,QAAA,aAAA,UAAA;EACE,MAAA,QAAA,SAAA;EACA,IAAA,OAAA;GACE,IAAA,MAAA,QAAA,YAAA,MAAA,QAAA,aACM;QAAA,MAAA,UAAA,IAAA,aAAA,SAAA;KAEA,MAAA,cAAA,CAAA,GAAA,IAAA;KACA,YAAA,IAAA;KACA,OAAA;IACF,CAAA;GAAA;GAIJ,IAAA,MAAA,QAAA,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AA,OAAA;OAAK,WAAA;OAAL,UAAA,CAAA,oBAAA,OAAA;QACO,WAAA;QACF,UAAA,SAAA,MAAA,mBAAA,eAAA,UAAA,KAAA,KAAA,IAAA,oBAAA,WAAA,EAAA,WAAA,UAAA,CAAA,IAAA,oBAAA,OAAA,EAAA,WAAA,UAAA,CAAA;OAKE,CAAA,GAAA,oBAAA,OAAA,EAAA,UAAA,KAAA,MAAA,CAAA,CAAA;;KAGI,GAAA,QAAA,KAAA,OAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA;;IAMtB,SAAA,SAAA,KAAA,oBAAA,OAAA;KACM,WAAA;KACF,UAAA,SAAA,KAAA,SAAA,oBAAA,MAAA;MACwB,GAAA;MAAe,WAAA;MAAuB,gBAAA,eAAA,IAAA;MAC1D,UAAA,KAAA;KACG,GAAA,KAAA,KAAA,CAAA;IAEL,CAAA;GAEA;;CACE,CAAA;AAEjB,CAAA;AAGF,YAAA,cAAA"}
|
|
1
|
+
{"version":3,"file":"MultiSelect.js","names":["React"],"sources":["../../../../src/components/inputs/MultiSelect/MultiSelect.tsx"],"sourcesContent":["'use client'\n\nimport { CaretUpDownIcon } from '@phosphor-icons/react/dist/ssr/CaretUpDown'\nimport { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport * as React from 'react'\nimport { ControllerFieldState } from 'react-hook-form'\n\nimport { Chip } from '../../data-display/Chip'\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '../../utils/Command'\nimport { PopoverContent, PopoverRoot, PopoverTrigger } from '../../utils/Popover'\nimport { Button, buttonVariants } from '../Button'\n\nimport { SURFACE_LIST } from '@/lib/surface'\nimport { cn } from '@/lib/utils'\n\n/**\n * Represents a selectable option in the MultiSelect component\n */\ntype Option = {\n /** Unique identifier for the option */\n value: string\n /** Display text for the option */\n label: string\n}\n\nexport type MultiSelectProps = {\n /**\n * Array of options to display in the select menu\n */\n options: Array<Option>\n\n /**\n * Props to be passed to the individual Chip components\n */\n chipProps?: React.ComponentProps<typeof Chip>\n\n /**\n * Callback fired when selected values change\n * @param value Array of selected option values\n */\n onChange?: (value: Array<string>) => void\n\n /**\n * Form field state from react-hook-form\n */\n fieldState?: ControllerFieldState\n\n /**\n * Initially selected option values\n */\n defaultValue?: Array<string>\n\n /**\n * Text shown in the select button when no option is selected\n * @default \"Select your options...\"\n */\n placeholder?: string\n\n /**\n * Text shown when no options match the search query\n * @default \"Options not found\"\n */\n notFoundText?: string\n\n /**\n * Placeholder text for the search input\n * @default \"Search...\"\n */\n commandInputPlaceholder?: string\n\n /**\n * Maximum number of items that can be selected\n * Shows a counter chip when specified\n */\n max?: number\n\n /**\n * Additional class names for the select button component\n */\n className?: string\n\n /**\n * Unique identifier for the select button component\n */\n id?: string\n}\n\n/**\n * A multi-select component with search functionality and chip display for selected items.\n * Supports keyboard navigation, search filtering, and maximum selection limit.\n *\n * @example\n * // Basic usage\n * <MultiSelect\n * options={[\n * { value: '1', label: 'Option 1' },\n * { value: '2', label: 'Option 2' }\n * ]}\n * onChange={(values) => console.log(values)}\n * />\n *\n * // With maximum selection limit\n * <MultiSelect\n * options={options}\n * max={3}\n * placeholder=\"Select up to 3 options\"\n * />\n *\n * // With custom chip styling\n * <MultiSelect\n * options={options}\n * chipProps={{ variant: 'primary' }}\n * />\n */\nexport const MultiSelect = React.forwardRef<HTMLInputElement, MultiSelectProps>(\n ({\n options,\n onChange,\n chipProps,\n defaultValue,\n placeholder = 'Select your options...',\n notFoundText = 'Options not found',\n fieldState,\n commandInputPlaceholder = 'Search...',\n max,\n className,\n id,\n }) => {\n const inputRef = React.useRef<HTMLInputElement>(null)\n const [open, setOpen] = React.useState(false)\n const [selected, setSelected] = React.useState<MultiSelectProps['options']>(\n options.filter((option) => defaultValue?.includes(option.value) ?? []),\n )\n const [inputValue, setInputValue] = React.useState('')\n\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n })\n\n const handleUnselect = React.useCallback((item: Option) => {\n setSelected((prev) => prev.filter((selectedOption) => selectedOption.value !== item.value))\n }, [])\n\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (input) {\n if (event.key === 'Delete' || event.key === 'Backspace') {\n if (input.value === '') {\n setSelected((prev) => {\n const newSelected = [...prev]\n newSelected.pop()\n return newSelected\n })\n }\n }\n\n if (event.key === 'Escape') {\n input.blur()\n }\n }\n }, [])\n\n React.useEffect(() => {\n onChangeRef.current?.(selected.map((item) => item.value))\n }, [selected])\n\n return (\n <PopoverRoot open={open} onOpenChange={setOpen}>\n <Command onKeyDown={handleKeyDown}>\n <PopoverTrigger asChild>\n <Button\n id={id}\n variant=\"text\"\n role=\"combobox\"\n aria-expanded={open}\n className={cn(\n buttonVariants({ variant: 'input', size: 'lg' }),\n 'w-full justify-between',\n open && 'border-neutral-950',\n fieldState?.invalid && 'border-error-400 focus-visible:border-error-700',\n className,\n )}\n >\n {placeholder}\n <CaretUpDownIcon className=\"ml-2 h-4 w-4 shrink-0 opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className={cn(SURFACE_LIST, 'p-0')}>\n <CommandInput\n placeholder={commandInputPlaceholder}\n ref={inputRef}\n value={inputValue}\n onValueChange={setInputValue}\n >\n {max && (\n <Chip\n variant={selected.length >= max ? 'primary' : 'default'}\n size=\"sm\"\n className=\"my-1 whitespace-nowrap\"\n >\n {selected.length} / {max}\n </Chip>\n )}\n </CommandInput>\n\n <CommandList>\n <CommandEmpty>{notFoundText}</CommandEmpty>\n {open && options.length > 0 && (\n <CommandGroup>\n {options.map((item) => (\n <CommandItem\n key={`item-${item.value}`}\n onMouseDown={(event) => {\n event.preventDefault()\n event.stopPropagation()\n }}\n onSelect={(value) => {\n const isSelected = selected.find((selectedOption) => selectedOption.label === value)\n if (isSelected) {\n handleUnselect(isSelected)\n } else if (!max || selected.length < max) {\n setInputValue('')\n setSelected((prev) => [...prev, item])\n }\n }}\n >\n <span aria-hidden className=\"mr-1 flex size-6 shrink-0 items-center justify-end\">\n {selected.some((selectedOption) => selectedOption.value === item.value) && (\n <CheckIcon weight=\"bold\" />\n )}\n </span>\n {item.label}\n </CommandItem>\n ))}\n </CommandGroup>\n )}\n </CommandList>\n </PopoverContent>\n {selected.length > 0 && (\n <div className=\"flex flex-wrap gap-2 pt-2\">\n {selected.map((item) => (\n <Chip key={item.value} {...chipProps} className=\"gap-2 pr-1\" onRemove={() => handleUnselect(item)}>\n {item.label}\n </Chip>\n ))}\n </div>\n )}\n </Command>\n </PopoverRoot>\n )\n },\n)\n\nMultiSelect.displayName = 'MultiSelect'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,IAAA,cAAA,QAAA,YAAA,EAAA,SAAA,UAAA,WAAA,cAAA,cAAA,0BAAA,eAAA,qBAAA,YAAA,0BAAA,aAAA,KAAA,WAAA,SAAA;CAcI,MAAA,WAAA,QAAA,OAAA,IAAA;CACA,MAAA,CAAA,MAAA,WAAA,QAAA,SAAA,KAAA;CACA,MAAA,CAAA,UAAA,eAAA,QAAA,SAAA,QAAA,QAAA,WAAA,cAAA,SAAA,OAAA,KAAA,KAAA,CAAA,CAAA,CAAA;CAGA,MAAA,CAAA,YAAA,iBAAA,QAAA,SAAA,EAAA;CAEA,MAAA,cAAA,QAAA,OAAA,QAAA;CACA,QAAA,gBAAA;EACE,YAAA,UAAA;CACF,CAAA;CAEA,MAAA,iBAAA,QAAA,aAAA,SAAA;EACE,aAAA,SAAA,KAAA,QAAA,mBAAA,eAAA,UAAA,KAAA,KAAA,CAAA;CACF,GAAA,CAAA,CAAA;CAEA,MAAA,gBAAA,QAAA,aAAA,UAAA;EACE,MAAA,QAAA,SAAA;EACA,IAAA,OAAA;GACE,IAAA,MAAA,QAAA,YAAA,MAAA,QAAA,aACM;QAAA,MAAA,UAAA,IAAA,aAAA,SAAA;KAEA,MAAA,cAAA,CAAA,GAAA,IAAA;KACA,YAAA,IAAA;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