-
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.
Merge pull request #37 from kitsuyui/update-readme-stopwatch
Update README
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1 +1,55 @@ | ||
# @kitsuyui/react-stopwatch | ||
|
||
[![npm version](https://badge.fury.io/js/@kitsuyui%2Freact-stopwatch.svg)](https://badge.fury.io/js/@kitsuyui%2Freact-stopwatch) | ||
|
||
<img width="204" alt="Stopwatch" src="https://github.com/kitsuyui/react-playground/assets/2596972/b25cc228-24ce-45eb-850a-c3775b708d3d"> | ||
|
||
## Installation | ||
|
||
### npm | ||
|
||
```sh | ||
npm install @kitsuyui/react-stopwatch | ||
``` | ||
|
||
### yarn | ||
|
||
```sh | ||
yarn add @kitsuyui/react-stopwatch | ||
``` | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { StopWatchContainer, MinimalStopwatch } from '@kitsuyui/react-stopwatch' | ||
|
||
const Stopwatch = () => { | ||
return ( | ||
<StopwatchContainer> | ||
<StopwatchContext.Consumer> | ||
{(props: StopwatchProps) => <MinimalStopwatch {...props} />} | ||
</StopwatchContext.Consumer> | ||
</StopwatchContainer> | ||
) | ||
} | ||
``` | ||
|
||
StopwatchContainer is a component that provides StopwatchContext. | ||
Stopwatchs are pure components that do not depend on StopwatchContext. Accept StopwatchProps as props. | ||
So you can define your own Stopwatch component by same interface. | ||
|
||
```typescript | ||
export interface StopwatchValue { | ||
elapsedTime: number | ||
running: boolean | ||
} | ||
|
||
export interface StopwatchActions { | ||
start(): void | ||
stop(): void | ||
toggle(): void | ||
reset(): void | ||
} | ||
|
||
export type StopwatchProps = StopwatchValue & StopwatchActions | ||
``` |