Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storybook-config): add Carbon Theme & Type Panel #7569

Merged
merged 34 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
07b089b
feat(storybook-config): add custom panel
Jan 14, 2021
0b70528
storybook config custom preset with create-react-app package
andreancardona Jan 14, 2021
b517bf2
storybook config custom presets - need to transpile
andreancardona Jan 14, 2021
42dffe4
storybook-config-custom-presets: added babel cli & babel core
andreancardona Jan 15, 2021
36f4fd8
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Jan 15, 2021
79512d7
Merge branch 'storybook-config-custom-presets' of github.com:aledavil…
Jan 15, 2021
8a962b0
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Jan 19, 2021
62e83b6
stuck on panel rendering with custom properties variable
andreancardona Jan 19, 2021
8456773
stuck on panel rendering with custom properties variable
andreancardona Jan 19, 2021
41a3453
testing file path
andreancardona Jan 20, 2021
e0e0aa4
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Jan 20, 2021
9ea715e
Merge branch 'storybook-config-custom-presets' of github.com:aledavil…
Jan 20, 2021
8b7a5f8
panel is showing up - just not fully functioning
andreancardona Jan 20, 2021
9a759fd
Merge branch 'storybook-config-custom-presets' of github.com:aledavil…
Jan 20, 2021
eebbc2c
feat(storybook-config): add theme and type addon panels
Jan 20, 2021
ff2e87a
chore: remove theme addon files
Jan 21, 2021
6aef262
feat(storybook-config): add theme and type addon panels - added copyr…
andreancardona Jan 21, 2021
ccbb482
feat(storybook-config): ran yarn dedupe
andreancardona Jan 21, 2021
ea90be7
feat(storybook-config): make custom panel conditionally appear
Jan 21, 2021
053c606
Merge branch 'storybook-config-custom-presets' of github.com:aledavil…
Jan 21, 2021
c6cdab3
Merge branch 'master' into storybook-config-custom-presets
Jan 21, 2021
0d83225
chore(storybook-config): remove merge messages
Jan 22, 2021
3f24d3b
Merge branch 'master' into storybook-config-custom-presets
andreancardona Jan 25, 2021
7ce1678
Merge branch 'master' into storybook-config-custom-presets
andreancardona Jan 26, 2021
70ba2cc
Merge branch 'master' into storybook-config-custom-presets
andreancardona Jan 26, 2021
3f578c9
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Jan 28, 2021
7c40cdd
Merge branch 'storybook-config-custom-presets' of github.com:aledavil…
Jan 28, 2021
94d6f14
chore(storybook-config): add missing dependencies
Jan 28, 2021
2e87bd4
chore(storybook-config): rename panel file
Jan 28, 2021
0f26f4b
chore(storybook-config): adds clean script
Jan 28, 2021
ed8244c
chore: run dedupe
Jan 28, 2021
7c9b671
Merge branch 'master' into storybook-config-custom-presets
Jan 28, 2021
71e3c3a
Merge branch 'master' of github.com:carbon-design-system/carbon into …
Feb 1, 2021
3bf7dbb
chore(storybook-config): add use strict:
Feb 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions config/storybook-preset-carbon/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright IBM Corp. 2021, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
andreancardona marked this conversation as resolved.
Show resolved Hide resolved
presets: ['@babel/preset-env', '@babel/preset-react'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2018
* Copyright IBM Corp. 2021, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -36,10 +36,7 @@ const typeTokenDefaults = {
'productive-heading-04': '28-36',
};

/**
* Storybook add-on panel for Carbon theme switcher.
*/
export const CarbonThemesPanel = ({ api, active }) => {
export const CarbonThemePanel = ({ api, active }) => {
const [currentTheme, setCurrentTheme] = useState('white');
const handleChange = useCallback(
(event) => {
Expand Down Expand Up @@ -77,29 +74,31 @@ export const CarbonThemesPanel = ({ api, active }) => {
);
};

CarbonThemesPanel.propTypes = {
CarbonThemePanel.propTypes = {
/**
* `true` if this Storybook add-on panel is active.
*/
active: PropTypes.bool.isRequired,

/**
* The Storybook API object.
*/
api: PropTypes.shape({
getChannel: PropTypes.func,
}).isRequired,

/**
* `true` if this Storybook add-on panel is active.
*/
active: PropTypes.bool.isRequired,
};

/**
* Storybook add-on panel for Carbon type token switcher.
*/
export const CarbonTypePanel = ({ api, active }) => {
const [currentTypeTokens, setCurrentTypeTokens] = useState(typeTokenDefaults);
const handleTokenChange = useCallback(
(event) => {
const { name: tokenName, value: tokenValue } = event.target;
setCurrentTypeTokens({ ...currentTypeTokens, [tokenName]: tokenValue });
setCurrentTypeTokens((currentTypeTokens) => {
return {
...currentTypeTokens,
[tokenName]: tokenValue,
};
});
api.getChannel().emit(CARBON_TYPE_TOKEN, { tokenName, tokenValue });
},
[api]
Expand Down Expand Up @@ -131,15 +130,15 @@ export const CarbonTypePanel = ({ api, active }) => {
};

CarbonTypePanel.propTypes = {
/**
* `true` if this Storybook add-on panel is active.
*/
active: PropTypes.bool.isRequired,

/**
* The Storybook API object.
*/
api: PropTypes.shape({
getChannel: PropTypes.func,
}).isRequired,

/**
* `true` if this Storybook add-on panel is active.
*/
active: PropTypes.bool.isRequired,
};
14 changes: 14 additions & 0 deletions config/storybook-preset-carbon/carbon-theme-addon/src/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright IBM Corp. 2021, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

aledavila marked this conversation as resolved.
Show resolved Hide resolved
'use strict';

module.exports = {
managerEntries(entry = []) {
return [...entry, require.resolve('./register')];
},
};
36 changes: 36 additions & 0 deletions config/storybook-preset-carbon/carbon-theme-addon/src/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright IBM Corp. 2021, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { addons } from '@storybook/addons';
import { CarbonThemePanel, CarbonTypePanel } from './components/Panel';
import {
CARBON_THEMES_ADDON_ID,
CARBON_THEME_PANEL_ID,
CARBON_TYPE_ADDON_ID,
CARBON_TYPE_PANEL_ID,
} from './shared';

// Disabling because storybook addons doesn't provide proptypes or display names for these panels
/* eslint-disable react/display-name, react/prop-types */
addons.register(CARBON_THEMES_ADDON_ID, (api) => {
addons.addPanel(CARBON_THEME_PANEL_ID, {
title: 'Carbon Theme',
render: ({ active, key }) => (
<CarbonThemePanel api={api} key={key} active={active} />
),
});
});

addons.register(CARBON_TYPE_ADDON_ID, (api) => {
addons.addPanel(CARBON_TYPE_PANEL_ID, {
title: 'Carbon Type',
render: ({ active, key }) => (
<CarbonTypePanel api={api} key={key} active={active} />
),
});
});
13 changes: 13 additions & 0 deletions config/storybook-preset-carbon/carbon-theme-addon/src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright IBM Corp. 2021, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

export const CARBON_THEMES_ADDON_ID = 'carbon-theme';
export const CARBON_CURRENT_THEME = `${CARBON_THEMES_ADDON_ID}/current`;
export const CARBON_THEME_PANEL_ID = `${CARBON_THEMES_ADDON_ID}/panel`;
export const CARBON_TYPE_ADDON_ID = 'carbon-type';
export const CARBON_TYPE_TOKEN = `${CARBON_TYPE_ADDON_ID}/type`;
export const CARBON_TYPE_PANEL_ID = `${CARBON_TYPE_ADDON_ID}/panel`;
6 changes: 3 additions & 3 deletions config/storybook-preset-carbon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ module.exports = {
'@storybook/addon-storysource',
'@storybook/addon-knobs',
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-docs',
'@storybook/addon-notes/register',
aledavila marked this conversation as resolved.
Show resolved Hide resolved
'storybook-readme/register',

// Phase 3: port over custom panels/add-ons
'@storybook/addon-links',
CARBON_REACT_STORYBOOK_USE_CUSTOM_PROPERTIES === 'true' &&
require.resolve('./dist/preset.js'),
],

webpack(config) {
Expand Down
17 changes: 15 additions & 2 deletions config/storybook-preset-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
"components",
"react"
],
"scripts": {
"build": "babel ./carbon-theme-addon/src --out-dir ./dist",
"clean": "rimraf ./dist"
},
"peerDependencies": {
"@storybook/react": "^5.3.19"
"@storybook/react": "^5.3.19",
"react": "^16.8.6 || ^17.0.1",
"react-dom": "^16.8.6 || ^17.0.1"
},
"dependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-docs": "^5.3.19",
"@storybook/addon-knobs": "^5.3.19",
Expand All @@ -29,9 +37,14 @@
"@storybook/addon-storysource": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/source-loader": "^5.3.19",
"react-is": "^16.8.6",
"storybook-readme": "^5.0.8"
},
"devDependencies": {
"@storybook/react": "^5.3.19"
"@storybook/react": "^5.3.19",
"babel-loader": "^8.2.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"webpack": "^4.41.5"
}
}
36 changes: 0 additions & 36 deletions packages/react/.storybook/addon-carbon-theme/register.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
'use strict';

module.exports = {
addons: [
'storybook-preset-carbon',
require.resolve('./addon-carbon-theme/register'),
],
addons: ['storybook-preset-carbon'],
stories: ['../src/**/*-story.js', '../src/**/*.stories.mdx'],
};
5 changes: 1 addition & 4 deletions packages/react/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { addDecorator, addParameters } from '@storybook/react';
import addons from '@storybook/addons';
import { themes } from '@storybook/theming';
import { configureActions } from '@storybook/addon-actions';
import {
CARBON_CURRENT_THEME,
CARBON_TYPE_TOKEN,
} from './addon-carbon-theme/shared';
import { CARBON_CURRENT_THEME, CARBON_TYPE_TOKEN } from './shared';
import Container from './Container';
import PackageInfo from './../package.json';

Expand Down
Loading