mirror of
https://github.com/luxfi/market.git
synced 2026-09-24 00:25:57 +00:00
gray = mix of radix (grayDark) and Zach's selected values primary = slate secondary = slateDark Voila! Since all original code used the Radix guidelines (which I references and link to in the config file), it all just works. So removed most of my mods to colors from first PR (checking intent and result of each carefully). Did not touch light theme (TODO?) NOTE: using the $ notation within the theme itself seems to break, so I grabbed the actual hex values from Radix.
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
import { styled } from 'stitches.config'
|
|
import React, {
|
|
ComponentPropsWithoutRef,
|
|
ElementRef,
|
|
forwardRef,
|
|
ReactNode,
|
|
useState,
|
|
} from 'react'
|
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
|
|
import { AnimatePresence, motion } from 'framer-motion'
|
|
|
|
const DropdownMenuContent = styled(DropdownMenuPrimitive.DropdownMenuContent, {
|
|
mx: '$4',
|
|
p: '$2',
|
|
borderRadius: 8,
|
|
zIndex: 5,
|
|
backgroundColor: '$panelBg',
|
|
$$borderColor: '$colors$gray7',
|
|
boxShadow: '0 0 0 1px $$borderColor',
|
|
})
|
|
|
|
const AnimatedDropdownMenuContent = forwardRef<
|
|
ElementRef<typeof DropdownMenuContent>,
|
|
ComponentPropsWithoutRef<typeof DropdownMenuContent>
|
|
>(({ children, ...props }, forwardedRef) => (
|
|
<DropdownMenuContent asChild forceMount {...props}>
|
|
<motion.div
|
|
ref={forwardedRef}
|
|
initial={{ scale: 0.9, opacity: 0, y: -20 }}
|
|
animate={{
|
|
scale: 1,
|
|
opacity: 1,
|
|
y: 0,
|
|
transition: { mass: 0.05, type: 'spring', duration: 0.1 },
|
|
}}
|
|
exit={{
|
|
y: -20,
|
|
scale: 0.9,
|
|
opacity: 0,
|
|
transition: { duration: 0.1 },
|
|
}}
|
|
>
|
|
{children}
|
|
</motion.div>
|
|
</DropdownMenuContent>
|
|
))
|
|
|
|
const DropdownMenuItem = styled(DropdownMenuPrimitive.DropdownMenuItem, {
|
|
fontSize: 16,
|
|
fontFamily: '$body',
|
|
color: '$gray12',
|
|
px: '$2',
|
|
py: '$3',
|
|
borderRadius: 8,
|
|
outline: 'none',
|
|
cursor: 'pointer',
|
|
'&:hover': {
|
|
backgroundColor: '$gray5',
|
|
},
|
|
'&:focus': {
|
|
backgroundColor: '$gray5',
|
|
},
|
|
})
|
|
|
|
type Props = {
|
|
trigger: ReactNode
|
|
contentProps?: DropdownMenuPrimitive.DropdownMenuContentProps
|
|
}
|
|
|
|
const Dropdown = forwardRef<
|
|
ElementRef<typeof DropdownMenuPrimitive.Root>,
|
|
ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Root> & Props
|
|
>(({ children, trigger, contentProps, ...props }, forwardedRef) => {
|
|
const [open, setOpen] = useState(false)
|
|
|
|
return (
|
|
<DropdownMenuPrimitive.Root {...props} open={open} onOpenChange={setOpen}>
|
|
<DropdownMenuPrimitive.Trigger asChild>
|
|
{trigger}
|
|
</DropdownMenuPrimitive.Trigger>
|
|
<AnimatePresence>
|
|
{open && (
|
|
<AnimatedDropdownMenuContent ref={forwardedRef} {...contentProps}>
|
|
{children}
|
|
</AnimatedDropdownMenuContent>
|
|
)}
|
|
</AnimatePresence>
|
|
</DropdownMenuPrimitive.Root>
|
|
)
|
|
})
|
|
|
|
export { Dropdown, DropdownMenuContent, DropdownMenuItem }
|