storybook/docs/snippets/angular/badge-story-starter-example.mdx.mdx
2022-07-07 22:47:17 +01:00

78 lines
1.7 KiB
Plaintext

```md
<!-- Badge.stories.mdx -->
import { Canvas, Meta, Story } from '@storybook/addon-docs';
import { moduleMetadata } from '@storybook/angular';
import { CommonModule } from '@angular/common';
import { Badge } from './badge.component';
import { Icon } from './icon.component';
<Meta title="MDX/Badge" component={Badge} />
<!--
👇 Render functions are a framework specific feature to allow you control on how the component renders.
See https://storybook.js.org/docs/7.0/angular/api/csf
to learn how to use render functions.
-->
# Badge
Let's define a story for our `Badge` component:
<Story
name="positive"
render={() => ({
template:`<Badge status="positive">Positive</Badge>`,
})} />
We can drop it in a `Canvas` to get a code snippet:
<Canvas>
<Story
name="negative"
render={() => ({
template: `<Badge status="negative">Negative</Badge>`,
})} />
</Canvas>
We can even preview multiple stories in a block. This
gets rendered as a group, but defines individual stories
with unique URLs and isolated snapshot tests.
<Canvas>
<Story
name="warning"
render={() => ({
template: `<Badge status="warning">Warning</Badge>`,
})} />
<Story
name="neutral"
render={() => ({
template: `<Badge status="neutral">Neutral</Badge>`,
})} />
<Story
name="error"
render={() => ({
template: `<Badge status="error">Error</Badge>`,
})} />
<Story
name="with icon"
decorators={[
moduleMetadata({
declarations: [Badge, Icon],
imports: [CommonModule],
})
]}
render={() => ({
template: `
<Badge status="warning">
<Icon icon="check" inline></Icon>
with icon
</Badge>
`,
})} />
</Canvas>
```