From 987d41e6b2a0d75ab9456934a94e455fa815edb9 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Tue, 18 Apr 2023 11:40:59 -0600 Subject: [PATCH 1/2] Add TS version of Button story with hooks snippet --- .../react/button-story.with-hooks.js.mdx | 2 +- .../react/button-story.with-hooks.ts-4-9.mdx | 43 +++++++++++++++++++ .../react/button-story.with-hooks.ts.mdx | 43 +++++++++++++++++++ docs/writing-stories/introduction.md | 2 +- 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 docs/snippets/react/button-story.with-hooks.ts-4-9.mdx create mode 100644 docs/snippets/react/button-story.with-hooks.ts.mdx diff --git a/docs/snippets/react/button-story.with-hooks.js.mdx b/docs/snippets/react/button-story.with-hooks.js.mdx index 6c1f41e95d99..06c4cfec6cc6 100644 --- a/docs/snippets/react/button-story.with-hooks.js.mdx +++ b/docs/snippets/react/button-story.with-hooks.js.mdx @@ -1,5 +1,5 @@ ```js -// Button.stories.js|ts|jsx|tsx +// Button.stories.js|jsx import React, { useState } from 'react'; diff --git a/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx b/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx new file mode 100644 index 000000000000..85bdd6e903e1 --- /dev/null +++ b/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx @@ -0,0 +1,43 @@ +```tsx +// Button.stories.ts|tsx + +import React, { useState } from 'react'; +import { Meta, StoryObj } from '@storybook/react' + +import { Button } from './Button'; + +const meta = { + /* 👇 The title prop is optional. + * See https://storybook.js.org/docs/react/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button +} satisfies Meta; +export default meta; + +type Story = StoryObj; + +/* + * Example Button story with React Hooks. + * See note below related to this example. + */ +const ButtonWithHooks = () => { + // Sets the hooks for both the label and primary props + const [value, setValue] = useState('Secondary'); + const [isPrimary, setIsPrimary] = useState(false); + + // Sets a click handler to change the label's value + const handleOnChange = () => { + if (!isPrimary) { + setIsPrimary(true); + setValue('Primary'); + } + }; + return