hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { DropdownMenu as DropdownMenuPrimitive } from "@kobalte/core/dropdown-menu"; |
| 2 | import type { ComponentProps, ParentProps, ValidComponent } from "solid-js"; |
| 3 | import { splitProps } from "solid-js"; |
| 4 | import { IconCheck, IconChevronRight } from "@/components/ui/icons"; |
| 5 | import { cn } from "@/lib/cn"; |
| 6 | |
| 7 | export const DropdownMenu = DropdownMenuPrimitive; |
| 8 | export const DropdownMenuPortal = DropdownMenuPrimitive.Portal; |
| 9 | export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger; |
| 10 | export const DropdownMenuGroup = DropdownMenuPrimitive.Group; |
| 11 | export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup; |
| 12 | export const DropdownMenuSub = DropdownMenuPrimitive.Sub; |
| 13 | |
| 14 | export function DropdownMenuContent<T extends ValidComponent = "div">( |
| 15 | props: ComponentProps<typeof DropdownMenuPrimitive.Content<T>>, |
| 16 | ) { |
| 17 | const [local, rest] = splitProps(props as ComponentProps<typeof DropdownMenuPrimitive.Content>, [ |
| 18 | "class", |
| 19 | ]); |
| 20 | return ( |
| 21 | <DropdownMenuPrimitive.Portal> |
| 22 | <DropdownMenuPrimitive.Content |
| 23 | class={cn( |
| 24 | "z-[70] min-w-32 overflow-hidden rounded-md border border-border/80 bg-popover p-1 text-popover-foreground shadow-xl shadow-black/10 outline-hidden", |
| 25 | "origin-(--kb-menu-content-transform-origin)", |
| 26 | "animate-in fade-in-0 zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", |
| 27 | local.class, |
| 28 | )} |
| 29 | {...rest} |
| 30 | /> |
| 31 | </DropdownMenuPrimitive.Portal> |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | export function DropdownMenuItem<T extends ValidComponent = "div">( |
| 36 | props: ComponentProps<typeof DropdownMenuPrimitive.Item<T>> & { |
| 37 | inset?: boolean; |
| 38 | destructive?: boolean; |
| 39 | }, |
| 40 | ) { |
| 41 | const [local, rest] = splitProps(props as any, ["class", "inset", "destructive"]); |
| 42 | return ( |
| 43 | <DropdownMenuPrimitive.Item |
| 44 | class={cn( |
| 45 | "relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors", |
| 46 | "focus:bg-accent focus:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground", |
| 47 | "data-disabled:pointer-events-none data-disabled:opacity-40", |
| 48 | local.inset && "pl-9", |
| 49 | local.destructive && |
| 50 | "text-destructive-text focus:bg-destructive/10 focus:text-destructive-text data-highlighted:bg-destructive/10 data-highlighted:text-destructive-text", |
| 51 | local.class, |
| 52 | )} |
| 53 | {...rest} |
| 54 | /> |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | export function DropdownMenuCheckboxItem<T extends ValidComponent = "div">( |
| 59 | props: ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem<T>>, |
| 60 | ) { |
| 61 | const [local, rest] = splitProps(props as any, ["class", "children"]); |
| 62 | return ( |
| 63 | <DropdownMenuPrimitive.CheckboxItem |
| 64 | class={cn( |
| 65 | "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors", |
| 66 | "focus:bg-accent focus:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground", |
| 67 | "data-disabled:pointer-events-none data-disabled:opacity-40", |
| 68 | local.class, |
| 69 | )} |
| 70 | {...rest} |
| 71 | > |
| 72 | <span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 73 | <DropdownMenuPrimitive.ItemIndicator> |
| 74 | <IconCheck class="h-4 w-4 stroke-[2.5]" /> |
| 75 | </DropdownMenuPrimitive.ItemIndicator> |
| 76 | </span> |
| 77 | {local.children} |
| 78 | </DropdownMenuPrimitive.CheckboxItem> |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | export function DropdownMenuLabel(props: ParentProps<{ class?: string }>) { |
| 83 | return ( |
| 84 | <div |
| 85 | class={cn("px-2 py-1.5 text-sm font-semibold", props.class)} |
| 86 | > |
| 87 | {props.children} |
| 88 | </div> |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | export function DropdownMenuSeparator(props: { class?: string }) { |
| 93 | return <DropdownMenuPrimitive.Separator class={cn("-mx-1 my-1.5 h-px bg-border/60", props.class)} />; |
| 94 | } |
| 95 | |
| 96 | export function DropdownMenuRadioItem<T extends ValidComponent = "div">( |
| 97 | props: ComponentProps<typeof DropdownMenuPrimitive.RadioItem<T>>, |
| 98 | ) { |
| 99 | const [local, rest] = splitProps(props as ComponentProps<typeof DropdownMenuPrimitive.RadioItem>, [ |
| 100 | "class", |
| 101 | "children", |
| 102 | ]); |
| 103 | return ( |
| 104 | <DropdownMenuPrimitive.RadioItem |
| 105 | class={cn( |
| 106 | "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors", |
| 107 | "focus:bg-accent focus:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground", |
| 108 | "data-disabled:pointer-events-none data-disabled:opacity-40", |
| 109 | local.class, |
| 110 | )} |
| 111 | {...rest} |
| 112 | > |
| 113 | <span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> |
| 114 | <DropdownMenuPrimitive.ItemIndicator> |
| 115 | <svg viewBox="0 0 8 8" class="h-2.5 w-2.5 fill-current" aria-hidden> |
| 116 | <circle cx="4" cy="4" r="3.5" /> |
| 117 | </svg> |
| 118 | </DropdownMenuPrimitive.ItemIndicator> |
| 119 | </span> |
| 120 | {local.children} |
| 121 | </DropdownMenuPrimitive.RadioItem> |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | export function DropdownMenuSubTrigger<T extends ValidComponent = "div">( |
| 126 | props: ComponentProps<typeof DropdownMenuPrimitive.SubTrigger<T>> & { inset?: boolean }, |
| 127 | ) { |
| 128 | const [local, rest] = splitProps(props as any, ["class", "children", "inset"]); |
| 129 | return ( |
| 130 | <DropdownMenuPrimitive.SubTrigger |
| 131 | class={cn( |
| 132 | "flex w-full cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors", |
| 133 | "focus:bg-accent focus:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground data-expanded:bg-accent", |
| 134 | local.inset && "pl-9", |
| 135 | local.class, |
| 136 | )} |
| 137 | {...rest} |
| 138 | > |
| 139 | {local.children} |
| 140 | <IconChevronRight class="ml-auto h-4 w-4 shrink-0 opacity-50" /> |
| 141 | </DropdownMenuPrimitive.SubTrigger> |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | export function DropdownMenuSubContent<T extends ValidComponent = "div">( |
| 146 | props: ComponentProps<typeof DropdownMenuPrimitive.SubContent<T>>, |
| 147 | ) { |
| 148 | const [local, rest] = splitProps(props as ComponentProps<typeof DropdownMenuPrimitive.SubContent>, [ |
| 149 | "class", |
| 150 | ]); |
| 151 | return ( |
| 152 | <DropdownMenuPrimitive.Portal> |
| 153 | <DropdownMenuPrimitive.SubContent |
| 154 | class={cn( |
| 155 | "z-[70] min-w-32 overflow-hidden rounded-md border border-border/80 bg-popover p-1 text-popover-foreground shadow-xl shadow-black/10 outline-hidden", |
| 156 | "origin-(--kb-menu-content-transform-origin)", |
| 157 | "animate-in fade-in-0 zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", |
| 158 | local.class, |
| 159 | )} |
| 160 | {...rest} |
| 161 | /> |
| 162 | </DropdownMenuPrimitive.Portal> |
| 163 | ); |
| 164 | } |