Skip to content

Commit 10a6ea9

Browse files
authored
chore(accordion): refactor storybook (#420)
1 parent 559da4b commit 10a6ea9

15 files changed

+266
-237
lines changed

packages/.template/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Check out [storybook](https://zendeskgarden.github.io/react-containers) for live
1818

1919
### use{{capitalize component}}
2020

21-
```jsx static
21+
```jsx
2222
import { use{{capitalize component}} } from '@zendeskgarden/container-{{lowercase component}}';
2323

2424
const {{capitalize component}} = () => {
@@ -30,7 +30,7 @@ const {{capitalize component}} = () => {
3030

3131
### {{capitalize component}}Container
3232

33-
```jsx static
33+
```jsx
3434
import { {{capitalize component}}Container } from '@zendeskgarden/container-{{lowercase component}}';
3535

3636
<{{capitalize component}}Container>{({ get{{capitalize component}}Props }) => <div {...get{{capitalize component}}Props()} />}</{{capitalize component}}Container>;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Meta, Description } from '@storybook/addon-docs';
2+
import README from '../README.md';
3+
4+
<Meta title="Packages/{{capitalize component}}/README" />
5+
6+
<Description>{README}</Description>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright Zendesk, Inc.
3+
*
4+
* Use of this source code is governed under the Apache License, Version 2.0
5+
* found at http://www.apache.org/licenses/LICENSE-2.0.
6+
*/
7+
8+
import React, { HTMLAttributes, HTMLProps } from 'react';
9+
import { Story } from '@storybook/react';
10+
import {
11+
I{{capitalize component}}ContainerProps,
12+
IUse{{capitalize component}}Props,
13+
IUse{{capitalize component}}ReturnValue,
14+
{{capitalize component}}Container,
15+
use{{capitalize component}}
16+
} from '@zendeskgarden/container-{{lowercase component}}';
17+
18+
const Container = ({ label, text }: I{{capitalize component}}ContainerProps & { text: string }) => (
19+
<{{capitalize component}}Container>
20+
{({ get{{capitalize component}}Props }: IUse{{capitalize component}}ReturnValue) => <div {...get{{capitalize component}}Props({ label })}>{text}</div>}
21+
</{{capitalize component}}Container>
22+
);
23+
24+
const Hook = ({ label, ...props }: IUse{{capitalize component}}Props & HTMLProps<HTMLAttributes<HTMLDivElement>>) => {
25+
const { get{{capitalize component}}Props } = use{{capitalize component}}({ label });
26+
27+
return <div {...get{{capitalize component}}Props()} {...props} />;
28+
};
29+
30+
interface IArgs extends I{{capitalize component}}ContainerProps {
31+
as: 'hook' | 'container';
32+
text: string;
33+
}
34+
35+
export const {{capitalize component}}Story: Story<IArgs> = ({ as, text, ...props }) => {
36+
switch (as) {
37+
case 'container':
38+
return <Container text={text} {...props} />;
39+
40+
case 'hook':
41+
default:
42+
return <Hook {...props}>{text}</Hook>;
43+
}
44+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Meta, ArgsTable, Canvas, Story } from '@storybook/addon-docs';
2+
import { {{capitalize component}}Container } from '@zendeskgarden/container-{{lowercase component}}';
3+
import { {{capitalize component}}Story } from './stories/{{capitalize component}}Story';
4+
5+
<Meta title="Packages/{{capitalize component}}" component={ {{capitalize component}}Container } />
6+
7+
# API
8+
9+
<ArgsTable />
10+
11+
# Demo
12+
13+
export const args = { as: 'hook', text: 'Hello world', label: 'test' };
14+
15+
export const argTypes = {
16+
as: { options: ['container', 'hook'], control: 'radio', table: { category: 'Story' } },
17+
text: { table: { category: 'Story' } }
18+
};
19+
20+
<Canvas>
21+
<Story name="{{capitalize component}}" args={args} argTypes={argTypes}>
22+
{args => <{{capitalize component}}Story {...args} />}
23+
</Story>
24+
</Canvas>

packages/.template/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
/* Hooks */
9-
export { use{{capitalize component}}, IUse{{capitalize component}}Props, IUse{{capitalize component}}ReturnValue } from './use{{capitalize component}}';
9+
export { use{{capitalize component}} } from './use{{capitalize component}}';
10+
export type { IUse{{capitalize component}}Props, IUse{{capitalize component}}ReturnValue } from './use{{capitalize component}}';
1011

1112
/* Render-props */
12-
export { {{capitalize component}}Container, I{{capitalize component}}ContainerProps } from './{{capitalize component}}Container';
13+
export { {{capitalize component}}Container } from './{{capitalize component}}Container';
14+
export type { I{{capitalize component}}ContainerProps } from './{{capitalize component}}Container';

packages/.template/tsconfig.build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"sourceMap": false,
88
"noEmit": false,
99
"paths": {}
10-
1110
},
1211
"include": ["src/**/*"],
1312
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]

packages/.template/{{lowercase component}}.stories.tsx

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/accordion/.size-snapshot.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
}
2020
},
2121
"index.cjs.js": {
22-
"bundled": 7276,
23-
"minified": 3738,
24-
"gzipped": 1460
22+
"bundled": 7388,
23+
"minified": 3836,
24+
"gzipped": 1471
2525
},
2626
"index.esm.js": {
27-
"bundled": 6666,
28-
"minified": 3227,
29-
"gzipped": 1345,
27+
"bundled": 6738,
28+
"minified": 3291,
29+
"gzipped": 1356,
3030
"treeshaked": {
3131
"rollup": {
32-
"code": 146,
32+
"code": 161,
3333
"import_statements": 101
3434
},
3535
"webpack": {
36-
"code": 3932
36+
"code": 3984
3737
}
3838
}
3939
}

packages/accordion/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ npm install @zendeskgarden/container-accordion
1414

1515
## Usage
1616

17-
For live examples check out our
18-
[storybook](https://zendeskgarden.github.io/react-containers/?path=/story/accordion-container--useaccordion).
17+
This container implements the
18+
[accordion](https://www.w3.org/TR/wai-aria-practices-1.1/#accordion) design
19+
pattern and can be used to build an accordion component. Check out
20+
[storybook](https://zendeskgarden.github.io/react-containers) for live examples.
1921

2022
### useAccordion
2123

2224
The `useAccordion` hook manages toggle state and required accessibility
2325
attributes for a group of sections.
2426

25-
```jsx static
27+
```jsx
2628
import { useAccordion } from '@zendeskgarden/container-accordion';
2729

2830
const Accordion = ({ expandable = true, collapsible = true } = {}) => {
@@ -77,7 +79,7 @@ return <Accordion expandable={true} collapsible={true} />;
7779

7880
`AccordionContainer` is a render-prop wrapper for the `useAccordion` hook.
7981

80-
```jsx static
82+
```jsx
8183
import { AccordionContainer } from '@zendeskgarden/container-accordion';
8284

8385
const Accordion = ({ expandable = true, collapsible = true } = {}) => (

packages/accordion/accordion.stories.tsx

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)