Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/molecules/Tabs/Tabs.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ export interface Tab<T> {
disabled?: boolean;
}

export interface Tabs<T> {
export interface TabsScrollProps {
scrollable?: boolean;
amountPerScrollPage?: number;
}

export interface Tabs<T> extends TabsScrollProps {
selected: T;
onChange: (value: T) => void;
onHover?: (hoveredTabValue: T) => void;
options: Tab<T>[];
scrollable?: boolean;
amountPerScrollPage?: number;
centered?: boolean;
animated?: boolean;
}
58 changes: 49 additions & 9 deletions src/organisms/TableOfContents/TableOfContents.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<StoryProps> = {
title: 'Organisms/TableOfContents',
component: TableOfContents,
parameters: {
Expand All @@ -32,7 +34,6 @@ const meta: Meta = {
argTypes: {
items: { control: 'object' },
onlyShowSelectedChildren: { control: 'boolean' },
variant: { control: 'radio', items: ['border', 'buttons'] },
},
args: {
items: [
Expand All @@ -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',
},
};

Expand Down Expand Up @@ -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({
Expand All @@ -141,8 +156,6 @@ function Section({
);
}

type StoryProps = TableOfContentsProviderProps & TableOfContentsProps;

type Story = StoryObj<StoryProps>;

export const Default: Story = {
Expand Down Expand Up @@ -235,6 +248,33 @@ export const Horizontal: Story = {
},
};

export const HorizontalScrollable: Story = {
render: (args) => {
return (
<div style={{ width: '40rem', maxWidth: '40rem' }}>
<TableOfContentsProvider items={args.items}>
<HorizontalContainer>
<TableOfContents
mode="horizontal"
tabsProps={{ scrollable: true, amountPerScrollPage: 3 }}
/>
<section>
{args.items.map((item, index) => (
<Section
key={item.value}
label={item.label}
value={item.value}
color={COLORS[index]}
/>
))}
</section>
</HorizontalContainer>
</TableOfContentsProvider>
</div>
);
},
};

const ITEMS_WITH_CHILDREN: TableOfContentsItemType[] = [
{
label: '2023',
Expand Down
1 change: 1 addition & 0 deletions src/organisms/TableOfContents/TableOfContents.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const Button = styled.button<ButtonProps>`
`;

export const HorizontalItemsContainer = styled.div`
overflow: hidden;
Comment thread
arkadiy93 marked this conversation as resolved.
button[role='tab'] {
.count {
background: ${colors.ui.background__light_medium.rgba};
Expand Down
23 changes: 18 additions & 5 deletions src/organisms/TableOfContents/TableOfContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Comment thread
arkadiy93 marked this conversation as resolved.
Comment thread
arkadiy93 marked this conversation as resolved.
export const TableOfContents: FC<TableOfContentsProps> = ({
mode = 'vertical',
onlyShowSelectedChildren = true,
...props
}) => {
const { items, selected, setSelected } = useTableOfContents();

Expand All @@ -40,7 +52,7 @@ export const TableOfContents: FC<TableOfContentsProps> = ({
/* v8 ignore end */
}, [items, selected]);

if (mode === 'horizontal') {
if (props.mode === 'horizontal') {
return (
<HorizontalItemsContainer>
<Tabs
Expand All @@ -49,6 +61,7 @@ export const TableOfContents: FC<TableOfContentsProps> = ({
if (value) setSelected(value);
}}
options={items}
{...props.tabsProps}
/>
</HorizontalItemsContainer>
);
Expand Down
1 change: 0 additions & 1 deletion src/organisms/TableOfContents/TableOfContents.types.ts

This file was deleted.

Loading