hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { Combobox as ComboboxPrimitive } from "@kobalte/core/combobox"; |
| 2 | import type { ComponentProps, ValidComponent } from "solid-js"; |
| 3 | import { splitProps } from "solid-js"; |
| 4 | import { IconCheck, IconChevronDown } from "@/components/ui/icons"; |
| 5 | import { cn } from "@/lib/cn"; |
| 6 | |
| 7 | export const Combobox = ComboboxPrimitive; |
| 8 | export const ComboboxItemLabel = ComboboxPrimitive.ItemLabel; |
| 9 | export const ComboboxHiddenSelect = ComboboxPrimitive.HiddenSelect; |
| 10 | |
| 11 | export function ComboboxControl<T extends ValidComponent = "div">( |
| 12 | props: ComponentProps<typeof ComboboxPrimitive.Control<T>>, |
| 13 | ) { |
| 14 | const [local, rest] = splitProps(props as ComponentProps<typeof ComboboxPrimitive.Control>, ["class"]); |
| 15 | return ( |
| 16 | <ComboboxPrimitive.Control |
| 17 | class={cn( |
| 18 | "relative flex h-9 w-full items-center rounded-md border border-input bg-background/90 shadow-sm transition-all", |
| 19 | "hover:border-ring/45 focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-1 data-disabled:cursor-not-allowed data-disabled:opacity-50", |
| 20 | local.class, |
| 21 | )} |
| 22 | {...rest} |
| 23 | /> |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | export function ComboboxInput<T extends ValidComponent = "input">( |
| 28 | props: ComponentProps<typeof ComboboxPrimitive.Input<T>>, |
| 29 | ) { |
| 30 | const [local, rest] = splitProps(props as ComponentProps<typeof ComboboxPrimitive.Input>, ["class"]); |
| 31 | return ( |
| 32 | <ComboboxPrimitive.Input |
| 33 | class={cn( |
| 34 | "flex h-full min-w-0 flex-1 bg-transparent pl-3.5 pr-1 text-xs font-medium text-foreground outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed", |
| 35 | local.class, |
| 36 | )} |
| 37 | {...rest} |
| 38 | /> |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | export function ComboboxTrigger<T extends ValidComponent = "button">( |
| 43 | props: ComponentProps<typeof ComboboxPrimitive.Trigger<T>>, |
| 44 | ) { |
| 45 | const [local, rest] = splitProps(props as ComponentProps<typeof ComboboxPrimitive.Trigger>, ["class"]); |
| 46 | return ( |
| 47 | <ComboboxPrimitive.Trigger |
| 48 | class={cn("flex h-full shrink-0 items-center pr-3 pl-1 text-muted-foreground/70 outline-hidden", local.class)} |
| 49 | {...rest} |
| 50 | > |
| 51 | <ComboboxPrimitive.Icon> |
| 52 | <IconChevronDown class="h-4 w-4" /> |
| 53 | </ComboboxPrimitive.Icon> |
| 54 | </ComboboxPrimitive.Trigger> |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | export function ComboboxContent<T extends ValidComponent = "div">( |
| 59 | props: ComponentProps<typeof ComboboxPrimitive.Content<T>>, |
| 60 | ) { |
| 61 | const [local, rest] = splitProps(props as ComponentProps<typeof ComboboxPrimitive.Content>, [ |
| 62 | "class", |
| 63 | "children", |
| 64 | ]); |
| 65 | return ( |
| 66 | <ComboboxPrimitive.Portal> |
| 67 | <ComboboxPrimitive.Content |
| 68 | class={cn( |
| 69 | "z-[70] mt-1.5 max-h-72 min-w-(--kb-popper-anchor-width) overflow-hidden rounded-md border border-border/80 bg-popover p-1 text-popover-foreground shadow-xl shadow-black/10 outline-hidden", |
| 70 | "origin-(--kb-combobox-content-transform-origin) animate-in fade-in-0 zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", |
| 71 | local.class, |
| 72 | )} |
| 73 | {...rest} |
| 74 | > |
| 75 | <ComboboxPrimitive.Listbox class="max-h-64 overflow-y-auto" /> |
| 76 | {local.children} |
| 77 | </ComboboxPrimitive.Content> |
| 78 | </ComboboxPrimitive.Portal> |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | export function ComboboxItem<T extends ValidComponent = "li">( |
| 83 | props: ComponentProps<typeof ComboboxPrimitive.Item<T>>, |
| 84 | ) { |
| 85 | const [local, rest] = splitProps(props as ComponentProps<typeof ComboboxPrimitive.Item>, ["class", "children"]); |
| 86 | return ( |
| 87 | <ComboboxPrimitive.Item |
| 88 | class={cn( |
| 89 | "relative flex cursor-pointer select-none items-center justify-between gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors", |
| 90 | "data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-40", |
| 91 | local.class, |
| 92 | )} |
| 93 | {...rest} |
| 94 | > |
| 95 | {local.children} |
| 96 | <ComboboxPrimitive.ItemIndicator> |
| 97 | <IconCheck class="h-3.5 w-3.5 shrink-0 text-primary-text" /> |
| 98 | </ComboboxPrimitive.ItemIndicator> |
| 99 | </ComboboxPrimitive.Item> |
| 100 | ); |
| 101 | } |