@polymarbot/nuxt-layer-shadcn-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/assets/styles/animate.css +71 -0
- package/app/assets/styles/colors.css +116 -0
- package/app/assets/styles/globals.css +43 -0
- package/app/assets/styles/index.stories.ts +211 -0
- package/app/assets/styles/transition.css +34 -0
- package/app/assets/styles/utilities.css +26 -0
- package/app/components/shadcn/accordion/Accordion.vue +18 -0
- package/app/components/shadcn/accordion/AccordionContent.vue +23 -0
- package/app/components/shadcn/accordion/AccordionItem.vue +24 -0
- package/app/components/shadcn/accordion/AccordionTrigger.vue +37 -0
- package/app/components/shadcn/accordion/index.ts +4 -0
- package/app/components/shadcn/alert/Alert.vue +21 -0
- package/app/components/shadcn/alert/AlertDescription.vue +17 -0
- package/app/components/shadcn/alert/AlertTitle.vue +17 -0
- package/app/components/shadcn/alert/index.ts +24 -0
- package/app/components/shadcn/avatar/Avatar.vue +18 -0
- package/app/components/shadcn/avatar/AvatarFallback.vue +21 -0
- package/app/components/shadcn/avatar/AvatarImage.vue +16 -0
- package/app/components/shadcn/avatar/index.ts +3 -0
- package/app/components/shadcn/badge/Badge.vue +26 -0
- package/app/components/shadcn/badge/index.ts +26 -0
- package/app/components/shadcn/breadcrumb/Breadcrumb.vue +17 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbItem.vue +17 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbLink.vue +21 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbList.vue +17 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbPage.vue +20 -0
- package/app/components/shadcn/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/app/components/shadcn/breadcrumb/index.ts +7 -0
- package/app/components/shadcn/button/Button.vue +31 -0
- package/app/components/shadcn/button/index.ts +38 -0
- package/app/components/shadcn/card/Card.vue +22 -0
- package/app/components/shadcn/card/CardAction.vue +17 -0
- package/app/components/shadcn/card/CardContent.vue +17 -0
- package/app/components/shadcn/card/CardDescription.vue +17 -0
- package/app/components/shadcn/card/CardFooter.vue +17 -0
- package/app/components/shadcn/card/CardHeader.vue +17 -0
- package/app/components/shadcn/card/CardTitle.vue +17 -0
- package/app/components/shadcn/card/index.ts +7 -0
- package/app/components/shadcn/checkbox/Checkbox.vue +35 -0
- package/app/components/shadcn/checkbox/index.ts +1 -0
- package/app/components/shadcn/collapsible/Collapsible.vue +19 -0
- package/app/components/shadcn/collapsible/CollapsibleContent.vue +15 -0
- package/app/components/shadcn/collapsible/CollapsibleTrigger.vue +15 -0
- package/app/components/shadcn/collapsible/index.ts +3 -0
- package/app/components/shadcn/command/Command.vue +87 -0
- package/app/components/shadcn/command/CommandDialog.vue +31 -0
- package/app/components/shadcn/command/CommandEmpty.vue +27 -0
- package/app/components/shadcn/command/CommandGroup.vue +45 -0
- package/app/components/shadcn/command/CommandInput.vue +39 -0
- package/app/components/shadcn/command/CommandItem.vue +76 -0
- package/app/components/shadcn/command/CommandList.vue +25 -0
- package/app/components/shadcn/command/CommandSeparator.vue +21 -0
- package/app/components/shadcn/command/CommandShortcut.vue +17 -0
- package/app/components/shadcn/command/index.ts +25 -0
- package/app/components/shadcn/dialog/Dialog.vue +19 -0
- package/app/components/shadcn/dialog/DialogClose.vue +15 -0
- package/app/components/shadcn/dialog/DialogContent.vue +53 -0
- package/app/components/shadcn/dialog/DialogDescription.vue +23 -0
- package/app/components/shadcn/dialog/DialogFooter.vue +27 -0
- package/app/components/shadcn/dialog/DialogHeader.vue +17 -0
- package/app/components/shadcn/dialog/DialogOverlay.vue +21 -0
- package/app/components/shadcn/dialog/DialogScrollContent.vue +59 -0
- package/app/components/shadcn/dialog/DialogTitle.vue +23 -0
- package/app/components/shadcn/dialog/DialogTrigger.vue +15 -0
- package/app/components/shadcn/dialog/index.ts +10 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenu.vue +19 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuCheckboxItem.vue +39 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuContent.vue +39 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuGroup.vue +15 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuItem.vue +31 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuLabel.vue +23 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuRadioGroup.vue +21 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuRadioItem.vue +40 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuSeparator.vue +23 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuShortcut.vue +17 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuSub.vue +18 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuSubContent.vue +27 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuSubTrigger.vue +31 -0
- package/app/components/shadcn/dropdown-menu/DropdownMenuTrigger.vue +17 -0
- package/app/components/shadcn/dropdown-menu/index.ts +16 -0
- package/app/components/shadcn/field/Field.vue +25 -0
- package/app/components/shadcn/field/FieldContent.vue +20 -0
- package/app/components/shadcn/field/FieldDescription.vue +22 -0
- package/app/components/shadcn/field/FieldError.vue +53 -0
- package/app/components/shadcn/field/FieldGroup.vue +20 -0
- package/app/components/shadcn/field/FieldLabel.vue +23 -0
- package/app/components/shadcn/field/FieldLegend.vue +24 -0
- package/app/components/shadcn/field/FieldSeparator.vue +29 -0
- package/app/components/shadcn/field/FieldSet.vue +21 -0
- package/app/components/shadcn/field/FieldTitle.vue +20 -0
- package/app/components/shadcn/field/index.ts +39 -0
- package/app/components/shadcn/input/Input.vue +33 -0
- package/app/components/shadcn/input/index.ts +1 -0
- package/app/components/shadcn/input-group/InputGroup.vue +35 -0
- package/app/components/shadcn/input-group/InputGroupAddon.vue +36 -0
- package/app/components/shadcn/input-group/InputGroupButton.vue +29 -0
- package/app/components/shadcn/input-group/InputGroupInput.vue +19 -0
- package/app/components/shadcn/input-group/InputGroupText.vue +19 -0
- package/app/components/shadcn/input-group/InputGroupTextarea.vue +19 -0
- package/app/components/shadcn/input-group/index.ts +51 -0
- package/app/components/shadcn/label/Label.vue +26 -0
- package/app/components/shadcn/label/index.ts +1 -0
- package/app/components/shadcn/number-field/NumberField.vue +20 -0
- package/app/components/shadcn/number-field/NumberFieldContent.vue +14 -0
- package/app/components/shadcn/number-field/NumberFieldDecrement.vue +22 -0
- package/app/components/shadcn/number-field/NumberFieldIncrement.vue +22 -0
- package/app/components/shadcn/number-field/NumberFieldInput.vue +16 -0
- package/app/components/shadcn/number-field/index.ts +5 -0
- package/app/components/shadcn/pagination/Pagination.vue +26 -0
- package/app/components/shadcn/pagination/PaginationContent.vue +22 -0
- package/app/components/shadcn/pagination/PaginationEllipsis.vue +25 -0
- package/app/components/shadcn/pagination/PaginationFirst.vue +33 -0
- package/app/components/shadcn/pagination/PaginationItem.vue +34 -0
- package/app/components/shadcn/pagination/PaginationLast.vue +33 -0
- package/app/components/shadcn/pagination/PaginationNext.vue +33 -0
- package/app/components/shadcn/pagination/PaginationPrevious.vue +33 -0
- package/app/components/shadcn/pagination/index.ts +8 -0
- package/app/components/shadcn/pin-input/PinInput.vue +26 -0
- package/app/components/shadcn/pin-input/PinInputGroup.vue +21 -0
- package/app/components/shadcn/pin-input/PinInputSeparator.vue +19 -0
- package/app/components/shadcn/pin-input/PinInputSlot.vue +21 -0
- package/app/components/shadcn/pin-input/index.ts +4 -0
- package/app/components/shadcn/popover/Popover.vue +19 -0
- package/app/components/shadcn/popover/PopoverAnchor.vue +15 -0
- package/app/components/shadcn/popover/PopoverContent.vue +45 -0
- package/app/components/shadcn/popover/PopoverTrigger.vue +15 -0
- package/app/components/shadcn/popover/index.ts +4 -0
- package/app/components/shadcn/progress/Progress.vue +38 -0
- package/app/components/shadcn/progress/index.ts +1 -0
- package/app/components/shadcn/radio-group/RadioGroup.vue +25 -0
- package/app/components/shadcn/radio-group/RadioGroupItem.vue +40 -0
- package/app/components/shadcn/radio-group/index.ts +2 -0
- package/app/components/shadcn/scroll-area/ScrollArea.vue +33 -0
- package/app/components/shadcn/scroll-area/ScrollBar.vue +32 -0
- package/app/components/shadcn/scroll-area/index.ts +2 -0
- package/app/components/shadcn/select/Select.vue +19 -0
- package/app/components/shadcn/select/SelectContent.vue +51 -0
- package/app/components/shadcn/select/SelectGroup.vue +15 -0
- package/app/components/shadcn/select/SelectItem.vue +44 -0
- package/app/components/shadcn/select/SelectItemText.vue +15 -0
- package/app/components/shadcn/select/SelectLabel.vue +17 -0
- package/app/components/shadcn/select/SelectScrollDownButton.vue +26 -0
- package/app/components/shadcn/select/SelectScrollUpButton.vue +26 -0
- package/app/components/shadcn/select/SelectSeparator.vue +19 -0
- package/app/components/shadcn/select/SelectTrigger.vue +33 -0
- package/app/components/shadcn/select/SelectValue.vue +15 -0
- package/app/components/shadcn/select/index.ts +11 -0
- package/app/components/shadcn/separator/Separator.vue +29 -0
- package/app/components/shadcn/separator/index.ts +1 -0
- package/app/components/shadcn/sheet/Sheet.vue +19 -0
- package/app/components/shadcn/sheet/SheetClose.vue +15 -0
- package/app/components/shadcn/sheet/SheetContent.vue +62 -0
- package/app/components/shadcn/sheet/SheetDescription.vue +21 -0
- package/app/components/shadcn/sheet/SheetFooter.vue +16 -0
- package/app/components/shadcn/sheet/SheetHeader.vue +15 -0
- package/app/components/shadcn/sheet/SheetOverlay.vue +21 -0
- package/app/components/shadcn/sheet/SheetTitle.vue +21 -0
- package/app/components/shadcn/sheet/SheetTrigger.vue +15 -0
- package/app/components/shadcn/sheet/index.ts +8 -0
- package/app/components/shadcn/sidebar/Sidebar.vue +96 -0
- package/app/components/shadcn/sidebar/SidebarContent.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarFooter.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarGroup.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarGroupAction.vue +27 -0
- package/app/components/shadcn/sidebar/SidebarGroupContent.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarGroupLabel.vue +25 -0
- package/app/components/shadcn/sidebar/SidebarHeader.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarInput.vue +22 -0
- package/app/components/shadcn/sidebar/SidebarInset.vue +21 -0
- package/app/components/shadcn/sidebar/SidebarMenu.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarMenuAction.vue +35 -0
- package/app/components/shadcn/sidebar/SidebarMenuBadge.vue +26 -0
- package/app/components/shadcn/sidebar/SidebarMenuButton.vue +48 -0
- package/app/components/shadcn/sidebar/SidebarMenuButtonChild.vue +36 -0
- package/app/components/shadcn/sidebar/SidebarMenuItem.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarMenuSkeleton.vue +35 -0
- package/app/components/shadcn/sidebar/SidebarMenuSub.vue +22 -0
- package/app/components/shadcn/sidebar/SidebarMenuSubButton.vue +36 -0
- package/app/components/shadcn/sidebar/SidebarMenuSubItem.vue +18 -0
- package/app/components/shadcn/sidebar/SidebarProvider.vue +82 -0
- package/app/components/shadcn/sidebar/SidebarRail.vue +33 -0
- package/app/components/shadcn/sidebar/SidebarSeparator.vue +19 -0
- package/app/components/shadcn/sidebar/SidebarTrigger.vue +27 -0
- package/app/components/shadcn/sidebar/index.ts +60 -0
- package/app/components/shadcn/sidebar/utils.ts +19 -0
- package/app/components/shadcn/skeleton/Skeleton.vue +17 -0
- package/app/components/shadcn/skeleton/index.ts +1 -0
- package/app/components/shadcn/slider/Slider.vue +43 -0
- package/app/components/shadcn/slider/index.ts +1 -0
- package/app/components/shadcn/sonner/Sonner.vue +42 -0
- package/app/components/shadcn/sonner/index.ts +1 -0
- package/app/components/shadcn/switch/Switch.vue +38 -0
- package/app/components/shadcn/switch/index.ts +1 -0
- package/app/components/shadcn/table/Table.vue +16 -0
- package/app/components/shadcn/table/TableBody.vue +17 -0
- package/app/components/shadcn/table/TableCaption.vue +17 -0
- package/app/components/shadcn/table/TableCell.vue +22 -0
- package/app/components/shadcn/table/TableEmpty.vue +34 -0
- package/app/components/shadcn/table/TableFooter.vue +17 -0
- package/app/components/shadcn/table/TableHead.vue +17 -0
- package/app/components/shadcn/table/TableHeader.vue +17 -0
- package/app/components/shadcn/table/TableRow.vue +17 -0
- package/app/components/shadcn/table/index.ts +9 -0
- package/app/components/shadcn/table/utils.ts +10 -0
- package/app/components/shadcn/tabs/Tabs.vue +24 -0
- package/app/components/shadcn/tabs/TabsContent.vue +21 -0
- package/app/components/shadcn/tabs/TabsList.vue +24 -0
- package/app/components/shadcn/tabs/TabsTrigger.vue +26 -0
- package/app/components/shadcn/tabs/index.ts +4 -0
- package/app/components/shadcn/textarea/Textarea.vue +28 -0
- package/app/components/shadcn/textarea/index.ts +1 -0
- package/app/components/shadcn/toggle/Toggle.vue +35 -0
- package/app/components/shadcn/toggle/index.ts +28 -0
- package/app/components/shadcn/toggle-group/ToggleGroup.vue +49 -0
- package/app/components/shadcn/toggle-group/ToggleGroupItem.vue +46 -0
- package/app/components/shadcn/toggle-group/index.ts +2 -0
- package/app/components/shadcn/tooltip/Tooltip.vue +19 -0
- package/app/components/shadcn/tooltip/TooltipContent.vue +34 -0
- package/app/components/shadcn/tooltip/TooltipProvider.vue +14 -0
- package/app/components/shadcn/tooltip/TooltipTrigger.vue +15 -0
- package/app/components/shadcn/tooltip/index.ts +4 -0
- package/app/components/ui/Accordion/index.stories.ts +108 -0
- package/app/components/ui/Accordion/index.vue +80 -0
- package/app/components/ui/Accordion/types.ts +27 -0
- package/app/components/ui/Alert/index.stories.ts +53 -0
- package/app/components/ui/Alert/index.vue +61 -0
- package/app/components/ui/Alert/types.ts +9 -0
- package/app/components/ui/AlertDialog/index.stories.ts +108 -0
- package/app/components/ui/AlertDialog/index.vue +25 -0
- package/app/components/ui/AsyncDataTable/en.json +3 -0
- package/app/components/ui/AsyncDataTable/index.stories.ts +141 -0
- package/app/components/ui/AsyncDataTable/index.vue +312 -0
- package/app/components/ui/AsyncDataTable/types.ts +53 -0
- package/app/components/ui/Avatar/index.stories.ts +84 -0
- package/app/components/ui/Avatar/index.vue +52 -0
- package/app/components/ui/Avatar/types.ts +8 -0
- package/app/components/ui/Badge/index.stories.ts +67 -0
- package/app/components/ui/Badge/index.vue +12 -0
- package/app/components/ui/Badge/types.ts +3 -0
- package/app/components/ui/Breadcrumb/index.stories.ts +52 -0
- package/app/components/ui/Breadcrumb/index.vue +61 -0
- package/app/components/ui/Breadcrumb/types.ts +11 -0
- package/app/components/ui/Button/index.stories.ts +145 -0
- package/app/components/ui/Button/index.vue +63 -0
- package/app/components/ui/Button/types.ts +14 -0
- package/app/components/ui/ButtonGroup/index.stories.ts +75 -0
- package/app/components/ui/ButtonGroup/index.vue +22 -0
- package/app/components/ui/ButtonGroup/types.ts +3 -0
- package/app/components/ui/Card/index.stories.ts +65 -0
- package/app/components/ui/Card/index.vue +28 -0
- package/app/components/ui/Card/types.ts +3 -0
- package/app/components/ui/Checkbox/index.stories.ts +68 -0
- package/app/components/ui/Checkbox/index.vue +23 -0
- package/app/components/ui/Checkbox/types.ts +3 -0
- package/app/components/ui/CopyButton/en.json +4 -0
- package/app/components/ui/CopyButton/index.stories.ts +55 -0
- package/app/components/ui/CopyButton/index.vue +98 -0
- package/app/components/ui/CopyButton/types.ts +10 -0
- package/app/components/ui/DataTable/en.json +3 -0
- package/app/components/ui/DataTable/index.stories.ts +231 -0
- package/app/components/ui/DataTable/index.vue +505 -0
- package/app/components/ui/DataTable/types.ts +42 -0
- package/app/components/ui/DatePicker/en.json +9 -0
- package/app/components/ui/DatePicker/index.stories.ts +70 -0
- package/app/components/ui/DatePicker/index.vue +127 -0
- package/app/components/ui/DatePicker/style.css +88 -0
- package/app/components/ui/DatePicker/types.ts +41 -0
- package/app/components/ui/DateRangePicker/en.json +5 -0
- package/app/components/ui/DateRangePicker/index.stories.ts +67 -0
- package/app/components/ui/DateRangePicker/index.vue +138 -0
- package/app/components/ui/DateRangePicker/types.ts +31 -0
- package/app/components/ui/Divider/index.stories.ts +42 -0
- package/app/components/ui/Divider/index.vue +16 -0
- package/app/components/ui/Divider/types.ts +3 -0
- package/app/components/ui/Drawer/index.stories.ts +124 -0
- package/app/components/ui/Drawer/index.vue +197 -0
- package/app/components/ui/Drawer/types.ts +22 -0
- package/app/components/ui/Dropdown/index.stories.ts +145 -0
- package/app/components/ui/Dropdown/index.vue +258 -0
- package/app/components/ui/Dropdown/types.ts +87 -0
- package/app/components/ui/FormItem/index.stories.ts +70 -0
- package/app/components/ui/FormItem/index.vue +56 -0
- package/app/components/ui/FormItem/types.ts +14 -0
- package/app/components/ui/Help/index.stories.ts +54 -0
- package/app/components/ui/Help/index.vue +35 -0
- package/app/components/ui/Help/types.ts +8 -0
- package/app/components/ui/Icon/index.stories.ts +68 -0
- package/app/components/ui/Icon/index.vue +30 -0
- package/app/components/ui/Icon/types.ts +5 -0
- package/app/components/ui/Input/index.stories.ts +73 -0
- package/app/components/ui/Input/index.vue +92 -0
- package/app/components/ui/Input/types.ts +9 -0
- package/app/components/ui/InputCurrency/index.stories.ts +75 -0
- package/app/components/ui/InputCurrency/index.vue +31 -0
- package/app/components/ui/InputCurrency/types.ts +4 -0
- package/app/components/ui/InputNumber/index.stories.ts +56 -0
- package/app/components/ui/InputNumber/index.vue +76 -0
- package/app/components/ui/InputNumber/types.ts +10 -0
- package/app/components/ui/InputOtp/index.stories.ts +39 -0
- package/app/components/ui/InputOtp/index.vue +45 -0
- package/app/components/ui/InputOtp/types.ts +5 -0
- package/app/components/ui/InputPercent/index.stories.ts +32 -0
- package/app/components/ui/InputPercent/index.vue +8 -0
- package/app/components/ui/InputRange/index.stories.ts +37 -0
- package/app/components/ui/InputRange/index.vue +49 -0
- package/app/components/ui/InputRange/types.ts +8 -0
- package/app/components/ui/Loading/index.stories.ts +36 -0
- package/app/components/ui/Loading/index.vue +15 -0
- package/app/components/ui/Loading/types.ts +3 -0
- package/app/components/ui/Markdown/index.stories.ts +52 -0
- package/app/components/ui/Markdown/index.vue +22 -0
- package/app/components/ui/Markdown/themes/github.css +1248 -0
- package/app/components/ui/Markdown/types.ts +3 -0
- package/app/components/ui/Modal/index.stories.ts +124 -0
- package/app/components/ui/Modal/index.vue +202 -0
- package/app/components/ui/Modal/types.ts +23 -0
- package/app/components/ui/ModalContent/index.stories.ts +47 -0
- package/app/components/ui/ModalContent/index.vue +79 -0
- package/app/components/ui/ModalContent/types.ts +9 -0
- package/app/components/ui/PageCard/index.stories.ts +106 -0
- package/app/components/ui/PageCard/index.vue +135 -0
- package/app/components/ui/PageCard/types.ts +16 -0
- package/app/components/ui/Pagination/en.json +3 -0
- package/app/components/ui/Pagination/index.stories.ts +82 -0
- package/app/components/ui/Pagination/index.vue +173 -0
- package/app/components/ui/Pagination/types.ts +18 -0
- package/app/components/ui/Popover/index.stories.ts +67 -0
- package/app/components/ui/Popover/index.vue +21 -0
- package/app/components/ui/Popover/types.ts +5 -0
- package/app/components/ui/Qrcode/index.stories.ts +57 -0
- package/app/components/ui/Qrcode/index.vue +40 -0
- package/app/components/ui/Qrcode/types.ts +3 -0
- package/app/components/ui/Radio/index.stories.ts +71 -0
- package/app/components/ui/Radio/index.vue +10 -0
- package/app/components/ui/Radio/types.ts +3 -0
- package/app/components/ui/RadioCardGroup/index.stories.ts +90 -0
- package/app/components/ui/RadioCardGroup/index.vue +64 -0
- package/app/components/ui/RadioCardGroup/types.ts +13 -0
- package/app/components/ui/ScrollArea/index.stories.ts +66 -0
- package/app/components/ui/ScrollArea/index.vue +64 -0
- package/app/components/ui/ScrollArea/types.ts +5 -0
- package/app/components/ui/SearchSelect/en.json +5 -0
- package/app/components/ui/SearchSelect/index.stories.ts +126 -0
- package/app/components/ui/SearchSelect/index.vue +259 -0
- package/app/components/ui/SearchSelect/types.ts +39 -0
- package/app/components/ui/Select/en.json +6 -0
- package/app/components/ui/Select/index.stories.ts +128 -0
- package/app/components/ui/Select/index.vue +267 -0
- package/app/components/ui/Select/types.ts +34 -0
- package/app/components/ui/Skeleton/index.stories.ts +56 -0
- package/app/components/ui/Skeleton/index.vue +12 -0
- package/app/components/ui/Skeleton/types.ts +4 -0
- package/app/components/ui/Slider/index.stories.ts +60 -0
- package/app/components/ui/Slider/index.vue +27 -0
- package/app/components/ui/Slider/types.ts +5 -0
- package/app/components/ui/Surface/index.stories.ts +50 -0
- package/app/components/ui/Surface/index.vue +108 -0
- package/app/components/ui/Surface/types.ts +8 -0
- package/app/components/ui/Switch/index.stories.ts +32 -0
- package/app/components/ui/Switch/index.vue +10 -0
- package/app/components/ui/Switch/types.ts +3 -0
- package/app/components/ui/Tabs/index.stories.ts +116 -0
- package/app/components/ui/Tabs/index.vue +94 -0
- package/app/components/ui/Tabs/types.ts +19 -0
- package/app/components/ui/Tag/index.stories.ts +51 -0
- package/app/components/ui/Tag/index.vue +108 -0
- package/app/components/ui/Tag/types.ts +8 -0
- package/app/components/ui/Textarea/index.stories.ts +35 -0
- package/app/components/ui/Textarea/index.vue +50 -0
- package/app/components/ui/Textarea/types.ts +8 -0
- package/app/components/ui/Toast/index.stories.ts +48 -0
- package/app/components/ui/Toast/index.vue +21 -0
- package/app/components/ui/Toast/types.ts +5 -0
- package/app/components/ui/Tooltip/index.stories.ts +62 -0
- package/app/components/ui/Tooltip/index.vue +72 -0
- package/app/components/ui/Tooltip/types.ts +7 -0
- package/app/components/ui/WebLink/index.stories.ts +59 -0
- package/app/components/ui/WebLink/index.vue +61 -0
- package/app/components/ui/WebLink/types.ts +11 -0
- package/app/composables/index.ts +9 -0
- package/app/composables/useDialog.ts +76 -0
- package/app/composables/useToast.ts +49 -0
- package/app/en.json +23 -0
- package/app/types/index.ts +7 -0
- package/app/utils/index.ts +6 -0
- package/i18n/messages/ar.json +65 -0
- package/i18n/messages/de.json +65 -0
- package/i18n/messages/en.json +65 -0
- package/i18n/messages/es.json +65 -0
- package/i18n/messages/fr.json +65 -0
- package/i18n/messages/hi.json +65 -0
- package/i18n/messages/id.json +65 -0
- package/i18n/messages/it.json +65 -0
- package/i18n/messages/ja.json +65 -0
- package/i18n/messages/ko.json +65 -0
- package/i18n/messages/nl.json +65 -0
- package/i18n/messages/pl.json +65 -0
- package/i18n/messages/pt.json +65 -0
- package/i18n/messages/ru.json +65 -0
- package/i18n/messages/th.json +65 -0
- package/i18n/messages/tr.json +65 -0
- package/i18n/messages/vi.json +65 -0
- package/i18n/messages/zh-CN.json +65 -0
- package/i18n/messages/zh-TW.json +65 -0
- package/i18n.config.ts +19 -0
- package/nuxt.config.ts +62 -0
- package/package.json +46 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
<script setup lang="ts" generic="TValue extends string | number = string, TMeta = unknown">
|
|
2
|
+
import { debounce } from 'lodash-es'
|
|
3
|
+
import type { SelectOption } from '../Select/types'
|
|
4
|
+
import type { SearchSelectProps } from './types'
|
|
5
|
+
|
|
6
|
+
type Option = SelectOption<TValue, TMeta>
|
|
7
|
+
|
|
8
|
+
const T = useTranslations('components.ui.SearchSelect')
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<SearchSelectProps<TValue, TMeta>>(), {
|
|
11
|
+
modelValue: undefined,
|
|
12
|
+
defaultOptions: () => [],
|
|
13
|
+
autoLoad: false,
|
|
14
|
+
loadMethod: undefined,
|
|
15
|
+
loadValueOptionMethod: undefined,
|
|
16
|
+
loadLimit: 20,
|
|
17
|
+
placeholder: undefined,
|
|
18
|
+
disabled: false,
|
|
19
|
+
searchPlaceholder: undefined,
|
|
20
|
+
emptyText: undefined,
|
|
21
|
+
searchEmptyText: undefined,
|
|
22
|
+
createNewTo: undefined,
|
|
23
|
+
createNewText: undefined,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{
|
|
27
|
+
'update:modelValue': [value: TValue | undefined]
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const model = computed({
|
|
31
|
+
get: () => props.modelValue,
|
|
32
|
+
set: value => emit('update:modelValue', value),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const keyword = ref('')
|
|
36
|
+
const isLoading = ref(false)
|
|
37
|
+
const fetchedValueOption = shallowRef<Option | null>(null)
|
|
38
|
+
const pagination = usePagination<Option>([], { limit: props.loadLimit })
|
|
39
|
+
|
|
40
|
+
// -- Data loading --
|
|
41
|
+
|
|
42
|
+
async function fetchOptions (offset: number, limit: number) {
|
|
43
|
+
if (!props.loadMethod) return
|
|
44
|
+
const result = await props.loadMethod({ keyword: keyword.value, offset, limit })
|
|
45
|
+
pagination.update(result.items, { total: result.total })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function loadMore () {
|
|
49
|
+
if (!props.loadMethod || isLoading.value) return
|
|
50
|
+
const next = pagination.next.value
|
|
51
|
+
if (!next) return
|
|
52
|
+
|
|
53
|
+
isLoading.value = true
|
|
54
|
+
try {
|
|
55
|
+
await fetchOptions(next.offset, next.limit)
|
|
56
|
+
} finally {
|
|
57
|
+
isLoading.value = false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function resetAndLoad () {
|
|
62
|
+
if (!props.loadMethod) return
|
|
63
|
+
|
|
64
|
+
fetchedValueOption.value = null
|
|
65
|
+
pagination.reset([], { limit: props.loadLimit })
|
|
66
|
+
isLoading.value = true
|
|
67
|
+
try {
|
|
68
|
+
await fetchOptions(0, props.loadLimit)
|
|
69
|
+
|
|
70
|
+
// Fetch value option if not found in loaded results
|
|
71
|
+
if (model.value != null && !isValueInOptions(model.value)) {
|
|
72
|
+
fetchValueOption(model.value)
|
|
73
|
+
}
|
|
74
|
+
} finally {
|
|
75
|
+
isLoading.value = false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// -- Value option fetching --
|
|
80
|
+
|
|
81
|
+
function isValueInOptions (value: TValue): boolean {
|
|
82
|
+
if (props.defaultOptions?.some(opt => opt.value === value)) return true
|
|
83
|
+
if (pagination.items.value.some(opt => opt.value === value)) return true
|
|
84
|
+
if (fetchedValueOption.value?.value === value) return true
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function fetchValueOption (value: TValue) {
|
|
89
|
+
if (!props.loadValueOptionMethod) return
|
|
90
|
+
if (fetchedValueOption.value?.value === value) return
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
fetchedValueOption.value = await props.loadValueOptionMethod(value)
|
|
94
|
+
} catch {
|
|
95
|
+
fetchedValueOption.value = null
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// -- Displayed options (deduplication) --
|
|
100
|
+
|
|
101
|
+
const displayedOptions = computed<Option[]>(() => {
|
|
102
|
+
const fetched = fetchedValueOption.value
|
|
103
|
+
const defaults = props.defaultOptions ?? []
|
|
104
|
+
const loaded = pagination.items.value
|
|
105
|
+
|
|
106
|
+
const priorityValues = new Set<TValue>(defaults.map(opt => opt.value))
|
|
107
|
+
const priorityOptions: Option[] = []
|
|
108
|
+
|
|
109
|
+
if (fetched && !priorityValues.has(fetched.value)) {
|
|
110
|
+
priorityOptions.push(fetched)
|
|
111
|
+
priorityValues.add(fetched.value)
|
|
112
|
+
}
|
|
113
|
+
priorityOptions.push(...defaults)
|
|
114
|
+
|
|
115
|
+
const dedupedLoaded = loaded.filter(opt => !priorityValues.has(opt.value))
|
|
116
|
+
|
|
117
|
+
return [ ...priorityOptions, ...dedupedLoaded ]
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const hasMore = computed(() => !!props.loadMethod && !!pagination.next.value)
|
|
121
|
+
|
|
122
|
+
// -- Filter (bypass client-side filtering, delegate to server) --
|
|
123
|
+
|
|
124
|
+
const filterFunction: SelectFilterFunction = items => items
|
|
125
|
+
|
|
126
|
+
// -- Search --
|
|
127
|
+
|
|
128
|
+
const debouncedSearch = debounce(() => resetAndLoad(), 300)
|
|
129
|
+
|
|
130
|
+
function handleSearch (value: string) {
|
|
131
|
+
keyword.value = value
|
|
132
|
+
debouncedSearch()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// -- Empty text --
|
|
136
|
+
|
|
137
|
+
const computedEmptyText = computed(() => {
|
|
138
|
+
if (keyword.value) return props.searchEmptyText ?? T('noSearchItems')
|
|
139
|
+
return props.emptyText ?? T('noItems')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
// -- Popover open/close --
|
|
143
|
+
|
|
144
|
+
function handleOpen () {
|
|
145
|
+
if (props.loadMethod && displayedOptions.value.length === 0) {
|
|
146
|
+
resetAndLoad()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function handleClose () {
|
|
151
|
+
if (keyword.value) {
|
|
152
|
+
keyword.value = ''
|
|
153
|
+
debouncedSearch.cancel()
|
|
154
|
+
resetAndLoad()
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// -- Auto-load --
|
|
159
|
+
|
|
160
|
+
function shouldAutoLoad (): boolean {
|
|
161
|
+
if (!props.autoLoad || !props.loadMethod) return false
|
|
162
|
+
if (pagination.items.value.length === 0) return true
|
|
163
|
+
if (model.value != null) return !isValueInOptions(model.value)
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
watch(
|
|
168
|
+
[ () => props.autoLoad, () => model.value ?? undefined ],
|
|
169
|
+
() => {
|
|
170
|
+
if (shouldAutoLoad()) resetAndLoad()
|
|
171
|
+
},
|
|
172
|
+
{ immediate: true },
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
// -- Value option lookup for value slot --
|
|
176
|
+
|
|
177
|
+
function findOptionByValue (value: TValue | undefined): Option | undefined {
|
|
178
|
+
if (value == null) return undefined
|
|
179
|
+
return displayedOptions.value.find(opt => opt.value === value)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
defineExpose({ refresh: resetAndLoad })
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<Select
|
|
187
|
+
v-model="model"
|
|
188
|
+
:options="displayedOptions"
|
|
189
|
+
:filter="filterFunction"
|
|
190
|
+
:placeholder="placeholder"
|
|
191
|
+
:disabled="disabled"
|
|
192
|
+
:searchPlaceholder="searchPlaceholder"
|
|
193
|
+
:emptyText="computedEmptyText"
|
|
194
|
+
@search="handleSearch"
|
|
195
|
+
@open="handleOpen"
|
|
196
|
+
@close="handleClose"
|
|
197
|
+
>
|
|
198
|
+
<template
|
|
199
|
+
v-if="$slots.value"
|
|
200
|
+
#value="slotProps"
|
|
201
|
+
>
|
|
202
|
+
<slot
|
|
203
|
+
name="value"
|
|
204
|
+
v-bind="slotProps"
|
|
205
|
+
:option="findOptionByValue(model)"
|
|
206
|
+
/>
|
|
207
|
+
</template>
|
|
208
|
+
|
|
209
|
+
<template
|
|
210
|
+
v-if="$slots.option"
|
|
211
|
+
#option="slotProps"
|
|
212
|
+
>
|
|
213
|
+
<slot
|
|
214
|
+
name="option"
|
|
215
|
+
v-bind="slotProps"
|
|
216
|
+
/>
|
|
217
|
+
</template>
|
|
218
|
+
|
|
219
|
+
<template #listEnd>
|
|
220
|
+
<EffectIntersectionChecker
|
|
221
|
+
v-if="hasMore"
|
|
222
|
+
:disabled="isLoading"
|
|
223
|
+
class="flex items-center justify-center py-2"
|
|
224
|
+
@show="loadMore"
|
|
225
|
+
>
|
|
226
|
+
<Icon
|
|
227
|
+
name="loader-circle"
|
|
228
|
+
class="size-4 animate-spin text-muted-foreground"
|
|
229
|
+
/>
|
|
230
|
+
</EffectIntersectionChecker>
|
|
231
|
+
</template>
|
|
232
|
+
|
|
233
|
+
<template
|
|
234
|
+
v-if="createNewTo || $slots.footer"
|
|
235
|
+
#footer
|
|
236
|
+
>
|
|
237
|
+
<slot name="footer">
|
|
238
|
+
<div class="border-t border-border">
|
|
239
|
+
<WebLink
|
|
240
|
+
:to="createNewTo!"
|
|
241
|
+
target="_blank"
|
|
242
|
+
unstyled
|
|
243
|
+
class="
|
|
244
|
+
flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground
|
|
245
|
+
transition-colors
|
|
246
|
+
hover:bg-accent
|
|
247
|
+
"
|
|
248
|
+
>
|
|
249
|
+
<Icon
|
|
250
|
+
name="plus"
|
|
251
|
+
class="size-4"
|
|
252
|
+
/>
|
|
253
|
+
{{ createNewText ?? T('createNew') }}
|
|
254
|
+
</WebLink>
|
|
255
|
+
</div>
|
|
256
|
+
</slot>
|
|
257
|
+
</template>
|
|
258
|
+
</Select>
|
|
259
|
+
</template>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SelectOption } from '../Select/types'
|
|
2
|
+
|
|
3
|
+
/** Result returned by loadMethod */
|
|
4
|
+
export interface SearchSelectLoadMethodResult<V extends string | number = string, M = unknown> {
|
|
5
|
+
items: SelectOption<V, M>[]
|
|
6
|
+
total: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Parameters passed to loadMethod */
|
|
10
|
+
export interface SearchSelectLoadMethodParams {
|
|
11
|
+
keyword: string
|
|
12
|
+
offset: number
|
|
13
|
+
limit: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SearchSelectProps<V extends string | number = string, M = unknown> {
|
|
17
|
+
modelValue?: V
|
|
18
|
+
/** Default options displayed at the top (always visible, not affected by search) */
|
|
19
|
+
defaultOptions?: SelectOption<V, M>[]
|
|
20
|
+
/** Auto-load on mount or when selected value is not in options */
|
|
21
|
+
autoLoad?: boolean
|
|
22
|
+
/** Async function to load options */
|
|
23
|
+
loadMethod?: (params: SearchSelectLoadMethodParams) => Promise<SearchSelectLoadMethodResult<V, M>>
|
|
24
|
+
/** Async function to load a single option by value (called if value not found after first load) */
|
|
25
|
+
loadValueOptionMethod?: (value: V) => Promise<SelectOption<V, M> | null>
|
|
26
|
+
/** Items per request (default: 20) */
|
|
27
|
+
loadLimit?: number
|
|
28
|
+
placeholder?: string
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
searchPlaceholder?: string
|
|
31
|
+
/** Message when no options available (no search keyword) */
|
|
32
|
+
emptyText?: string
|
|
33
|
+
/** Message when search returns no results */
|
|
34
|
+
searchEmptyText?: string
|
|
35
|
+
/** Link URL for "Create new" footer action */
|
|
36
|
+
createNewTo?: string
|
|
37
|
+
/** Custom text for "Create new" link */
|
|
38
|
+
createNewText?: string
|
|
39
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
|
+
import Select from './index.vue'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'UI/Select',
|
|
6
|
+
component: Select as any,
|
|
7
|
+
argTypes: {
|
|
8
|
+
disabled: { control: 'boolean' },
|
|
9
|
+
},
|
|
10
|
+
args: {
|
|
11
|
+
disabled: false,
|
|
12
|
+
},
|
|
13
|
+
} satisfies Meta
|
|
14
|
+
|
|
15
|
+
export default meta
|
|
16
|
+
type Story = StoryObj<typeof meta>
|
|
17
|
+
|
|
18
|
+
export const Default: Story = {
|
|
19
|
+
render: args => ({
|
|
20
|
+
components: { Select },
|
|
21
|
+
setup () {
|
|
22
|
+
const selected = ref<string>()
|
|
23
|
+
const filtered = ref<string>()
|
|
24
|
+
const multiple = ref<string[]>([])
|
|
25
|
+
const scrollable = ref<string>()
|
|
26
|
+
const grouped = ref<string>()
|
|
27
|
+
|
|
28
|
+
const frameworks = [
|
|
29
|
+
{ label: 'React', value: 'react' },
|
|
30
|
+
{ label: 'Vue', value: 'vue' },
|
|
31
|
+
{ label: 'Angular', value: 'angular' },
|
|
32
|
+
{ label: 'Svelte', value: 'svelte' },
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
const withDisabled = [
|
|
36
|
+
{ label: 'React', value: 'react' },
|
|
37
|
+
{ label: 'Vue', value: 'vue' },
|
|
38
|
+
{ label: 'Angular', value: 'angular', disabled: true },
|
|
39
|
+
{ label: 'Svelte', value: 'svelte' },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const manyOptions = Array.from({ length: 50 }, (_, i) => ({
|
|
43
|
+
label: `Option ${i + 1}`,
|
|
44
|
+
value: `option-${i + 1}`,
|
|
45
|
+
}))
|
|
46
|
+
|
|
47
|
+
const withGroups = [
|
|
48
|
+
{ label: 'React', value: 'react', group: 'Frontend' },
|
|
49
|
+
{ label: 'Vue', value: 'vue', group: 'Frontend' },
|
|
50
|
+
{ label: 'Angular', value: 'angular', group: 'Frontend' },
|
|
51
|
+
{ label: 'Node.js', value: 'node', group: 'Backend' },
|
|
52
|
+
{ label: 'Django', value: 'django', group: 'Backend' },
|
|
53
|
+
{ label: 'Rails', value: 'rails', group: 'Backend' },
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
return { args, selected, filtered, multiple, scrollable, grouped, frameworks, withDisabled, manyOptions, withGroups }
|
|
57
|
+
},
|
|
58
|
+
template: `
|
|
59
|
+
<div class="space-y-10 max-w-sm">
|
|
60
|
+
<!-- Controlled -->
|
|
61
|
+
<section>
|
|
62
|
+
<h3 class="mb-4 text-lg font-medium">Controlled</h3>
|
|
63
|
+
<Select
|
|
64
|
+
v-model="selected"
|
|
65
|
+
:options="frameworks"
|
|
66
|
+
v-bind="args"
|
|
67
|
+
/>
|
|
68
|
+
<div class="mt-2 text-sm text-muted-foreground">Selected: {{ selected ?? 'none' }}</div>
|
|
69
|
+
</section>
|
|
70
|
+
|
|
71
|
+
<!-- With Filter -->
|
|
72
|
+
<section>
|
|
73
|
+
<h3 class="mb-4 text-lg font-medium">With Filter</h3>
|
|
74
|
+
<Select
|
|
75
|
+
v-model="filtered"
|
|
76
|
+
:options="manyOptions"
|
|
77
|
+
placeholder="Search and select"
|
|
78
|
+
filter
|
|
79
|
+
/>
|
|
80
|
+
<div class="mt-2 text-sm text-muted-foreground">Selected: {{ filtered ?? 'none' }}</div>
|
|
81
|
+
</section>
|
|
82
|
+
|
|
83
|
+
<!-- Multiple -->
|
|
84
|
+
<section>
|
|
85
|
+
<h3 class="mb-4 text-lg font-medium">Multiple</h3>
|
|
86
|
+
<Select
|
|
87
|
+
v-model="multiple"
|
|
88
|
+
:options="frameworks"
|
|
89
|
+
placeholder="Select frameworks"
|
|
90
|
+
multiple
|
|
91
|
+
/>
|
|
92
|
+
<div class="mt-2 text-sm text-muted-foreground">Selected: {{ multiple.length > 0 ? multiple.join(', ') : 'none' }}</div>
|
|
93
|
+
</section>
|
|
94
|
+
|
|
95
|
+
<!-- With Disabled Options -->
|
|
96
|
+
<section>
|
|
97
|
+
<h3 class="mb-4 text-lg font-medium">With Disabled Options</h3>
|
|
98
|
+
<Select
|
|
99
|
+
:options="withDisabled"
|
|
100
|
+
placeholder="Select a framework"
|
|
101
|
+
/>
|
|
102
|
+
</section>
|
|
103
|
+
|
|
104
|
+
<!-- Scrollable (50 items) -->
|
|
105
|
+
<section>
|
|
106
|
+
<h3 class="mb-4 text-lg font-medium">Scrollable (50 items)</h3>
|
|
107
|
+
<Select
|
|
108
|
+
v-model="scrollable"
|
|
109
|
+
:options="manyOptions"
|
|
110
|
+
placeholder="Select an option"
|
|
111
|
+
/>
|
|
112
|
+
<div class="mt-2 text-sm text-muted-foreground">Selected: {{ scrollable ?? 'none' }}</div>
|
|
113
|
+
</section>
|
|
114
|
+
|
|
115
|
+
<!-- Grouped -->
|
|
116
|
+
<section>
|
|
117
|
+
<h3 class="mb-4 text-lg font-medium">Grouped</h3>
|
|
118
|
+
<Select
|
|
119
|
+
v-model="grouped"
|
|
120
|
+
:options="withGroups"
|
|
121
|
+
placeholder="Select a framework"
|
|
122
|
+
/>
|
|
123
|
+
<div class="mt-2 text-sm text-muted-foreground">Selected: {{ grouped ?? 'none' }}</div>
|
|
124
|
+
</section>
|
|
125
|
+
</div>
|
|
126
|
+
`,
|
|
127
|
+
}),
|
|
128
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<script setup lang="ts" generic="TValue extends string | number = string, TMeta = unknown">
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
CommandEmpty,
|
|
5
|
+
CommandGroup,
|
|
6
|
+
CommandInput,
|
|
7
|
+
CommandItem,
|
|
8
|
+
CommandList,
|
|
9
|
+
CommandSeparator,
|
|
10
|
+
} from '@polymarbot/nuxt-layer-shadcn-ui/app/components/shadcn/command'
|
|
11
|
+
import {
|
|
12
|
+
InputGroup,
|
|
13
|
+
InputGroupAddon,
|
|
14
|
+
InputGroupButton,
|
|
15
|
+
} from '@polymarbot/nuxt-layer-shadcn-ui/app/components/shadcn/input-group'
|
|
16
|
+
import {
|
|
17
|
+
Popover as ShadcnPopover,
|
|
18
|
+
PopoverContent,
|
|
19
|
+
PopoverTrigger,
|
|
20
|
+
} from '@polymarbot/nuxt-layer-shadcn-ui/app/components/shadcn/popover'
|
|
21
|
+
import type { SelectOption, SelectProps } from './types'
|
|
22
|
+
|
|
23
|
+
type Option = SelectOption<TValue, TMeta>
|
|
24
|
+
|
|
25
|
+
const T = useTranslations('components.ui.Select')
|
|
26
|
+
|
|
27
|
+
const props = withDefaults(defineProps<SelectProps<TValue, TMeta>>(), {
|
|
28
|
+
options: () => [],
|
|
29
|
+
modelValue: undefined,
|
|
30
|
+
placeholder: undefined,
|
|
31
|
+
disabled: false,
|
|
32
|
+
filter: false,
|
|
33
|
+
searchPlaceholder: undefined,
|
|
34
|
+
emptyText: undefined,
|
|
35
|
+
multiple: false,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{
|
|
39
|
+
'update:modelValue': [value: TValue | TValue[]]
|
|
40
|
+
'search': [value: string]
|
|
41
|
+
'open': []
|
|
42
|
+
'close': []
|
|
43
|
+
}>()
|
|
44
|
+
|
|
45
|
+
const open = ref(false)
|
|
46
|
+
|
|
47
|
+
watch(open, value => {
|
|
48
|
+
if (value && props.disabled) {
|
|
49
|
+
open.value = false
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
value ? emit('open') : emit('close')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// -- Filter --
|
|
56
|
+
|
|
57
|
+
const commandFilterFunction = computed(() => {
|
|
58
|
+
return typeof props.filter === 'function' ? props.filter : undefined
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// -- Selection --
|
|
62
|
+
|
|
63
|
+
function isSelected (value: TValue): boolean {
|
|
64
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
65
|
+
return props.modelValue.includes(value)
|
|
66
|
+
}
|
|
67
|
+
return props.modelValue === value
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function handleSelect (optionValue: TValue) {
|
|
71
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
72
|
+
const current = props.modelValue
|
|
73
|
+
const newValue = current.includes(optionValue)
|
|
74
|
+
? current.filter(v => v !== optionValue)
|
|
75
|
+
: [ ...current, optionValue ]
|
|
76
|
+
emit('update:modelValue', newValue)
|
|
77
|
+
} else {
|
|
78
|
+
emit('update:modelValue', optionValue)
|
|
79
|
+
open.value = false
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// -- Selected display --
|
|
84
|
+
|
|
85
|
+
const selectedOption = computed(() => {
|
|
86
|
+
if (props.multiple) return undefined
|
|
87
|
+
return props.options?.find(opt => opt.value === props.modelValue)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const selectedOptions = computed(() => {
|
|
91
|
+
if (!props.multiple || !Array.isArray(props.modelValue)) return []
|
|
92
|
+
return props.modelValue
|
|
93
|
+
.map(val => props.options?.find(opt => opt.value === val))
|
|
94
|
+
.filter((opt): opt is Option => !!opt)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// -- Grouping --
|
|
98
|
+
|
|
99
|
+
type OptionGroupEntry = { label: string | undefined, items: Option[] }
|
|
100
|
+
|
|
101
|
+
const groupedOptions = computed<OptionGroupEntry[]>(() => {
|
|
102
|
+
const groups: OptionGroupEntry[] = []
|
|
103
|
+
const map = new Map<string | undefined, OptionGroupEntry>()
|
|
104
|
+
|
|
105
|
+
for (const opt of props.options ?? []) {
|
|
106
|
+
const key = opt.group
|
|
107
|
+
let group = map.get(key)
|
|
108
|
+
if (!group) {
|
|
109
|
+
group = { label: key, items: []}
|
|
110
|
+
map.set(key, group)
|
|
111
|
+
groups.push(group)
|
|
112
|
+
}
|
|
113
|
+
group.items.push(opt)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return groups
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// -- Command modelValue (sync selection state with ListboxRoot) --
|
|
120
|
+
|
|
121
|
+
const commandModelValue = computed(() => {
|
|
122
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
123
|
+
return props.modelValue.map(String)
|
|
124
|
+
}
|
|
125
|
+
return props.modelValue !== undefined ? String(props.modelValue) : ''
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// -- Clear --
|
|
129
|
+
|
|
130
|
+
const hasValue = computed(() => {
|
|
131
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
132
|
+
return props.modelValue.length > 0
|
|
133
|
+
}
|
|
134
|
+
return props.modelValue !== undefined && props.modelValue !== null
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const showClearButton = computed(() => hasValue.value && !props.disabled)
|
|
138
|
+
|
|
139
|
+
function handleClear (event: MouseEvent) {
|
|
140
|
+
event.stopPropagation()
|
|
141
|
+
if (props.multiple) {
|
|
142
|
+
emit('update:modelValue', [] as TValue[])
|
|
143
|
+
} else {
|
|
144
|
+
emit('update:modelValue', undefined as unknown as TValue)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<template>
|
|
150
|
+
<ShadcnPopover v-model:open="open">
|
|
151
|
+
<PopoverTrigger asChild>
|
|
152
|
+
<InputGroup
|
|
153
|
+
role="combobox"
|
|
154
|
+
tabindex="0"
|
|
155
|
+
:aria-expanded="open"
|
|
156
|
+
:data-disabled="disabled || undefined"
|
|
157
|
+
:data-state="open ? 'open' : 'closed'"
|
|
158
|
+
class="
|
|
159
|
+
cursor-pointer
|
|
160
|
+
data-[state=open]:border-ring data-[state=open]:ring-[3px]
|
|
161
|
+
data-[state=open]:ring-ring/50
|
|
162
|
+
"
|
|
163
|
+
>
|
|
164
|
+
<span
|
|
165
|
+
class="
|
|
166
|
+
line-clamp-1 flex flex-1 items-center gap-2 px-3 py-1 text-base
|
|
167
|
+
whitespace-nowrap
|
|
168
|
+
md:text-sm
|
|
169
|
+
"
|
|
170
|
+
>
|
|
171
|
+
<template v-if="multiple && selectedOptions.length > 0">
|
|
172
|
+
<slot
|
|
173
|
+
name="value"
|
|
174
|
+
:options="selectedOptions"
|
|
175
|
+
>
|
|
176
|
+
{{ selectedOptions.length >= 3 ? T('itemsSelected', { count: selectedOptions.length }) : selectedOptions.map(opt => opt.label).join(', ') }}
|
|
177
|
+
</slot>
|
|
178
|
+
</template>
|
|
179
|
+
<template v-else-if="!multiple && selectedOption">
|
|
180
|
+
<slot
|
|
181
|
+
name="value"
|
|
182
|
+
:option="selectedOption"
|
|
183
|
+
>
|
|
184
|
+
{{ selectedOption.label }}
|
|
185
|
+
</slot>
|
|
186
|
+
</template>
|
|
187
|
+
<span
|
|
188
|
+
v-else
|
|
189
|
+
class="text-muted-foreground"
|
|
190
|
+
>
|
|
191
|
+
{{ placeholder ?? T('placeholder') }}
|
|
192
|
+
</span>
|
|
193
|
+
</span>
|
|
194
|
+
<InputGroupAddon
|
|
195
|
+
v-if="showClearButton"
|
|
196
|
+
align="inline-end"
|
|
197
|
+
>
|
|
198
|
+
<InputGroupButton
|
|
199
|
+
size="icon-xs"
|
|
200
|
+
@click="handleClear"
|
|
201
|
+
>
|
|
202
|
+
<Icon name="x" />
|
|
203
|
+
</InputGroupButton>
|
|
204
|
+
</InputGroupAddon>
|
|
205
|
+
<InputGroupAddon align="inline-end">
|
|
206
|
+
<Icon
|
|
207
|
+
name="chevron-down"
|
|
208
|
+
class="size-4 opacity-50"
|
|
209
|
+
/>
|
|
210
|
+
</InputGroupAddon>
|
|
211
|
+
</InputGroup>
|
|
212
|
+
</PopoverTrigger>
|
|
213
|
+
<PopoverContent class="w-(--reka-popover-trigger-width) p-0">
|
|
214
|
+
<Command
|
|
215
|
+
:modelValue="commandModelValue"
|
|
216
|
+
:filterFunction="commandFilterFunction"
|
|
217
|
+
:multiple="multiple"
|
|
218
|
+
highlightOnHover
|
|
219
|
+
@update:searchTerm="(value: string) => emit('search', value)"
|
|
220
|
+
>
|
|
221
|
+
<CommandInput
|
|
222
|
+
v-if="!!filter"
|
|
223
|
+
:placeholder="searchPlaceholder ?? T('searchPlaceholder')"
|
|
224
|
+
/>
|
|
225
|
+
<CommandList>
|
|
226
|
+
<CommandEmpty>
|
|
227
|
+
{{ emptyText ?? T('noItems') }}
|
|
228
|
+
</CommandEmpty>
|
|
229
|
+
|
|
230
|
+
<template
|
|
231
|
+
v-for="(group, index) in groupedOptions"
|
|
232
|
+
:key="group.label ?? '_ungrouped'"
|
|
233
|
+
>
|
|
234
|
+
<CommandSeparator v-if="index > 0 && group.label" />
|
|
235
|
+
<CommandGroup :heading="group.label">
|
|
236
|
+
<CommandItem
|
|
237
|
+
v-for="option in group.items"
|
|
238
|
+
:key="String(option.value)"
|
|
239
|
+
:value="String(option.value)"
|
|
240
|
+
:disabled="option.disabled"
|
|
241
|
+
@select="handleSelect(option.value)"
|
|
242
|
+
>
|
|
243
|
+
<slot
|
|
244
|
+
name="option"
|
|
245
|
+
:option="option"
|
|
246
|
+
:selected="isSelected(option.value)"
|
|
247
|
+
>
|
|
248
|
+
{{ option.label }}
|
|
249
|
+
</slot>
|
|
250
|
+
<Icon
|
|
251
|
+
name="check"
|
|
252
|
+
:class="cn(
|
|
253
|
+
'ml-auto size-4 shrink-0',
|
|
254
|
+
isSelected(option.value) ? 'opacity-100' : 'opacity-0',
|
|
255
|
+
)"
|
|
256
|
+
/>
|
|
257
|
+
</CommandItem>
|
|
258
|
+
</CommandGroup>
|
|
259
|
+
</template>
|
|
260
|
+
|
|
261
|
+
<slot name="listEnd" />
|
|
262
|
+
</CommandList>
|
|
263
|
+
</Command>
|
|
264
|
+
<slot name="footer" />
|
|
265
|
+
</PopoverContent>
|
|
266
|
+
</ShadcnPopover>
|
|
267
|
+
</template>
|