-
Notifications
You must be signed in to change notification settings - Fork 4
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
4 changed files
with
86 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { PropsWithChildren, useState } from "react"; | ||
|
||
const RenderingControls = ({ | ||
children, | ||
}: PropsWithChildren<Record<string, unknown>>) => { | ||
const [key, setKey] = useState(1); | ||
const [_, setRerender] = useState(1); | ||
|
||
return ( | ||
<div key={key}> | ||
{children} | ||
<hr /> | ||
<div> | ||
<button onClick={() => setRerender((x) => x + 1)}>Rerender</button> | ||
<button onClick={() => setKey((x) => x + 1)}>Remount</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export { RenderingControls }; |
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,60 @@ | ||
import { Meta, Story } from "@storybook/react"; | ||
import React from "react"; | ||
import { useCounter } from "reactjs-view-core"; | ||
import { RenderingControls } from "../../container/renderingControls"; | ||
|
||
type DemoProps = Parameters<typeof useCounter>[0]; | ||
|
||
const Demo = ({ ...options }: Parameters<typeof useCounter>[0]) => { | ||
const data = useCounter(options); | ||
|
||
return ( | ||
<> | ||
<pre> | ||
<code>{JSON.stringify(data, null, 4)}</code> | ||
</pre> | ||
<button onClick={() => data.startCounting()}>startCounting</button> | ||
<button onClick={() => data.reset()}>reset</button> | ||
</> | ||
); | ||
}; | ||
|
||
const DemoWithControls = (props: DemoProps) => ( | ||
<RenderingControls> | ||
<Demo {...props} /> | ||
</RenderingControls> | ||
); | ||
|
||
const meta: Meta<DemoProps> = { | ||
title: "Hooks/useCounter", | ||
component: DemoWithControls, | ||
argTypes: { | ||
start: { | ||
control: { | ||
type: "number", | ||
}, | ||
defaultValue: 0, | ||
}, | ||
end: { | ||
control: { | ||
type: "number", | ||
}, | ||
defaultValue: 60, | ||
}, | ||
step: { | ||
control: { | ||
type: "number", | ||
}, | ||
defaultValue: 1, | ||
}, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: Story<DemoProps> = (args) => <DemoWithControls {...args} />; | ||
export const Default = Template.bind({}); | ||
Default.args = {}; |