forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutlineSelector.tsx
More file actions
49 lines (40 loc) · 1.28 KB
/
Copy pathOutlineSelector.tsx
File metadata and controls
49 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { memo, useCallback, useEffect } from 'react';
import { ToggleButton } from 'storybook/internal/components';
import { OutlineIcon } from '@storybook/icons';
import { useGlobals, useStorybookApi } from 'storybook/manager-api';
import { ADDON_ID, PARAM_KEY } from './constants.ts';
export const OutlineSelector = memo(function OutlineSelector() {
const [globals, updateGlobals] = useGlobals();
const api = useStorybookApi();
const isActive = [true, 'true'].includes(globals[PARAM_KEY]);
const toggleOutline = useCallback(
() =>
updateGlobals({
[PARAM_KEY]: !isActive,
}),
[isActive, updateGlobals]
);
useEffect(() => {
api.setAddonShortcut(ADDON_ID, {
label: 'Toggle Outline',
defaultShortcut: ['alt', 'O'],
actionName: 'outline',
showInMenu: false,
action: toggleOutline,
});
}, [toggleOutline, api]);
return (
<ToggleButton
key="outline"
padding="small"
variant="ghost"
pressed={isActive}
ariaLabel="Outline tool"
ariaDescription="When enabled, this tool displays the outline of every element in the preview area, which helps understand their layout."
tooltip="Toggle outline"
onClick={toggleOutline}
>
<OutlineIcon />
</ToggleButton>
);
});