2022-03-22 23:06:15 -04:00
|
|
|
import Button from "@components/button"
|
|
|
|
import React, { useCallback, useEffect } from "react"
|
|
|
|
import { useState } from "react"
|
2022-04-09 20:48:19 -04:00
|
|
|
import styles from "./dropdown.module.css"
|
|
|
|
import DownIcon from "@geist-ui/icons/arrowDown"
|
2022-11-28 21:33:06 -05:00
|
|
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu"
|
2022-03-22 23:06:15 -04:00
|
|
|
type Props = {
|
2022-04-09 20:48:19 -04:00
|
|
|
type?: "primary" | "secondary"
|
|
|
|
loading?: boolean
|
|
|
|
disabled?: boolean
|
|
|
|
className?: string
|
|
|
|
iconHeight?: number
|
2022-03-22 23:06:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Attrs = Omit<React.HTMLAttributes<any>, keyof Props>
|
|
|
|
type ButtonDropdownProps = Props & Attrs
|
|
|
|
|
2022-04-09 20:48:19 -04: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 21:33:06 -05:00
|
|
|
<DropdownMenu.Root>
|
|
|
|
<div className={styles.dropdown}>
|
2022-04-09 20:48:19 -04:00
|
|
|
{props.children[0]}
|
2022-11-28 21:33:06 -05:00
|
|
|
<DropdownMenu.Trigger
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "flex-end"
|
|
|
|
}}
|
|
|
|
asChild
|
2022-04-09 20:48:19 -04:00
|
|
|
>
|
2022-11-28 21:33:06 -05:00
|
|
|
<Button
|
|
|
|
iconLeft={<DownIcon />}
|
|
|
|
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 20:48:19 -04:00
|
|
|
</div>
|
2022-11-28 21:33:06 -05:00
|
|
|
</DropdownMenu.Root>
|
2022-04-09 20:48:19 -04:00
|
|
|
)
|
2022-03-22 23:06:15 -04:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
export default ButtonDropdown
|