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

Add storybook #46

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9efb8c0
Updated library versions
MikeTschudi Dec 6, 2021
f93fea0
Updated libraries and built product name
MikeTschudi Dec 14, 2021
d3364d1
Merge branch 'develop' into ch/update-libraries
MikeTschudi Dec 14, 2021
08948eb
Patched merge
MikeTschudi Dec 14, 2021
daa6875
Changed to recommended module and path style
MikeTschudi Dec 14, 2021
471ff9d
Moved calcite-components to `dependencies`
MikeTschudi Dec 15, 2021
1561553
Merge branch 'develop' into ch/update-libraries
MikeTschudi Dec 15, 2021
b971859
Merge branch 'develop' into ch/update-libraries
MikeTschudi Dec 15, 2021
89e224e
Removed faulty package entry
MikeTschudi Dec 16, 2021
94cb213
Updated version
MikeTschudi Dec 16, 2021
344bbfc
Removed deprecated stenciljs property
MikeTschudi Dec 28, 2021
4772550
Updated libraries from hub-components
MikeTschudi Dec 30, 2021
d281962
Changed config call to match setLocale version for clarity
MikeTschudi Dec 30, 2021
2d2f6b9
Combined locale effort for app and JSON editor
MikeTschudi Dec 31, 2021
4d83e97
Generalized setLocale so that it can be used in requirejs or dojo env…
MikeTschudi Dec 31, 2021
bf9aee9
Added storybook
MikeTschudi Jan 12, 2022
529b25f
Copied arcgis-hub-input-color from hub-components for testing
MikeTschudi Jan 12, 2022
79b8b34
Set node & npm to latest LTS
MikeTschudi Jan 12, 2022
0f6b69e
Adjustments to get storybook to display
MikeTschudi Jan 14, 2022
296a612
Fixed allocation of packages
MikeTschudi Jan 14, 2022
8f4eabd
Adjustments to get storybook to display
MikeTschudi Jan 18, 2022
bdfc23e
Merge branch 'develop' into enh/add-storybook
MikeTschudi Jan 18, 2022
778e935
Updated build product
MikeTschudi Jan 18, 2022
976c571
Merge branch 'develop' into enh/add-storybook
MikeTschudi Jan 21, 2022
9e99975
Post-merge build result
MikeTschudi Jan 21, 2022
966f872
Merge branch 'develop' into enh/add-storybook
MikeTschudi Feb 16, 2022
77d3d21
Updated Storybook
MikeTschudi Feb 16, 2022
2960b8c
Removed test component and updated node & npm
MikeTschudi Feb 16, 2022
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:jest/recommended",
"plugin:storybook/recommended",
"prettier"
],
"ignorePatterns": ["assets", "test", "json-editor"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ __*
src/**/*.js
!src/**/assets/**/*.js
!src/demos/**/*.js
storybook-static/
22 changes: 22 additions & 0 deletions .storybook/addons/theme/apply-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect } from '@storybook/addons';

/*
A global decorator that applies the theme defined in globals.currentTheme
*/

const applyTheme = theme => {
Object.entries(theme).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value);
});
};

export const withTheme = (StoryFn, context) => {
const { globals } = context;
const currentTheme = globals.currentTheme;

useEffect(() => {
applyTheme(currentTheme);
}, [currentTheme]);

return StoryFn();
};
19 changes: 19 additions & 0 deletions .storybook/addons/theme/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { AddonPanel } from '@storybook/components';
import { addons, types } from '@storybook/addons';
import { ThemePicker } from './theme-picker';

const ADDON_ID = 'theme-picker';
const PANEL_ID = `${ADDON_ID}/panel`;

addons.register(ADDON_ID, (api) => {
addons.add(PANEL_ID, {
type: types.PANEL,
title: 'Theme',
render: ({ active, key }) => (
<AddonPanel active={active} key={key}>
<ThemePicker />
</AddonPanel>
),
});
});
73 changes: 73 additions & 0 deletions .storybook/addons/theme/theme-picker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useState } from 'react';
import { useGlobals } from '@storybook/api';
import { Button, } from '@storybook/components';
import * as themes from './themes';

/*
A panel that allows setting the theme defined in globals.currentTheme
*/

// TODO: there are better ways to do this....
const containerStyle = {
padding: '10px',
};

const toolbarStyle = {
display: 'flex',
gap: '1rem',
};

const swatchesStyle = {
marginTop: '10px',
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))',
gap: '5px',
};

const labelStyle = {
display: 'flex',
justifyContent: 'space-between',
padding: '5px 10px',
border: 'solid 1px lightgray',
};

export const ThemePicker = _ => {
const [globals, updateGlobals] = useGlobals();

const [namedTheme, setNamedTheme] = useState(0);

const setColor = evt => {
const { name, value } = evt.target;
const currentTheme = { ...globals.currentTheme, [name]: value };
applyTheme(currentTheme);
}

const applyNamedTheme = themeName => {
const theme = themes[themeName];
setNamedTheme(themeName);
theme && applyTheme(theme);
};

const applyTheme = theme => {
updateGlobals({ currentTheme: theme })
}

const currentTheme = globals.currentTheme || {};

return (
<div className="theme-picker" style={containerStyle}>
<div className="theme-picker-toolbar" style={toolbarStyle}>
{Object.keys(themes).map((theme, idx) => {
const themeName = theme.replace('Theme', '');
return <Button key={idx} secondary outline small onClick={_ => applyNamedTheme(theme)}>{themeName}</Button>;
}
)}
</div>
<div className="theme-picker-swatches" style={swatchesStyle}>
{Object.keys(currentTheme).map((key, idx) => (
<label key={idx} style={labelStyle}>{key}: <input type="color" name={key} value={currentTheme[key]} onChange={setColor} /></label>
))}
</div>
</div>
);
};
75 changes: 75 additions & 0 deletions .storybook/addons/theme/themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// TODO: this could just come from calcite-colors
export const defaultTheme = {
'--calcite-ui-brand': '#007ac2', // **
'--calcite-ui-brand-hover': '#00619b', // **
'--calcite-ui-brand-press': '#004874', // **
'--calcite-ui-info': '#00619b',
'--calcite-ui-success': '#35ac46',
'--calcite-ui-warning': '#edd317',
'--calcite-ui-danger': '#d83020',
'--calcite-ui-danger-hover': '#a82b1e',
'--calcite-ui-danger-press': '#7c1d13',
'--calcite-ui-background': '#f8f8f8', // **
'--calcite-ui-foreground-1': '#ffffff', // **
'--calcite-ui-foreground-2': '#f3f3f3', // **
'--calcite-ui-foreground-3': '#eaeaea', // **
'--calcite-ui-text-1': '#151515', // **
'--calcite-ui-text-2': '#4a4a4a', // **
'--calcite-ui-text-3': '#6a6a6a', // **
'--calcite-ui-text-inverse': '#ffffff', // **
'--calcite-ui-text-link': '#00619b', // **
'--calcite-ui-border-1': '#cacaca', // **
'--calcite-ui-border-2': '#d4d4d4',
'--calcite-ui-border-3': '#dfdfdf',
'--calcite-ui-border-input': '#949494'
};

export const greenTheme = {
'--calcite-ui-brand': '#309c3d',
'--calcite-ui-brand-hover': '#367d3e',
'--calcite-ui-brand-press': '#367d3e',
'--calcite-ui-info': '#00619b',
'--calcite-ui-success': '#35ac46',
'--calcite-ui-warning': '#edd317',
'--calcite-ui-danger': '#d83020',
'--calcite-ui-danger-hover': '#a82b1e',
'--calcite-ui-danger-press': '#7c1d13',
'--calcite-ui-background': '#f3f7f3', // **
'--calcite-ui-foreground-1': '#f3f9f3',
'--calcite-ui-foreground-2': '#f3f3f3',
'--calcite-ui-foreground-3': '#eaeaea',
'--calcite-ui-text-1': '#367d3e', // **
'--calcite-ui-text-2': '#309c3d', // **
'--calcite-ui-text-3': '#2da43b', // **
'--calcite-ui-text-inverse': '#f3f7f3', // **
'--calcite-ui-text-link': '#367d3e', // **
'--calcite-ui-border-1': '#cacaca', // **
'--calcite-ui-border-2': '#d4d4d4',
'--calcite-ui-border-3': '#dfdfdf',
'--calcite-ui-border-input': '#949494'
};

export const redTheme = {
'--calcite-ui-brand': '#9e0000',
'--calcite-ui-brand-hover': '#850000',
'--calcite-ui-brand-press': '#850000',
'--calcite-ui-info': '#00619b',
'--calcite-ui-success': '#35ac46',
'--calcite-ui-warning': '#edd317',
'--calcite-ui-danger': '#d83020',
'--calcite-ui-danger-hover': '#a82b1e',
'--calcite-ui-danger-press': '#7c1d13',
'--calcite-ui-background': '#f3f7f3', // **
'--calcite-ui-foreground-1': '#ecbbbb',
'--calcite-ui-foreground-2': '#f3f3f3',
'--calcite-ui-foreground-3': '#eaeaea',
'--calcite-ui-text-1': '#841a1a', // **
'--calcite-ui-text-2': '#aa2222', // **
'--calcite-ui-text-3': '#d52a2a', // **
'--calcite-ui-text-inverse': '#f3f7f3', // **
'--calcite-ui-text-link': '#367d3e', // **
'--calcite-ui-border-1': '#cacaca', // **
'--calcite-ui-border-2': '#d4d4d4',
'--calcite-ui-border-3': '#dfdfdf',
'--calcite-ui-border-input': '#949494'
};
7 changes: 7 additions & 0 deletions .storybook/decorators/direction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const withDirection = (Story,context) => {
return (
`<div class="dir-el" dir="${context.globals.dir}">
${Story(context)}
</div>`
)
}
7 changes: 7 additions & 0 deletions .storybook/decorators/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const withLocale = (Story,context) => {
return (
`<div class="lang-el" lang="${context.globals.locale}">
${Story(context)}
</div>`
)
}
12 changes: 12 additions & 0 deletions .storybook/decorators/withRenderCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import addons from "@storybook/addons";
import { STORY_RENDERED } from "@storybook/core-events"

export const withRenderCallback = (selector, callback) => {
return (Story, context) => {
const { args } = context;
addons.getChannel().once(STORY_RENDERED, () => {
callback(document.querySelector(selector), { args });
});
return Story();
};
};
21 changes: 21 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
stories: [
"../src/**/*.stories.@(mdx|ts|tsx)",
"../doc/**/*.stories.mdx"
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@pxtrn/storybook-addon-docs-stencil",
//"@storybook/addon-controls", // recommended replacement for @storybook/addon-knobs
"./addons/theme/register",
"@storybook/addon-a11y",
"@storybook/addon-knobs" // we don't use knobs but calcite-components does
],
refs: {
calciteComponents: {
title: "Calcite Components",
url: "https://esri.github.io/calcite-components"
},
},
}
1 change: 1 addition & 0 deletions .storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel='icon' href='solutions-icon.svg'/>
8 changes: 8 additions & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { addons } from '@storybook/addons';
import theme from './theme';

// this is the storybook theme
addons.setConfig({
theme,
enableShortcuts: false
});
15 changes: 15 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<meta name="solutions-components-assets-url" content="solutions-components/assets/i18n">
<style>
html,
body,
#root,
.lang-el,
.dir-el {
height: 100%;
}
</style>
<link
rel="stylesheet"
type="text/css"
href="https://unpkg.com/@esri/[email protected]/dist/calcite/calcite.css"
/>
81 changes: 81 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { withDirection } from './decorators/direction';
import { withLocale } from './decorators/locale';
import { withTheme } from './addons/theme/apply-theme';
import { defineCustomElements } from '../dist/esm/loader';
import { extractArgTypes, extractComponentDescription, setStencilDocJson } from '@pxtrn/storybook-addon-docs-stencil';
import docJson from '../dist/docs.json';
import { defaultTheme } from './addons/theme/themes';

// get the URL that the application is deployed to
// when running locally or when deployed to gh-pages
const url = new URL(document.currentScript.src);
url.pathname = url.pathname.startsWith('/solutions-components/') ? '/solutions-components/' : '/';

// initialize hub components
defineCustomElements(window, {
// NOTE: in this case /solutions-components refers to the subfolder
// where the assets are output during the build
// see this comment on why it's not just solutions-components
// https://github.com/ArcGIS/opendata-ui/blob/c0ead8e71203bb855202310fcda13fdc00631e6d/packages/opendata-ui/app/initializers/solutions-components.js#L7-L11
resourcesUrl: `${url.href}solutions-components/assets`
});

setStencilDocJson(docJson);

export const parameters = {
options: {
storySort: {
order: [
'Guides',
['License'],
'Components'
]
},
},
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
hideNoControlsWarning: true,
matchers: {
color: /(background|fill|color)$/i,
date: /Date$/,
},
},
docs: {
extractArgTypes,
extractComponentDescription,
},
}

export const globalTypes = {
dir: {
name: 'Direction',
description: 'Direction css property on ancestor element',
defaultValue: 'ltr',
toolbar: {
icon: 'transfer',
items: ['ltr', 'rtl'],
showName: true,
},
},
locale: {
name: 'Locale',
description: 'Internationalization locale',
defaultValue: 'en',
toolbar: {
icon: 'globe',
items: [
{ value: 'en', right: '🇺🇸', title: 'English' },
{ value: 'fr', right: '🇫🇷', title: 'Français' },
{ value: 'es', right: '🇪🇸', title: 'Español' },
{ value: 'zh-cn', right: '🇨🇳', title: '中文' },
{ value: 'ko', right: '🇰🇷', title: '한국어' },
],
showName: true,
},
},
currentTheme: {
defaultValue: defaultTheme
}
};

export const decorators = [ withDirection, withLocale, withTheme ];
7 changes: 7 additions & 0 deletions .storybook/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { create } from '@storybook/theming';

export default create({
base: 'light',
brandTitle: 'Solutions Components',
brandImage: 'solutions-icon.svg',
});
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

## [0.0.10] - December 16th 2021

* Fixed distribution

## [0.0.9] - December 15th 2021

* Updated configuration of `solution-configuration`
Expand All @@ -14,5 +18,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

[0.0.2]: https://github.com/Esri/solution.js/compare/3dc2e8e89cd42b447420b2c0cba988738d0c7195...v0.0.2 "v0.0.2"
[0.0.9]: https://github.com/Esri/solution.js/compare/v0.0.2...v0.0.9 "v0.0.9"
[Unreleased]: https://github.com/Esri/solution.js/compare/v0.0.5...HEAD "Unreleased Changes"
[0.0.10]: https://github.com/Esri/solution.js/compare/v0.0.9...v0.0.10 "v0.0.10"
[Unreleased]: https://github.com/Esri/solution.js/compare/v0.0.10...HEAD "Unreleased Changes"

Loading