Skip to content

Commit

Permalink
Merge pull request #594 from shopgate/PWA-1787-theme-config
Browse files Browse the repository at this point in the history
The theme's color variables and global font variables are now configurable via the New Merchant Admin
  • Loading branch information
alexbridge committed Apr 2, 2019
2 parents 88817de + 79a6ba5 commit 4be468c
Show file tree
Hide file tree
Showing 207 changed files with 713 additions and 587 deletions.
16 changes: 4 additions & 12 deletions libraries/common/helpers/config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { themeConfig as mock } from './mock';
import pck from './../../package';
import { getThemeConfig } from './theme';

/**
* Provides a default app config as a fallback.
* @type {Object}
Expand All @@ -25,6 +26,7 @@ const defaultAppConfig = {
showGmdMenuSubHeaders: false,
benchmark: false,
sentry: {},
theme: {},
cartShippingHideAnonymousLegacy: null,
cartShippingTextAnonymousLegacy: null,
cart: {},
Expand All @@ -38,16 +40,6 @@ export const themeName = process.env.THEME || 'theme';
*/
export const pckVersion = pck.version;

/**
* Provides a default theme config as a fallback.
* @type {Object}
*/
const defaultThemeConfig = {
font: {},
colors: {},
variables: {},
};

/**
* Provides a default components config as a fallback.
* @type {{portals: {}, widgets: {}}}
Expand Down Expand Up @@ -76,7 +68,7 @@ export const componentsConfig = {
* The theme configuration.
* @typedef {Object}
*/
export const themeConfig = process.env.NODE_ENV === 'test' ? mock : (process.env.THEME_CONFIG || defaultThemeConfig);
export const themeConfig = getThemeConfig(appConfig);

/**
* The shop number.
Expand Down
33 changes: 33 additions & 0 deletions libraries/common/helpers/config/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { themeConfig } from './mock';

/**
* Provides a default theme config as a fallback.
* @type {Object}
*/
const defaultConfig = {
font: {},
colors: {},
variables: {},
};

/**
* Builds the theme config.
* @param {Object} appConfig The app config.
* @returns {Object}
*/
export function getThemeConfig({ theme: { styles: { globals = {} } = {} } = {} } = {}) {
if (process.env.NODE_ENV === 'test') {
return themeConfig;
}

const oldTheme = process.env.THEME_CONFIG || defaultConfig;

return {
font: globals.font,
colors: globals.colors,
variables: {
...(oldTheme.variables || {}),
materialShadow: globals.variables.baseShadow,
},
};
}
8 changes: 8 additions & 0 deletions libraries/common/styles/reset/root.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { css } from 'glamor';
import { themeConfig } from '../../helpers/config';

const { font } = themeConfig;

css.global('*, *:before, *:after', {
boxSizing: 'border-box',
Expand All @@ -20,8 +23,13 @@ css.global('html', {
});

css.global('body', {
font: `${font.rootSize}px/${font.lineHeight} ${font.family}`,
overflow: 'auto',
margin: 0,
WebkitOverflowScrolling: 'touch',
WebkitUserSelect: 'none',
});

css.global('[data-pattern]', {
height: '100% !important',
});
3 changes: 1 addition & 2 deletions themes/theme-gmd/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"Components": "./components",
"Config": "./config",
"Extensions": "./extensions",
"Pages": "./pages",
"Styles": "./styles"
"Pages": "./pages"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

export default css({
position: 'absolute',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
APP_BAR_CART_BUTTON_BEFORE,
APP_BAR_CART_BUTTON_AFTER,
} from '@shopgate/pwa-common/constants/Portals';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import Badge from '../CartBadge';
import connect from './connector';
import styles from './style';
import transition from './transition';

const { colors } = themeConfig;

/**
* The CartButton component.
*/
Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/CategoryList/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

export default css({
background: colors.light,
Expand Down
6 changes: 4 additions & 2 deletions themes/theme-gmd/components/ChipLayout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import I18n from '@shopgate/pwa-common/components/I18n';
import RippleButton from '@shopgate/pwa-ui-shared/RippleButton';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import styles from './style';

const { variables } = themeConfig;

/**
* The height of one row.
* @type {number}
Expand Down Expand Up @@ -34,7 +36,7 @@ class ChipLayout extends Component {

static defaultProps = {
children: null,
handleMoreButton: () => {},
handleMoreButton: () => { },
invertMoreButton: false,
maxRows: 2,
moreLabel: 'more',
Expand Down
5 changes: 3 additions & 2 deletions themes/theme-gmd/components/ChipLayout/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

/**
* Returns the styling based on the container height.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

const button = css({
color: 'inherit',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

export default css({
overflow: 'auto',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

const button = css({
color: 'inherit',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

const button = css({
color: 'inherit',
Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/FilterBar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import Content from './components/Content';
import styles from './style';

const { colors } = themeConfig;

/**
* The FilterBar component.
*/
Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/Headline/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

const headline = css({
fontSize: 18,
Expand Down
5 changes: 3 additions & 2 deletions themes/theme-gmd/components/List/components/Item/style.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import { IMAGE_SPACE } from '../../style';

const { colors, variables } = themeConfig;

const disabled = css({
color: colors.shade5,
}).toString();
Expand Down
5 changes: 3 additions & 2 deletions themes/theme-gmd/components/List/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables, colors } = themeConfig;

export const IMAGE_SPACE = 72;

Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/Logo/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

const container = css({
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { onlyUpdateForKeys } from 'recompose';
import I18n from '@shopgate/pwa-common/components/I18n';
import { NavDrawer } from '@shopgate/pwa-ui-material';
import AccountBoxIcon from '@shopgate/pwa-ui-shared/icons/AccountBoxIcon';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import connect from './connector';
import styles from './style';

const { colors } = themeConfig;

const enhance = onlyUpdateForKeys(['email']);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

const container = css({
color: colors.accentContrast,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

const size = variables.gap.big * 1.125;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

export default css({
background: colors.primary,
Expand Down
5 changes: 3 additions & 2 deletions themes/theme-gmd/components/Picker/components/Button/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

const buttonDefaults = {
display: 'block',
Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/Picker/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { variables } = themeConfig;

export default css({
display: 'flex',
Expand Down
4 changes: 3 additions & 1 deletion themes/theme-gmd/components/ProductCard/style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

const container = css({
position: 'relative',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

export default css({
position: 'relative',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

export default css({
paddingBottom: 2,
Expand Down
6 changes: 4 additions & 2 deletions themes/theme-gmd/components/ProductImage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import Image from '@shopgate/pwa-common/components/Image';
import Placeholder from '@shopgate/pwa-ui-shared/icons/PlaceholderIcon';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
import styles from './style';

const { colors } = themeConfig;

/**
* The product image component.
* This component will behave like the core Image component with the additional
Expand Down Expand Up @@ -37,7 +39,7 @@ class ProductImage extends Component {
animating: true,
className: null,
forcePlaceholder: false,
highestResolutionLoaded: () => {},
highestResolutionLoaded: () => { },
ratio: null,
resolutions: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import variables from 'Styles/variables';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors, variables } = themeConfig;

const elementPadding = variables.gap.big / 2;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { css } from 'glamor';
import colors from 'Styles/colors';
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const { colors } = themeConfig;

const list = css({
background: colors.background,
Expand Down
Loading

0 comments on commit 4be468c

Please sign in to comment.