Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jul 4, 2023
1 parent 2ee9393 commit 65f3695
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
39 changes: 21 additions & 18 deletions code/addons/a11y/src/manager.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import React from 'react';
import { addons, types } from '@storybook/manager-api';
import { addons, types, useStorybookApi } from '@storybook/manager-api';
import { Badge, Spaced } from '@storybook/components';
import { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants';
import { VisionSimulator } from './components/VisionSimulator';
import { A11YPanel } from './components/A11YPanel';
import type { Results } from './components/A11yContext';
import { A11yContextProvider } from './components/A11yContext';

const Title = () => {
const api = useStorybookApi();
const addonState: Results = api?.getAddonState(ADDON_ID);
const violationsNb = addonState?.violations?.length || 0;
const incompleteNb = addonState?.incomplete?.length || 0;
const count = violationsNb + incompleteNb;

const suffix = count === 0 ? '' : <Badge status="neutral">{count}</Badge>;

return (
<div>
<Spaced col={1}>
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>Accessibility</span>
{suffix}
</Spaced>
</div>
);
};

addons.register(ADDON_ID, (api) => {
addons.add(PANEL_ID, {
title: '',
Expand All @@ -16,23 +35,7 @@ addons.register(ADDON_ID, (api) => {
});

addons.add(PANEL_ID, {
title() {
const addonState: Results = api?.getAddonState(ADDON_ID);
const violationsNb = addonState?.violations?.length || 0;
const incompleteNb = addonState?.incomplete?.length || 0;
const count = violationsNb + incompleteNb;

const suffix = count === 0 ? '' : <Badge status="neutral">{count}</Badge>;

return (
<div>
<Spaced col={1}>
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>Accessibility</span>
{suffix}
</Spaced>
</div>
);
},
title: Title,
type: types.PANEL,
render: ({ active = true, key }) => (
<A11yContextProvider key={key} active={active}>
Expand Down
2 changes: 1 addition & 1 deletion code/addons/controls/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Title() {

addons.register(ADDON_ID, (api) => {
addons.add(ADDON_ID, {
title: <Title />,
title: Title,
type: types.PANEL,
paramKey: PARAM_KEY,
render: ({ key, active }) => {
Expand Down
4 changes: 1 addition & 3 deletions code/addons/links/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { addons } from '@storybook/manager-api';
import EVENTS, { ADDON_ID } from './constants';

addons.register(ADDON_ID, (api) => {
const channel = addons.getChannel();

channel.on(EVENTS.REQUEST, ({ kind, name }) => {
api.on(EVENTS.REQUEST, ({ kind, name }) => {
const id = api.storyId(kind, name);
api.emit(EVENTS.RECEIVE, id);
});
Expand Down

0 comments on commit 65f3695

Please sign in to comment.