From 60cd3ae4bbe5b4010bedf38b09019b22ec654aba Mon Sep 17 00:00:00 2001 From: Mauricio Rivera Date: Sat, 18 Feb 2023 17:09:12 -0500 Subject: [PATCH 01/36] Added solid to frameworks list. --- docs/frameworks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/frameworks.js b/docs/frameworks.js index f37ffd6cd8cc..f98084101d8c 100644 --- a/docs/frameworks.js +++ b/docs/frameworks.js @@ -1,6 +1,6 @@ module.exports = { coreFrameworks: ['react', 'vue', 'angular', 'web-components'], - communityFrameworks: ['ember', 'html', 'svelte', 'preact', 'qwik'], + communityFrameworks: ['ember', 'html', 'svelte', 'preact', 'qwik', 'solid'], featureGroups: [ { name: 'Essentials', From e998e3be0e0a3f63fffd497abbbab30776a9b65f Mon Sep 17 00:00:00 2001 From: Mauricio Rivera Date: Sat, 18 Feb 2023 17:09:48 -0500 Subject: [PATCH 02/36] Added helper script for synchronizing docs with frontpage repo. --- docs/sync.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/sync.js diff --git a/docs/sync.js b/docs/sync.js new file mode 100644 index 000000000000..e7bddb54eb94 --- /dev/null +++ b/docs/sync.js @@ -0,0 +1,74 @@ +/** + * Util script for synchronizing docs with frontpage repository. + * For running it: + * - cd /storybook/docs + * - node sync.js + */ +const fs = require('fs'); +const readline = require('readline'); +const path = require('path'); + +const askQuestion = (query) => { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return new Promise(resolve => rl.question(`${query}\n`, ans => { + rl.close(); + resolve(ans); + })) +} + +const run = async () => { + let frontpageDocsPath = '/src/content/docs' + + const frontpageAbsPath = await askQuestion('Provide the frontpage project absolute path:') + frontpageDocsPath = `${frontpageAbsPath}${frontpageDocsPath}`; + + if (!fs.existsSync(frontpageDocsPath)) { + console.error(`The directory ${frontpageDocsPath} doesn't exists`); + process.exit(1) + } + + console.log(`Synchronizing files from: \n${__dirname} \nto: \n${frontpageDocsPath}`) + + fs.watch(__dirname , {recursive: true}, (_, filename) => { + const srcFilePath = path.join(__dirname, filename); + const targetFilePath = path.join(frontpageDocsPath, filename); + const targetDir = targetFilePath.split('/').slice(0, -1).join('/'); + + if (filename === 'sync.js') return; + + //Syncs create file + if (!fs.existsSync(targetFilePath)) { + fs.mkdirSync(targetDir, {recursive: true}) + + try { + fs.closeSync(fs.openSync(targetFilePath, 'w')); + console.log(`Created ${filename}.`); + } catch (error) { + throw error; + } + } + + //Syncs remove file + if (!fs.existsSync(srcFilePath)) { + try { + fs.unlinkSync(targetFilePath); + console.log(`Removed ${filename}.`); + } catch (error) { + throw error; + } + return; + } + + //Syncs update file + fs.copyFile(srcFilePath, targetFilePath, (err) => { + console.log(`Updated ${filename}.`); + if (err) throw err; + }); + }) +} + +run(); \ No newline at end of file From ab4e73e288895ccd56625a3c3f18d424968e3123 Mon Sep 17 00:00:00 2001 From: Mauricio Rivera Date: Sat, 18 Feb 2023 17:23:05 -0500 Subject: [PATCH 03/36] Added basic button story docs. --- docs/get-started/install.md | 2 ++ .../installation-command-section/solid.mdx | 15 ++++++++++ .../installation-problems/solid.mdx | 11 +++++++ docs/get-started/whats-a-story.md | 4 +++ .../solid/button-story-with-args.js.mdx | 21 ++++++++++++++ .../solid/button-story-with-args.ts-4-9.mdx | 27 +++++++++++++++++ .../solid/button-story-with-args.ts.mdx | 26 +++++++++++++++++ docs/snippets/solid/button-story.js.mdx | 23 +++++++++++++++ docs/snippets/solid/button-story.ts-4-9.mdx | 29 +++++++++++++++++++ docs/snippets/solid/button-story.ts.mdx | 28 ++++++++++++++++++ 10 files changed, 186 insertions(+) create mode 100644 docs/get-started/installation-command-section/solid.mdx create mode 100644 docs/get-started/installation-problems/solid.mdx create mode 100644 docs/snippets/solid/button-story-with-args.js.mdx create mode 100644 docs/snippets/solid/button-story-with-args.ts-4-9.mdx create mode 100644 docs/snippets/solid/button-story-with-args.ts.mdx create mode 100644 docs/snippets/solid/button-story.js.mdx create mode 100644 docs/snippets/solid/button-story.ts-4-9.mdx create mode 100644 docs/snippets/solid/button-story.ts.mdx diff --git a/docs/get-started/install.md b/docs/get-started/install.md index 77db823a856b..6fcd24f8001f 100644 --- a/docs/get-started/install.md +++ b/docs/get-started/install.md @@ -15,6 +15,7 @@ title: 'Install Storybook' 'get-started/installation-command-section/vue.mdx', 'get-started/installation-command-section/web-components.mdx', 'get-started/installation-command-section/qwik.mdx', + 'get-started/installation-command-section/solid.mdx', ]} /> @@ -88,6 +89,7 @@ Below are some of the most common installation issues and instructions on how to 'get-started/installation-problems/vue.mdx', 'get-started/installation-problems/web-components.mdx', 'get-started/installation-problems/qwik.mdx', + 'get-started/installation-problems/solid.mdx', ]} /> diff --git a/docs/get-started/installation-command-section/solid.mdx b/docs/get-started/installation-command-section/solid.mdx new file mode 100644 index 000000000000..41e5c040cc9d --- /dev/null +++ b/docs/get-started/installation-command-section/solid.mdx @@ -0,0 +1,15 @@ +Use the Storybook CLI to install it in a single command. Run this inside your _existing project’s_ root directory: + +- With npm: + +```shell +npx storybook init +``` + +- With pnpm: + +```shell +pnpm dlx storybook init +``` + +If you run into issues with the installation, check the [Troubleshooting section](#troubleshooting) below for guidance on how to solve it. diff --git a/docs/get-started/installation-problems/solid.mdx b/docs/get-started/installation-problems/solid.mdx new file mode 100644 index 000000000000..9308bb9b154a --- /dev/null +++ b/docs/get-started/installation-problems/solid.mdx @@ -0,0 +1,11 @@ +- Add the `--type solid` flag to the installation command to set up Storybook manually: + + ```shell + npx storybook init --type solid + ``` + +- Storybook's CLI provides support for [Yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), and [pnpm](https://pnpm.io/) package managers. If you have Yarn installed in your environment but prefer to use another as your default package manager add the `--package-manager` flag to your installation command. For example: + + ```shell + npx storybook init --package-manager=npm + ``` diff --git a/docs/get-started/whats-a-story.md b/docs/get-started/whats-a-story.md index 52e04afae91f..ed9e8689e905 100644 --- a/docs/get-started/whats-a-story.md +++ b/docs/get-started/whats-a-story.md @@ -26,6 +26,8 @@ Let’s start with the `Button` component. A story is a function that describes 'html/button-story.js.mdx', 'html/button-story.ts.mdx', 'preact/button-story.js.mdx', + 'solid/button-story.js.mdx', + 'solid/button-story.ts.mdx', ]} usesCsf3 csf2Path="get-started/whats-a-story#snippet-button-story" @@ -56,6 +58,8 @@ The above story definition can be further improved to take advantage of [Storybo 'html/button-story-with-args.js.mdx', 'html/button-story-with-args.ts.mdx', 'preact/button-story-with-args.js.mdx', + 'solid/button-story-with-args.js.mdx', + 'solid/button-story-with-args.ts.mdx', ]} usesCsf3 csf2Path="get-started/whats-a-story#snippet-button-story-with-args" diff --git a/docs/snippets/solid/button-story-with-args.js.mdx b/docs/snippets/solid/button-story-with-args.js.mdx new file mode 100644 index 000000000000..119f049a57cd --- /dev/null +++ b/docs/snippets/solid/button-story-with-args.js.mdx @@ -0,0 +1,21 @@ +```js +// Button.stories.js|jsx + +import { Button } from './Button'; + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +}; + +export const Primary = { + args: { + label: 'Button', + primary: true, + }, +}; +``` diff --git a/docs/snippets/solid/button-story-with-args.ts-4-9.mdx b/docs/snippets/solid/button-story-with-args.ts-4-9.mdx new file mode 100644 index 000000000000..498436f4f995 --- /dev/null +++ b/docs/snippets/solid/button-story-with-args.ts-4-9.mdx @@ -0,0 +1,27 @@ +```tsx +// Button.stories.ts|tsx + +import type { Meta, StoryObj } from '@storybook/solid'; + +import { Button, ButtonProps } from './Button'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + + component: Button, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Primary: Story = { + args: { + primary: true, + label: 'Button', + }, +}; +``` diff --git a/docs/snippets/solid/button-story-with-args.ts.mdx b/docs/snippets/solid/button-story-with-args.ts.mdx new file mode 100644 index 000000000000..60b45603ae58 --- /dev/null +++ b/docs/snippets/solid/button-story-with-args.ts.mdx @@ -0,0 +1,26 @@ +```tsx +// Button.stories.ts|tsx + +import type { Meta, StoryObj } from '@storybook/solid'; + +import { Button, ButtonProps } from './Button'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +}; + +export default meta; +type Story = StoryObj; + +export const Primary: Story = { + args: { + primary: true, + label: 'Button', + }, +}; +``` diff --git a/docs/snippets/solid/button-story.js.mdx b/docs/snippets/solid/button-story.js.mdx new file mode 100644 index 000000000000..6a3c4c9adedb --- /dev/null +++ b/docs/snippets/solid/button-story.js.mdx @@ -0,0 +1,23 @@ +```js +// Button.stories.js|jsx + +import { Button } from './Button'; + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +}; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const Primary = { + render: () => , +}; +``` diff --git a/docs/snippets/solid/button-story-with-addon-example.ts-4-9.mdx b/docs/snippets/solid/button-story-with-addon-example.ts-4-9.mdx new file mode 100644 index 000000000000..f067347d3780 --- /dev/null +++ b/docs/snippets/solid/button-story-with-addon-example.ts-4-9.mdx @@ -0,0 +1,36 @@ +```tsx +// Button.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { Button } from './Button'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + + component: Button, + + //πŸ‘‡ Creates specific parameters for the story + parameters: { + myAddon: { + data: 'this data is passed to the addon', + }, + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const Basic: Story = { + render: () => , +}; +``` diff --git a/docs/snippets/solid/button-story-with-addon-example.ts.mdx b/docs/snippets/solid/button-story-with-addon-example.ts.mdx new file mode 100644 index 000000000000..90d87c014d76 --- /dev/null +++ b/docs/snippets/solid/button-story-with-addon-example.ts.mdx @@ -0,0 +1,34 @@ +```tsx +// Button.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { Button } from './Button'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, + //πŸ‘‡ Creates specific parameters for the story + parameters: { + myAddon: { + data: 'this data is passed to the addon', + }, + }, +}; + +export default meta; +type Story = StoryObj; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const Basic: Story = { + render: () => , +}; +``` From 697ae4a99ab5efc54275fae314fd1682c03644e1 Mon Sep 17 00:00:00 2001 From: Mauricio Rivera Date: Wed, 22 Feb 2023 09:41:12 -0500 Subject: [PATCH 16/36] Added docs code snippets. --- docs/configure/environment-variables.md | 2 ++ docs/configure/frameworks.md | 2 +- docs/configure/images-and-assets.md | 6 ++++ docs/configure/telemetry.md | 2 +- .../component-story-static-asset-cdn.js.mdx | 22 ++++++++++++ ...omponent-story-static-asset-cdn.ts-4-9.mdx | 24 +++++++++++++ .../component-story-static-asset-cdn.ts.mdx | 24 +++++++++++++ ...nent-story-static-asset-with-import.js.mdx | 27 +++++++++++++++ ...-story-static-asset-with-import.ts-4-9.mdx | 34 +++++++++++++++++++ ...nent-story-static-asset-with-import.ts.mdx | 34 +++++++++++++++++++ ...t-story-static-asset-without-import.js.mdx | 16 +++++++++ ...ory-static-asset-without-import.ts-4-9.mdx | 23 +++++++++++++ ...t-story-static-asset-without-import.ts.mdx | 23 +++++++++++++ .../my-component-with-env-variables.js.mdx | 20 +++++++++++ ...my-component-with-env-variables.ts-4-9.mdx | 26 ++++++++++++++ .../my-component-with-env-variables.ts.mdx | 25 ++++++++++++++ 16 files changed, 308 insertions(+), 2 deletions(-) create mode 100644 docs/snippets/solid/component-story-static-asset-cdn.js.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-cdn.ts-4-9.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-cdn.ts.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-with-import.js.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-with-import.ts-4-9.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-with-import.ts.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-without-import.js.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-without-import.ts-4-9.mdx create mode 100644 docs/snippets/solid/component-story-static-asset-without-import.ts.mdx create mode 100644 docs/snippets/solid/my-component-with-env-variables.js.mdx create mode 100644 docs/snippets/solid/my-component-with-env-variables.ts-4-9.mdx create mode 100644 docs/snippets/solid/my-component-with-env-variables.ts.mdx diff --git a/docs/configure/environment-variables.md b/docs/configure/environment-variables.md index fe3eb4ad0b0a..91bb89ea0dc5 100644 --- a/docs/configure/environment-variables.md +++ b/docs/configure/environment-variables.md @@ -59,6 +59,8 @@ Then you can access this environment variable anywhere, even within your stories 'web-components/my-component-with-env-variables.js.mdx', 'web-components/my-component-with-env-variables.ts.mdx', 'svelte/my-component-with-env-variables.js.mdx', + 'solid/my-component-with-env-variables.js.mdx', + 'solid/my-component-with-env-variables.ts.mdx', ]} usesCsf3 csf2Path="configure/environment-variables#snippet-my-component-with-env-variables" diff --git a/docs/configure/frameworks.md b/docs/configure/frameworks.md index 079f4b3b0de4..4928420ccd23 100644 --- a/docs/configure/frameworks.md +++ b/docs/configure/frameworks.md @@ -15,7 +15,7 @@ Storybook provides support for the leading industry builders and frameworks. How | Builder | Framework | | ------- | ------------------------------------------------------------------------ | | Webpack | React, Angular, Vue, Web Components, NextJS, HTML, Ember, Preact, Svelte | -| Vite | React, Vue, Web Components, HTML, Svelte, SvelteKit, Qwik | +| Vite | React, Vue, Web Components, HTML, Svelte, SvelteKit, Qwik, Solid | ## Configure diff --git a/docs/configure/images-and-assets.md b/docs/configure/images-and-assets.md index 63dd3dc26c97..e7e21826e2c3 100644 --- a/docs/configure/images-and-assets.md +++ b/docs/configure/images-and-assets.md @@ -24,6 +24,8 @@ Afterward, you can use any asset in your stories: 'svelte/component-story-static-asset-with-import.js.mdx', 'web-components/component-story-static-asset-with-import.js.mdx', 'web-components/component-story-static-asset-with-import.ts.mdx', + 'solid/component-story-static-asset-with-import.js.mdx', + 'solid/component-story-static-asset-with-import.ts.mdx', ]} usesCsf3 csf2Path="configure/images-and-assets#snippet-component-story-static-asset-with-import" @@ -62,6 +64,8 @@ Here `../public` is your static directory. Now use it in a component or story li 'svelte/component-story-static-asset-without-import.js.mdx', 'web-components/component-story-static-asset-without-import.js.mdx', 'web-components/component-story-static-asset-without-import.ts.mdx', + 'solid/component-story-static-asset-without-import.js.mdx', + 'solid/component-story-static-asset-without-import.ts.mdx', ]} usesCsf3 csf2Path="configure/images-and-assets#snippet-component-story-static-asset-without-import" @@ -115,6 +119,8 @@ Upload your files to an online CDN and reference them. In this example, we’re 'svelte/component-story-static-asset-cdn.js.mdx', 'web-components/component-story-static-asset-cdn.js.mdx', 'web-components/component-story-static-asset-cdn.ts.mdx', + 'solid/component-story-static-asset-cdn.js.mdx', + 'solid/component-story-static-asset-cdn.ts.mdx', ]} usesCsf3 csf2Path="configure/images-and-assets#snippet-component-story-static-asset-cdn" diff --git a/docs/configure/telemetry.md b/docs/configure/telemetry.md index 3ac997b7128d..d6c4265a04f8 100644 --- a/docs/configure/telemetry.md +++ b/docs/configure/telemetry.md @@ -8,7 +8,7 @@ Storybook collects completely anonymous data to help us improve user experience. Hundreds of thousands of developers use Storybook daily to build, test, and document components. Storybook is framework agnostic and integrates with the front-end ecosystem: -- **JavaScript frameworks** such as [React](https://reactjs.org/), [Vue](https://vuejs.org/), and [Svelte](https://svelte.dev/) +- **JavaScript frameworks** such as [React](https://reactjs.org/), [Vue](https://vuejs.org/), [Svelte](https://svelte.dev/) and [Solid](https://www.solidjs.com/) - **Libraries** such as [Styled-Components](https://styled-components.com/), [Tailwind](https://tailwindcss.com/), [Redux](https://redux.js.org/) - **Design tools** such as [Figma](https://figma.com/), [Sketch](https://www.sketch.com/), [Zeplin](https://zeplin.io/) and [InVision](https://www.invisionapp.com/) - **Workflow tools** such as [Notion](https://www.notion.so/product), [Confluence](https://www.atlassian.com/software/confluence), and [Jira](https://www.atlassian.com/software/jira) diff --git a/docs/snippets/solid/component-story-static-asset-cdn.js.mdx b/docs/snippets/solid/component-story-static-asset-cdn.js.mdx new file mode 100644 index 000000000000..2f8c7f3db332 --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-cdn.js.mdx @@ -0,0 +1,22 @@ +```js +// MyComponent.stories.js|jsx|ts|tsx + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const WithAnImage = { + render: () => ( + My CDN placeholder + ), +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-cdn.ts-4-9.mdx b/docs/snippets/solid/component-story-static-asset-cdn.ts-4-9.mdx new file mode 100644 index 000000000000..57bfb86222ea --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-cdn.ts-4-9.mdx @@ -0,0 +1,24 @@ +```tsx +// MyComponent.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const WithAnImage: Story = { + render: () => ( + My CDN placeholder + ), +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-cdn.ts.mdx b/docs/snippets/solid/component-story-static-asset-cdn.ts.mdx new file mode 100644 index 000000000000..336e99a0abcb --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-cdn.ts.mdx @@ -0,0 +1,24 @@ +```tsx +// MyComponent.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +export default meta; +type Story = StoryObj; + +export const WithAnImage: Story = { + render: () => ( + My CDN placeholder + ), +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-with-import.js.mdx b/docs/snippets/solid/component-story-static-asset-with-import.js.mdx new file mode 100644 index 000000000000..163bba9ed83b --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-with-import.js.mdx @@ -0,0 +1,27 @@ +```js +// MyComponent.stories.js|jsx|ts|tsx + +import imageFile from './static/image.png'; + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +const image = { + src: imageFile, + alt: 'my image', +}; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const WithAnImage = { + render: () => {image.alt}, +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-with-import.ts-4-9.mdx b/docs/snippets/solid/component-story-static-asset-with-import.ts-4-9.mdx new file mode 100644 index 000000000000..b98463450c01 --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-with-import.ts-4-9.mdx @@ -0,0 +1,34 @@ +```tsx +// MyComponent.stories.ts|tsx + +import imageFile from './static/image.png'; + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +const image = { + src: imageFile, + alt: 'my image', +}; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const WithAnImage: Story = { + render: () => {image.alt}, +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-with-import.ts.mdx b/docs/snippets/solid/component-story-static-asset-with-import.ts.mdx new file mode 100644 index 000000000000..77064765117a --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-with-import.ts.mdx @@ -0,0 +1,34 @@ +```tsx +// MyComponent.stories.ts|tsx + +import imageFile from './static/image.png'; + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +export default meta; +type Story = StoryObj; + +const image = { + src: imageFile, + alt: 'my image', +}; + +/* + *πŸ‘‡ Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/7.0/solid/api/csf + * to learn how to use render functions. + */ +export const WithAnImage: Story = { + render: () => {image.alt}, +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-without-import.js.mdx b/docs/snippets/solid/component-story-static-asset-without-import.js.mdx new file mode 100644 index 000000000000..aada809e54ea --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-without-import.js.mdx @@ -0,0 +1,16 @@ +```js +// MyComponent.stories.js|jsx|ts|tsx + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +// Assume image.png is located in the "public" directory. +export const WithAnImage = { + render: () => my image, +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-without-import.ts-4-9.mdx b/docs/snippets/solid/component-story-static-asset-without-import.ts-4-9.mdx new file mode 100644 index 000000000000..81fe5daf9982 --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-without-import.ts-4-9.mdx @@ -0,0 +1,23 @@ +```tsx +// MyComponent.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +// Assume image.png is located in the "public" directory. +export const WithAnImage: Story = { + render: () => my image, +}; +``` diff --git a/docs/snippets/solid/component-story-static-asset-without-import.ts.mdx b/docs/snippets/solid/component-story-static-asset-without-import.ts.mdx new file mode 100644 index 000000000000..c51e1ea80737 --- /dev/null +++ b/docs/snippets/solid/component-story-static-asset-without-import.ts.mdx @@ -0,0 +1,23 @@ +```tsx +// MyComponent.stories.ts|tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'img', +}; + +export default meta; +type Story = StoryObj; + +// Assume image.png is located in the "public" directory. +export const WithAnImage: Story = { + render: () => my image, +}; +``` diff --git a/docs/snippets/solid/my-component-with-env-variables.js.mdx b/docs/snippets/solid/my-component-with-env-variables.js.mdx new file mode 100644 index 000000000000..00fdd19ee49c --- /dev/null +++ b/docs/snippets/solid/my-component-with-env-variables.js.mdx @@ -0,0 +1,20 @@ +```js +// MyComponent.stories.js|jsx + +import { MyComponent } from './MyComponent'; + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'MyComponent', + component: MyComponent, +}; + +export const ExampleStory = { + args: { + propertyA: process.env.STORYBOOK_DATA_KEY, + }, +}; +``` diff --git a/docs/snippets/solid/my-component-with-env-variables.ts-4-9.mdx b/docs/snippets/solid/my-component-with-env-variables.ts-4-9.mdx new file mode 100644 index 000000000000..0e780ce37568 --- /dev/null +++ b/docs/snippets/solid/my-component-with-env-variables.ts-4-9.mdx @@ -0,0 +1,26 @@ +```tsx +// MyComponent.stories.ts| tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'MyComponent', + + component: MyComponent, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const ExampleStory: Story = { + args: { + propertyA: process.env.STORYBOOK_DATA_KEY, + }, +}; +``` diff --git a/docs/snippets/solid/my-component-with-env-variables.ts.mdx b/docs/snippets/solid/my-component-with-env-variables.ts.mdx new file mode 100644 index 000000000000..aac9f319c808 --- /dev/null +++ b/docs/snippets/solid/my-component-with-env-variables.ts.mdx @@ -0,0 +1,25 @@ +```tsx +// MyComponent.stories.ts| tsx + +import type { Meta, StoryObj } from 'storybook-solidjs'; + +import { MyComponent } from './MyComponent'; + +const meta: Meta = { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'MyComponent', + component: MyComponent, +}; + +export default meta; +type Story = StoryObj; + +export const ExampleStory: Story = { + args: { + propertyA: process.env.STORYBOOK_DATA_KEY, + }, +}; +``` From d7ccdb4ad7c4387ede8ffa4e8a9ef5733d845764 Mon Sep 17 00:00:00 2001 From: Mauricio Rivera Date: Wed, 22 Feb 2023 10:59:39 -0500 Subject: [PATCH 17/36] Added api and contribute snippets. --- docs/api/csf.md | 21 +++++++++ docs/contribute/new-snippets.md | 10 +++-- .../button-story-click-handler-args.js.mdx | 26 +++++++++++ ...button-story-click-handler-args.ts-4-9.mdx | 30 +++++++++++++ .../button-story-click-handler-args.ts.mdx | 29 +++++++++++++ ...n-story-click-handler-simplificated.js.mdx | 18 ++++++++ ...ory-click-handler-simplificated.ts-4-9.mdx | 24 +++++++++++ ...n-story-click-handler-simplificated.ts.mdx | 23 ++++++++++ .../solid/button-story-click-handler.js.mdx | 20 +++++++++ .../button-story-click-handler.ts-4-9.mdx | 26 +++++++++++ .../solid/button-story-click-handler.ts.mdx | 25 +++++++++++ .../solid/button-story-with-sample.js.mdx | 23 ++++++++++ ...t-story-with-custom-render-function.js.mdx | 32 ++++++++++++++ ...ory-with-custom-render-function.ts-4-9.mdx | 36 ++++++++++++++++ ...t-story-with-custom-render-function.ts.mdx | 35 +++++++++++++++ .../solid/csf-2-example-starter.js.mdx | 13 ++++++ .../solid/csf-2-example-starter.ts.mdx | 15 +++++++ .../snippets/solid/csf-2-example-story.js.mdx | 6 +++ .../snippets/solid/csf-2-example-story.ts.mdx | 6 +++ .../solid/csf-3-example-render.js.mdx | 8 ++++ .../solid/csf-3-example-render.ts.mdx | 8 ++++ .../solid/csf-3-example-starter.ts-4-9.mdx | 16 +++++++ .../solid/csf-3-example-starter.ts.mdx | 14 ++++++ .../my-component-story-basic-and-props.js.mdx | 20 +++++++++ ...component-story-basic-and-props.ts-4-9.mdx | 26 +++++++++++ .../my-component-story-basic-and-props.ts.mdx | 25 +++++++++++ .../my-component-story-with-nonstory.js.mdx | 33 ++++++++++++++ ...y-component-story-with-nonstory.ts-4-9.mdx | 43 +++++++++++++++++++ .../my-component-story-with-nonstory.ts.mdx | 38 ++++++++++++++++ 29 files changed, 646 insertions(+), 3 deletions(-) create mode 100644 docs/snippets/solid/button-story-click-handler-args.js.mdx create mode 100644 docs/snippets/solid/button-story-click-handler-args.ts-4-9.mdx create mode 100644 docs/snippets/solid/button-story-click-handler-args.ts.mdx create mode 100644 docs/snippets/solid/button-story-click-handler-simplificated.js.mdx create mode 100644 docs/snippets/solid/button-story-click-handler-simplificated.ts-4-9.mdx create mode 100644 docs/snippets/solid/button-story-click-handler-simplificated.ts.mdx create mode 100644 docs/snippets/solid/button-story-click-handler.js.mdx create mode 100644 docs/snippets/solid/button-story-click-handler.ts-4-9.mdx create mode 100644 docs/snippets/solid/button-story-click-handler.ts.mdx create mode 100644 docs/snippets/solid/button-story-with-sample.js.mdx create mode 100644 docs/snippets/solid/component-story-with-custom-render-function.js.mdx create mode 100644 docs/snippets/solid/component-story-with-custom-render-function.ts-4-9.mdx create mode 100644 docs/snippets/solid/component-story-with-custom-render-function.ts.mdx create mode 100644 docs/snippets/solid/csf-2-example-starter.js.mdx create mode 100644 docs/snippets/solid/csf-2-example-starter.ts.mdx create mode 100644 docs/snippets/solid/csf-2-example-story.js.mdx create mode 100644 docs/snippets/solid/csf-2-example-story.ts.mdx create mode 100644 docs/snippets/solid/csf-3-example-render.js.mdx create mode 100644 docs/snippets/solid/csf-3-example-render.ts.mdx create mode 100644 docs/snippets/solid/csf-3-example-starter.ts-4-9.mdx create mode 100644 docs/snippets/solid/csf-3-example-starter.ts.mdx create mode 100644 docs/snippets/solid/my-component-story-basic-and-props.js.mdx create mode 100644 docs/snippets/solid/my-component-story-basic-and-props.ts-4-9.mdx create mode 100644 docs/snippets/solid/my-component-story-basic-and-props.ts.mdx create mode 100644 docs/snippets/solid/my-component-story-with-nonstory.js.mdx create mode 100644 docs/snippets/solid/my-component-story-with-nonstory.ts-4-9.mdx create mode 100644 docs/snippets/solid/my-component-story-with-nonstory.ts.mdx diff --git a/docs/api/csf.md b/docs/api/csf.md index c935f45e389a..02604e69a175 100644 --- a/docs/api/csf.md +++ b/docs/api/csf.md @@ -51,6 +51,8 @@ With CSF, every named export in the file represents a story object by default. 'angular/my-component-story-basic-and-props.ts.mdx', 'web-components/my-component-story-basic-and-props.js.mdx', 'web-components/my-component-story-basic-and-props.ts.mdx', + 'solid/my-component-story-basic-and-props.js.mdx', + 'solid/my-component-story-basic-and-props.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-my-component-story-basic-and-props" @@ -107,6 +109,8 @@ Consider Storybook’s ["Button" example](../writing-stories/introduction.md#def 'angular/button-story-click-handler.ts.mdx', 'web-components/button-story-click-handler.js.mdx', 'web-components/button-story-click-handler.ts.mdx', + 'solid/button-story-click-handler.js.mdx', + 'solid/button-story-click-handler.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-button-story-click-handler" @@ -130,6 +134,8 @@ Now consider the same example, re-written with args: 'svelte/button-story-click-handler-args.js.mdx', 'web-components/button-story-click-handler-args.js.mdx', 'web-components/button-story-click-handler-args.ts.mdx', + 'solid/button-story-click-handler-args.js.mdx', + 'solid/button-story-click-handler-args.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-button-story-click-handler-args" @@ -150,6 +156,8 @@ Or even more simply: 'vue/button-story-click-handler-simplificated.ts.mdx', 'web-components/button-story-click-handler-simplificated.js.mdx', 'web-components/button-story-click-handler-simplificated.ts.mdx', + 'solid/button-story-click-handler-simplificated.js.mdx', + 'solid/button-story-click-handler-simplificated.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-button-story-click-handler-simplificated" @@ -181,6 +189,8 @@ A good use case for the `play` function is a form component. With previous Story 'web-components/login-form-with-play-function.js.mdx', 'web-components/login-form-with-play-function.ts.mdx', 'svelte/login-form-with-play-function.js.mdx', + 'solid/login-form-with-play-function.js.mdx', + 'solid/login-form-with-play-function.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-login-form-with-play-function" @@ -206,6 +216,8 @@ Starting in Storybook 6.4, you can write your stories as JavaScript objects, red 'preact/component-story-with-custom-render-function.js.mdx', 'web-components/component-story-with-custom-render-function.js.mdx', 'web-components/component-story-with-custom-render-function.ts.mdx', + 'solid/component-story-with-custom-render-function.js.mdx', + 'solid/component-story-with-custom-render-function.ts.mdx', ]} usesCsf3 /> @@ -261,6 +273,8 @@ Consider the following story file: 'angular/my-component-story-with-nonstory.ts.mdx', 'web-components/my-component-story-with-nonstory.js.mdx', 'web-components/my-component-story-with-nonstory.ts.mdx', + 'solid/my-component-story-with-nonstory.js.mdx', + 'solid/my-component-story-with-nonstory.ts.mdx', ]} usesCsf3 csf2Path="api/csf#snippet-my-component-story-with-nonstory" @@ -298,6 +312,8 @@ In CSF 2, the named exports are always functions that instantiate a component, a 'angular/csf-2-example-starter.ts.mdx', 'web-components/csf-2-example-starter.js.mdx', 'web-components/csf-2-example-starter.ts.mdx', + 'solid/csf-2-example-starter.js.mdx', + 'solid/csf-2-example-starter.ts.mdx', ]} /> @@ -318,6 +334,7 @@ Here's the CSF 3 equivalent: 'angular/csf-3-example-starter.ts.mdx', 'web-components/csf-3-example-starter.js.mdx', 'web-components/csf-3-example-starter.ts.mdx', + 'solid/csf-3-example-starter.ts.mdx', ]} /> @@ -378,6 +395,8 @@ Let's start with a simple CSF 2 story function: 'angular/csf-2-example-story.ts.mdx', 'web-components/csf-2-example-story.js.mdx', 'web-components/csf-2-example-story.ts.mdx', + 'solid/csf-2-example-story.js.mdx', + 'solid/csf-2-example-story.ts.mdx', ]} /> @@ -398,6 +417,8 @@ Now, let's rewrite it as a story object in CSF 3 with an explicit `render` funct 'angular/csf-3-example-render.ts.mdx', 'web-components/csf-3-example-render.js.mdx', 'web-components/csf-3-example-render.ts.mdx', + 'solid/csf-3-example-render.js.mdx', + 'solid/csf-3-example-render.ts.mdx', ]} /> diff --git a/docs/contribute/new-snippets.md b/docs/contribute/new-snippets.md index 9b70c7e4250d..8a36a0d67702 100644 --- a/docs/contribute/new-snippets.md +++ b/docs/contribute/new-snippets.md @@ -10,9 +10,9 @@ Storybook maintains code snippets for a [variety of frameworks](./../api/framewo We welcome community contributions to the code snippets. Here's a matrix of the frameworks we have snippets for. Help us add snippets for your favorite framework. -| React | Vue | Angular | Web Components | Svelte | Ember | HTML | Preact | -| ---------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----- | ---- | ------ | -| [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/react) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/vue) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/angular) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/web-components) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/svelte) | ❌ | ❌ | ❌ | +| React | Vue | Angular | Web Components | Svelte | Solid | Ember | HTML | Preact | +| ---------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ----- | ---- | ------ | +| [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/react) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/vue) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/angular) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/web-components) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/svelte) | [βœ…](https://github.com/storybookjs/storybook/tree/next/docs/snippets/solid) | ❌ | ❌ | ❌ | ## Setup @@ -44,6 +44,8 @@ Browse the documentation and look for the code snippets you're willing to contri 'vue/your-component.3.js.mdx', 'svelte/your-component.js.mdx', 'web-components/your-component.js.mdx', + 'solid/your-component.js.mdx', + 'solid/your-component.ts.mdx', ]} /> @@ -66,6 +68,8 @@ Create the file `ember/your-component.js.mdx`, similar to the other frameworks, 'vue/your-component.3.js.mdx', 'svelte/your-component.js.mdx', 'web-components/your-component.js.mdx', + 'solid/your-component.js.mdx', + 'solid/your-component.ts.mdx', 'ember/your-component.js.mdx', //πŸ‘ˆπŸΌ The code snippet you created. ]} /> diff --git a/docs/snippets/solid/button-story-click-handler-args.js.mdx b/docs/snippets/solid/button-story-click-handler-args.js.mdx new file mode 100644 index 000000000000..68a3262dce72 --- /dev/null +++ b/docs/snippets/solid/button-story-click-handler-args.js.mdx @@ -0,0 +1,26 @@ +```js +// Button.stories.js|jsx + +import solid from 'solid'; + +import { action } from '@storybook/addon-actions'; + +import { Button } from './Button'; + +export default { + /* πŸ‘‡ The title prop is optional. + * See https://storybook.js.org/docs/7.0/solid/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +}; + +export const Text = { + args: { + label: 'Hello', + onClick: action('clicked'), + }, + render: ({ label, onClick }) =>