From f336327360031b6fa132d5b3a1b15beb67b84fa6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Roy Date: Fri, 24 Jan 2020 12:05:17 -0500 Subject: [PATCH 1/3] Enables the consumer to hide the code --- addons/cssresources/src/CssResource.ts | 1 + addons/cssresources/src/css-resource-panel.tsx | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/cssresources/src/CssResource.ts b/addons/cssresources/src/CssResource.ts index 0067ca677488..ee67b93e2a7c 100644 --- a/addons/cssresources/src/CssResource.ts +++ b/addons/cssresources/src/CssResource.ts @@ -2,4 +2,5 @@ export interface CssResource { id: string; code: string; picked: boolean; + hideCode: boolean; } diff --git a/addons/cssresources/src/css-resource-panel.tsx b/addons/cssresources/src/css-resource-panel.tsx index 2db8391fa7f6..5155edb71c31 100644 --- a/addons/cssresources/src/css-resource-panel.tsx +++ b/addons/cssresources/src/css-resource-panel.tsx @@ -112,16 +112,16 @@ export class CssResourcePanel extends Component { return (
{list && - list.map(({ id, code, picked }) => ( + list.map(({ id, code, picked, hideCode = false }) => (
- {code && code.length < maxLimitToUseSyntaxHighlighter && ( + {code && !hideCode && code.length < maxLimitToUseSyntaxHighlighter && ( {code} )} - {code && code.length >= maxLimitToUseSyntaxHighlighter && ( + {code && !hideCode && code.length >= maxLimitToUseSyntaxHighlighter && ( {code.substring(0, maxLimitToUseSyntaxHighlighter)} ... From 1988d8b2bb901aba5d136f15cd11a35758e06858 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Roy Date: Fri, 24 Jan 2020 12:12:28 -0500 Subject: [PATCH 2/3] Adds minimal documentation to the README --- addons/cssresources/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/cssresources/README.md b/addons/cssresources/README.md index c3b91348eef0..bf15532f593e 100644 --- a/addons/cssresources/README.md +++ b/addons/cssresources/README.md @@ -20,8 +20,8 @@ Add following content to it: ```js module.exports = { - addons: ['@storybook/addon-cssresources/register'] -} + addons: ['@storybook/addon-cssresources/register'], +}; ``` ## Usage @@ -34,17 +34,17 @@ import { withCssResources } from '@storybook/addon-cssresources'; export default { title: 'CssResources', parameters: { - cssresources: [{ + cssresources: [ + { id: `bluetheme`, code: ``, picked: false, + hideCode: false, // Defaults to false, this enables you to hide the code snippet and only displays the style selector }, ], }, decorators: [withCssResources], }; -export const defaultView = () => ( -
-); +export const defaultView = () =>
; ``` From a6f80b1d2ccc8bf7b9c9fc3dee04eb00056656c4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Roy Date: Fri, 24 Jan 2020 12:16:02 -0500 Subject: [PATCH 3/3] Adds basic test --- .../src/css-resource-panel.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/addons/cssresources/src/css-resource-panel.test.js b/addons/cssresources/src/css-resource-panel.test.js index cd0f47303045..ef75ae2ba376 100644 --- a/addons/cssresources/src/css-resource-panel.test.js +++ b/addons/cssresources/src/css-resource-panel.test.js @@ -300,5 +300,32 @@ describe('CSSResourcePanel', () => { node.instance().onStoryChange('fake-story-id'); expect(node.find(SyntaxHighlighter).length).toEqual(1); }); + + it('should not render code for items /w the `hideCode` flag', () => { + const apiGetParameters = jest.fn(() => [ + { + id: 'local-fake-id-1', + code: 'local-fake-code-1', + picked: true, + hideCode: true, + }, + { + id: 'local-fake-id-2', + code: 'local-fake-code-2', + picked: false, + }, + ]); + + const node = shallowNode({ + ...defaultProps, + api: { + ...defaultProps.api, + getParameters: apiGetParameters, + }, + }); + + node.instance().onStoryChange('fake-story-id'); + expect(node.find(SyntaxHighlighter).length).toEqual(1); + }); }); });