mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 05:51:48 +08:00
243 lines
6.2 KiB
Markdown
243 lines
6.2 KiB
Markdown
```ts filename="MyComponent.stories.ts" renderer="angular" language="ts"
|
|
import type { Meta, StoryObj } from '@storybook/angular';
|
|
import { componentWrapperDecorator } from '@storybook/angular';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import { MyComponent } from './MyComponent.component';
|
|
|
|
const meta: Meta<MyComponent> = {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<MyComponent>;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
componentWrapperDecorator((story) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return story;
|
|
}),
|
|
],
|
|
};
|
|
```
|
|
|
|
```js filename="MyComponent.stories.js|jsx" renderer="react" language="js"
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
export default {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export const ResetHighlight = {
|
|
decorators: [
|
|
(storyFn) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return storyFn();
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```ts filename="MyComponent.stories.ts|tsx" renderer="react" language="ts-4-9"
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
const meta = {
|
|
component: MyComponent,
|
|
} satisfies Meta<typeof MyComponent>;
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
(storyFn) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return storyFn();
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```ts filename="MyComponent.stories.ts|tsx" renderer="react" language="ts"
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
const meta: Meta<typeof MyComponent> = {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof MyComponent>;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
(storyFn) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return storyFn();
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```js filename="MyComponent.stories.js" renderer="vue" language="js"
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import MyComponent from './MyComponent.vue';
|
|
|
|
export default {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export const ResetHighlight = {
|
|
decorators: [
|
|
() => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return {
|
|
template: '<story />',
|
|
};
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```ts filename="MyComponent.stories.ts" renderer="vue" language="ts-4-9"
|
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import MyComponent from './MyComponent.vue';
|
|
|
|
const meta = {
|
|
component: MyComponent,
|
|
} satisfies Meta<typeof MyComponent>;
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
() => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return {
|
|
template: '<story />',
|
|
};
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```ts filename="MyComponent.stories.ts" renderer="vue" language="ts"
|
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
import MyComponent from './MyComponent.vue';
|
|
|
|
const meta: Meta<typeof MyComponent> = {
|
|
component: MyComponent,
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof MyComponent>;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
() => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return {
|
|
template: '<story />',
|
|
};
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```js filename="MyComponent.stories.js" renderer="web-components" language="js"
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
export default {
|
|
component: 'my-component',
|
|
};
|
|
|
|
export const ResetHighlight = {
|
|
decorators: [
|
|
(story) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return story();
|
|
},
|
|
],
|
|
};
|
|
```
|
|
|
|
```ts filename="MyComponent.stories.ts" renderer="web-components" language="ts"
|
|
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
import { useChannel } from '@storybook/preview-api';
|
|
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
|
|
const meta: Meta = {
|
|
component: 'my-component',
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj;
|
|
|
|
export const ResetHighlight: Story = {
|
|
decorators: [
|
|
(story) => {
|
|
const emit = useChannel({});
|
|
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
emit(HIGHLIGHT, {
|
|
elements: ['header', 'section', 'footer'],
|
|
});
|
|
return story();
|
|
},
|
|
],
|
|
};
|
|
```
|