Skip to content

Commit

Permalink
Merge pull request #534 from pixiv/toshusai/add-story-docs
Browse files Browse the repository at this point in the history
Feat: add docs for storybook
  • Loading branch information
toshusai authored May 10, 2024
2 parents 6a23d6c + 785afa0 commit 290b382
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const glob = promisify(require('glob'))
const { viteCommonjs } = require('@originjs/vite-plugin-commonjs')

module.exports = {
stories: ['../packages/**/*.mdx', '../packages/**/*.story.@(tsx)'],
stories: [
'../packages/**/*.mdx',
'../packages/**/*.story.@(tsx)',
'./src/**/*.mdx',
],

addons: [
getAbsolutePath('@storybook/addon-essentials'),
Expand Down
5 changes: 5 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const parameters = {
date: /Date$/,
},
},
options: {
storySort: {
order: ['DOCS'],
},
},
viewMode: 'docs',
docs: {
container: DocsContainer,
Expand Down
23 changes: 23 additions & 0 deletions .storybook/src/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meta, Story } from '@storybook/addon-docs'

<Meta title="DOCS/README" />

![charcoal logo](https://charcoal-web.pixiv.design/charcoal-ogp.jpg)

# Charcoal

## charcoal について

charcoal は [ピクシブ株式会社](https://www.pixiv.co.jp/)
のデザインシステムです。ここでは特に、Web フロントエンドの実装に用いる npm パッケージ集のことを言います。
オープンソースであり、ソースコードは全て[Apache License 2.0 ](https://www.apache.org/licenses/LICENSE-2.0) のもと [GitHub リポジトリ](https://github.com/pixiv/charcoal) として公開されています。

## charcoal という名前

「charcoal(木炭)」とはデッサンの道具であり、線を引く、表現の基礎となる素材の一つです。
また創作物を主役とするサービスの基盤として、それ自体は色を持たないモノクロの素材である、というニュアンスも含みます。

## 設計思想

charcoal はいわゆるコンポーネント実装も含みますが、それ以外にも UI の実装に必要なパッケージを多数収録しています。
charcoal の設計思想は「定数」「ユーティリティ」「コンポーネント」の三層構造として説明されます。
44 changes: 44 additions & 0 deletions packages/styled/src/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Meta, Story } from '@storybook/addon-docs'

<Meta title="styled/README" />

# Install

## yarn

```
yarn add @charcoal-ui/styled
```

# Usage

```tsx
import { FC, ReactNode } from 'react'
import { light, dark } from '@charcoal-ui/theme'
import {
TokenInjector,
useTheme,
useThemeSetter,
themeSelector,
prefersColorScheme,
} from '@charcoal-ui/styled'

const ExampleProvider: FC<{ children: ReactNode }> = ({ children }) => {
const [theme] = useTheme()
useThemeSetter()
return (
<ThemeProvider theme={theme === 'dark' ? dark : light}>
<TokenInjector
theme={{
':root': light,
[themeSelector('light')]: light,
[themeSelector('dark')]: dark,
[prefersColorScheme('dark')]: dark,
}}
background="background1"
/>
{children}
</ThemeProvider>
)
}
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storybook Tests styled/example Example 1`] = `
exports[`Storybook Tests styled/addThemeUtils Example 1`] = `
.c0 {
gap: 40px;
color: #1f1f1f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Canvas, Meta } from '@storybook/blocks'

import * as CheckboxStories from './index.story'
import * as Stories from './addThemeUtils.story'

<Meta title="styled/addThemeUtils" />

Expand Down Expand Up @@ -41,4 +41,4 @@ const AssertiveRingDiv = styled.div`

### Example

<Canvas of={CheckboxStories.Example} />
<Canvas of={Stories.Example} />
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled, { ThemeProvider } from 'styled-components'
import { MyTheme, myTheme } from './storyHelper'

export default {
title: 'styled/example',
title: 'styled/addThemeUtils',
}

declare module 'styled-components' {
Expand Down
35 changes: 35 additions & 0 deletions packages/styled/src/createTheme.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Canvas, Meta } from '@storybook/blocks'

<Meta title="styled/createTheme" />

# `createTheme`(`deprecated`)

The helper function for styled-components has a performance issue.

```tsx
import styled from 'styled-components'
import { createTheme } from '@charcoal-ui/styled'

export const theme = createTheme(styled)

export const Preview = () => {
return (
<>
<Ex>brand</Ex>
<Ex2>hover or press me</Ex2>
</>
)
}
const Ex = styled.p`
${theme((o) => [o.bg.brand, o.font.text5, o.width.px(104), o.height.px(104)])}
`

const Ex2 = styled.p`
${theme((o) => [
o.bg.success.hover.press,
o.font.text5,
o.width.px(104),
o.height.px(104),
])}
`
```
2 changes: 1 addition & 1 deletion packages/styled/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'jest-styled-components'

import renderer from 'react-test-renderer'
import styled, { ThemeProvider } from 'styled-components'
import { Example } from './index.story'
import { Example } from './addThemeUtils.story'
import { MyTheme, myTheme } from './storyHelper'

function render(children: JSX.Element) {
Expand Down

0 comments on commit 290b382

Please sign in to comment.