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.web.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* eslint-disable @typescript-eslint/naming-convention */
  2. import { adaptV4Theme, createTheme } from '@mui/material/styles';
  3. import { ITypography, IPalette as Palette1 } from '../ui/types';
  4. import { createColorTokens } from './utils';
  5. declare module '@mui/material/styles' {
  6. // eslint-disable-next-line @typescript-eslint/no-empty-interface
  7. interface Palette extends Palette1 {}
  8. // eslint-disable-next-line @typescript-eslint/no-empty-interface
  9. interface TypographyVariants extends ITypography {}
  10. }
  11. interface ThemeProps {
  12. breakpoints: Object;
  13. colorMap: Object;
  14. colors: Object;
  15. font: Object;
  16. shape: Object;
  17. spacing: Array<number>;
  18. typography: Object;
  19. }
  20. /**
  21. * Creates a MUI theme based on local UI tokens.
  22. *
  23. * @param {Object} arg - The ui tokens.
  24. * @returns {Object}
  25. */
  26. export function createWebTheme({ font, colors, colorMap, shape, spacing, typography, breakpoints }: ThemeProps) {
  27. return createTheme(adaptV4Theme({
  28. spacing,
  29. palette: createColorTokens(colorMap, colors),
  30. shape,
  31. // @ts-ignore
  32. typography: {
  33. // @ts-ignore
  34. font,
  35. ...typography
  36. },
  37. breakpoints
  38. }));
  39. }
  40. /**
  41. * Find the first styled ancestor component of an element.
  42. *
  43. * @param {HTMLElement|null} target - Element to look up.
  44. * @param {string} cssClass - Styled component reference.
  45. * @returns {HTMLElement|null} Ancestor.
  46. */
  47. export const findAncestorByClass = (target: HTMLElement | null, cssClass: string): HTMLElement | null => {
  48. if (!target || target.classList.contains(cssClass)) {
  49. return target;
  50. }
  51. return findAncestorByClass(target.parentElement, cssClass);
  52. };