Skip to content

Commit

Permalink
Add storybook example
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 28, 2024
1 parent fec2b43 commit 935c2e7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/components/src/composite/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Meta, StoryObj } from '@storybook/react';
/**
* WordPress dependencies
*/
import { useContext, useMemo } from '@wordpress/element';
import { useContext, useMemo, useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -353,3 +353,27 @@ const Fill = ( { children } ) => {
},
},
};

export const RemoveActiveItem: StoryObj< typeof Composite > = {
render: ( args ) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [ showThirdItem, setShowThirdItem ] = useState( true );
return (
<>
<Composite { ...args }>
<Composite.Item>Item one</Composite.Item>
<Composite.Item>Item two</Composite.Item>
{ showThirdItem && (
<Composite.Item>Item three</Composite.Item>
) }
</Composite>
<button
style={ { marginTop: '1em' } }
onClick={ () => setShowThirdItem( ( value ) => ! value ) }
>
Toggle third item
</button>
</>
);
},
};

0 comments on commit 935c2e7

Please sign in to comment.