From 3a27259eb24d1bcd66376c8055a1eab02ebf96ff Mon Sep 17 00:00:00 2001 From: Stephanie Yang Date: Fri, 17 May 2024 00:56:32 -0500 Subject: [PATCH 1/2] add ability to style states of disabled toggle --- src/form/Toggle/Toggle.story.tsx | 11 +++++++---- src/form/Toggle/Toggle.tsx | 3 ++- src/form/Toggle/ToggleTheme.ts | 15 +++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/form/Toggle/Toggle.story.tsx b/src/form/Toggle/Toggle.story.tsx index 253ea5d3..1a2be79e 100644 --- a/src/form/Toggle/Toggle.story.tsx +++ b/src/form/Toggle/Toggle.story.tsx @@ -11,10 +11,13 @@ export const Simple = () => { return ; }; -export const Disabled = () => { - const [state, setState] = useState(true); - return ; -}; +export const Disabled = () => ( + <> + +
+ + +); export const Sizes = () => { const [stateSmall, setStateSmall] = useState(true); diff --git a/src/form/Toggle/Toggle.tsx b/src/form/Toggle/Toggle.tsx index 00f8fdb0..c3cd6ba0 100644 --- a/src/form/Toggle/Toggle.tsx +++ b/src/form/Toggle/Toggle.tsx @@ -74,7 +74,8 @@ export const Toggle: FC = forwardRef< tabIndex={0} className={twMerge( theme.base, - disabled && theme.disabled, + disabled && theme.disabled.base, + disabled && checked && theme.disabled.checked, checked && theme.checked, theme.sizes[size], className diff --git a/src/form/Toggle/ToggleTheme.ts b/src/form/Toggle/ToggleTheme.ts index 6f477eca..2083baf8 100644 --- a/src/form/Toggle/ToggleTheme.ts +++ b/src/form/Toggle/ToggleTheme.ts @@ -1,6 +1,6 @@ export interface ToggleTheme { base: string; - disabled: string; + disabled: { base: string; checked: string }; checked: string; handle: { base: string; @@ -19,7 +19,7 @@ export interface ToggleTheme { const baseTheme: ToggleTheme = { base: 'flex items-center justify-start cursor-pointer bg-surface box-border border border-panel-accent rounded-full', - disabled: 'cursor-not-allowed opacity-60', + disabled: { base: 'cursor-not-allowed opacity-60', checked: '' }, checked: 'justify-end bg-primary', handle: { base: 'rounded-full bg-panel', @@ -44,10 +44,13 @@ export const legacyToggleTheme: ToggleTheme = { baseTheme.base, 'bg-[var(--toggle-background)] rounded-[var(--toggle-border-radius)] [border:_var(--toggle-border)]' ].join(' '), - disabled: [ - baseTheme.disabled, - 'opacity-[var(--toggle-disabled-opacity,0.8)] bg-[var(--toggle-disabled-background)]' - ].join(' '), + disabled: { + base: [ + baseTheme.disabled, + 'opacity-[var(--toggle-disabled-opacity,0.8)] bg-[var(--toggle-disabled-background)]' + ].join(' '), + checked: '' + }, checked: [ baseTheme.checked, 'bg-[var(--toggle-background-checked)] [border:_var(--toggle-border-checked)]' From 45c2607772e4bb41fd57cb9b2ff11deb37b5471e Mon Sep 17 00:00:00 2001 From: Stephanie Yang Date: Fri, 17 May 2024 12:10:04 -0500 Subject: [PATCH 2/2] tweaks to toggle disabled theme --- src/form/Toggle/Toggle.story.tsx | 2 +- src/form/Toggle/Toggle.tsx | 10 +++++++--- src/form/Toggle/ToggleTheme.ts | 23 +++++++++++++---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/form/Toggle/Toggle.story.tsx b/src/form/Toggle/Toggle.story.tsx index 1a2be79e..31a82995 100644 --- a/src/form/Toggle/Toggle.story.tsx +++ b/src/form/Toggle/Toggle.story.tsx @@ -1,5 +1,5 @@ -import { Toggle } from './Toggle'; import React, { useState } from 'react'; +import { Toggle } from './Toggle'; export default { title: 'Components/Form/Toggle', diff --git a/src/form/Toggle/Toggle.tsx b/src/form/Toggle/Toggle.tsx index c3cd6ba0..5931aca0 100644 --- a/src/form/Toggle/Toggle.tsx +++ b/src/form/Toggle/Toggle.tsx @@ -74,8 +74,7 @@ export const Toggle: FC = forwardRef< tabIndex={0} className={twMerge( theme.base, - disabled && theme.disabled.base, - disabled && checked && theme.disabled.checked, + disabled && theme.disabled, checked && theme.checked, theme.sizes[size], className @@ -93,7 +92,12 @@ export const Toggle: FC = forwardRef< }} >