From 20493edd077d5299da20f2fc2ef6aefd56dca8f7 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 14 Aug 2024 10:51:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84(frontend)=20support=20bordeless=20?= =?UTF-8?q?Tabs=20and=20TabList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a new variant for Tabs and TabList components to support borderless styles. By default, both Tabs and TabList include borders. Using React context, TabList’s children will automatically inherit a borderless style if specified via props. However, you can still explicitly apply borders to individual children, even if the parent TabList is set to be borderless. --- src/frontend/src/primitives/Tabs.tsx | 67 ++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/frontend/src/primitives/Tabs.tsx b/src/frontend/src/primitives/Tabs.tsx index c44110f5..c2b76fb3 100644 --- a/src/frontend/src/primitives/Tabs.tsx +++ b/src/frontend/src/primitives/Tabs.tsx @@ -10,6 +10,7 @@ import { } from 'react-aria-components' import { styled } from '@/styled-system/jsx' import { StyledVariantProps } from '@/styled-system/types' +import React from 'react' const StyledTabs = styled(RACTabs, { base: { @@ -42,34 +43,64 @@ const StyledTab = styled(RACTab, { transition: 'color 200ms ease, backgroundColor 200ms ease', borderColor: 'transparent', forcedColorAdjust: 'none', - '&[data-focused]': {}, - '&[data-selected]': { - borderColor: 'primary', + }, + variants: { + border: { + true: { + '&[data-selected]': { + borderColor: 'primary', + }, + borderBottom: 'var(--horizontal) solid', + borderInlineEnd: 'var(--vertical) solid', + }, + false: { + border: 'none', + }, }, - borderBottom: 'var(--horizontal) solid', - borderInlineEnd: 'var(--vertical) solid', + }, + defaultVariants: { + border: true, }, }) export type TabProps = RACTabProps & StyledVariantProps export const Tab = ({ children, ...props }: TabProps) => { - return {children} + const parentBorder = React.useContext(BorderContext) + return ( + + {children} + + ) } const StyledTabList = styled(RACTabList, { base: { display: 'flex', - '&[data-orientation=horizontal]': { - borderBottom: '1px solid', - borderColor: 'gray.300', - }, '&[data-orientation=vertical]': { flexDirection: 'column', - borderInlineEnd: '1px solid', - borderColor: 'gray.300', }, }, + variants: { + border: { + false: { + border: 'none', + }, + true: { + '&[data-orientation=horizontal]': { + borderBottom: '1px solid', + borderColor: 'gray.300', + }, + '&[data-orientation=vertical]': { + borderInlineEnd: '1px solid', + borderColor: 'gray.300', + }, + }, + }, + }, + defaultVariants: { + border: true, + }, }) // @fixme type could be simplified to avoid redefining the children props @@ -78,8 +109,16 @@ export type TabListProps = { } & RACTabListProps & StyledVariantProps -export const TabList = ({ children, ...props }: TabListProps) => { - return {children} +const BorderContext = React.createContext(true) + +export const TabList = ({ children, border, ...props }: TabListProps) => { + return ( + + + {children} + + + ) } const StyledTabPanel = styled(RACTabPanel, {