Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.web.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { createMuiTheme } from '@material-ui/core/styles';
  2. import { Theme } from './types';
  3. import { createColorTokens } from './utils';
  4. interface ThemeProps {
  5. breakpoints: Object;
  6. colorMap: Object;
  7. colors: Object;
  8. font: Object;
  9. shape: Object;
  10. spacing: Array<number>;
  11. typography: Object;
  12. }
  13. /**
  14. * Creates a MUI theme based on local UI tokens.
  15. *
  16. * @param {Object} arg - The ui tokens.
  17. * @returns {Object}
  18. */
  19. export function createWebTheme({ font, colors, colorMap, shape, spacing, typography, breakpoints }: ThemeProps): Theme {
  20. return createMuiTheme({
  21. props: {
  22. // disable ripple effect on buttons globally
  23. MuiButtonBase: {
  24. disableRipple: true
  25. }
  26. },
  27. // use token spacing array
  28. spacing
  29. }, {
  30. palette: createColorTokens(colorMap, colors),
  31. shape,
  32. typography: {
  33. font,
  34. ...typography
  35. },
  36. breakpoints
  37. }) as unknown as Theme;
  38. }
  39. /**
  40. * Formats the common styles object to be interpreted as proper CSS.
  41. *
  42. * @param {Object} stylesObj - The styles object.
  43. * @returns {Object}
  44. */
  45. export function formatCommonClasses(stylesObj: Object) {
  46. const formatted: any = {};
  47. for (const [ key, value ] of Object.entries(stylesObj)) {
  48. formatted[`.${key}`] = value;
  49. }
  50. return formatted;
  51. }