Skip to content

Commit

Permalink
feat: Using mdx syntax to create stories (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltongarbin committed Oct 1, 2020
1 parent 68ccbdd commit 9d9f03f
Show file tree
Hide file tree
Showing 11 changed files with 2,496 additions and 911 deletions.
18 changes: 7 additions & 11 deletions packages/ocean-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const path = require('path');

module.exports = {
stories: ['../src/**/*.stories.tsx'],
addons: ['@storybook/addon-viewport/register'],
stories: ['../src/**/*.stories.mdx'],
addons: [
'@storybook/addon-viewport',
'@storybook/addon-docs',
'@storybook/addon-controls',
'@storybook/addon-a11y',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});

config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{ loader: require.resolve('ts-loader') },
{ loader: require.resolve('react-docgen-typescript-loader') },
],
});
config.resolve.extensions.push('.ts', '.tsx');

return config;
},
};
9 changes: 9 additions & 0 deletions packages/ocean-components/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { addParameters } from '@storybook/react';
import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks';

addParameters({
docs: {
container: DocsContainer,
page: DocsPage,
},
});
3 changes: 2 additions & 1 deletion packages/ocean-components/.vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"orta.vscode-jest",
"coenraads.bracket-pair-colorizer"
"coenraads.bracket-pair-colorizer",
"silvenon.mdx"
]
}
12 changes: 7 additions & 5 deletions packages/ocean-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@storybook/addon-viewport": "^5.3.19",
"@storybook/react": "^5.3.19",
"@storybook/addon-a11y": "^6.0.0-beta.36",
"@storybook/addon-controls": "^6.0.0-beta.36",
"@storybook/addon-docs": "^6.0.0-beta.35",
"@storybook/addon-viewport": "^6.0.0-beta.35",
"@storybook/react": "^6.0.0-beta.35",
"@storybook/storybook-deployer": "^2.8.6",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^10.3.0",
"@types/classnames": "2.2.10",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.14",
"@types/react": "^16.9.38",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.3.0",
Expand All @@ -49,7 +53,6 @@
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"react": "^16.13.1",
"react-docgen-typescript-loader": "^3.7.2",
"react-dom": "^16.13.1",
"rollup": "^2.17.1",
"rollup-plugin-peer-deps-external": "^2.2.2",
Expand All @@ -58,7 +61,6 @@
"rollup-plugin-typescript2": "^0.27.1",
"sass-loader": "^8.0.2",
"ts-jest": "^26.1.0",
"ts-loader": "^7.0.5",
"typescript": "^3.9.5"
},
"peerDependencies": {
Expand All @@ -74,7 +76,7 @@
}
},
"dependencies": {
"blu-tokens": "^0.0.4",
"@useblu/tokens": "^1.0.0",
"classnames": "2.2.6"
}
}
16 changes: 14 additions & 2 deletions packages/ocean-components/src/Typography/Typography.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';

import './styles/_typography.scss';
import './styles/typography.scss';

export const defaultTypesMapping: Record<string, string> = {
heading1: 'h1',
Expand All @@ -25,8 +25,17 @@ export type Variant =
| 'description';

export type TypographyProps = {
/**
* Applies the theme typography styles.
*/
variant: Variant;
/**
* The content of the component.
*/
children: React.ReactNode;
/**
* The CSS class name of the wrapper element.
*/
className?: string;
} & React.ComponentPropsWithoutRef<'span'>;

Expand All @@ -37,7 +46,10 @@ const Typography = React.forwardRef<unknown, TypographyProps>(
return (
<Component
ref={ref}
className={classNames(`typography typography__${variant}`, className)}
className={classNames(
`ods-typography ods-typography__${variant}`,
className
)}
{...rest}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('render element', () => {

expect(getByText('Hello')).toMatchInlineSnapshot(`
<h1
class="typography typography__heading1"
class="ods-typography ods-typography__heading1"
data-cy="typo-heading1"
style="width: 200px;"
>
Expand All @@ -32,7 +32,9 @@ test.each(Object.keys(defaultTypesMapping))(
<Typography variant={variant as Variant}>Hey</Typography>
);

expect(getByText('Hey')).toHaveClass(`typography typography__${variant}`);
expect(getByText('Hey')).toHaveClass(
`ods-typography ods-typography__${variant}`
);
}
);

Expand All @@ -49,6 +51,6 @@ test('render another class', () => {
);

expect(getByText('My Text')).toHaveClass(
`typography typography__paragraph another-css-class__1 another-css-class__2`
`ods-typography ods-typography__paragraph another-css-class__1 another-css-class__2`
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
import Typography from '../Typography';

<Meta title="Components|Typography" component={Typography} />

# Typography API

The API documentation of the Typography React component. Learn more about the props and the CSS customization points.

## Import

```javascript
import Typography from '@useblu/ocean-ui/Typography';
// or
import { Typography } from '@useblu/ocean-ui';
```

## Usage

<Preview withSource="open" withToolbar>
<Story
name="Usage"
parameters={{ controls: { hideNoControlsWarning: true } }}
>
<Typography variant="paragraph">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos blanditiis
tenetur
</Typography>
</Story>
</Preview>

## Props

<Props component={Typography} parameters />

The ref is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

## CSS

| Rule name | Global class | Description |
| ----------- | ------------------------------ | ------------------------------------------------------------ |
| Root | .ods-typography | Styles applied to the root element. |
| heading1 | .ods-typography\_\_heading1 | Styles applied to the root element if variant="heading1". |
| heading2 | .ods-typography\_\_heading2 | Styles applied to the root element if variant="heading2". |
| heading3 | .ods-typography\_\_heading3 | Styles applied to the root element if variant="heading3". |
| heading4 | .ods-typography\_\_heading4 | Styles applied to the root element if variant="heading4". |
| subtitle1 | .ods-typography\_\_subtitle1 | Styles applied to the root element if variant="subtitle1". |
| subtitle2 | .ods-typography\_\_subtitle2 | Styles applied to the root element if variant="subtitle2". |
| paragraph | .ods-typography\_\_paragraph | Styles applied to the root element if variant="paragraph". |
| description | .ods-typography\_\_description | Styles applied to the root element if variant="description". |
| caption | .ods-typography\_\_caption | Styles applied to the root element if variant="caption". |

If that's not sufficient, you can check the [implementation of the component](https://github.com/Pagnet/ocean-ds/blob/master/src/Typography/Typography.tsx) for more detail.

## Playground

<Preview>
<Story
name="Playground"
args={{
variant: 'heading3',
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
}}
>
{(props) => <Typography {...props} />}
</Story>
</Preview>

<Props story="Playground" />

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~blu-tokens/dist/tokens.scss';
@import '~@useblu/tokens/dist/tokens.scss';

@mixin headings {
font-family: $font-family-highlight;
Expand All @@ -21,7 +21,7 @@
color: $color-interface-dark-down;
}

.typography {
.ods-typography {
margin: 0;

&__heading1 {
Expand Down
2 changes: 1 addition & 1 deletion packages/ocean-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"exclude": [
"node_modules",
"dist",
"src/**/*.stories.tsx",
"src/**/*.stories.mdx",
"src/**/*.test.tsx"
]
}
Loading

0 comments on commit 9d9f03f

Please sign in to comment.