-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters