-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 #25800 from storybookjs/docs-sub-components
Docs: Re-document subcomponents
- Loading branch information
Showing
14 changed files
with
313 additions
and
5 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
39 changes: 39 additions & 0 deletions
39
docs/snippets/angular/list-story-with-subcomponents.ts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
```ts | ||
// List.stories.ts | ||
import type { Meta, StoryObj } from '@storybook/angular'; | ||
|
||
import { moduleMetadata } from '@storybook/angular'; | ||
|
||
import { CommonModule } from '@angular/common'; | ||
|
||
import { List } from './list.component'; | ||
import { ListItem } from './list-item.component'; | ||
|
||
const meta: Meta<List> = { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
decorators: [ | ||
moduleMetadata({ | ||
declarations: [List, ListItem], | ||
imports: [CommonModule], | ||
}), | ||
], | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<List>; | ||
|
||
export const Empty: Story = {}; | ||
|
||
export const OneItem: Story = { | ||
args: {}, | ||
render: (args) => ({ | ||
props: args, | ||
template: ` | ||
<app-list> | ||
<app-list-item></app-list-item> | ||
</app-list> | ||
`, | ||
}), | ||
}; | ||
``` |
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,22 @@ | ||
```jsx | ||
// List.stories.js|jsx | ||
import React from 'react'; | ||
|
||
import { List } from './List'; | ||
import { ListItem } from './ListItem'; | ||
|
||
export default { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
}; | ||
|
||
export const Empty = {}; | ||
|
||
export const OneItem = { | ||
render: (args) => ( | ||
<List {...args}> | ||
<ListItem /> | ||
</List> | ||
), | ||
}; | ||
``` |
26 changes: 26 additions & 0 deletions
26
docs/snippets/react/list-story-with-subcomponents.ts-4-9.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
```tsx | ||
// List.stories.ts|tsx | ||
import React from 'react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { List } from './List'; | ||
import { ListItem } from './ListItem'; | ||
|
||
const meta = { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
} satisfies Meta<typeof List>; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Empty: Story = {}; | ||
|
||
export const OneItem: Story = { | ||
render: (args) => ( | ||
<List {...args}> | ||
<ListItem /> | ||
</List> | ||
), | ||
}; | ||
``` |
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,26 @@ | ||
```tsx | ||
// List.stories.ts|tsx | ||
import React from 'react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { List } from './List'; | ||
import { ListItem } from './ListItem'; | ||
|
||
const meta: Meta<typeof List> = { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof List>; | ||
|
||
export const Empty: Story = {}; | ||
|
||
export const OneItem: Story = { | ||
render: (args) => ( | ||
<List {...args}> | ||
<ListItem /> | ||
</List> | ||
), | ||
}; | ||
``` |
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,27 @@ | ||
```js | ||
// List.stories.js | ||
import List from './List.vue'; | ||
import ListItem from './ListItem.vue'; | ||
|
||
export default { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
}; | ||
|
||
export const Empty = { | ||
render: () => ({ | ||
components: { List }, | ||
template: '<List/>', | ||
}), | ||
}; | ||
|
||
export const OneItem = { | ||
render: (args) => ({ | ||
components: { List, ListItem }, | ||
setup() { | ||
return { args } | ||
} | ||
template: '<List v-bind="args"><ListItem /></List>', | ||
}), | ||
}; | ||
``` |
32 changes: 32 additions & 0 deletions
32
docs/snippets/vue/list-story-with-sub-components.ts-4-9.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
```ts | ||
// List.stories.ts | ||
import type { Meta, StoryObj } from '@storybook/vue3'; | ||
|
||
import List from './List.vue'; | ||
import ListItem from './ListItem.vue'; | ||
|
||
const meta = { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
} satisfies Meta<typeof List>; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Empty: Story = { | ||
render: () => ({ | ||
components: { List }, | ||
template: '<List />', | ||
}), | ||
}; | ||
|
||
export const OneItem: Story = { | ||
render: (args) => ({ | ||
components: { List, ListItem }, | ||
setup() { | ||
return { args } | ||
} | ||
template: '<List v-bind="args"><ListItem /></List>', | ||
}), | ||
}; | ||
``` |
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,32 @@ | ||
```ts | ||
// List.stories.ts | ||
import type { Meta, StoryObj } from '@storybook/vue3'; | ||
|
||
import List from './List.vue'; | ||
import ListItem from './ListItem.vue'; | ||
|
||
const meta: Meta<typeof List> = { | ||
component: List, | ||
subcomponents: { ListItem }, //👈 Adds the ListItem component as a subcomponent | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof List>; | ||
|
||
export const Empty: Story = { | ||
render: () => ({ | ||
components: { List }, | ||
template: '<List />', | ||
}), | ||
}; | ||
|
||
export const OneItem: Story = { | ||
render: (args) => ({ | ||
components: { List, ListItem }, | ||
setup() { | ||
return { args } | ||
} | ||
template: '<List v-bind="args"><ListItem /></List>', | ||
}), | ||
}; | ||
``` |
20 changes: 20 additions & 0 deletions
20
docs/snippets/web-components/list-story-with-subcomponents.js.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
```js | ||
// List.stories.js | ||
import { html } from 'lit'; | ||
|
||
export default { | ||
title: 'List', | ||
component: 'demo-list', | ||
subcomponents: { ListItem: 'demo-list-item' }, // 👈 Adds the ListItem component as a subcomponent | ||
}; | ||
|
||
export const Empty = {}; | ||
|
||
export const OneItem = { | ||
render: () => html` | ||
<demo-list> | ||
<demo-list-item></demo-list-item> | ||
</demo-list> | ||
`, | ||
}; | ||
``` |
25 changes: 25 additions & 0 deletions
25
docs/snippets/web-components/list-story-with-subcomponents.ts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
```ts | ||
// List.stories.ts | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
|
||
import { html } from 'lit'; | ||
|
||
const meta: Meta = { | ||
title: 'List', | ||
component: 'demo-list', | ||
subcomponents: { ListItem: 'demo-list-item' }, // 👈 Adds the ListItem component as a subcomponent | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Empty: Story = {}; | ||
|
||
export const OneItem: Story = { | ||
render: () => html` | ||
<demo-list> | ||
<demo-list-item></demo-list-item> | ||
</demo-list> | ||
`, | ||
}; | ||
``` |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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