2022-03-22 20:06:15 -07:00
|
|
|
import Button from "@components/button"
|
2022-11-29 00:43:04 -08:00
|
|
|
import React from "react"
|
2022-04-09 17:48:19 -07:00
|
|
|
import styles from "./dropdown.module.css"
|
2022-11-28 18:33:06 -08:00
|
|
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu"
|
2022-11-29 00:43:04 -08:00
|
|
|
import { ArrowDown } from "react-feather"
|
2022-03-22 20:06:15 -07:00
|
|
|
type Props = {
|
2022-04-09 17:48:19 -07:00
|
|
|
type?: "primary" | "secondary"
|
|
|
|
loading?: boolean
|
|
|
|
disabled?: boolean
|
|
|
|
className?: string
|
|
|
|
iconHeight?: number
|
2022-03-22 20:06:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Attrs = Omit<React.HTMLAttributes<any>, keyof Props>
|
|
|
|
type ButtonDropdownProps = Props & Attrs
|
|
|
|
|
2022-04-09 17:48:19 -07:00
|
|
|
const ButtonDropdown: React.FC<
|
|
|
|
React.PropsWithChildren<ButtonDropdownProps>
|
|
|
|
> = ({ type, className, disabled, loading, iconHeight = 24, ...props }) => {
|
|
|
|
if (!Array.isArray(props.children)) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-11-28 18:33:06 -08:00
|
|
|
<DropdownMenu.Root>
|
|
|
|
<div className={styles.dropdown}>
|
2022-04-09 17:48:19 -07:00
|
|
|
{props.children[0]}
|
2022-11-28 18:33:06 -08:00
|
|
|
<DropdownMenu.Trigger
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "flex-end"
|
|
|
|
}}
|
|
|
|
asChild
|
2022-04-09 17:48:19 -07:00
|
|
|
>
|
2022-11-28 18:33:06 -08:00
|
|
|
<Button
|
2022-11-29 00:43:04 -08:00
|
|
|
iconLeft={<ArrowDown />}
|
2022-11-28 18:33:06 -08:00
|
|
|
type={type}
|
|
|
|
className={styles.icon}
|
|
|
|
/>
|
|
|
|
</DropdownMenu.Trigger>
|
|
|
|
<DropdownMenu.Portal>
|
|
|
|
<DropdownMenu.Content align="end">
|
|
|
|
{props.children.slice(1).map((child, index) => (
|
|
|
|
<DropdownMenu.Item key={index}>{child}</DropdownMenu.Item>
|
|
|
|
))}
|
|
|
|
</DropdownMenu.Content>
|
|
|
|
</DropdownMenu.Portal>
|
2022-04-09 17:48:19 -07:00
|
|
|
</div>
|
2022-11-28 18:33:06 -08:00
|
|
|
</DropdownMenu.Root>
|
2022-04-09 17:48:19 -07:00
|
|
|
)
|
2022-03-22 20:06:15 -07:00
|
|
|
}
|
|
|
|
|
2022-04-09 17:48:19 -07:00
|
|
|
export default ButtonDropdown
|