From 5206d8420b4616c01a14755ca6545cbf4161b0c5 Mon Sep 17 00:00:00 2001 From: 9ssi7 Date: Wed, 20 Mar 2024 23:52:17 +0300 Subject: [PATCH 1/3] refactor/toggle: update the props --- packages/ui/package.json | 2 +- packages/ui/src/form/toggle/index.tsx | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/ui/package.json b/packages/ui/package.json index efdc68c..7bc039e 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@turistikrota/ui", - "version": "1.3.9", + "version": "1.4.0", "description": "the turistikrota ui library for React", "main": "./index.js", "module": "./index.js", diff --git a/packages/ui/src/form/toggle/index.tsx b/packages/ui/src/form/toggle/index.tsx index e7abbd5..eca42b6 100644 --- a/packages/ui/src/form/toggle/index.tsx +++ b/packages/ui/src/form/toggle/index.tsx @@ -5,6 +5,7 @@ type Size = 'sm' | 'md' | 'lg' type Props = { defaultChecked?: boolean + secondary?: boolean checked?: boolean disabled?: boolean onChange?: (checked: boolean) => void @@ -15,6 +16,7 @@ type Props = { type Variants = { default: string + secondary: string checked: string circle: string circleChecked: string @@ -28,31 +30,36 @@ type Sizes = { const variants: Record = { primary: { - default: 'bg-second', + default: 'bg-default', + secondary: 'bg-second', checked: 'bg-primary-500 bg-opacity-20 dark:bg-primary-500 dark:bg-opacity-20', circleChecked: 'bg-primary-500 dark:bg-primary-500', circle: 'bg-gray-400 dark:bg-gray-700', }, secondary: { - default: 'bg-second', + default: 'bg-default', + secondary: 'bg-second', checked: 'bg-secondary-500 bg-opacity-20 dark:bg-secondary-500 dark:bg-opacity-20', circleChecked: 'bg-secondary-500 dark:bg-secondary-500', circle: 'bg-gray-400 dark:bg-gray-700', }, success: { - default: 'bg-second', + default: 'bg-default', + secondary: 'bg-second', checked: 'bg-green-500 bg-opacity-20 dark:bg-green-500 dark:bg-opacity-20', circleChecked: 'bg-green-500 dark:bg-green-500', circle: 'bg-gray-400 dark:bg-gray-700', }, error: { - default: 'bg-second', + default: 'bg-default', + secondary: 'bg-second', checked: 'bg-red-500 bg-opacity-20 dark:bg-red-500 dark:bg-opacity-20', circleChecked: 'bg-red-500 dark:bg-red-500', circle: 'bg-gray-400 dark:bg-gray-700', }, warning: { - default: 'bg-second', + default: 'bg-default', + secondary: 'bg-second', checked: 'bg-orange-500 bg-opacity-20 dark:bg-orange-500 dark:bg-opacity-20', circleChecked: 'bg-orange-500 dark:bg-orange-500', circle: 'bg-gray-400 dark:bg-gray-700', @@ -82,6 +89,7 @@ const ToggleButton: React.FC = ({ checked: checkedProp, variant = 'primary', size = 'md', + secondary = false, disabled = false, title, onChange, @@ -107,7 +115,7 @@ const ToggleButton: React.FC = ({ type='button' className={`disable-highlight relative inline-flex items-center rounded-full shadow-none transition-colors focus:ring-0 focus:ring-transparent focus:ring-offset-0 focus:ring-offset-transparent ${ sizes[size].default - } ${checked ? variants[variant].checked : variants[variant].default}`} + } ${checked ? variants[variant].checked : secondary ? variants[variant].secondary : variants[variant].default}`} onClick={handleChange} disabled={disabled} title={title} From 3a4397a6037ceee111573102b31bf58c2d79fe5d Mon Sep 17 00:00:00 2001 From: 9ssi7 Date: Sun, 24 Mar 2024 21:36:48 +0300 Subject: [PATCH 2/3] 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 (