Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redmine 1257478): added ResponsiveTabs component #42

Merged
merged 9 commits into from
Oct 18, 2023
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
5 changes: 5 additions & 0 deletions .changeset/wicked-ways-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@smile/react-front-kit': minor
---

Added `ResponsiveTabs` component
217 changes: 112 additions & 105 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import { CaretDown, CaretUp } from '@phosphor-icons/react';
import { useId, useState } from 'react';

export interface IDropdownButtonProps extends MenuProps {
/** Override default menu target with custom component*/
buttonComponent?: ReactNode;
children?: ReactNode;
label: string;
label?: string;
}

/** Additional props will be forwarded to the [Mantine Menu component](https://mantine.dev/core/menu) */
export function DropdownButton(props: IDropdownButtonProps): ReactElement {
const { children, label, position = 'bottom-start', ...menuProps } = props;
const {
buttonComponent,
children,
label,
position = 'bottom-start',
...menuProps
} = props;
const [opened, setOpened] = useState(false);
const id = useId();

Expand All @@ -27,12 +35,14 @@ export function DropdownButton(props: IDropdownButtonProps): ReactElement {
{...menuProps}
>
<Menu.Target>
<Button
data-testid="button"
rightIcon={opened ? <CaretUp /> : <CaretDown />}
>
{label}
</Button>
{buttonComponent ?? (
<Button
data-testid="button"
rightIcon={opened ? <CaretUp /> : <CaretDown />}
>
{label}
</Button>
)}
MorganeLeCaignec marked this conversation as resolved.
Show resolved Hide resolved
</Menu.Target>
<Menu.Dropdown data-testid="dropdown">{children}</Menu.Dropdown>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Tabs } from '@mantine/core';

export const contents = (
<>
<Tabs.Panel value="1">First Content</Tabs.Panel>
<Tabs.Panel value="2">Second Content</Tabs.Panel>
<Tabs.Panel value="3">Third Content</Tabs.Panel>
<Tabs.Panel value="4">Fourth Content</Tabs.Panel>
<Tabs.Panel value="5">Overflow 1 Content</Tabs.Panel>
<Tabs.Panel value="6">Overflow 2 Content</Tabs.Panel>
</>
);

export const tabs = [
<Tabs.Tab key={1} id="tab-1" value="1">
First
</Tabs.Tab>,
<Tabs.Tab key={2} data-testid="test-tab" id="tab-1" value="2">
Second
</Tabs.Tab>,
<Tabs.Tab key={3} value="3">
Third
</Tabs.Tab>,
<Tabs.Tab key={4} value="4">
Fourth
</Tabs.Tab>,
<Tabs.Tab key={5} value="5">
Overflow 1
</Tabs.Tab>,
<Tabs.Tab key={6} value="6">
Overflow 2
</Tabs.Tab>,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ReactNode } from 'react';

import { sleep } from '@smile/react-front-kit-shared/src/storybook-utils';
import { expect } from '@storybook/jest';
import { userEvent, within } from '@storybook/testing-library';

import { ResponsiveTabs as Cmp } from './ResponsiveTabs';
import { contents, tabs } from './ResponsiveTabs.mock';

const meta = {
component: Cmp,
tags: ['autodocs'],
title: '3-custom/Components/ResponsiveTabs',
} satisfies Meta<typeof Cmp>;

export default meta;
type IStory = StoryObj<typeof meta>;

function Wrapper({ children }: { children: ReactNode }): ReactNode {
return (
<div
style={{
border: '1px solid darkgrey',
boxSizing: 'content-box',
height: 250,
margin: 'auto',
overflow: 'hidden',
padding: 30,
resize: 'both',
width: 300,
}}
>
{children}
</div>
);
}

export const ResponsiveTabs: IStory = {
args: {
children: contents,
defaultValue: '1',
tabs,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(canvas.getByText('First Content')).toBeVisible();
await userEvent.click(canvas.getAllByTestId('test-tab')[1]);
await sleep(200);
await expect(canvas.getByText('Second Content')).toBeVisible();
},
render: ({ children, ...props }) => (
<Wrapper>
<Cmp {...props}>{children}</Cmp>
</Wrapper>
),
};
Loading