From d39ec0faa643c5b0e984188c74133a84e48572bb Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Mon, 16 Oct 2023 12:19:50 +0200 Subject: [PATCH] feat: add support for disabled prop to SubTab (#525) --- src/components/SubTab.tsx | 21 +++++++++++++++------ src/components/TabList.tsx | 3 +++ src/stories/Tab.stories.tsx | 6 ++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/components/SubTab.tsx b/src/components/SubTab.tsx index 96d08c76..ccf56d26 100644 --- a/src/components/SubTab.tsx +++ b/src/components/SubTab.tsx @@ -29,15 +29,21 @@ const parentFillLevelToHoverBG = { const SubTabBase = styled.div<{ size: SubTabSize active: boolean + disabled: boolean parentFillLevel: FillLevel -}>(({ theme, active, size, parentFillLevel }) => ({ +}>(({ theme, active, disabled, size, parentFillLevel }) => ({ ...(size === 'small' ? theme.partials.text.buttonSmall : theme.partials.text.buttonMedium), tabIndex: 0, userSelect: 'none', - cursor: active ? 'default' : 'pointer', - color: active ? theme.colors.text : theme.colors['text-xlight'], + cursor: disabled ? 'default' : active ? 'default' : 'pointer', + pointerEvents: disabled ? 'none' : 'all', + color: disabled + ? theme.colors['text-disabled'] + : active + ? theme.colors.text + : theme.colors['text-xlight'], backgroundColor: active ? theme.colors[parentFillLevelToActiveBG[parentFillLevel]] : 'transparent', @@ -51,9 +57,10 @@ const SubTabBase = styled.div<{ }px ${theme.spacing.medium}px`, align: 'center', ':hover': { - backgroundColor: !active - ? theme.colors[parentFillLevelToHoverBG[parentFillLevel]] - : undefined, + backgroundColor: + !active && !disabled + ? theme.colors[parentFillLevelToHoverBG[parentFillLevel]] + : undefined, }, transition: 'background-color 150ms ease, border-color 150ms ease, color 150ms ease', @@ -63,6 +70,7 @@ const SubTabBase = styled.div<{ function SubTabRef( { active, + disabled, children, textValue: _textValue, size = 'medium', @@ -76,6 +84,7 @@ function SubTabRef( } children?: ChildrenType } + function TabListRef( { stateRef, stateProps, renderer, as, ...props }: TabListProps & FlexProps, incomingRef: RefObject @@ -179,6 +181,7 @@ type TabRendererProps = { stateProps: AriaTabListProps stateRef: TabStateRef } + function TabRenderer({ item, state, stateProps, stateRef }: TabRendererProps) { const ref = useRef(null) const { tabProps: props } = useTab({ key: item.key }, state, ref) diff --git a/src/stories/Tab.stories.tsx b/src/stories/Tab.stories.tsx index db64aca4..a79d5f58 100644 --- a/src/stories/Tab.stories.tsx +++ b/src/stories/Tab.stories.tsx @@ -146,7 +146,7 @@ Vertical.args = { vertical: true, } -function SubTabs({ args }: any) { +function SubTabs(args: any) { const [active, setActive] = useState(0) return ( @@ -198,4 +198,6 @@ function SubTabTemplate(args: any) { export const Subtab = SubTabTemplate.bind({}) -Subtab.args = {} +Subtab.args = { + disabled: false, +}