Skip to content

Commit

Permalink
Merge pull request #68 from kitsuyui/update-examples
Browse files Browse the repository at this point in the history
update examples
  • Loading branch information
kitsuyui authored May 25, 2023
2 parents da1ea21 + ed22ed6 commit f4fbed0
Show file tree
Hide file tree
Showing 19 changed files with 1,267 additions and 603 deletions.
16 changes: 0 additions & 16 deletions examples/storybook/.babelrc.json

This file was deleted.

1 change: 1 addition & 0 deletions examples/storybook/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const config = {
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'storybook-addon-swc',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
Expand Down
20 changes: 10 additions & 10 deletions examples/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"license": "MIT",
"private": true,
"devDependencies": {
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@kitsuyui/react-clock": "file:../../packages/clock",
"@kitsuyui/react-stopwatch": "file:../../packages/stopwatch",
"@kitsuyui/react-timer": "file:../../packages/timer",
"@playwright/test": "^1.34.0",
"@storybook/addon-essentials": "^7.0.8",
"@storybook/addon-interactions": "^7.0.8",
"@storybook/addon-links": "^7.0.8",
"@storybook/blocks": "^7.0.8",
"@storybook/react": "^7.0.8",
"@storybook/react-webpack5": "^7.0.8",
"@storybook/addon-essentials": "^7.0.17",
"@storybook/addon-interactions": "^7.0.17",
"@storybook/addon-links": "^7.0.17",
"@storybook/blocks": "^7.0.17",
"@storybook/react": "^7.0.17",
"@storybook/react-webpack5": "^7.0.17",
"@storybook/testing-library": "^0.1.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.60",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.8"
"storybook": "^7.0.17",
"storybook-addon-swc": "^1.2.0"
},
"scripts": {
"start": "storybook dev -p 6006",
Expand Down
28 changes: 0 additions & 28 deletions examples/storybook/stories/Clock.stories.js

This file was deleted.

74 changes: 0 additions & 74 deletions examples/storybook/stories/Stopwatch.stories.js

This file was deleted.

86 changes: 0 additions & 86 deletions examples/storybook/stories/Timer.stories.js

This file was deleted.

50 changes: 50 additions & 0 deletions examples/storybook/stories/Welcome.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Welcome

import { Canvas, Meta } from '@storybook/blocks'

import * as ClockStories from './clock/Example.stories'

<Canvas of={ClockStories.Default} />

This is a collection of React components by [Kitsuyui](https://github.com/kitsuyui).

## Install

```sh
$ npm install @kitsuyui/react-clock @kitsuyui/react-stopwatch @kitsuyui/react-timer
```

## Usage

Clock, Stopwatch, Timer, etc. change their state depending on the time.
To separate the change of the state and the representation of the UI, I use React Context.
For example, the following code is a clock that displays the current time in Tokyo.

```tsx
import {
AnalogClock,
ClockContainer,
DateContext,
DigitalClock,
} from '@kitsuyui/react-clock'
import React from 'react'

const Clock = () => {
return (
<ClockContainer refreshInterval={10}>
<DateContext.Consumer>
{(date) => (
<>
<AnalogClock timezone="Asia/Tokyo" date={date} />
<DigitalClock timezone="Asia/Tokyo" date={date} />
</>
)}
</DateContext.Consumer>
</ClockContainer>
)
}
```

`ClockContainer` is a component that manages the state of the clock.
The `refreshInterval` property is the interval at which the clock is updated.
`AnalogClock` and `DigitalClock` are components that display the clock. These components are independent of the state of the clock.
47 changes: 47 additions & 0 deletions examples/storybook/stories/clock/Analog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { AnalogClock } from '@kitsuyui/react-clock'

import type { Meta, StoryObj } from '@storybook/react'

const meta: Meta<typeof AnalogClock> = {
title: 'Clock/Analog',
component: AnalogClock,
}

export default meta
type Story = StoryObj<typeof AnalogClock>

export const Default: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
face: 'arabic',
step: 'tick',
},
}

export const Roman: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
face: 'roman',
step: 'tick',
},
}

export const Sweep: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
face: 'arabic',
step: 'sweep',
},
}

export const Tokyo: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'Asia/Tokyo',
face: 'arabic',
step: 'tick',
},
}
25 changes: 25 additions & 0 deletions examples/storybook/stories/clock/Digital.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DigitalClock } from '@kitsuyui/react-clock'

import type { Meta, StoryObj } from '@storybook/react'

const meta: Meta<typeof DigitalClock> = {
title: 'Clock/Digital',
component: DigitalClock,
}

export default meta
type Story = StoryObj<typeof DigitalClock>

export const Default: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
},
}

export const Tokyo: Story = {
args: {
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'Asia/Tokyo',
},
}
Loading

0 comments on commit f4fbed0

Please sign in to comment.