@storybook/addon-backgrounds 7.6.3 → 8.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/manager.js +3 -2
- package/package.json +11 -10
package/dist/manager.js
CHANGED
@@ -2,7 +2,8 @@ import React, { memo, useState, useMemo, useCallback, Fragment } from 'react';
|
|
2
2
|
import { useParameter, useGlobals, addons, types } from '@storybook/manager-api';
|
3
3
|
import memoize from 'memoizerific';
|
4
4
|
import { logger } from '@storybook/client-logger';
|
5
|
-
import { WithTooltip, TooltipLinkList, IconButton
|
5
|
+
import { WithTooltip, TooltipLinkList, IconButton } from '@storybook/components';
|
6
|
+
import { PhotoIcon, GridIcon } from '@storybook/icons';
|
6
7
|
import { styled } from '@storybook/theming';
|
7
8
|
import '@storybook/global';
|
8
9
|
import { dedent } from 'ts-dedent';
|
@@ -11,4 +12,4 @@ var ADDON_ID="storybook/background",PARAM_KEY="backgrounds";var ColorIcon=styled
|
|
11
12
|
Backgrounds Addon: could not find the default color "${defaultName}".
|
12
13
|
These are the available colors for your story based on your configuration:
|
13
14
|
${availableColors}.
|
14
|
-
`);}return "transparent"};var createBackgroundSelectorItem=memoize(1e3)((id,name,value,hasSwatch,change,active)=>({id:id||name,title:name,onClick:()=>{change({selected:value,name});},value,right:hasSwatch?React.createElement(ColorIcon,{background:value}):void 0,active})),getDisplayedItems=memoize(10)((backgrounds,selectedBackgroundColor,change)=>{let backgroundSelectorItems=backgrounds.map(({name,value})=>createBackgroundSelectorItem(null,name,value,!0,change,value===selectedBackgroundColor));return selectedBackgroundColor!=="transparent"?[createBackgroundSelectorItem("reset","Clear background","transparent",null,change,!1),...backgroundSelectorItems]:backgroundSelectorItems}),DEFAULT_BACKGROUNDS_CONFIG={default:null,disable:!0,values:[]},BackgroundSelector=memo(function(){let backgroundsConfig=useParameter(PARAM_KEY,DEFAULT_BACKGROUNDS_CONFIG),[isTooltipVisible,setIsTooltipVisible]=useState(!1),[globals,updateGlobals]=useGlobals(),globalsBackgroundColor=globals[PARAM_KEY]?.value,selectedBackgroundColor=useMemo(()=>getBackgroundColorByName(globalsBackgroundColor,backgroundsConfig.values,backgroundsConfig.default),[backgroundsConfig,globalsBackgroundColor]);Array.isArray(backgroundsConfig)&&logger.warn("Addon Backgrounds api has changed in Storybook 6.0. Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md");let onBackgroundChange=useCallback(value=>{updateGlobals({[PARAM_KEY]:{...globals[PARAM_KEY],value}});},[backgroundsConfig,globals,updateGlobals]);return backgroundsConfig.disable?null:React.createElement(Fragment,null,React.createElement(WithTooltip,{placement:"top",closeOnOutsideClick:!0,tooltip:({onHide})=>React.createElement(TooltipLinkList,{links:getDisplayedItems(backgroundsConfig.values,selectedBackgroundColor,({selected})=>{selectedBackgroundColor!==selected&&onBackgroundChange(selected),onHide();})}),onVisibleChange:setIsTooltipVisible},React.createElement(IconButton,{key:"background",title:"Change the background of the preview",active:selectedBackgroundColor!=="transparent"||isTooltipVisible},React.createElement(
|
15
|
+
`);}return "transparent"};var createBackgroundSelectorItem=memoize(1e3)((id,name,value,hasSwatch,change,active)=>({id:id||name,title:name,onClick:()=>{change({selected:value,name});},value,right:hasSwatch?React.createElement(ColorIcon,{background:value}):void 0,active})),getDisplayedItems=memoize(10)((backgrounds,selectedBackgroundColor,change)=>{let backgroundSelectorItems=backgrounds.map(({name,value})=>createBackgroundSelectorItem(null,name,value,!0,change,value===selectedBackgroundColor));return selectedBackgroundColor!=="transparent"?[createBackgroundSelectorItem("reset","Clear background","transparent",null,change,!1),...backgroundSelectorItems]:backgroundSelectorItems}),DEFAULT_BACKGROUNDS_CONFIG={default:null,disable:!0,values:[]},BackgroundSelector=memo(function(){let backgroundsConfig=useParameter(PARAM_KEY,DEFAULT_BACKGROUNDS_CONFIG),[isTooltipVisible,setIsTooltipVisible]=useState(!1),[globals,updateGlobals]=useGlobals(),globalsBackgroundColor=globals[PARAM_KEY]?.value,selectedBackgroundColor=useMemo(()=>getBackgroundColorByName(globalsBackgroundColor,backgroundsConfig.values,backgroundsConfig.default),[backgroundsConfig,globalsBackgroundColor]);Array.isArray(backgroundsConfig)&&logger.warn("Addon Backgrounds api has changed in Storybook 6.0. Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md");let onBackgroundChange=useCallback(value=>{updateGlobals({[PARAM_KEY]:{...globals[PARAM_KEY],value}});},[backgroundsConfig,globals,updateGlobals]);return backgroundsConfig.disable?null:React.createElement(Fragment,null,React.createElement(WithTooltip,{placement:"top",closeOnOutsideClick:!0,tooltip:({onHide})=>React.createElement(TooltipLinkList,{links:getDisplayedItems(backgroundsConfig.values,selectedBackgroundColor,({selected})=>{selectedBackgroundColor!==selected&&onBackgroundChange(selected),onHide();})}),onVisibleChange:setIsTooltipVisible},React.createElement(IconButton,{key:"background",title:"Change the background of the preview",active:selectedBackgroundColor!=="transparent"||isTooltipVisible},React.createElement(PhotoIcon,null))))});var GridSelector=memo(function(){let[globals,updateGlobals]=useGlobals(),{grid}=useParameter(PARAM_KEY,{grid:{disable:!1}});if(grid?.disable)return null;let isActive=globals[PARAM_KEY]?.grid||!1;return React.createElement(IconButton,{key:"background",active:isActive,title:"Apply a grid to the preview",onClick:()=>updateGlobals({[PARAM_KEY]:{...globals[PARAM_KEY],grid:!isActive}})},React.createElement(GridIcon,null))});addons.register(ADDON_ID,()=>{addons.add(ADDON_ID,{title:"Backgrounds",type:types.TOOL,match:({viewMode})=>!!(viewMode&&viewMode.match(/^(story|docs)$/)),render:()=>React.createElement(Fragment,null,React.createElement(BackgroundSelector,null),React.createElement(GridSelector,null))});});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/addon-backgrounds",
|
3
|
-
"version": "
|
3
|
+
"version": "8.0.0-alpha.1",
|
4
4
|
"description": "Switch backgrounds to view components in different settings",
|
5
5
|
"keywords": [
|
6
6
|
"addon",
|
@@ -53,19 +53,20 @@
|
|
53
53
|
},
|
54
54
|
"dependencies": {
|
55
55
|
"@storybook/global": "^5.0.0",
|
56
|
+
"@storybook/icons": "^1.2.1",
|
56
57
|
"memoizerific": "^1.11.3",
|
57
58
|
"ts-dedent": "^2.0.0"
|
58
59
|
},
|
59
60
|
"devDependencies": {
|
60
|
-
"@storybook/client-logger": "
|
61
|
-
"@storybook/components": "
|
62
|
-
"@storybook/manager-api": "
|
63
|
-
"@storybook/preview-api": "
|
64
|
-
"@storybook/theming": "
|
65
|
-
"@storybook/types": "
|
66
|
-
"react": "^
|
67
|
-
"react-dom": "^
|
68
|
-
"typescript": "
|
61
|
+
"@storybook/client-logger": "8.0.0-alpha.1",
|
62
|
+
"@storybook/components": "8.0.0-alpha.1",
|
63
|
+
"@storybook/manager-api": "8.0.0-alpha.1",
|
64
|
+
"@storybook/preview-api": "8.0.0-alpha.1",
|
65
|
+
"@storybook/theming": "8.0.0-alpha.1",
|
66
|
+
"@storybook/types": "8.0.0-alpha.1",
|
67
|
+
"react": "^18.2.0",
|
68
|
+
"react-dom": "^18.2.0",
|
69
|
+
"typescript": "^5.3.2"
|
69
70
|
},
|
70
71
|
"publishConfig": {
|
71
72
|
"access": "public"
|