diff --git a/src/molecules/Tabs/Tabs.types.ts b/src/molecules/Tabs/Tabs.types.ts index f28870622..58ebbb063 100644 --- a/src/molecules/Tabs/Tabs.types.ts +++ b/src/molecules/Tabs/Tabs.types.ts @@ -12,13 +12,16 @@ export interface Tab { disabled?: boolean; } -export interface Tabs { +export interface TabsScrollProps { + scrollable?: boolean; + amountPerScrollPage?: number; +} + +export interface Tabs extends TabsScrollProps { selected: T; onChange: (value: T) => void; onHover?: (hoveredTabValue: T) => void; options: Tab[]; - scrollable?: boolean; - amountPerScrollPage?: number; centered?: boolean; animated?: boolean; } diff --git a/src/organisms/TableOfContents/TableOfContents.stories.tsx b/src/organisms/TableOfContents/TableOfContents.stories.tsx index b30ae91e5..fbedf1d94 100644 --- a/src/organisms/TableOfContents/TableOfContents.stories.tsx +++ b/src/organisms/TableOfContents/TableOfContents.stories.tsx @@ -5,10 +5,7 @@ import { tokens } from '@equinor/eds-tokens'; import { faker } from '@faker-js/faker'; import { Meta, StoryFn, StoryObj } from '@storybook/react-vite'; -import { - TableOfContents, - TableOfContentsProps, -} from 'src/organisms/TableOfContents/TableOfContents'; +import { TableOfContents } from 'src/organisms/TableOfContents/TableOfContents'; import { TableOfContentsItemType, TableOfContentsProvider, @@ -20,7 +17,12 @@ import styled from 'styled-components'; const { colors } = tokens; -const meta: Meta = { +type StoryProps = TableOfContentsProviderProps & { + mode?: 'vertical' | 'horizontal'; + onlyShowSelectedChildren?: boolean; +}; + +const meta: Meta = { title: 'Organisms/TableOfContents', component: TableOfContents, parameters: { @@ -32,7 +34,6 @@ const meta: Meta = { argTypes: { items: { control: 'object' }, onlyShowSelectedChildren: { control: 'boolean' }, - variant: { control: 'radio', items: ['border', 'buttons'] }, }, args: { items: [ @@ -48,9 +49,20 @@ const meta: Meta = { label: 'Third section', value: 'id-3', }, + { + label: 'Fourth section', + value: 'id-4', + }, + { + label: 'Fifth section', + value: 'id-5', + }, + { + label: 'Sixth section', + value: 'id-6', + }, ], onlyShowSelectedChildren: false, - variant: 'buttons', }, }; @@ -118,6 +130,9 @@ const COLORS = [ colors.infographic.substitute__blue_ocean.rgba, colors.infographic.substitute__blue_sky.rgba, colors.infographic.substitute__blue_overcast.rgba, + colors.infographic.substitute__green_cucumber.rgba, + colors.infographic.substitute__green_succulent.rgba, + colors.infographic.substitute__green_mint.rgba, ]; function Section({ @@ -141,8 +156,6 @@ function Section({ ); } -type StoryProps = TableOfContentsProviderProps & TableOfContentsProps; - type Story = StoryObj; export const Default: Story = { @@ -235,6 +248,33 @@ export const Horizontal: Story = { }, }; +export const HorizontalScrollable: Story = { + render: (args) => { + return ( +
+ + + +
+ {args.items.map((item, index) => ( +
+ ))} +
+ + +
+ ); + }, +}; + const ITEMS_WITH_CHILDREN: TableOfContentsItemType[] = [ { label: '2023', diff --git a/src/organisms/TableOfContents/TableOfContents.styles.ts b/src/organisms/TableOfContents/TableOfContents.styles.ts index 8f3459649..aa73822d3 100644 --- a/src/organisms/TableOfContents/TableOfContents.styles.ts +++ b/src/organisms/TableOfContents/TableOfContents.styles.ts @@ -65,6 +65,7 @@ export const Button = styled.button` `; export const HorizontalItemsContainer = styled.div` + overflow: hidden; button[role='tab'] { .count { background: ${colors.ui.background__light_medium.rgba}; diff --git a/src/organisms/TableOfContents/TableOfContents.tsx b/src/organisms/TableOfContents/TableOfContents.tsx index 7e0cb24a5..2bc31a793 100644 --- a/src/organisms/TableOfContents/TableOfContents.tsx +++ b/src/organisms/TableOfContents/TableOfContents.tsx @@ -5,20 +5,32 @@ import { TableOfContentsContainer, VerticalItemsContainer, } from './TableOfContents.styles'; -import { TableOfContentsMode } from './TableOfContents.types'; import { TableOfContentsItem } from './TableOfContentsItem'; import { Tabs } from 'src/molecules/Tabs/Tabs'; +import { TabsScrollProps } from 'src/molecules/Tabs/Tabs.types'; import { useTableOfContents } from 'src/providers/TableOfContentsProvider'; import { getValues } from 'src/providers/TableOfContentsProvider.utils'; -export interface TableOfContentsProps { - mode?: TableOfContentsMode; +interface TableOfContentsBaseProps { onlyShowSelectedChildren?: boolean; } +interface TableOfContentsVerticalProps extends TableOfContentsBaseProps { + mode?: 'vertical'; +} + +interface TableOfContentsHorizontalProps extends TableOfContentsBaseProps { + mode: 'horizontal'; + tabsProps?: TabsScrollProps; +} + +export type TableOfContentsProps = + | TableOfContentsVerticalProps + | TableOfContentsHorizontalProps; + export const TableOfContents: FC = ({ - mode = 'vertical', onlyShowSelectedChildren = true, + ...props }) => { const { items, selected, setSelected } = useTableOfContents(); @@ -40,7 +52,7 @@ export const TableOfContents: FC = ({ /* v8 ignore end */ }, [items, selected]); - if (mode === 'horizontal') { + if (props.mode === 'horizontal') { return ( = ({ if (value) setSelected(value); }} options={items} + {...props.tabsProps} /> ); diff --git a/src/organisms/TableOfContents/TableOfContents.types.ts b/src/organisms/TableOfContents/TableOfContents.types.ts deleted file mode 100644 index 7defa6bdd..000000000 --- a/src/organisms/TableOfContents/TableOfContents.types.ts +++ /dev/null @@ -1 +0,0 @@ -export type TableOfContentsMode = 'vertical' | 'horizontal';