components.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { Shadow, ThemeColorsOptions } from "@mui/material";
  2. import { Components } from "@mui/material/styles/components";
  3. import { TypographyOptions } from "@mui/material/styles/createTypography";
  4. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  5. export const getComponents = (
  6. colors: ThemeColorsOptions,
  7. typography: TypographyOptions,
  8. ): Components => ({
  9. MuiCssBaseline: {
  10. styleOverrides: {
  11. body: {
  12. fontFamily: typography.fontFamily,
  13. letterSpacing: "-0.011em",
  14. },
  15. strong: { fontWeight: 700 },
  16. },
  17. },
  18. MuiTypography: {
  19. defaultProps: {
  20. variant: "body",
  21. variantMapping: {
  22. large: "p",
  23. body: "p",
  24. small: "p",
  25. mini: "p",
  26. tiny: "p",
  27. },
  28. },
  29. },
  30. MuiDrawer: {
  31. styleOverrides: {
  32. root: {
  33. ".MuiBackdrop-root": {
  34. backgroundColor: colors.backdrop.faint,
  35. },
  36. },
  37. },
  38. },
  39. MuiDialog: {
  40. styleOverrides: {
  41. root: {
  42. ".MuiBackdrop-root": {
  43. backgroundColor: colors.backdrop.faint,
  44. },
  45. "& .MuiDialog-paper": {
  46. filter: getDropShadowStyle(colors.shadows.float),
  47. },
  48. "& .MuiDialogTitle-root": {
  49. padding: "16px",
  50. },
  51. "& .MuiDialogContent-root": {
  52. padding: "16px",
  53. overflowY: "overlay",
  54. },
  55. "& .MuiDialogActions-root": {
  56. padding: "16px",
  57. },
  58. ".MuiDialogTitle-root + .MuiDialogContent-root": {
  59. paddingTop: "16px",
  60. },
  61. },
  62. },
  63. defaultProps: {
  64. fullWidth: true,
  65. maxWidth: "sm",
  66. },
  67. },
  68. MuiPaper: {
  69. styleOverrides: { root: { backgroundImage: "none" } },
  70. },
  71. MuiLink: {
  72. defaultProps: {
  73. color: colors.accent.A500,
  74. underline: "none",
  75. },
  76. styleOverrides: {
  77. root: {
  78. "&:hover": {
  79. underline: "always",
  80. color: colors.accent.A500,
  81. },
  82. },
  83. },
  84. },
  85. MuiButton: {
  86. defaultProps: {
  87. variant: "contained",
  88. },
  89. styleOverrides: {
  90. root: {
  91. padding: "12px 16px",
  92. borderRadius: "4px",
  93. textTransform: "none",
  94. fontWeight: "bold",
  95. fontSize: typography.body.fontSize,
  96. lineHeight: typography.body.lineHeight,
  97. },
  98. startIcon: {
  99. marginRight: "12px",
  100. "&& >svg": {
  101. fontSize: "20px",
  102. },
  103. },
  104. endIcon: {
  105. marginLeft: "12px",
  106. "&& >svg": {
  107. fontSize: "20px",
  108. },
  109. },
  110. sizeLarge: {
  111. width: "100%",
  112. },
  113. },
  114. },
  115. MuiInputBase: {
  116. styleOverrides: {
  117. formControl: {
  118. borderRadius: "8px",
  119. "::before": {
  120. borderBottom: "none !important",
  121. },
  122. },
  123. },
  124. },
  125. MuiFilledInput: {
  126. styleOverrides: {
  127. input: {
  128. "&:autofill": {
  129. boxShadow: "#c7fd4f",
  130. },
  131. },
  132. },
  133. },
  134. MuiTextField: {
  135. defaultProps: {
  136. variant: "filled",
  137. margin: "dense",
  138. },
  139. styleOverrides: {
  140. root: {
  141. "& .MuiInputAdornment-root": {
  142. marginRight: "8px",
  143. },
  144. },
  145. },
  146. },
  147. MuiSvgIcon: {
  148. styleOverrides: {
  149. root: ({ ownerState }) => ({
  150. ...getIconColor(ownerState, colors),
  151. }),
  152. },
  153. },
  154. MuiIconButton: {
  155. styleOverrides: {
  156. root: ({ ownerState }) => ({
  157. ...getIconColor(ownerState, colors),
  158. padding: "12px",
  159. }),
  160. },
  161. },
  162. MuiSnackbar: {
  163. styleOverrides: {
  164. root: {
  165. borderRadius: "8px",
  166. },
  167. },
  168. },
  169. MuiModal: {
  170. styleOverrides: {
  171. root: {
  172. '&:has(> div[style*="opacity: 0"])': {
  173. pointerEvents: "none",
  174. },
  175. },
  176. },
  177. },
  178. MuiMenuItem: {
  179. styleOverrides: {
  180. // don't reduce opacity of disabled items
  181. root: {
  182. "&.Mui-disabled": {
  183. opacity: 1,
  184. },
  185. },
  186. },
  187. },
  188. });
  189. const getDropShadowStyle = (shadows: Shadow[]) => {
  190. return shadows
  191. .map(
  192. (shadow) =>
  193. `drop-shadow(${shadow.x}px ${shadow.y}px ${shadow.blur}px ${shadow.color})`,
  194. )
  195. .join(" ");
  196. };
  197. function getIconColor(ownerState, colors: ThemeColorsOptions) {
  198. switch (ownerState.color) {
  199. case "primary":
  200. return {
  201. color: colors.stroke.base,
  202. };
  203. case "secondary":
  204. return {
  205. color: colors.stroke.muted,
  206. };
  207. }
  208. if (ownerState.disabled) {
  209. return {
  210. color: colors.stroke.faint,
  211. };
  212. }
  213. }