@storybook/addon-highlight 7.3.2 → 7.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -30
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -4,61 +4,143 @@ Storybook addon allows for highlighting specific DOM nodes within your story.
|
|
|
4
4
|
|
|
5
5
|
Use it to call attention to particular parts of the story. Or use it to enhance other addons that you might be building. For example, [Accessibility](https://storybook.js.org/addons/@storybook/addon-a11y/) addon uses it to highlight DOM nodes that are failing accessibility checks.
|
|
6
6
|
|
|
7
|
-

|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
-
This addon requires Storybook 6.5 or later. Highlight is part of [essentials](https://storybook.js.org/docs/react/essentials/introduction) and so is installed in all new Storybooks by default. If you need to add it to your Storybook, you can run:
|
|
11
|
+
This addon requires Storybook 6.5 or later. Highlight is part of [essentials](https://storybook.js.org/docs/react/essentials/introduction) and so is installed in all new Storybooks by default. If you need to add it to your Storybook, you can run the following command:
|
|
12
|
+
|
|
13
|
+
yarn:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add --dev @storybook/addon-highlight
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
npm:
|
|
12
20
|
|
|
13
21
|
```sh
|
|
14
|
-
npm
|
|
22
|
+
npm install @storybook/addon-highlight --save-dev
|
|
15
23
|
```
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
pnpm:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pnpm add --save-dev @storybook/addon-highlight
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Add `"@storybook/addon-highlight"` to the addons array in your `.storybook/main.js|ts`:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// .storybook/main.ts
|
|
18
35
|
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
|
|
37
|
+
import type { StorybookConfig } from '@storybook/your-framework';
|
|
38
|
+
|
|
39
|
+
const config: StorybookConfig = {
|
|
21
40
|
addons: ['@storybook/addon-highlight'],
|
|
22
41
|
};
|
|
42
|
+
|
|
43
|
+
export default config;
|
|
23
44
|
```
|
|
24
45
|
|
|
25
|
-
###
|
|
46
|
+
### Highlighting DOM Elements
|
|
26
47
|
|
|
27
|
-
Highlight DOM nodes by emitting the `HIGHLIGHT` event from within a story or an addon. The event payload must contain
|
|
48
|
+
Highlight DOM nodes by emitting the `HIGHLIGHT` event from within a story or an addon. The event payload must contain an `elements` property assigned to an array of selectors matching the elements you want to highlight.
|
|
28
49
|
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
import { useChannel } from '@storybook/preview-api';
|
|
32
|
-
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
33
|
-
import { MyComponent } from './MyComponent';
|
|
50
|
+
```ts
|
|
51
|
+
// MyComponent.stories.ts
|
|
34
52
|
|
|
35
|
-
|
|
53
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
54
|
+
import { useChannel } from '@storybook/preview-api';
|
|
55
|
+
import { HIGHLIGHT } from '@storybook/addon-highlight';
|
|
36
56
|
|
|
37
|
-
|
|
38
|
-
const emit = useChannel({});
|
|
57
|
+
import { MyComponent } from './MyComponent';
|
|
39
58
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
}, []);
|
|
59
|
+
const meta: Meta<typeof MyComponent> = {
|
|
60
|
+
component: MyComponent,
|
|
61
|
+
};
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
export default meta;
|
|
64
|
+
type Story = StoryObj<typeof MyComponent>;
|
|
65
|
+
|
|
66
|
+
export const Highlighted: Story = {
|
|
67
|
+
decorators: [
|
|
68
|
+
(storyFn) => {
|
|
69
|
+
const emit = useChannel({});
|
|
70
|
+
emit(HIGHLIGHT, {
|
|
71
|
+
elements: ['.title', '.subtitle'],
|
|
72
|
+
});
|
|
73
|
+
return storyFn();
|
|
74
|
+
},
|
|
75
|
+
],
|
|
47
76
|
};
|
|
48
77
|
```
|
|
49
78
|
|
|
79
|
+
### Reset highlighted elements
|
|
80
|
+
|
|
50
81
|
Highlights are automatically cleared when the story changes. You can also manually clear them by emitting the `RESET_HIGHLIGHT` event.
|
|
51
82
|
|
|
52
|
-
```
|
|
53
|
-
|
|
83
|
+
```ts
|
|
84
|
+
// MyComponent.stories.ts|tsx
|
|
85
|
+
|
|
86
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
87
|
+
import { useChannel } from '@storybook/preview-api';
|
|
88
|
+
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
89
|
+
|
|
90
|
+
import { MyComponent } from './MyComponent';
|
|
91
|
+
|
|
92
|
+
const meta: Meta<typeof MyComponent> = {
|
|
93
|
+
component: MyComponent,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default meta;
|
|
97
|
+
type Story = StoryObj<typeof MyComponent>;
|
|
98
|
+
|
|
99
|
+
export const ResetHighlight: Story = {
|
|
100
|
+
decorators: [
|
|
101
|
+
(storyFn) => {
|
|
102
|
+
const emit = useChannel({});
|
|
103
|
+
emit(RESET_HIGHLIGHT); //👈 Remove previously highlighted elements
|
|
104
|
+
emit(HIGHLIGHT, {
|
|
105
|
+
elements: ['header', 'section', 'footer'],
|
|
106
|
+
});
|
|
107
|
+
return storyFn();
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
54
111
|
```
|
|
55
112
|
|
|
56
113
|
### Customize style
|
|
57
114
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
115
|
+
The addon applies a standard style to the highlighted elements you've enabled for the story. However, you can enable your custom style by extending the payload object and providing a `color` and/or `style` properties. For example:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// MyComponent.stories.ts
|
|
119
|
+
|
|
120
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
121
|
+
import { useChannel } from '@storybook/preview-api';
|
|
122
|
+
import { HIGHLIGHT } from '@storybook/addon-highlight';
|
|
123
|
+
|
|
124
|
+
import { MyComponent } from './MyComponent';
|
|
125
|
+
|
|
126
|
+
const meta: Meta<typeof MyComponent> = {
|
|
127
|
+
component: MyComponent,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default meta;
|
|
131
|
+
type Story = StoryObj<typeof MyComponent>;
|
|
132
|
+
|
|
133
|
+
export const StyledHighlight: Story = {
|
|
134
|
+
decorators: [
|
|
135
|
+
(storyFn) => {
|
|
136
|
+
const emit = useChannel({});
|
|
137
|
+
emit(HIGHLIGHT, {
|
|
138
|
+
elements: ['.title', '.subtitle'],
|
|
139
|
+
color: 'red',
|
|
140
|
+
style: 'solid', // 'dotted' | 'dashed' | 'solid' | 'double'
|
|
141
|
+
});
|
|
142
|
+
return storyFn();
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
};
|
|
64
146
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-highlight",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0-alpha.1",
|
|
4
4
|
"description": "Highlight DOM nodes within your stories",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook-addons",
|
|
@@ -54,16 +54,17 @@
|
|
|
54
54
|
"dist/**/*",
|
|
55
55
|
"README.md",
|
|
56
56
|
"*.js",
|
|
57
|
-
"*.d.ts"
|
|
57
|
+
"*.d.ts",
|
|
58
|
+
"!src/**/*"
|
|
58
59
|
],
|
|
59
60
|
"scripts": {
|
|
60
61
|
"check": "../../../scripts/prepare/check.ts",
|
|
61
62
|
"prep": "../../../scripts/prepare/bundle.ts"
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
|
-
"@storybook/core-events": "7.
|
|
65
|
+
"@storybook/core-events": "7.4.0-alpha.1",
|
|
65
66
|
"@storybook/global": "^5.0.0",
|
|
66
|
-
"@storybook/preview-api": "7.
|
|
67
|
+
"@storybook/preview-api": "7.4.0-alpha.1"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
70
|
"@types/webpack-env": "^1.16.0",
|