Skip to content

Commit

Permalink
move themesd
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraVieira committed Jan 13, 2020
1 parent 81b8988 commit 61b0191
Show file tree
Hide file tree
Showing 18 changed files with 17,508 additions and 52 deletions.
35 changes: 15 additions & 20 deletions packages/components/.storybook/config.tsx
Expand Up @@ -56,26 +56,21 @@ export const withGlobal = (cb: any) => (
</>
);

export const getAllThemes = async () => {
const allThemes = await getThemes();
return allThemes.map(b => makeTheme(b, b.name));
};

getAllThemes().then((themes: any) => {
const blackCodesandbox = themes.find(
theme => theme.name === 'CodeSandbox Black'
);
const allThemes = getThemes();
const vsCodeThemes = allThemes.map(b => makeTheme(b, b.name));
const blackCodesandbox = vsCodeThemes.find(
theme => theme.name === 'CodeSandbox Black'
);

const rest = themes.filter(theme => theme.name !== 'CodeSandbox Black');
addDecorator(withGlobal);
addDecorator(withThemesProvider([blackCodesandbox, ...rest]));
addDecorator(withA11y);
addDecorator(withKnobs);
addParameters({ viewport: { viewports } });
const rest = vsCodeThemes.filter(theme => theme.name !== 'CodeSandbox Black');
addDecorator(withGlobal);
addDecorator(withThemesProvider([blackCodesandbox, ...rest]));
addDecorator(withA11y);
addDecorator(withKnobs);
addParameters({ viewport: { viewports } });

// Option defaults.
addParameters({ options: { theme: themes.dark } });
// Option defaults.
addParameters({ options: { theme: themes.dark } });

// automatically import all files ending in *.stories.js
configure(require.context('../src', true, /\.stories\.tsx$/), module);
});
// automatically import all files ending in *.stories.js
configure(require.context('../src', true, /\.stories\.tsx$/), module);
39 changes: 7 additions & 32 deletions packages/components/src/components/ThemeProvider/index.tsx
Expand Up @@ -8,41 +8,16 @@
import dot from 'dot-object';
import deepmerge from 'deepmerge';
import designLanguage from '@codesandbox/common/lib/design-language';
import VSCodeThemes from '@codesandbox/common/lib/themes/';
import VSCodeThemes from '../../themes';
import polyfillTheme from '../../utils/polyfill-theme';

export const getThemes = async () => {
// eslint-disable-next-line consistent-return
const results = VSCodeThemes.map(async theme => {
if (theme.content) {
return {
name: theme.name,
...theme.content,
};
}
if (theme.get) {
const t = await theme.get();
return {
name: theme.name,
...t,
};
}
if (theme.url) {
try {
const t = await fetch(theme.url).then(a => a.json());
return {
name: theme.name,
...t,
};
} catch {
return null;
}
}
});
export const getThemes = () => {
const results = VSCodeThemes.map(theme => ({
name: theme.name,
...theme.content,
}));

const values = await Promise.all(results);

return values.filter(a => a);
return results.filter(a => a);
};
export const makeTheme = (vsCodeTheme = { colors: {} }, name: string) => {
// black is the default, it would be helpful to use storybook-addon-themes
Expand Down

0 comments on commit 61b0191

Please sign in to comment.