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

chore(accordion): refactor storybook #420

Merged
merged 9 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions packages/.template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Check out [storybook](https://zendeskgarden.github.io/react-containers) for live

### use{{capitalize component}}

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

const {{capitalize component}} = () => {
Expand All @@ -30,7 +30,7 @@ const {{capitalize component}} = () => {

### {{capitalize component}}Container

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

<{{capitalize component}}Container>{({ get{{capitalize component}}Props }) => <div {...get{{capitalize component}}Props()} />}</{{capitalize component}}Container>;
Expand Down
6 changes: 6 additions & 0 deletions packages/.template/demo/#readme.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta, Description } from '@storybook/addon-docs';
import README from '../README.md';

<Meta title="Packages/{{capitalize component}}/README" />

<Description>{README}</Description>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright Zendesk, Inc.
*
* Use of this source code is governed under the Apache License, Version 2.0
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import React, { HTMLAttributes, HTMLProps } from 'react';
import { Story } from '@storybook/react';
import {
I{{capitalize component}}ContainerProps,
IUse{{capitalize component}}Props,
IUse{{capitalize component}}ReturnValue,
{{capitalize component}}Container,
use{{capitalize component}}
} from '@zendeskgarden/container-{{lowercase component}}';

const Container = ({ label, text }: I{{capitalize component}}ContainerProps & { text: string }) => (
<{{capitalize component}}Container>
{({ get{{capitalize component}}Props }: IUse{{capitalize component}}ReturnValue) => <div {...get{{capitalize component}}Props({ label })}>{text}</div>}
</{{capitalize component}}Container>
);

const Hook = ({ label, ...props }: IUse{{capitalize component}}Props & HTMLProps<HTMLAttributes<HTMLDivElement>>) => {
const { get{{capitalize component}}Props } = use{{capitalize component}}({ label });

return <div {...get{{capitalize component}}Props()} {...props} />;
};

interface IArgs extends I{{capitalize component}}ContainerProps {
as: 'hook' | 'container';
text: string;
}

export const {{capitalize component}}Story: Story<IArgs> = ({ as, text, ...props }) => {
switch (as) {
case 'container':
return <Container text={text} {...props} />;

case 'hook':
default:
return <Hook {...props}>{text}</Hook>;
}
};
24 changes: 24 additions & 0 deletions packages/.template/demo/{{lowercase component}}.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Meta, ArgsTable, Canvas, Story } from '@storybook/addon-docs';
import { {{capitalize component}}Container } from '@zendeskgarden/container-{{lowercase component}}';
import { {{capitalize component}}Story } from './stories/{{capitalize component}}Story';

<Meta title="Packages/{{capitalize component}}" component={ {{capitalize component}}Container } />

# API

<ArgsTable />

# Demo

export const args = { as: 'hook', text: 'Hello world', label: 'test' };

export const argTypes = {
as: { options: ['container', 'hook'], control: 'radio', table: { category: 'Story' } },
text: { table: { category: 'Story' } }
};

<Canvas>
<Story name="{{capitalize component}}" args={args} argTypes={argTypes}>
{args => <{{capitalize component}}Story {...args} />}
</Story>
</Canvas>
6 changes: 4 additions & 2 deletions packages/.template/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

/* Hooks */
export { use{{capitalize component}}, IUse{{capitalize component}}Props, IUse{{capitalize component}}ReturnValue } from './use{{capitalize component}}';
export { use{{capitalize component}} } from './use{{capitalize component}}';
export type { IUse{{capitalize component}}Props, IUse{{capitalize component}}ReturnValue } from './use{{capitalize component}}';

/* Render-props */
export { {{capitalize component}}Container, I{{capitalize component}}ContainerProps } from './{{capitalize component}}Container';
export { {{capitalize component}}Container } from './{{capitalize component}}Container';
export type { I{{capitalize component}}ContainerProps } from './{{capitalize component}}Container';
1 change: 0 additions & 1 deletion packages/.template/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"sourceMap": false,
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
47 changes: 0 additions & 47 deletions packages/.template/{{lowercase component}}.stories.tsx

This file was deleted.

16 changes: 8 additions & 8 deletions packages/accordion/.size-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
}
},
"index.cjs.js": {
"bundled": 7276,
"minified": 3738,
"gzipped": 1460
"bundled": 7388,
"minified": 3836,
"gzipped": 1471
},
"index.esm.js": {
"bundled": 6666,
"minified": 3227,
"gzipped": 1345,
"bundled": 6738,
"minified": 3291,
"gzipped": 1356,
"treeshaked": {
"rollup": {
"code": 146,
"code": 161,
"import_statements": 101
},
"webpack": {
"code": 3932
"code": 3984
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions packages/accordion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ npm install @zendeskgarden/container-accordion

## Usage

For live examples check out our
[storybook](https://zendeskgarden.github.io/react-containers/?path=/story/accordion-container--useaccordion).
Check out [storybook](https://zendeskgarden.github.io/react-containers) for live examples.

### useAccordion

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

```jsx static
Copy link
Member Author

Choose a reason for hiding this comment

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

These tags are leftover from styleguidist usage and prevent proper codeblock display in storybook.

```jsx
import { useAccordion } from '@zendeskgarden/container-accordion';

const Accordion = ({ expandable = true, collapsible = true } = {}) => {
Expand Down Expand Up @@ -77,7 +76,7 @@ return <Accordion expandable={true} collapsible={true} />;

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

```jsx static
```jsx
import { AccordionContainer } from '@zendeskgarden/container-accordion';

const Accordion = ({ expandable = true, collapsible = true } = {}) => (
Expand Down
172 changes: 0 additions & 172 deletions packages/accordion/accordion.stories.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions packages/accordion/demo/#readme.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta, Description } from '@storybook/addon-docs';
import README from '../README.md';

<Meta title="Packages/Accordion/README" />

<Description>{README}</Description>
Loading