Skip to content

Commit

Permalink
Docs(web-react): Add Tabs demo #DS-909
Browse files Browse the repository at this point in the history
- Tabs demo in web-react is now same as demo in web and web-twig
  • Loading branch information
pavelklibani committed Sep 19, 2023
1 parent b16595c commit a56fbdb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 112 deletions.
2 changes: 1 addition & 1 deletion packages/web-react/docs/DocsSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DocsStack from './DocsStack';
interface DocsSectionProps {
children: ReactNode;
hasStack?: boolean;
stackAlignment?: 'start' | 'center' | 'end';
stackAlignment?: 'start' | 'center' | 'end' | 'stretch';
tag?: string;
title: string;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-react/docs/DocsStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode } from 'react';

interface DocsStackProps {
children: ReactNode;
stackAlignment?: 'start' | 'center' | 'end';
stackAlignment?: 'start' | 'center' | 'end' | 'stretch';
}

const DocsStack = ({ children, stackAlignment }: DocsStackProps) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/web-react/src/components/Tabs/TabLink.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import classNames from 'classnames';
import { ChildrenProps, TransferProps } from '../../types';
import { useTabsStyleProps } from './useTabsStyleProps';
import { useStyleProps } from '../../hooks';

export interface TabLinkProps extends ChildrenProps, TransferProps {
href: string;
}

const TabLink = ({ children, href, ...restProps }: TabLinkProps): JSX.Element => {
const { classProps } = useTabsStyleProps();
const { styleProps, props: transferProps } = useStyleProps(restProps);

return (
<li className={classProps.item}>
<a {...restProps} href={href} className={classProps.link} role="tab">
<li {...transferProps} className={classNames(classProps.item, styleProps.className)}>
<a href={href} className={classProps.link} role="tab">
{children}
</a>
</li>
Expand Down
35 changes: 0 additions & 35 deletions packages/web-react/src/components/Tabs/demo/TabLinks.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions packages/web-react/src/components/Tabs/demo/Tabs.tsx

This file was deleted.

35 changes: 35 additions & 0 deletions packages/web-react/src/components/Tabs/demo/TabsDefault.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useState } from 'react';
import { TabId } from '../../../types';
import Tabs from '../Tabs';
import TabList from '../TabList';
import TabItem from '../TabItem';
import TabLink from '../TabLink';
import TabContent from '../TabContent';
import TabPane from '../TabPane';

const TabsDefault = () => {
const [selectedTabId, setSelectedTabId] = useState<TabId>(1);

const selectTab = (tabId: TabId) => {
setSelectedTabId(tabId);
};

return (
<Tabs selectedTab={selectedTabId} toggle={selectTab}>
<TabList>
<TabItem forTab={1}>Item 1</TabItem>
<TabItem forTab={2}>Item 2</TabItem>
<TabLink href="https://www.example.com">Item link</TabLink>
<TabLink href="https://www.example.com" UNSAFE_className="d-none d-desktop-block" className="test">
Item link, desktop only
</TabLink>
</TabList>
<TabContent>
<TabPane tabId={1}>Pane 1 content</TabPane>
<TabPane tabId={2}>Pane 2 content</TabPane>
</TabContent>
</Tabs>
);
};

export default TabsDefault;
23 changes: 0 additions & 23 deletions packages/web-react/src/components/Tabs/demo/UncontrolledTabs.tsx

This file was deleted.

22 changes: 4 additions & 18 deletions packages/web-react/src/components/Tabs/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@
/* eslint-disable import/no-extraneous-dependencies, import/extensions, import/no-unresolved */
import React from 'react';
import ReactDOM from 'react-dom/client';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, import/extensions, import/no-unresolved
// @ts-ignore: No declaration file
import icons from '@lmc-eu/spirit-icons/dist/icons';
import { IconsProvider } from '../../../context';
import DocsSection from '../../../../docs/DocsSections';
import Tabs from './Tabs';
import TabLinks from './TabLinks';
import UncontrolledTabs from './UncontrolledTabs';
import TabsDefault from './TabsDefault';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<IconsProvider value={icons}>
<DocsSection title="Default">
<Tabs />
</DocsSection>
<DocsSection title="Links">
<TabLinks />
</DocsSection>
<DocsSection title="Uncontrolled">
<UncontrolledTabs />
</DocsSection>
</IconsProvider>
<DocsSection title="Default" stackAlignment="stretch">
<TabsDefault />
</DocsSection>
</React.StrictMode>,
);

0 comments on commit a56fbdb

Please sign in to comment.