-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #17800 from storybookjs/addon-highlight
Essentials: Add highlight addon
- Loading branch information
Showing
59 changed files
with
859 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
export const ADDON_ID = 'storybook/a11y'; | ||
export const PANEL_ID = `${ADDON_ID}/panel`; | ||
export const PARAM_KEY = `a11y`; | ||
export const HIGHLIGHT_STYLE_ID = 'a11yHighlight'; | ||
const RESULT = `${ADDON_ID}/result`; | ||
const REQUEST = `${ADDON_ID}/request`; | ||
const RUNNING = `${ADDON_ID}/running`; | ||
const ERROR = `${ADDON_ID}/error`; | ||
const MANUAL = `${ADDON_ID}/manual`; | ||
const HIGHLIGHT = `${ADDON_ID}/highlight`; | ||
|
||
export const EVENTS = { RESULT, REQUEST, RUNNING, ERROR, MANUAL, HIGHLIGHT }; | ||
export const EVENTS = { RESULT, REQUEST, RUNNING, ERROR, MANUAL }; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
import './a11yRunner'; | ||
import './a11yHighlight'; |
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
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,64 @@ | ||
# Storybook Addon Highlight | ||
|
||
Storybook addon allows for highlighting specific DOM nodes within your story. | ||
|
||
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. | ||
|
||
![](https://user-images.githubusercontent.com/42671/160146801-179eaa79-fff8-4bff-b17c-9262fdc94918.png) | ||
|
||
## Usage | ||
|
||
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: | ||
|
||
```sh | ||
npm i -D @storybook/addon-highlight | ||
``` | ||
|
||
Add `"@storybook/addon-highlight"` to the addons array in your `.storybook/main.js`: | ||
|
||
```js | ||
module.exports = { | ||
addons: ['@storybook/addon-highlight'], | ||
}; | ||
``` | ||
|
||
### Apply or clear highlights | ||
|
||
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. | ||
|
||
```js | ||
import React, { useEffect } from 'react'; | ||
import { useChannel } from '@storybook/addons'; | ||
import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight'; | ||
import { MyComponent } form './MyComponent'; | ||
|
||
export default { component: MyComponent }; | ||
|
||
export const MyStory = () => { | ||
const emit = useChannel({}); | ||
|
||
useEffect(() => { | ||
emit(HIGHLIGHT, { | ||
elements: ['.title', '.subtitle'], | ||
}); | ||
}, []); | ||
|
||
return <MyComponent />; | ||
}; | ||
``` | ||
|
||
Highlights are automatically cleared when the story changes. You can also manually clear them by emitting the `RESET_HIGHLIGHT` event. | ||
|
||
```js | ||
emit(RESET_HIGHLIGHT); | ||
``` | ||
|
||
### Customize style | ||
|
||
```js | ||
emit(HIGHLIGHT, { | ||
elements: ['.title', '.subtitle'], | ||
color: 'red', | ||
style: 'solid', // 'dotted' | 'dashed' | 'solid' | 'double' | ||
}); | ||
``` |
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,59 @@ | ||
{ | ||
"name": "@storybook/addon-highlight", | ||
"version": "7.0.0-alpha.6", | ||
"description": "Highlight DOM nodes within your stories", | ||
"keywords": [ | ||
"storybook-addons", | ||
"essentials", | ||
"style", | ||
"appearance" | ||
], | ||
"homepage": "https://github.com/storybookjs/storybook/tree/main/addons/highlight", | ||
"bugs": { | ||
"url": "https://github.com/storybookjs/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybookjs/storybook.git", | ||
"directory": "addons/highlight" | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/storybook" | ||
}, | ||
"license": "MIT", | ||
"author": "winkerVSbecks", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"files": [ | ||
"dist/**/*", | ||
"README.md", | ||
"*.js", | ||
"*.d.ts" | ||
], | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@storybook/addons": "7.0.0-alpha.6", | ||
"@storybook/core-events": "7.0.0-alpha.6", | ||
"core-js": "^3.8.2", | ||
"global": "^4.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/webpack-env": "^1.16.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "6cf4571e5a1200613de94aa066fe93f75aec6ad1", | ||
"sbmodern": "dist/modern/index.js", | ||
"storybook": { | ||
"displayName": "Highlight", | ||
"unsupportedFrameworks": [ | ||
"react-native" | ||
], | ||
"icon": "https://user-images.githubusercontent.com/42671/162045505-9d06fe2e-8fcb-4c41-9486-e0553bce10cc.png" | ||
} | ||
} |
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 @@ | ||
export * from './dist/esm/highlight'; |
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,5 @@ | ||
export const ADDON_ID = 'storybook/highlight'; | ||
export const HIGHLIGHT_STYLE_ID = 'storybookHighlight'; | ||
|
||
export const HIGHLIGHT = `${ADDON_ID}/add`; | ||
export const RESET_HIGHLIGHT = `${ADDON_ID}/reset`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export { HIGHLIGHT, RESET_HIGHLIGHT } from './constants'; | ||
|
||
if (module && module.hot && module.hot.decline) { | ||
module.hot.decline(); | ||
} | ||
|
||
// make it work with --isolatedModules | ||
export default {}; |
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 @@ | ||
declare module 'global'; |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": [ | ||
"webpack-env" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"src/**/*.test.*", | ||
"src/**/tests/**/*", | ||
"src/**/__tests__/**/*", | ||
"src/**/*.stories.*", | ||
"src/**/*.mockdata.*", | ||
"src/**/__testfixtures__/**" | ||
] | ||
} |
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,50 @@ | ||
--- | ||
title: 'Highlight' | ||
--- | ||
|
||
Storybook's [Highlight](https://storybook.js.org/addons/@storybook/addon-highlight/) addon allows you to highlight specific DOM nodes within your story. You can use it to call attention to particular parts of the story. | ||
|
||
![](highlight.png) | ||
|
||
This addon can be used to enhance other addons. For example, [Accessibility](https://storybook.js.org/addons/@storybook/addon-a11y/) addon uses it to highlight DOM nodes that are failing accessibility checks. | ||
|
||
## Apply or clear highlights | ||
|
||
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. | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'react/component-story-highlight-addon.js.mdx', | ||
'angular/component-story-highlight-addon.ts.mdx', | ||
'vue/component-story-highlight-addon.js.mdx', | ||
'web-components/component-story-highlight-addon.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
Highlights are automatically cleared when the story changes. You can also manually clear them by emitting the `RESET_HIGHLIGHT` event. | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/addon-highlight-reset.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> | ||
|
||
## Customize style | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
<CodeSnippets | ||
paths={[ | ||
'common/addon-highlight-customize.js.mdx', | ||
]} | ||
/> | ||
|
||
<!-- prettier-ignore-end --> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.