This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
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.
refactor: Move hooks to Storybook, #135
- Loading branch information
1 parent
e760d92
commit 3091e1d
Showing
20 changed files
with
336 additions
and
194 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
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
13 changes: 8 additions & 5 deletions
13
src/useBreakpoints/README.mdx → src/useBreakpoints/README.stories.mdx
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,35 @@ | ||
import {Meta} from '@storybook/addon-docs/blocks'; | ||
|
||
import useChartist from './'; | ||
|
||
<Meta title="Hooks/useChartist" component={useChartist} /> | ||
|
||
# useChartist | ||
|
||
```jsx | ||
import useChartist from 'base5-ui/useChartist'; | ||
``` | ||
|
||
A simple hook for using [Chartist.js](http://gionkunz.github.io/chartist-js/) in React. | ||
|
||
See below for a simplified example, or view the sources of [SimpleChart](https://github.com/5app/base5-ui/tree/master/src/SimpleChart) or [SimpleGauge](https://github.com/5app/base5-ui/tree/master/src/SimpleGauge) for real-world usage examples. | ||
|
||
## Example | ||
|
||
```jsx | ||
function MyChart({labels, data, options}) { | ||
const chartRef = useRef(null); | ||
|
||
useChartist(chartRef, { | ||
type: 'Line', | ||
data: { | ||
labels, | ||
series: [data], | ||
}, | ||
options, | ||
preserveAspectRatio: 'none', | ||
}); | ||
|
||
return <ChartContainer ref={chartRef} />; | ||
} | ||
``` |
13 changes: 9 additions & 4 deletions
13
src/useEventListener/README.mdx → src/useEventListener/README.stories.mdx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {Meta} from '@storybook/addon-docs/blocks'; | ||
|
||
import useHasMounted from './'; | ||
|
||
<Meta title="Hooks/useHasMounted" component={useHasMounted} /> | ||
|
||
# useHasMounted | ||
|
||
```jsx | ||
import useHasMounted from 'base5-ui/useHasMounted'; | ||
``` | ||
|
||
A simple hook that will return `true` only when the host component is rendered on the client. Causes an instant double-render, so it may be best to use a third-party hook like [useIsMounted](https://usehooks-typescript.com/react-hook/use-is-mounted) instead. |
15 changes: 8 additions & 7 deletions
15
src/useInterval/README.mdx → src/useInterval/README.stories.mdx
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,28 @@ | ||
import {Meta} from '@storybook/addon-docs/blocks'; | ||
|
||
import useMergedRefs from './'; | ||
|
||
<Meta title="Hooks/useMergedRefs" component={useMergedRefs} /> | ||
|
||
# useMergedRefs | ||
|
||
```jsx | ||
import useMergedRefs from 'base5-ui/useMergedRefs'; | ||
``` | ||
|
||
A hook for efficiently merging React refs. Usually used inside of a component that needs to expose a public ref via `React.forwardRef` while also using a ref locally. Supports both callback and object refs. | ||
|
||
## Example | ||
|
||
```jsx | ||
const AutoFocusingInput = forwardRef((props, ref) => { | ||
const inputRef = useRef(); | ||
const mergedRefs = useMergedRefs([ref, inputRef]); | ||
|
||
useEffect(() => { | ||
inputRef.current.focus(); | ||
}, []); | ||
|
||
return <input type="text" ref={mergedRefs} />; | ||
}); | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.