-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7986906
commit 325edf9
Showing
6 changed files
with
238 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 93 additions & 35 deletions
128
packages/libs/react-ui/src/components/Accordion/Accordion.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,117 @@ | ||
import { Accordion, IAccordionProps } from './Accordion'; | ||
import type { IAccordionProps, IAccordionSectionProps } from './'; | ||
import { Accordion } from './'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
const meta: Meta<{} & IAccordionProps> = { | ||
const generateSection = (i: number): IAccordionSectionProps => ({ | ||
title: `Section title ${i}`, | ||
children: ( | ||
<p> | ||
This is the content for section {i}. The type of this content is not | ||
restricted: any valid HTML content is allowed. | ||
</p> | ||
), | ||
onOpen: () => console.log(`open section ${i}`), | ||
onClose: () => console.log(`close section ${i}`), | ||
}); | ||
const generateSections = (n: number): IAccordionSectionProps[] => | ||
Array.from({ length: n }, (d, i) => generateSection(i + 1)); | ||
|
||
const sampleSections: IAccordionSectionProps[] = generateSections(5); | ||
|
||
type StoryProps = { | ||
sectionCount: number; | ||
linked: boolean; | ||
useCustomSections: boolean; | ||
customSections: IAccordionSectionProps[]; | ||
} & IAccordionProps; | ||
|
||
const meta: Meta<StoryProps> = { | ||
title: 'Components/Accordion', | ||
parameters: { | ||
controls: { | ||
hideNoControlsWarning: true, | ||
sort: 'requiredFirst', | ||
}, | ||
docs: { | ||
description: { | ||
component: | ||
'The Accordion component allows the user to show and hide sections of content on a page.<br />These sections can be expanded and collapsed by clicking the section headers.<br /><br /><strong>initialOpenSection</strong><br />This optional prop can be used on the Root element to set the initially opened section<br /><em>It defaults to `undefined` and has only been explcitly set to - 1 in the story code for demonstration purposes.</em><br /><br /><em>Note: this variant of the Accordion component is meant to be used to display content. For Navigation purposes, please check the other variant within the Navigation subgroup.</em>', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
linked: { | ||
type: 'boolean', | ||
defaultValue: true, | ||
control: { type: 'boolean' }, | ||
description: | ||
'Each section will close the other sections if they are linked', | ||
control: { | ||
type: 'boolean', | ||
'When linked, only one section can be open at a time. If a section is opened, the previously opened section will be closed.', | ||
table: { | ||
defaultValue: { summary: 'false' }, | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
sectionCount: { | ||
control: { type: 'range', min: 1, max: sampleSections.length, step: 1 }, | ||
description: 'Adjust sample section items count', | ||
if: { arg: 'useCustomContent', neq: true }, | ||
table: { | ||
defaultValue: { summary: 3 }, | ||
type: { summary: 'number' }, | ||
}, | ||
}, | ||
useCustomSections: { | ||
control: { type: 'boolean' }, | ||
description: 'Define your own sections instead of the sample ones?', | ||
table: { | ||
defaultValue: { summary: 'false' }, | ||
type: { summary: 'boolean' }, | ||
}, | ||
}, | ||
sections: { | ||
customSections: { | ||
defaultValue: [], | ||
description: 'Accordion children', | ||
description: 'Custom sections', | ||
control: { | ||
type: 'array', | ||
}, | ||
if: { arg: 'useCustomSections', eq: true }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<{} & IAccordionProps>; | ||
type IStory = StoryObj<StoryProps>; | ||
|
||
export const Dynamic: Story = { | ||
export const Dynamic: IStory = { | ||
name: 'Accordion', | ||
args: { | ||
linked: true, | ||
sections: [ | ||
{ | ||
title: <span>First Section</span>, | ||
children: <p>This is the content for the first section</p>, | ||
onOpen: () => console.log('open first item'), | ||
onClose: () => console.log('close first item'), | ||
}, | ||
{ | ||
title: <span>Second Section</span>, | ||
children: <p>This is the content for the second section</p>, | ||
onOpen: () => console.log('open second item'), | ||
onClose: () => console.log('close second item'), | ||
}, | ||
{ | ||
title: <span>Third Section</span>, | ||
children: <p>This is the content for the third section</p>, | ||
onOpen: () => console.log('open third item'), | ||
onClose: () => console.log('close third item'), | ||
}, | ||
], | ||
linked: false, | ||
sectionCount: 3, | ||
customSections: sampleSections, | ||
}, | ||
render: ({ linked, sections }) => { | ||
return <Accordion linked={Boolean(linked)} sections={sections} />; | ||
render: ({ linked, sectionCount, useCustomSections, customSections }) => { | ||
const sections = useCustomSections ? customSections : sampleSections; | ||
return ( | ||
<Accordion.Root linked={linked} initialOpenSection={-1}> | ||
{sections | ||
.slice(0, sectionCount) | ||
.map( | ||
( | ||
{ title, children, onOpen, onClose }: IAccordionSectionProps, | ||
index, | ||
) => ( | ||
<Accordion.Section | ||
onOpen={onOpen} | ||
onClose={onClose} | ||
title={title} | ||
key={index} | ||
> | ||
{children} | ||
</Accordion.Section> | ||
), | ||
)} | ||
</Accordion.Root> | ||
); | ||
}, | ||
}; | ||
|
||
export default meta; |
98 changes: 0 additions & 98 deletions
98
packages/libs/react-ui/src/components/Accordion/Accordion.test.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.