diff --git a/packages/react/src/components/Tabs/Tab.tsx b/packages/react/src/components/Tabs/Tab.tsx index e32538b33..32b966cae 100644 --- a/packages/react/src/components/Tabs/Tab.tsx +++ b/packages/react/src/components/Tabs/Tab.tsx @@ -6,16 +6,10 @@ import { useTabId, useTabListDescendant, useTabPanelId, useTabsState, } from './context'; -const BASE_NAME = 'nds-tab'; - -const styles = { - base: BASE_NAME, - contained: `${BASE_NAME}--contained`, - line: `${BASE_NAME}--line`, - selected: 'selected', -}; - export const Tab = ({ + baseName = 'nds-tab', + containedClass = `${baseName}--contained`, + lineClass = `${baseName}--line`, children, }: TabProps) => { const { index, register } = useTabListDescendant(); @@ -30,10 +24,10 @@ export const Tab = ({ setSelectedTabIndex(index); }, [index, setSelectedTabIndex]); - const className = classNames(BASE_NAME, { - [styles.contained]: variant === 'contained', - [styles.line]: variant === 'line', - [styles.selected]: isSelected, + const className = classNames(baseName, { + [containedClass]: variant === 'contained', + [lineClass]: variant === 'line', + selected: isSelected, }); return ( diff --git a/packages/react/src/components/Tabs/TabList.tsx b/packages/react/src/components/Tabs/TabList.tsx index 4835ba031..1401d6b9b 100644 --- a/packages/react/src/components/Tabs/TabList.tsx +++ b/packages/react/src/components/Tabs/TabList.tsx @@ -6,16 +6,13 @@ import { TabListDescendantsProvider, useTabListDescendants, useTabsState } from import { useTabListScroll } from './useTabListScroll'; import { useTabKeyboardNavigation } from './useTabKeyboardNavigation'; -const BASE_NAME = 'nds-tab-list'; - -const styles = { - base: BASE_NAME, - container: `${BASE_NAME}-container`, - left: `${BASE_NAME}--left`, - centered: `${BASE_NAME}--centered`, -}; - -export const TabList = ({ children }: TabListProps) => { +export const TabList = ({ + baseName = 'nds-tab-list', + containerClass = `${baseName}-container`, + leftClass = `${baseName}--left`, + centeredClass = `${baseName}--centered`, + children, +}: TabListProps) => { const tabListRef = React.useRef(null); useTabKeyboardNavigation(tabListRef); @@ -27,10 +24,10 @@ export const TabList = ({ children }: TabListProps) => { const { align } = useTabsState(); const className = classNames( - styles.base, + baseName, { - [styles.left]: align === 'left', - [styles.centered]: align === 'center', + [leftClass]: align === 'left', + [centeredClass]: align === 'center', }, ); @@ -38,7 +35,7 @@ export const TabList = ({ children }: TabListProps) => { return ( -
+
{children} diff --git a/packages/react/src/components/Tabs/Tabs.tsx b/packages/react/src/components/Tabs/Tabs.tsx index 8f054846c..edfaa2d86 100644 --- a/packages/react/src/components/Tabs/Tabs.tsx +++ b/packages/react/src/components/Tabs/Tabs.tsx @@ -10,13 +10,14 @@ function isControlled(props: TabsProps): props is ControlledTabsProps { const ControlledTabs = React.forwardRef(({ children, + className = 'nds-tabs', ...rest }, ref) => { const state = useInitControlledTabsState(rest); return ( -
+
{children}
@@ -25,13 +26,14 @@ const ControlledTabs = React.forwardRef(({ const UncontrolledTabs = React.forwardRef(({ children, + className = 'nds-tabs', ...rest }, ref) => { const state = useInitUncontrolledTabsState(rest); return ( -
+
{children}
diff --git a/packages/react/src/components/Tabs/index.stories.tsx b/packages/react/src/components/Tabs/index.stories.tsx index 7cba67315..a30c677b2 100644 --- a/packages/react/src/components/Tabs/index.stories.tsx +++ b/packages/react/src/components/Tabs/index.stories.tsx @@ -2,11 +2,7 @@ import React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; import { Link } from '../Link'; import { - Tabs, - Tab, - TabList, - TabPanel, - TabPanels, + Tabs, Tab, TabList, TabPanel, TabPanels, } from '.'; const BASE_TABS = ['Tab 1', 'Tab 2', 'Tab 3', 'Long Text "Tab 4"', 'Tab 5']; @@ -70,7 +66,9 @@ const TabsTemplate: Story = { Content Two Content Three. - A Link + + A Link + Content Four Content Five diff --git a/packages/react/src/components/Tabs/types.ts b/packages/react/src/components/Tabs/types.ts index c9174d0e9..2e9a6c0d3 100644 --- a/packages/react/src/components/Tabs/types.ts +++ b/packages/react/src/components/Tabs/types.ts @@ -61,14 +61,23 @@ export type CommonTabsProps = { */ variant?: 'contained' | 'line'; + className?: string; + children?: React.ReactNode; }; export type TabListProps = { + baseName?: string; + containerClass?: string; + leftClass?: string; + centeredClass?: string; children?: React.ReactNode; }; export type TabProps = { + baseName?: string; + containedClass?: string; + lineClass?: string; children?: React.ReactNode; };