You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @flow
  2. import { createMuiTheme } from '@material-ui/core/styles';
  3. /**
  4. * Creates the color tokens based on the color theme and the association map.
  5. * If a key is not fonund in the association map it defaults to the current value.
  6. *
  7. * @param {Object} colorMap - A map between the token name and the actual color value.
  8. * @param {Object} colors - An object containing all the theme colors.
  9. * @returns {Object}
  10. */
  11. function createColorTokens(colorMap: Object, colors: Object): Object {
  12. return Object.entries(colorMap)
  13. .reduce((result, [ token, value ]) =>
  14. Object.assign(result, { [token]: colors[value] || value }), {});
  15. }
  16. /**
  17. * Creates a MUI theme based on local UI tokens.
  18. *
  19. * @param {Object} arg - The ui tokens.
  20. * @returns {Object}
  21. */
  22. export function createWebTheme({ font, colors, colorMap, shape, spacing, typography }: Object) {
  23. return createMuiTheme({
  24. props: {
  25. // disable ripple effect on buttons globally
  26. MuiButtonBase: {
  27. disableRipple: true
  28. }
  29. },
  30. // use token spacing array
  31. spacing
  32. }, {
  33. palette: createColorTokens(colorMap, colors),
  34. shape,
  35. typography: {
  36. font,
  37. ...typography
  38. }
  39. });
  40. }