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

Tabs: Remove unnecessary stories #68463

Merged
merged 1 commit into from
Jan 2, 2025
Merged
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
131 changes: 0 additions & 131 deletions packages/components/src/tabs/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useState } from '@wordpress/element';
*/
import { Tabs } from '..';
import { Slot, Fill, Provider as SlotFillProvider } from '../../slot-fill';
import DropdownMenu from '../../dropdown-menu';
import Button from '../../button';
import Tooltip from '../../tooltip';
import Icon from '../../icon';
Expand Down Expand Up @@ -367,133 +366,3 @@ const CloseButtonTemplate: StoryFn< typeof Tabs > = ( props ) => {
);
};
export const InsertCustomElements = CloseButtonTemplate.bind( {} );

const ControlledModeTemplate: StoryFn< typeof Tabs > = ( props ) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controlled mode is explained better on the Best Practices page. Behavior should/can be covered in the unit tests.

const [ selectedTabId, setSelectedTabId ] = useState<
string | undefined | null
>( props.selectedTabId );

return (
<>
<Tabs
{ ...props }
selectedTabId={ selectedTabId }
onSelect={ ( selectedId ) => {
setSelectedTabId( selectedId );
props.onSelect?.( selectedId );
} }
>
<Tabs.TabList>
<Tabs.Tab tabId="tab1">Tab 1</Tabs.Tab>

<Tabs.Tab tabId="tab2">Tab 2</Tabs.Tab>

<Tabs.Tab tabId="tab3">Tab 3</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel tabId="tab1">
<p>Selected tab: Tab 1</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab2">
<p>Selected tab: Tab 2</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab3">
<p>Selected tab: Tab 3</p>
</Tabs.TabPanel>
</Tabs>
<div style={ { marginTop: '200px' } }>
<p>Select a tab:</p>
<DropdownMenu
controls={ [
{
onClick: () => setSelectedTabId( 'tab1' ),
title: 'Tab 1',
isActive: selectedTabId === 'tab1',
},
{
onClick: () => setSelectedTabId( 'tab2' ),
title: 'Tab 2',
isActive: selectedTabId === 'tab2',
},
{
onClick: () => setSelectedTabId( 'tab3' ),
title: 'Tab 3',
isActive: selectedTabId === 'tab3',
},
] }
label="Choose a tab. The power is yours."
/>
</div>
</>
);
};

export const ControlledMode = ControlledModeTemplate.bind( {} );
ControlledMode.args = {
selectedTabId: 'tab3',
};

const TabBecomesDisabledTemplate: StoryFn< typeof Tabs > = ( props ) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior should/can be covered in the unit tests.

const [ disableTab2, setDisableTab2 ] = useState( false );

return (
<>
<Button
variant="primary"
onClick={ () => setDisableTab2( ! disableTab2 ) }
>
{ disableTab2 ? 'Enable' : 'Disable' } Tab 2
</Button>
<Tabs { ...props }>
<Tabs.TabList>
<Tabs.Tab tabId="tab1">Tab 1</Tabs.Tab>
<Tabs.Tab tabId="tab2" disabled={ disableTab2 }>
Tab 2
</Tabs.Tab>
<Tabs.Tab tabId="tab3">Tab 3</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel tabId="tab1">
<p>Selected tab: Tab 1</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab2">
<p>Selected tab: Tab 2</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab3">
<p>Selected tab: Tab 3</p>
</Tabs.TabPanel>
</Tabs>
</>
);
};
export const TabBecomesDisabled = TabBecomesDisabledTemplate.bind( {} );

const TabGetsRemovedTemplate: StoryFn< typeof Tabs > = ( props ) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior should/can be covered in the unit tests.

const [ removeTab1, setRemoveTab1 ] = useState( false );

return (
<>
<Button
variant="primary"
onClick={ () => setRemoveTab1( ! removeTab1 ) }
>
{ removeTab1 ? 'Restore' : 'Remove' } Tab 1
</Button>
<Tabs { ...props }>
<Tabs.TabList>
{ ! removeTab1 && <Tabs.Tab tabId="tab1">Tab 1</Tabs.Tab> }
<Tabs.Tab tabId="tab2">Tab 2</Tabs.Tab>
<Tabs.Tab tabId="tab3">Tab 3</Tabs.Tab>
</Tabs.TabList>
<Tabs.TabPanel tabId="tab1">
<p>Selected tab: Tab 1</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab2">
<p>Selected tab: Tab 2</p>
</Tabs.TabPanel>
<Tabs.TabPanel tabId="tab3">
<p>Selected tab: Tab 3</p>
</Tabs.TabPanel>
</Tabs>
</>
);
};
export const TabGetsRemoved = TabGetsRemovedTemplate.bind( {} );
Loading