|
| 1 | +import "./index.scss"; |
| 2 | +import { processProps } from "../utilities"; |
| 3 | +import { DropdownMenu as KobalteDropdownMenu, As } from "@kobalte/core"; |
| 4 | +import { Button, Icon } from ".."; |
| 5 | +import { DropdownMenuItem } from "./item"; |
| 6 | +import { DropdownMenuGroup } from "./group"; |
| 7 | +import { DropdownMenuCheckbox } from "./checkbox"; |
| 8 | +import { DropdownMenuRadio } from "./radio"; |
| 9 | +import { DropdownMenuRadioGroup } from "./radio-group"; |
| 10 | +import { DropdownMenuSubmenu } from "./submenu"; |
| 11 | +import { JSXElement, Show } from "solid-js"; |
| 12 | +import { Menu, MenuProps } from "../menu"; |
| 13 | + |
| 14 | +export type DropdownMenuProps = { |
| 15 | + label?: string; |
| 16 | + customTrigger?: JSXElement; |
| 17 | + type?: "primary" | "default"; |
| 18 | + size?: "small" | "default" | "large"; |
| 19 | + disabled?: boolean; |
| 20 | + danger?: boolean; |
| 21 | +} & Omit<MenuProps, "type" | "trigger">; |
| 22 | + |
| 23 | +function DropdownMenu(props: DropdownMenuProps) { |
| 24 | + const [local, others] = processProps({ |
| 25 | + props, |
| 26 | + keys: ["label", "customTrigger", "type", "size", "disabled", "danger"], |
| 27 | + }); |
| 28 | + |
| 29 | + return ( |
| 30 | + <Menu |
| 31 | + type="dropdown" |
| 32 | + trigger={ |
| 33 | + <Show |
| 34 | + when={local.customTrigger} |
| 35 | + keyed |
| 36 | + fallback={ |
| 37 | + <KobalteDropdownMenu.Trigger asChild isDisabled={local.disabled}> |
| 38 | + <As |
| 39 | + component={Button} |
| 40 | + class="dropdown-menu-trigger" |
| 41 | + type={local.type} |
| 42 | + size={local.size} |
| 43 | + disabled={local.disabled} |
| 44 | + danger={local.danger} |
| 45 | + > |
| 46 | + {local.label} |
| 47 | + <Icon |
| 48 | + icon="arrow-down-s" |
| 49 | + line |
| 50 | + class="dropdown-menu-trigger-icon" |
| 51 | + /> |
| 52 | + </As> |
| 53 | + </KobalteDropdownMenu.Trigger> |
| 54 | + } |
| 55 | + > |
| 56 | + {(customTrigger) => ( |
| 57 | + <KobalteDropdownMenu.Trigger asChild isDisabled={local.disabled}> |
| 58 | + <As component="div" class="jdd dropdown-menu-trigger"> |
| 59 | + {customTrigger} |
| 60 | + </As> |
| 61 | + </KobalteDropdownMenu.Trigger> |
| 62 | + )} |
| 63 | + </Show> |
| 64 | + } |
| 65 | + {...others} |
| 66 | + /> |
| 67 | + ); |
| 68 | +} |
| 69 | + |
| 70 | +const CompoundedDropdownMenu = DropdownMenu as typeof DropdownMenu & { |
| 71 | + Checkbox: typeof DropdownMenuCheckbox; |
| 72 | + Group: typeof DropdownMenuGroup; |
| 73 | + Item: typeof DropdownMenuItem; |
| 74 | + Radio: typeof DropdownMenuRadio; |
| 75 | + RadioGroup: typeof DropdownMenuRadioGroup; |
| 76 | + Submenu: typeof DropdownMenuSubmenu; |
| 77 | +}; |
| 78 | +CompoundedDropdownMenu.Checkbox = DropdownMenuCheckbox; |
| 79 | +CompoundedDropdownMenu.Group = DropdownMenuGroup; |
| 80 | +CompoundedDropdownMenu.Item = DropdownMenuItem; |
| 81 | +CompoundedDropdownMenu.Radio = DropdownMenuRadio; |
| 82 | +CompoundedDropdownMenu.RadioGroup = DropdownMenuRadioGroup; |
| 83 | +CompoundedDropdownMenu.Submenu = DropdownMenuSubmenu; |
| 84 | +export { CompoundedDropdownMenu as DropdownMenu }; |
0 commit comments