Skip to content

Commit 682d31f

Browse files
committed
css variables theming using fe-brary
1 parent a264929 commit 682d31f

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1616
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
1717
const eslintFormatter = require('react-dev-utils/eslintFormatter');
1818
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
19+
const feBrary = require('@domain-group/fe-brary');
1920
const getClientEnvironment = require('./env');
2021
const paths = require('./paths');
2122

@@ -29,6 +30,22 @@ const publicUrl = '';
2930
// Get environment variables to inject into our app.
3031
const env = getClientEnvironment(publicUrl);
3132

33+
const themeVar = process.env.FE_BRARY_THEME || 'domain';
34+
const theme = feBrary.themeVariables[themeVar];
35+
36+
if (!theme) {
37+
throw new Error(
38+
`Unrecognised \`FE_BRARY_THEME\` env var \`${process.env
39+
.FE_BRARY_THEME}\` - must be one of ${JSON.stringify(feBrary.themes)}`
40+
);
41+
}
42+
43+
const postcssCustomPropertiesVariables = Object.values(
44+
theme
45+
).reduce((acc, cssVars) => {
46+
return Object.assign(acc, cssVars);
47+
}, {});
48+
3249
const postCSSLoaderOptions = {
3350
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
3451
plugins: loader => [
@@ -47,6 +64,9 @@ const postCSSLoaderOptions = {
4764
autoprefixer: {
4865
flexbox: 'no-2009',
4966
},
67+
customProperties: {
68+
variables: postcssCustomPropertiesVariables,
69+
},
5070
},
5171
}),
5272
],

packages/react-scripts/scripts/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ module.exports = function(
145145
);
146146
}
147147
devDepArgs.push('@domain-group/fe-co-demo');
148+
devDepArgs.push('@domain-group/fe-brary');
148149

149150
const proc = spawn.sync(command, devDepArgs, { stdio: 'inherit' });
150151
if (proc.status !== 0) {

packages/react-scripts/template/demo/legacy.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@import '@domain-group/fe-brary/fe-brary-theme-domain';
12
@import '@domain-group/fe-co-demo/lib/scss/fe-co-demo';
23

34
html,

packages/react-scripts/template/src/components/example/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
.heading {
2424
composes: shared;
2525
font-size: 30px;
26-
background-color: rgb(14, 168, 0);
27-
color: white;
26+
background-color: var(--brandGreen);
27+
color: var(--white);
2828
text-align: center;
2929
flex-grow: 1;
3030
}

packages/react-scripts/template/src/components/example/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function Example({ isTwoColumn }) {
99
? ` ${styles.isTwoColumn}`
1010
: ''}`}>
1111
<h1 className={styles.heading}>
12-
<code className={styles.code}>fe-co-foobar</code>
12+
fe-co-foobar
1313
</h1>
1414
<div className={styles.content}>
1515
<img src={logo} className={styles.appLogo} alt="logo" />

0 commit comments

Comments
 (0)