@storybook/addon-highlight 7.0.0-alpha.7
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/cjs/constants.js +14 -0
- package/dist/cjs/highlight.js +69 -0
- package/dist/cjs/index.js +28 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/highlight.js +50 -0
- package/dist/esm/index.js +8 -0
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/highlight.d.ts +8 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +59 -0
- package/preview.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Storybook Addon Highlight
|
|
2
|
+
|
|
3
|
+
Storybook addon allows for highlighting specific DOM nodes within your story.
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Usage
|
|
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:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i -D @storybook/addon-highlight
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Add `"@storybook/addon-highlight"` to the addons array in your `.storybook/main.js`:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
module.exports = {
|
|
21
|
+
addons: ['@storybook/addon-highlight'],
|
|
22
|
+
};
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Apply or clear highlights
|
|
26
|
+
|
|
27
|
+
Highlight DOM nodes by emitting the `HIGHLIGHT` event from within a story or an addon. The event payload must contain a list of selectors you want to highlight.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import React, { useEffect } from 'react';
|
|
31
|
+
import { useChannel } from '@storybook/addons';
|
|
32
|
+
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight';
|
|
33
|
+
import { MyComponent } form './MyComponent';
|
|
34
|
+
|
|
35
|
+
export default { component: MyComponent };
|
|
36
|
+
|
|
37
|
+
export const MyStory = () => {
|
|
38
|
+
const emit = useChannel({});
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
emit(HIGHLIGHT, {
|
|
42
|
+
elements: ['.title', '.subtitle'],
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
return <MyComponent />;
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Highlights are automatically cleared when the story changes. You can also manually clear them by emitting the `RESET_HIGHLIGHT` event.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
emit(RESET_HIGHLIGHT);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Customize style
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
emit(HIGHLIGHT, {
|
|
60
|
+
elements: ['.title', '.subtitle'],
|
|
61
|
+
color: 'red',
|
|
62
|
+
style: 'solid', // 'dotted' | 'dashed' | 'solid' | 'double'
|
|
63
|
+
});
|
|
64
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RESET_HIGHLIGHT = exports.HIGHLIGHT_STYLE_ID = exports.HIGHLIGHT = exports.ADDON_ID = void 0;
|
|
7
|
+
const ADDON_ID = 'storybook/highlight';
|
|
8
|
+
exports.ADDON_ID = ADDON_ID;
|
|
9
|
+
const HIGHLIGHT_STYLE_ID = 'storybookHighlight';
|
|
10
|
+
exports.HIGHLIGHT_STYLE_ID = HIGHLIGHT_STYLE_ID;
|
|
11
|
+
const HIGHLIGHT = `${ADDON_ID}/add`;
|
|
12
|
+
exports.HIGHLIGHT = HIGHLIGHT;
|
|
13
|
+
const RESET_HIGHLIGHT = `${ADDON_ID}/reset`;
|
|
14
|
+
exports.RESET_HIGHLIGHT = RESET_HIGHLIGHT;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.highlightStyle = exports.highlightObject = void 0;
|
|
7
|
+
|
|
8
|
+
var _global = _interopRequireDefault(require("global"));
|
|
9
|
+
|
|
10
|
+
var _addons = require("@storybook/addons");
|
|
11
|
+
|
|
12
|
+
var _coreEvents = require("@storybook/core-events");
|
|
13
|
+
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
/* eslint-env browser */
|
|
19
|
+
const {
|
|
20
|
+
document
|
|
21
|
+
} = _global.default;
|
|
22
|
+
|
|
23
|
+
const highlightStyle = (color = '#FF4785', style = 'dashed') => `
|
|
24
|
+
outline: 2px ${style} ${color};
|
|
25
|
+
outline-offset: 2px;
|
|
26
|
+
box-shadow: 0 0 0 6px rgba(255,255,255,0.6);
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports.highlightStyle = highlightStyle;
|
|
30
|
+
|
|
31
|
+
const highlightObject = color => ({
|
|
32
|
+
outline: `2px dashed ${color}`,
|
|
33
|
+
outlineOffset: 2,
|
|
34
|
+
boxShadow: '0 0 0 6px rgba(255,255,255,0.6)'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
exports.highlightObject = highlightObject;
|
|
38
|
+
|
|
39
|
+
if (module && module.hot && module.hot.decline) {
|
|
40
|
+
module.hot.decline();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const channel = _addons.addons.getChannel();
|
|
44
|
+
|
|
45
|
+
const highlight = infos => {
|
|
46
|
+
const id = _constants.HIGHLIGHT_STYLE_ID;
|
|
47
|
+
resetHighlight(); // Make sure there are no duplicated selectors
|
|
48
|
+
|
|
49
|
+
const elements = Array.from(new Set(infos.elements));
|
|
50
|
+
const sheet = document.createElement('style');
|
|
51
|
+
sheet.setAttribute('id', id);
|
|
52
|
+
sheet.innerHTML = elements.map(target => `${target}{
|
|
53
|
+
${highlightStyle(infos.color, infos.style)}
|
|
54
|
+
}`).join(' ');
|
|
55
|
+
document.head.appendChild(sheet);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const resetHighlight = () => {
|
|
59
|
+
const id = _constants.HIGHLIGHT_STYLE_ID;
|
|
60
|
+
const sheetToBeRemoved = document.getElementById(id);
|
|
61
|
+
|
|
62
|
+
if (sheetToBeRemoved) {
|
|
63
|
+
sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
channel.on(_coreEvents.STORY_CHANGED, resetHighlight);
|
|
68
|
+
channel.on(_constants.RESET_HIGHLIGHT, resetHighlight);
|
|
69
|
+
channel.on(_constants.HIGHLIGHT, highlight);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "HIGHLIGHT", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _constants.HIGHLIGHT;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "RESET_HIGHLIGHT", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _constants.RESET_HIGHLIGHT;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.default = void 0;
|
|
19
|
+
|
|
20
|
+
var _constants = require("./constants");
|
|
21
|
+
|
|
22
|
+
if (module && module.hot && module.hot.decline) {
|
|
23
|
+
module.hot.decline();
|
|
24
|
+
} // make it work with --isolatedModules
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var _default = {};
|
|
28
|
+
exports.default = _default;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
import global from 'global';
|
|
3
|
+
import { addons } from '@storybook/addons';
|
|
4
|
+
import { STORY_CHANGED } from '@storybook/core-events';
|
|
5
|
+
import { HIGHLIGHT, RESET_HIGHLIGHT, HIGHLIGHT_STYLE_ID } from './constants';
|
|
6
|
+
const {
|
|
7
|
+
document
|
|
8
|
+
} = global;
|
|
9
|
+
export const highlightStyle = (color = '#FF4785', style = 'dashed') => `
|
|
10
|
+
outline: 2px ${style} ${color};
|
|
11
|
+
outline-offset: 2px;
|
|
12
|
+
box-shadow: 0 0 0 6px rgba(255,255,255,0.6);
|
|
13
|
+
`;
|
|
14
|
+
export const highlightObject = color => ({
|
|
15
|
+
outline: `2px dashed ${color}`,
|
|
16
|
+
outlineOffset: 2,
|
|
17
|
+
boxShadow: '0 0 0 6px rgba(255,255,255,0.6)'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (module && module.hot && module.hot.decline) {
|
|
21
|
+
module.hot.decline();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const channel = addons.getChannel();
|
|
25
|
+
|
|
26
|
+
const highlight = infos => {
|
|
27
|
+
const id = HIGHLIGHT_STYLE_ID;
|
|
28
|
+
resetHighlight(); // Make sure there are no duplicated selectors
|
|
29
|
+
|
|
30
|
+
const elements = Array.from(new Set(infos.elements));
|
|
31
|
+
const sheet = document.createElement('style');
|
|
32
|
+
sheet.setAttribute('id', id);
|
|
33
|
+
sheet.innerHTML = elements.map(target => `${target}{
|
|
34
|
+
${highlightStyle(infos.color, infos.style)}
|
|
35
|
+
}`).join(' ');
|
|
36
|
+
document.head.appendChild(sheet);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const resetHighlight = () => {
|
|
40
|
+
const id = HIGHLIGHT_STYLE_ID;
|
|
41
|
+
const sheetToBeRemoved = document.getElementById(id);
|
|
42
|
+
|
|
43
|
+
if (sheetToBeRemoved) {
|
|
44
|
+
sheetToBeRemoved.parentNode.removeChild(sheetToBeRemoved);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
channel.on(STORY_CHANGED, resetHighlight);
|
|
49
|
+
channel.on(RESET_HIGHLIGHT, resetHighlight);
|
|
50
|
+
channel.on(HIGHLIGHT, highlight);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare type OutlineStyle = 'dotted' | 'dashed' | 'solid' | 'double';
|
|
2
|
+
export declare const highlightStyle: (color?: string, style?: OutlineStyle) => string;
|
|
3
|
+
export declare const highlightObject: (color: string) => {
|
|
4
|
+
outline: string;
|
|
5
|
+
outlineOffset: number;
|
|
6
|
+
boxShadow: string;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storybook/addon-highlight",
|
|
3
|
+
"version": "7.0.0-alpha.7",
|
|
4
|
+
"description": "Highlight DOM nodes within your stories",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"storybook-addons",
|
|
7
|
+
"essentials",
|
|
8
|
+
"style",
|
|
9
|
+
"appearance"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/main/addons/highlight",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/storybookjs/storybook/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/storybookjs/storybook.git",
|
|
18
|
+
"directory": "addons/highlight"
|
|
19
|
+
},
|
|
20
|
+
"funding": {
|
|
21
|
+
"type": "opencollective",
|
|
22
|
+
"url": "https://opencollective.com/storybook"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "winkerVSbecks",
|
|
26
|
+
"main": "dist/cjs/index.js",
|
|
27
|
+
"module": "dist/esm/index.js",
|
|
28
|
+
"types": "dist/types/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*",
|
|
31
|
+
"README.md",
|
|
32
|
+
"*.js",
|
|
33
|
+
"*.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prepare": "node ../../scripts/prepare.js"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@storybook/addons": "7.0.0-alpha.7",
|
|
40
|
+
"@storybook/core-events": "7.0.0-alpha.7",
|
|
41
|
+
"core-js": "^3.8.2",
|
|
42
|
+
"global": "^4.4.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/webpack-env": "^1.16.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074",
|
|
51
|
+
"sbmodern": "dist/modern/index.js",
|
|
52
|
+
"storybook": {
|
|
53
|
+
"displayName": "Highlight",
|
|
54
|
+
"unsupportedFrameworks": [
|
|
55
|
+
"react-native"
|
|
56
|
+
],
|
|
57
|
+
"icon": "https://user-images.githubusercontent.com/42671/162045505-9d06fe2e-8fcb-4c41-9486-e0553bce10cc.png"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/preview.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/esm/highlight';
|