From 3a4397a6037ceee111573102b31bf58c2d79fe5d Mon Sep 17 00:00:00 2001 From: 9ssi7 Date: Sun, 24 Mar 2024 21:36:48 +0300 Subject: [PATCH] refactor/button: add variant for dropdown --- packages/ui/package.json | 2 +- packages/ui/src/dropdown/index.tsx | 46 ++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/ui/package.json b/packages/ui/package.json index 7bc039e..c55d107 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@turistikrota/ui", - "version": "1.4.0", + "version": "1.4.1", "description": "the turistikrota ui library for React", "main": "./index.js", "module": "./index.js", diff --git a/packages/ui/src/dropdown/index.tsx b/packages/ui/src/dropdown/index.tsx index e2f05bd..03fd0f9 100644 --- a/packages/ui/src/dropdown/index.tsx +++ b/packages/ui/src/dropdown/index.tsx @@ -9,32 +9,60 @@ type PropsWithActive

= P & { active?: boolean } +type DropdownVariant = 'primary' | 'secondary' + type DropdownContext = { active: boolean + variant: DropdownVariant setActive: React.Dispatch> } -type DropdownType = React.FC & { +type DropdownType = React.FC< + React.PropsWithChildren<{ + variant?: DropdownVariant + }> +> & { Button: React.FC> Overlay: React.FC OverlayItem: React.FC>> } +type DropdownVariantMap = { + button: string + overlay: string + inactiveItem: string +} + +const variantMap: Record = { + primary: { + button: 'bg-default', + inactiveItem: 'hover:bg-second', + overlay: 'bg-default', + }, + secondary: { + button: 'bg-second', + inactiveItem: 'hover:bg-default', + overlay: 'bg-second', + }, +} + const Context = React.createContext({ active: false, + variant: 'primary', setActive: () => {}, }) const Button: React.FC> = ({ active, children }) => { - const { active: activeContext, setActive } = useContext(Context) + const { active: activeContext, setActive, variant } = useContext(Context) const debouncedBlur = debounce((activeContext) => { if (activeContext) setActive(false) }, 200) return (