@storybook/addon-a11y 6.5.0-beta.2 → 6.5.0-beta.5

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.
@@ -53,17 +53,11 @@ var channel = _addons.addons.getChannel(); // Holds axe core running state
53
53
  var active = false; // Holds latest story we requested a run
54
54
 
55
55
  var activeStoryId;
56
-
57
- var getElement = function getElement() {
58
- var storyRoot = document.getElementById('story-root');
59
- return storyRoot ? storyRoot.childNodes : document.getElementById('root');
60
- };
61
56
  /**
62
57
  * Handle A11yContext events.
63
58
  * Because the event are sent without manual check, we split calls
64
59
  */
65
60
 
66
-
67
61
  var handleRequest = /*#__PURE__*/function () {
68
62
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(storyId) {
69
63
  var _yield$getParams, manual;
@@ -102,7 +96,7 @@ var handleRequest = /*#__PURE__*/function () {
102
96
 
103
97
  var run = /*#__PURE__*/function () {
104
98
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(storyId) {
105
- var input, axe, _input$element, element, config, _input$options, options, result;
99
+ var input, axe, _input$element, element, config, _input$options, options, htmlElement, result;
106
100
 
107
101
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
108
102
  while (1) {
@@ -117,7 +111,7 @@ var run = /*#__PURE__*/function () {
117
111
  input = _context2.sent;
118
112
 
119
113
  if (active) {
120
- _context2.next = 18;
114
+ _context2.next = 19;
121
115
  break;
122
116
  }
123
117
 
@@ -130,17 +124,18 @@ var run = /*#__PURE__*/function () {
130
124
 
131
125
  case 10:
132
126
  axe = _context2.sent.default;
133
- _input$element = input.element, element = _input$element === void 0 ? getElement() : _input$element, config = input.config, _input$options = input.options, options = _input$options === void 0 ? {} : _input$options;
127
+ _input$element = input.element, element = _input$element === void 0 ? '#root' : _input$element, config = input.config, _input$options = input.options, options = _input$options === void 0 ? {} : _input$options;
128
+ htmlElement = document.querySelector(element);
134
129
  axe.reset();
135
130
 
136
131
  if (config) {
137
132
  axe.configure(config);
138
133
  }
139
134
 
140
- _context2.next = 16;
141
- return axe.run(element, options);
135
+ _context2.next = 17;
136
+ return axe.run(htmlElement, options);
142
137
 
143
- case 16:
138
+ case 17:
144
139
  result = _context2.sent;
145
140
 
146
141
  // It's possible that we requested a new run on a different story.
@@ -154,26 +149,26 @@ var run = /*#__PURE__*/function () {
154
149
  run(activeStoryId);
155
150
  }
156
151
 
157
- case 18:
158
- _context2.next = 23;
152
+ case 19:
153
+ _context2.next = 24;
159
154
  break;
160
155
 
161
- case 20:
162
- _context2.prev = 20;
156
+ case 21:
157
+ _context2.prev = 21;
163
158
  _context2.t0 = _context2["catch"](1);
164
159
  channel.emit(_constants.EVENTS.ERROR, _context2.t0);
165
160
 
166
- case 23:
167
- _context2.prev = 23;
161
+ case 24:
162
+ _context2.prev = 24;
168
163
  active = false;
169
- return _context2.finish(23);
164
+ return _context2.finish(24);
170
165
 
171
- case 26:
166
+ case 27:
172
167
  case "end":
173
168
  return _context2.stop();
174
169
  }
175
170
  }
176
- }, _callee2, null, [[1, 20, 23, 26]]);
171
+ }, _callee2, null, [[1, 21, 24, 27]]);
177
172
  }));
178
173
 
179
174
  return function run(_x2) {
@@ -119,20 +119,20 @@ var A11yContextProvider = function A11yContextProvider(_ref) {
119
119
  var active = _ref.active,
120
120
  props = _objectWithoutProperties(_ref, _excluded);
121
121
 
122
- var _React$useState = React.useState(defaultResult),
122
+ var _useAddonState = (0, _api.useAddonState)(_constants.ADDON_ID, defaultResult),
123
+ _useAddonState2 = _slicedToArray(_useAddonState, 2),
124
+ results = _useAddonState2[0],
125
+ setResults = _useAddonState2[1];
126
+
127
+ var _React$useState = React.useState(0),
123
128
  _React$useState2 = _slicedToArray(_React$useState, 2),
124
- results = _React$useState2[0],
125
- setResults = _React$useState2[1];
129
+ tab = _React$useState2[0],
130
+ setTab = _React$useState2[1];
126
131
 
127
- var _React$useState3 = React.useState(0),
132
+ var _React$useState3 = React.useState([]),
128
133
  _React$useState4 = _slicedToArray(_React$useState3, 2),
129
- tab = _React$useState4[0],
130
- setTab = _React$useState4[1];
131
-
132
- var _React$useState5 = React.useState([]),
133
- _React$useState6 = _slicedToArray(_React$useState5, 2),
134
- highlighted = _React$useState6[0],
135
- setHighlighted = _React$useState6[1];
134
+ highlighted = _React$useState4[0],
135
+ setHighlighted = _React$useState4[1];
136
136
 
137
137
  var _useStorybookState = (0, _api.useStorybookState)(),
138
138
  storyId = _useStorybookState.storyId;
@@ -14,7 +14,7 @@ var _A11yContext = require("./components/A11yContext");
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
- _addons.addons.register(_constants.ADDON_ID, function () {
17
+ _addons.addons.register(_constants.ADDON_ID, function (api) {
18
18
  _addons.addons.add(_constants.PANEL_ID, {
19
19
  title: '',
20
20
  type: _addons.types.TOOL,
@@ -28,7 +28,15 @@ _addons.addons.register(_constants.ADDON_ID, function () {
28
28
  });
29
29
 
30
30
  _addons.addons.add(_constants.PANEL_ID, {
31
- title: 'Accessibility',
31
+ title: function title() {
32
+ var _addonState$violation, _addonState$incomplet;
33
+
34
+ var addonState = api === null || api === void 0 ? void 0 : api.getAddonState(_constants.ADDON_ID);
35
+ var violationsNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$violation = addonState.violations) === null || _addonState$violation === void 0 ? void 0 : _addonState$violation.length) || 0;
36
+ var incompleteNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$incomplet = addonState.incomplete) === null || _addonState$incomplet === void 0 ? void 0 : _addonState$incomplet.length) || 0;
37
+ var totalNb = violationsNb + incompleteNb;
38
+ return totalNb !== 0 ? "Accessibility (".concat(totalNb, ")") : 'Accessibility';
39
+ },
32
40
  type: _addons.types.PANEL,
33
41
  render: function render(_ref2) {
34
42
  var _ref2$active = _ref2.active,
@@ -21,17 +21,11 @@ var channel = addons.getChannel(); // Holds axe core running state
21
21
  var active = false; // Holds latest story we requested a run
22
22
 
23
23
  var activeStoryId;
24
-
25
- var getElement = function getElement() {
26
- var storyRoot = document.getElementById('story-root');
27
- return storyRoot ? storyRoot.childNodes : document.getElementById('root');
28
- };
29
24
  /**
30
25
  * Handle A11yContext events.
31
26
  * Because the event are sent without manual check, we split calls
32
27
  */
33
28
 
34
-
35
29
  var handleRequest = /*#__PURE__*/function () {
36
30
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(storyId) {
37
31
  var _yield$getParams, manual;
@@ -70,7 +64,7 @@ var handleRequest = /*#__PURE__*/function () {
70
64
 
71
65
  var run = /*#__PURE__*/function () {
72
66
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(storyId) {
73
- var input, axe, _input$element, element, config, _input$options, options, result;
67
+ var input, axe, _input$element, element, config, _input$options, options, htmlElement, result;
74
68
 
75
69
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
76
70
  while (1) {
@@ -85,7 +79,7 @@ var run = /*#__PURE__*/function () {
85
79
  input = _context2.sent;
86
80
 
87
81
  if (active) {
88
- _context2.next = 18;
82
+ _context2.next = 19;
89
83
  break;
90
84
  }
91
85
 
@@ -96,17 +90,18 @@ var run = /*#__PURE__*/function () {
96
90
 
97
91
  case 10:
98
92
  axe = _context2.sent.default;
99
- _input$element = input.element, element = _input$element === void 0 ? getElement() : _input$element, config = input.config, _input$options = input.options, options = _input$options === void 0 ? {} : _input$options;
93
+ _input$element = input.element, element = _input$element === void 0 ? '#root' : _input$element, config = input.config, _input$options = input.options, options = _input$options === void 0 ? {} : _input$options;
94
+ htmlElement = document.querySelector(element);
100
95
  axe.reset();
101
96
 
102
97
  if (config) {
103
98
  axe.configure(config);
104
99
  }
105
100
 
106
- _context2.next = 16;
107
- return axe.run(element, options);
101
+ _context2.next = 17;
102
+ return axe.run(htmlElement, options);
108
103
 
109
- case 16:
104
+ case 17:
110
105
  result = _context2.sent;
111
106
 
112
107
  // It's possible that we requested a new run on a different story.
@@ -120,26 +115,26 @@ var run = /*#__PURE__*/function () {
120
115
  run(activeStoryId);
121
116
  }
122
117
 
123
- case 18:
124
- _context2.next = 23;
118
+ case 19:
119
+ _context2.next = 24;
125
120
  break;
126
121
 
127
- case 20:
128
- _context2.prev = 20;
122
+ case 21:
123
+ _context2.prev = 21;
129
124
  _context2.t0 = _context2["catch"](1);
130
125
  channel.emit(EVENTS.ERROR, _context2.t0);
131
126
 
132
- case 23:
133
- _context2.prev = 23;
127
+ case 24:
128
+ _context2.prev = 24;
134
129
  active = false;
135
- return _context2.finish(23);
130
+ return _context2.finish(24);
136
131
 
137
- case 26:
132
+ case 27:
138
133
  case "end":
139
134
  return _context2.stop();
140
135
  }
141
136
  }
142
- }, _callee2, null, [[1, 20, 23, 26]]);
137
+ }, _callee2, null, [[1, 21, 24, 27]]);
143
138
  }));
144
139
 
145
140
  return function run(_x2) {
@@ -48,9 +48,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
48
48
 
49
49
  import * as React from 'react';
50
50
  import { themes, convert } from '@storybook/theming';
51
- import { useChannel, useStorybookState } from '@storybook/api';
51
+ import { useChannel, useStorybookState, useAddonState } from '@storybook/api';
52
52
  import { STORY_CHANGED, STORY_RENDERED } from '@storybook/core-events';
53
- import { EVENTS } from '../constants';
53
+ import { ADDON_ID, EVENTS } from '../constants';
54
54
  var colorsByType = [convert(themes.normal).color.negative, // VIOLATION,
55
55
  convert(themes.normal).color.positive, // PASS,
56
56
  convert(themes.normal).color.warning // INCOMPLETION,
@@ -79,20 +79,20 @@ export var A11yContextProvider = function A11yContextProvider(_ref) {
79
79
  var active = _ref.active,
80
80
  props = _objectWithoutProperties(_ref, _excluded);
81
81
 
82
- var _React$useState = React.useState(defaultResult),
82
+ var _useAddonState = useAddonState(ADDON_ID, defaultResult),
83
+ _useAddonState2 = _slicedToArray(_useAddonState, 2),
84
+ results = _useAddonState2[0],
85
+ setResults = _useAddonState2[1];
86
+
87
+ var _React$useState = React.useState(0),
83
88
  _React$useState2 = _slicedToArray(_React$useState, 2),
84
- results = _React$useState2[0],
85
- setResults = _React$useState2[1];
89
+ tab = _React$useState2[0],
90
+ setTab = _React$useState2[1];
86
91
 
87
- var _React$useState3 = React.useState(0),
92
+ var _React$useState3 = React.useState([]),
88
93
  _React$useState4 = _slicedToArray(_React$useState3, 2),
89
- tab = _React$useState4[0],
90
- setTab = _React$useState4[1];
91
-
92
- var _React$useState5 = React.useState([]),
93
- _React$useState6 = _slicedToArray(_React$useState5, 2),
94
- highlighted = _React$useState6[0],
95
- setHighlighted = _React$useState6[1];
94
+ highlighted = _React$useState4[0],
95
+ setHighlighted = _React$useState4[1];
96
96
 
97
97
  var _useStorybookState = useStorybookState(),
98
98
  storyId = _useStorybookState.storyId;
@@ -4,7 +4,7 @@ import { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants';
4
4
  import { VisionSimulator } from './components/VisionSimulator';
5
5
  import { A11YPanel } from './components/A11YPanel';
6
6
  import { A11yContextProvider } from './components/A11yContext';
7
- addons.register(ADDON_ID, function () {
7
+ addons.register(ADDON_ID, function (api) {
8
8
  addons.add(PANEL_ID, {
9
9
  title: '',
10
10
  type: types.TOOL,
@@ -17,7 +17,15 @@ addons.register(ADDON_ID, function () {
17
17
  }
18
18
  });
19
19
  addons.add(PANEL_ID, {
20
- title: 'Accessibility',
20
+ title: function title() {
21
+ var _addonState$violation, _addonState$incomplet;
22
+
23
+ var addonState = api === null || api === void 0 ? void 0 : api.getAddonState(ADDON_ID);
24
+ var violationsNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$violation = addonState.violations) === null || _addonState$violation === void 0 ? void 0 : _addonState$violation.length) || 0;
25
+ var incompleteNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$incomplet = addonState.incomplete) === null || _addonState$incomplet === void 0 ? void 0 : _addonState$incomplet.length) || 0;
26
+ var totalNb = violationsNb + incompleteNb;
27
+ return totalNb !== 0 ? "Accessibility (".concat(totalNb, ")") : 'Accessibility';
28
+ },
21
29
  type: types.PANEL,
22
30
  render: function render(_ref2) {
23
31
  var _ref2$active = _ref2.active,
@@ -15,17 +15,11 @@ const channel = addons.getChannel(); // Holds axe core running state
15
15
  let active = false; // Holds latest story we requested a run
16
16
 
17
17
  let activeStoryId;
18
-
19
- const getElement = () => {
20
- const storyRoot = document.getElementById('story-root');
21
- return storyRoot ? storyRoot.childNodes : document.getElementById('root');
22
- };
23
18
  /**
24
19
  * Handle A11yContext events.
25
20
  * Because the event are sent without manual check, we split calls
26
21
  */
27
22
 
28
-
29
23
  const handleRequest = async storyId => {
30
24
  const {
31
25
  manual
@@ -47,17 +41,18 @@ const run = async storyId => {
47
41
  channel.emit(EVENTS.RUNNING);
48
42
  const axe = (await import('axe-core')).default;
49
43
  const {
50
- element = getElement(),
44
+ element = '#root',
51
45
  config,
52
46
  options = {}
53
47
  } = input;
48
+ const htmlElement = document.querySelector(element);
54
49
  axe.reset();
55
50
 
56
51
  if (config) {
57
52
  axe.configure(config);
58
53
  }
59
54
 
60
- const result = await axe.run(element, options); // It's possible that we requested a new run on a different story.
55
+ const result = await axe.run(htmlElement, options); // It's possible that we requested a new run on a different story.
61
56
  // Unfortunately, axe doesn't support a cancel method to abort current run.
62
57
  // We check if the story we run against is still the current one,
63
58
  // if not, trigger a new run using the current story
@@ -6,9 +6,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
6
6
 
7
7
  import * as React from 'react';
8
8
  import { themes, convert } from '@storybook/theming';
9
- import { useChannel, useStorybookState } from '@storybook/api';
9
+ import { useChannel, useStorybookState, useAddonState } from '@storybook/api';
10
10
  import { STORY_CHANGED, STORY_RENDERED } from '@storybook/core-events';
11
- import { EVENTS } from '../constants';
11
+ import { ADDON_ID, EVENTS } from '../constants';
12
12
  const colorsByType = [convert(themes.normal).color.negative, // VIOLATION,
13
13
  convert(themes.normal).color.positive, // PASS,
14
14
  convert(themes.normal).color.warning // INCOMPLETION,
@@ -37,7 +37,7 @@ export const A11yContextProvider = _ref => {
37
37
  } = _ref,
38
38
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
39
39
 
40
- const [results, setResults] = React.useState(defaultResult);
40
+ const [results, setResults] = useAddonState(ADDON_ID, defaultResult);
41
41
  const [tab, setTab] = React.useState(0);
42
42
  const [highlighted, setHighlighted] = React.useState([]);
43
43
  const {
@@ -4,7 +4,7 @@ import { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants';
4
4
  import { VisionSimulator } from './components/VisionSimulator';
5
5
  import { A11YPanel } from './components/A11YPanel';
6
6
  import { A11yContextProvider } from './components/A11yContext';
7
- addons.register(ADDON_ID, () => {
7
+ addons.register(ADDON_ID, api => {
8
8
  addons.add(PANEL_ID, {
9
9
  title: '',
10
10
  type: types.TOOL,
@@ -14,7 +14,16 @@ addons.register(ADDON_ID, () => {
14
14
  render: () => /*#__PURE__*/React.createElement(VisionSimulator, null)
15
15
  });
16
16
  addons.add(PANEL_ID, {
17
- title: 'Accessibility',
17
+ title() {
18
+ var _addonState$violation, _addonState$incomplet;
19
+
20
+ const addonState = api === null || api === void 0 ? void 0 : api.getAddonState(ADDON_ID);
21
+ const violationsNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$violation = addonState.violations) === null || _addonState$violation === void 0 ? void 0 : _addonState$violation.length) || 0;
22
+ const incompleteNb = (addonState === null || addonState === void 0 ? void 0 : (_addonState$incomplet = addonState.incomplete) === null || _addonState$incomplet === void 0 ? void 0 : _addonState$incomplet.length) || 0;
23
+ const totalNb = violationsNb + incompleteNb;
24
+ return totalNb !== 0 ? `Accessibility (${totalNb})` : 'Accessibility';
25
+ },
26
+
18
27
  type: types.PANEL,
19
28
  render: ({
20
29
  active = true,
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Result } from 'axe-core';
3
- interface Results {
3
+ export interface Results {
4
4
  passes: Result[];
5
5
  violations: Result[];
6
6
  incomplete: Result[];
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Result } from 'axe-core';
3
- interface Results {
3
+ export interface Results {
4
4
  passes: Result[];
5
5
  violations: Result[];
6
6
  incomplete: Result[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-a11y",
3
- "version": "6.5.0-beta.2",
3
+ "version": "6.5.0-beta.5",
4
4
  "description": "Test component compliance with web accessibility standards",
5
5
  "keywords": [
6
6
  "a11y",
@@ -45,14 +45,14 @@
45
45
  "prepare": "node ../../scripts/prepare.js"
46
46
  },
47
47
  "dependencies": {
48
- "@storybook/addons": "6.5.0-beta.2",
49
- "@storybook/api": "6.5.0-beta.2",
50
- "@storybook/channels": "6.5.0-beta.2",
51
- "@storybook/client-logger": "6.5.0-beta.2",
52
- "@storybook/components": "6.5.0-beta.2",
53
- "@storybook/core-events": "6.5.0-beta.2",
48
+ "@storybook/addons": "6.5.0-beta.5",
49
+ "@storybook/api": "6.5.0-beta.5",
50
+ "@storybook/channels": "6.5.0-beta.5",
51
+ "@storybook/client-logger": "6.5.0-beta.5",
52
+ "@storybook/components": "6.5.0-beta.5",
53
+ "@storybook/core-events": "6.5.0-beta.5",
54
54
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
55
- "@storybook/theming": "6.5.0-beta.2",
55
+ "@storybook/theming": "6.5.0-beta.5",
56
56
  "axe-core": "^4.2.0",
57
57
  "core-js": "^3.8.2",
58
58
  "global": "^4.4.0",
@@ -81,7 +81,7 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "b42ccab2b3f9d4f1f8f862242a5e4af0d3306061",
84
+ "gitHead": "77cd38edc2aa4728c360467c5418bb2ef2d8817a",
85
85
  "sbmodern": "dist/modern/index.js",
86
86
  "storybook": {
87
87
  "displayName": "Accessibility",