@mitodl/smoot-design 0.0.0-7bc0c0f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +31 -0
  3. package/dist/bundles/remoteTutorDrawer.es.js +38347 -0
  4. package/dist/bundles/remoteTutorDrawer.umd.js +207 -0
  5. package/dist/cjs/ai.d.ts +3 -0
  6. package/dist/cjs/ai.js +5 -0
  7. package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
  8. package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.js +87 -0
  9. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +57 -0
  10. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +276 -0
  11. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +16 -0
  12. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +283 -0
  13. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
  14. package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +241 -0
  15. package/dist/cjs/bundles/remoteTutorDrawer.d.ts +7 -0
  16. package/dist/cjs/bundles/remoteTutorDrawer.js +40 -0
  17. package/dist/cjs/components/AiChat/AiChat.d.ts +5 -0
  18. package/dist/cjs/components/AiChat/AiChat.js +247 -0
  19. package/dist/cjs/components/AiChat/AiChat.stories.d.ts +21 -0
  20. package/dist/cjs/components/AiChat/AiChat.stories.js +243 -0
  21. package/dist/cjs/components/AiChat/AiChat.test.d.ts +1 -0
  22. package/dist/cjs/components/AiChat/AiChat.test.js +211 -0
  23. package/dist/cjs/components/AiChat/ChatTitle.d.ts +8 -0
  24. package/dist/cjs/components/AiChat/ChatTitle.js +43 -0
  25. package/dist/cjs/components/AiChat/EntryScreen.d.ts +11 -0
  26. package/dist/cjs/components/AiChat/EntryScreen.js +123 -0
  27. package/dist/cjs/components/AiChat/TimLogo.d.ts +5 -0
  28. package/dist/cjs/components/AiChat/TimLogo.js +15 -0
  29. package/dist/cjs/components/AiChat/test-utils/api.d.ts +2 -0
  30. package/dist/cjs/components/AiChat/test-utils/api.js +125 -0
  31. package/dist/cjs/components/AiChat/types.d.ts +82 -0
  32. package/dist/cjs/components/AiChat/types.js +3 -0
  33. package/dist/cjs/components/AiChat/utils.d.ts +9 -0
  34. package/dist/cjs/components/AiChat/utils.js +41 -0
  35. package/dist/cjs/components/Alert/Alert.d.ts +15 -0
  36. package/dist/cjs/components/Alert/Alert.js +62 -0
  37. package/dist/cjs/components/Alert/Alert.stories.d.ts +8 -0
  38. package/dist/cjs/components/Alert/Alert.stories.js +53 -0
  39. package/dist/cjs/components/Button/ActionButton.d.ts +30 -0
  40. package/dist/cjs/components/Button/ActionButton.js +73 -0
  41. package/dist/cjs/components/Button/ActionButton.stories.d.ts +15 -0
  42. package/dist/cjs/components/Button/ActionButton.stories.js +113 -0
  43. package/dist/cjs/components/Button/Button.d.ts +54 -0
  44. package/dist/cjs/components/Button/Button.js +240 -0
  45. package/dist/cjs/components/Button/Button.stories.d.ts +17 -0
  46. package/dist/cjs/components/Button/Button.stories.js +135 -0
  47. package/dist/cjs/components/Button/Button.test.d.ts +1 -0
  48. package/dist/cjs/components/Button/Button.test.js +46 -0
  49. package/dist/cjs/components/ImageAdapter/ImageAdapter.d.ts +23 -0
  50. package/dist/cjs/components/ImageAdapter/ImageAdapter.js +30 -0
  51. package/dist/cjs/components/Input/Input.d.ts +116 -0
  52. package/dist/cjs/components/Input/Input.js +237 -0
  53. package/dist/cjs/components/Input/Input.stories.d.ts +19 -0
  54. package/dist/cjs/components/Input/Input.stories.js +135 -0
  55. package/dist/cjs/components/Input/Input.test.d.ts +1 -0
  56. package/dist/cjs/components/Input/Input.test.js +32 -0
  57. package/dist/cjs/components/LinkAdapter/LinkAdapter.d.ts +23 -0
  58. package/dist/cjs/components/LinkAdapter/LinkAdapter.js +34 -0
  59. package/dist/cjs/components/ScrollSnap/ScrollSnap.d.ts +19 -0
  60. package/dist/cjs/components/ScrollSnap/ScrollSnap.js +59 -0
  61. package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
  62. package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.js +43 -0
  63. package/dist/cjs/components/ScrollSnap/useScrollSnap.d.ts +6 -0
  64. package/dist/cjs/components/ScrollSnap/useScrollSnap.js +36 -0
  65. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
  66. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.js +43 -0
  67. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
  68. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.js +44 -0
  69. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
  70. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.js +62 -0
  71. package/dist/cjs/components/TabButtons/TabButtonList.d.ts +25 -0
  72. package/dist/cjs/components/TabButtons/TabButtonList.js +97 -0
  73. package/dist/cjs/components/TabButtons/TabButtonList.stories.d.ts +24 -0
  74. package/dist/cjs/components/TabButtons/TabButtonList.stories.js +139 -0
  75. package/dist/cjs/components/TextField/TextField.d.ts +29 -0
  76. package/dist/cjs/components/TextField/TextField.js +33 -0
  77. package/dist/cjs/components/TextField/TextField.stories.d.ts +10 -0
  78. package/dist/cjs/components/TextField/TextField.stories.js +136 -0
  79. package/dist/cjs/components/TextField/TextField.test.d.ts +1 -0
  80. package/dist/cjs/components/TextField/TextField.test.js +77 -0
  81. package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +21 -0
  82. package/dist/cjs/components/ThemeProvider/ThemeProvider.js +86 -0
  83. package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
  84. package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.js +102 -0
  85. package/dist/cjs/components/ThemeProvider/Typography.stories.d.ts +39 -0
  86. package/dist/cjs/components/ThemeProvider/Typography.stories.js +65 -0
  87. package/dist/cjs/components/ThemeProvider/breakpoints.d.ts +4 -0
  88. package/dist/cjs/components/ThemeProvider/breakpoints.js +19 -0
  89. package/dist/cjs/components/ThemeProvider/buttons.d.ts +7 -0
  90. package/dist/cjs/components/ThemeProvider/buttons.js +20 -0
  91. package/dist/cjs/components/ThemeProvider/chips.d.ts +3 -0
  92. package/dist/cjs/components/ThemeProvider/chips.js +154 -0
  93. package/dist/cjs/components/ThemeProvider/colors.d.ts +32 -0
  94. package/dist/cjs/components/ThemeProvider/colors.js +35 -0
  95. package/dist/cjs/components/ThemeProvider/typography.d.ts +18 -0
  96. package/dist/cjs/components/ThemeProvider/typography.js +173 -0
  97. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
  98. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js +33 -0
  99. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
  100. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.js +13 -0
  101. package/dist/cjs/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
  102. package/dist/cjs/components/internal/FormHelpers/FormHelpers.js +78 -0
  103. package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
  104. package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.js +93 -0
  105. package/dist/cjs/index.d.ts +16 -0
  106. package/dist/cjs/index.js +30 -0
  107. package/dist/cjs/jest-setup.d.ts +1 -0
  108. package/dist/cjs/jest-setup.js +18 -0
  109. package/dist/cjs/jsdom-extended.d.ts +6 -0
  110. package/dist/cjs/jsdom-extended.js +14 -0
  111. package/dist/cjs/story-utils/index.d.ts +6 -0
  112. package/dist/cjs/story-utils/index.js +17 -0
  113. package/dist/cjs/utils/composeRefs.d.ts +7 -0
  114. package/dist/cjs/utils/composeRefs.js +20 -0
  115. package/dist/cjs/utils/composeRefs.test.d.ts +1 -0
  116. package/dist/cjs/utils/composeRefs.test.js +19 -0
  117. package/dist/cjs/utils/useDevCheckStable.d.ts +8 -0
  118. package/dist/cjs/utils/useDevCheckStable.js +29 -0
  119. package/dist/cjs/utils/useInterval.d.ts +7 -0
  120. package/dist/cjs/utils/useInterval.js +25 -0
  121. package/dist/esm/ai.d.ts +3 -0
  122. package/dist/esm/ai.js +1 -0
  123. package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
  124. package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.js +83 -0
  125. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +57 -0
  126. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +273 -0
  127. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +16 -0
  128. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +280 -0
  129. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
  130. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +239 -0
  131. package/dist/esm/bundles/remoteTutorDrawer.d.ts +7 -0
  132. package/dist/esm/bundles/remoteTutorDrawer.js +37 -0
  133. package/dist/esm/components/AiChat/AiChat.d.ts +5 -0
  134. package/dist/esm/components/AiChat/AiChat.js +244 -0
  135. package/dist/esm/components/AiChat/AiChat.stories.d.ts +21 -0
  136. package/dist/esm/components/AiChat/AiChat.stories.js +240 -0
  137. package/dist/esm/components/AiChat/AiChat.test.d.ts +1 -0
  138. package/dist/esm/components/AiChat/AiChat.test.js +209 -0
  139. package/dist/esm/components/AiChat/ChatTitle.d.ts +8 -0
  140. package/dist/esm/components/AiChat/ChatTitle.js +40 -0
  141. package/dist/esm/components/AiChat/EntryScreen.d.ts +11 -0
  142. package/dist/esm/components/AiChat/EntryScreen.js +120 -0
  143. package/dist/esm/components/AiChat/TimLogo.d.ts +5 -0
  144. package/dist/esm/components/AiChat/TimLogo.js +13 -0
  145. package/dist/esm/components/AiChat/test-utils/api.d.ts +2 -0
  146. package/dist/esm/components/AiChat/test-utils/api.js +122 -0
  147. package/dist/esm/components/AiChat/types.d.ts +82 -0
  148. package/dist/esm/components/AiChat/types.js +2 -0
  149. package/dist/esm/components/AiChat/utils.d.ts +9 -0
  150. package/dist/esm/components/AiChat/utils.js +38 -0
  151. package/dist/esm/components/Alert/Alert.d.ts +15 -0
  152. package/dist/esm/components/Alert/Alert.js +59 -0
  153. package/dist/esm/components/Alert/Alert.stories.d.ts +8 -0
  154. package/dist/esm/components/Alert/Alert.stories.js +50 -0
  155. package/dist/esm/components/Button/ActionButton.d.ts +30 -0
  156. package/dist/esm/components/Button/ActionButton.js +68 -0
  157. package/dist/esm/components/Button/ActionButton.stories.d.ts +15 -0
  158. package/dist/esm/components/Button/ActionButton.stories.js +110 -0
  159. package/dist/esm/components/Button/Button.d.ts +54 -0
  160. package/dist/esm/components/Button/Button.js +232 -0
  161. package/dist/esm/components/Button/Button.stories.d.ts +17 -0
  162. package/dist/esm/components/Button/Button.stories.js +132 -0
  163. package/dist/esm/components/Button/Button.test.d.ts +1 -0
  164. package/dist/esm/components/Button/Button.test.js +44 -0
  165. package/dist/esm/components/ImageAdapter/ImageAdapter.d.ts +23 -0
  166. package/dist/esm/components/ImageAdapter/ImageAdapter.js +27 -0
  167. package/dist/esm/components/Input/Input.d.ts +116 -0
  168. package/dist/esm/components/Input/Input.js +232 -0
  169. package/dist/esm/components/Input/Input.stories.d.ts +19 -0
  170. package/dist/esm/components/Input/Input.stories.js +132 -0
  171. package/dist/esm/components/Input/Input.test.d.ts +1 -0
  172. package/dist/esm/components/Input/Input.test.js +30 -0
  173. package/dist/esm/components/LinkAdapter/LinkAdapter.d.ts +23 -0
  174. package/dist/esm/components/LinkAdapter/LinkAdapter.js +31 -0
  175. package/dist/esm/components/ScrollSnap/ScrollSnap.d.ts +19 -0
  176. package/dist/esm/components/ScrollSnap/ScrollSnap.js +56 -0
  177. package/dist/esm/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
  178. package/dist/esm/components/ScrollSnap/ScrollSnap.stories.js +40 -0
  179. package/dist/esm/components/ScrollSnap/useScrollSnap.d.ts +6 -0
  180. package/dist/esm/components/ScrollSnap/useScrollSnap.js +33 -0
  181. package/dist/esm/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
  182. package/dist/esm/components/SrAnnouncer/SrAnnouncer.js +40 -0
  183. package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
  184. package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.js +41 -0
  185. package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
  186. package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.js +60 -0
  187. package/dist/esm/components/TabButtons/TabButtonList.d.ts +25 -0
  188. package/dist/esm/components/TabButtons/TabButtonList.js +92 -0
  189. package/dist/esm/components/TabButtons/TabButtonList.stories.d.ts +24 -0
  190. package/dist/esm/components/TabButtons/TabButtonList.stories.js +136 -0
  191. package/dist/esm/components/TextField/TextField.d.ts +29 -0
  192. package/dist/esm/components/TextField/TextField.js +30 -0
  193. package/dist/esm/components/TextField/TextField.stories.d.ts +10 -0
  194. package/dist/esm/components/TextField/TextField.stories.js +133 -0
  195. package/dist/esm/components/TextField/TextField.test.d.ts +1 -0
  196. package/dist/esm/components/TextField/TextField.test.js +75 -0
  197. package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +21 -0
  198. package/dist/esm/components/ThemeProvider/ThemeProvider.js +82 -0
  199. package/dist/esm/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
  200. package/dist/esm/components/ThemeProvider/ThemeProvider.stories.js +99 -0
  201. package/dist/esm/components/ThemeProvider/Typography.stories.d.ts +39 -0
  202. package/dist/esm/components/ThemeProvider/Typography.stories.js +62 -0
  203. package/dist/esm/components/ThemeProvider/breakpoints.d.ts +4 -0
  204. package/dist/esm/components/ThemeProvider/breakpoints.js +15 -0
  205. package/dist/esm/components/ThemeProvider/buttons.d.ts +7 -0
  206. package/dist/esm/components/ThemeProvider/buttons.js +17 -0
  207. package/dist/esm/components/ThemeProvider/chips.d.ts +3 -0
  208. package/dist/esm/components/ThemeProvider/chips.js +151 -0
  209. package/dist/esm/components/ThemeProvider/colors.d.ts +32 -0
  210. package/dist/esm/components/ThemeProvider/colors.js +32 -0
  211. package/dist/esm/components/ThemeProvider/typography.d.ts +18 -0
  212. package/dist/esm/components/ThemeProvider/typography.js +167 -0
  213. package/dist/esm/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
  214. package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +30 -0
  215. package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
  216. package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.js +10 -0
  217. package/dist/esm/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
  218. package/dist/esm/components/internal/FormHelpers/FormHelpers.js +73 -0
  219. package/dist/esm/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
  220. package/dist/esm/components/internal/FormHelpers/FormHelpers.test.js +91 -0
  221. package/dist/esm/index.d.ts +16 -0
  222. package/dist/esm/index.js +11 -0
  223. package/dist/esm/jest-setup.d.ts +1 -0
  224. package/dist/esm/jest-setup.js +16 -0
  225. package/dist/esm/jsdom-extended.d.ts +6 -0
  226. package/dist/esm/jsdom-extended.js +12 -0
  227. package/dist/esm/story-utils/index.d.ts +6 -0
  228. package/dist/esm/story-utils/index.js +13 -0
  229. package/dist/esm/utils/composeRefs.d.ts +7 -0
  230. package/dist/esm/utils/composeRefs.js +17 -0
  231. package/dist/esm/utils/composeRefs.test.d.ts +1 -0
  232. package/dist/esm/utils/composeRefs.test.js +17 -0
  233. package/dist/esm/utils/useDevCheckStable.d.ts +8 -0
  234. package/dist/esm/utils/useDevCheckStable.js +26 -0
  235. package/dist/esm/utils/useInterval.d.ts +7 -0
  236. package/dist/esm/utils/useInterval.js +22 -0
  237. package/dist/tsconfig.tsbuildinfo +1 -0
  238. package/dist/type-augmentation/TypescriptDocs.mdx +17 -0
  239. package/dist/type-augmentation/imports.d.ts +3 -0
  240. package/dist/type-augmentation/index.d.ts +3 -0
  241. package/dist/type-augmentation/theme.d.ts +105 -0
  242. package/dist/type-augmentation/typography.d.ts +54 -0
  243. package/package.json +155 -0
@@ -0,0 +1,75 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as React from "react";
11
+ import { render, screen } from "@testing-library/react";
12
+ import user from "@testing-library/user-event";
13
+ import { TextField } from "./TextField";
14
+ import { ThemeProvider } from "../ThemeProvider/ThemeProvider";
15
+ import { faker } from "@faker-js/faker/locale/en";
16
+ describe("TextField", () => {
17
+ const setup = (props) => {
18
+ const defaults = {
19
+ name: "test-name",
20
+ value: "test-value",
21
+ label: "test-label",
22
+ };
23
+ const { rerender: _rerender } = render(React.createElement(TextField, Object.assign({}, defaults, props)), {
24
+ wrapper: ThemeProvider,
25
+ });
26
+ const rerender = (newProps) => {
27
+ _rerender(React.createElement(TextField, Object.assign({}, defaults, newProps)));
28
+ };
29
+ return { rerender };
30
+ };
31
+ it("Has a label", () => {
32
+ const label = faker.lorem.words();
33
+ setup({ label });
34
+ const input = screen.getByRole("textbox", { name: label });
35
+ expect(input).toBeInstanceOf(HTMLInputElement);
36
+ });
37
+ it("Marks the input as required if required", () => {
38
+ const label = faker.lorem.words();
39
+ setup({ label, required: true });
40
+ const input = screen.getByRole("textbox", { name: label });
41
+ expect(input).toBeRequired();
42
+ });
43
+ it("Emits the correct value on change", () => __awaiter(void 0, void 0, void 0, function* () {
44
+ const name = faker.lorem.word();
45
+ const value = faker.lorem.words();
46
+ const onChange = jest.fn();
47
+ setup({ name, onChange, value });
48
+ const input = screen.getByRole("textbox");
49
+ yield user.type(input, "x");
50
+ expect(onChange).toHaveBeenCalledTimes(1);
51
+ expect(onChange).toHaveBeenCalledWith(expect.objectContaining({
52
+ target: expect.objectContaining({ name }),
53
+ }));
54
+ }));
55
+ it("Forwards inputProps and InputProps", () => {
56
+ /**
57
+ * NOTE: This behavior is important for integrating easily with MUI's
58
+ * Autocomplete component
59
+ */
60
+ const inputRef = jest.fn();
61
+ const InputRef = jest.fn();
62
+ setup({
63
+ inputProps: {
64
+ ref: inputRef,
65
+ },
66
+ InputProps: {
67
+ ref: InputRef,
68
+ },
69
+ });
70
+ expect(inputRef).toHaveBeenCalledTimes(1);
71
+ expect(inputRef).toHaveBeenCalledWith(expect.any(HTMLInputElement));
72
+ expect(InputRef).toHaveBeenCalledTimes(1);
73
+ expect(InputRef).toHaveBeenCalledWith(expect.any(HTMLDivElement));
74
+ });
75
+ });
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import type { ThemeOptions, Theme } from "@mui/material/styles";
3
+ /**
4
+ * Create a customized Smoot Design theme for use with `ThemeProvider`.
5
+ *
6
+ * See [ThemeProvider Docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-themeprovider--docs#further-customized-theme-with-createtheme)
7
+ * for more.
8
+ */
9
+ declare const createTheme: (options?: ThemeOptions) => Theme;
10
+ type ThemeProviderProps = {
11
+ children?: React.ReactNode;
12
+ theme?: Theme;
13
+ };
14
+ /**
15
+ *
16
+ * @param param0
17
+ * @returns
18
+ */
19
+ declare const ThemeProvider: React.FC<ThemeProviderProps>;
20
+ export { ThemeProvider, createTheme };
21
+ export type { ThemeProviderProps, Theme };
@@ -0,0 +1,82 @@
1
+ import * as React from "react";
2
+ import { createTheme as muiCreateTheme, ThemeProvider as MuiThemeProvider, } from "@mui/material/styles";
3
+ import * as typography from "./typography";
4
+ import * as buttons from "./buttons";
5
+ import * as chips from "./chips";
6
+ import { colors } from "./colors";
7
+ import deepmerge from "@mui/utils/deepmerge";
8
+ const custom = {
9
+ colors,
10
+ dimensions: {
11
+ headerHeight: "72px",
12
+ headerHeightSm: "60px",
13
+ },
14
+ };
15
+ const BREAKPOINTS = {
16
+ values: {
17
+ xs: 0,
18
+ sm: 600,
19
+ md: 900,
20
+ lg: 1272 + 48,
21
+ xl: 1536,
22
+ },
23
+ };
24
+ const defaultThemeOptions = {
25
+ custom: custom,
26
+ palette: {
27
+ primary: {
28
+ main: colors.mitRed,
29
+ light: colors.lightRed,
30
+ active: colors.red,
31
+ contrastText: colors.white,
32
+ },
33
+ secondary: {
34
+ light: colors.darkGray2,
35
+ active: colors.silverGrayDark,
36
+ main: colors.black,
37
+ contrastText: colors.white,
38
+ },
39
+ },
40
+ shape: {
41
+ borderRadius: 8,
42
+ },
43
+ spacing: 8,
44
+ typography: typography.globalSettings,
45
+ breakpoints: BREAKPOINTS,
46
+ components: {
47
+ MuiButtonBase: buttons.buttonBaseComponent,
48
+ MuiTypography: typography.component,
49
+ MuiMenu: {
50
+ styleOverrides: { paper: { borderRadius: "4px" } },
51
+ },
52
+ MuiAutocomplete: {
53
+ styleOverrides: {
54
+ paper: { borderRadius: "4px" },
55
+ // Mui puts paddingRight: 2px, marginRight: -2px on the popupIndicator,
56
+ // which causes the browser to show a horizontal scrollbar on overflow
57
+ // containers when a scrollbar isn't really necessary.
58
+ popupIndicator: { paddingRight: 0, marginRight: 0 },
59
+ },
60
+ },
61
+ MuiChip: chips.chipComponent,
62
+ },
63
+ };
64
+ /**
65
+ * Create a customized Smoot Design theme for use with `ThemeProvider`.
66
+ *
67
+ * See [ThemeProvider Docs](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-themeprovider--docs#further-customized-theme-with-createtheme)
68
+ * for more.
69
+ */
70
+ const createTheme = (options) => {
71
+ return muiCreateTheme(deepmerge(defaultThemeOptions, options));
72
+ };
73
+ const defaultTheme = createTheme();
74
+ /**
75
+ *
76
+ * @param param0
77
+ * @returns
78
+ */
79
+ const ThemeProvider = ({ children, theme = defaultTheme, }) => {
80
+ return React.createElement(MuiThemeProvider, { theme: theme }, children);
81
+ };
82
+ export { ThemeProvider, createTheme };
@@ -0,0 +1,63 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { ThemeProvider } from "./ThemeProvider";
3
+ declare const meta: Meta<typeof ThemeProvider>;
4
+ type Story = StoryObj<typeof ThemeProvider>;
5
+ /**
6
+ * `ThemeProvider` must wrap all components from `smoot`-design, and allows
7
+ * styling any component via [`styled`](https://emotion.sh/docs/styled).
8
+ *
9
+ * In general, most useful theme properties are exposed on `theme.custom`. (Root
10
+ * `theme` properties are used internally by MUI.) See typescript definitions
11
+ * for more information about `theme.custom`.
12
+ *
13
+ * ## Further Customized Theme with `createTheme`
14
+ * Consuming applications can customize `smoot-design`'s default theme by creating
15
+ * a theme instance with `createTheme` and passing it to `ThemeProvider`:
16
+ *
17
+ * ```tsx
18
+ * const customTheme = createTheme({...})
19
+ *
20
+ * <ThemeProvider theme={customTheme}>
21
+ * {children}
22
+ * </ThemeProvider>
23
+ * ```
24
+ *
25
+ * ### Custom Link Adapter
26
+ * One particularly notable property is `theme.custom.LinkAdapter`. Some `smoot-design`
27
+ * components render links. These links are native anchor tags by default. In
28
+ * order to use these components with custom routing libraries (e.g. `react-router`
29
+ * or `next/link`), you can provide a custom link adapter.
30
+ *
31
+ * Components such as `ButtonLink` will:
32
+ * - use `Component` on `ButtonLink` if specified (`<ButtonLink Component={Link} />`)
33
+ * - else, use `theme.custom.LinkAdapter` if specified,
34
+ * - else, use `a` tag.
35
+ *
36
+ * For example, to use `next/link` as the default link implementation:
37
+ *
38
+ * ```tsx
39
+ * import Link from "next/link"
40
+ * const theme = createTheme({ LinkAdapter: Link })
41
+ * ```
42
+ *
43
+ * You can use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
44
+ * to add the custom props to relevant components. For example, to expose
45
+ * `next/link`'s `scroll` prop on `ButtonLink`:
46
+ *
47
+ * ```ts
48
+ * // Add scroll prop to all components using LinkAdapter
49
+ * declare module "@mitodl/smoot-design" {
50
+ * interface LinkAdapterPropsOverrides {
51
+ * scroll?: boolean
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * ### ImageAdapter
57
+ * Similarly, `theme.custom.ImageAdapter` can be used to customize the image
58
+ * component used by `smoot-design`. By default, `ImageAdapter` uses a simple `img`
59
+ * tag. Interface `ImageAdapterPropsOverrides` is similarly available for
60
+ * augmentation.
61
+ */
62
+ export declare const LinkAdapterOverride: Story;
63
+ export default meta;
@@ -0,0 +1,99 @@
1
+ import * as React from "react";
2
+ import { ThemeProvider, createTheme } from "./ThemeProvider";
3
+ import { ButtonLink } from "../Button/Button";
4
+ const CustomLinkAdapater = React.forwardRef((props, ref) => (
5
+ // eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
6
+ React.createElement("a", Object.assign({ ref: ref, onClick: (e) => {
7
+ e.preventDefault();
8
+ alert(`Custom link to: ${e.currentTarget.href}. (Preventing Navigation.)`);
9
+ }, "data-custom": "theme-default" }, props))));
10
+ CustomLinkAdapater.displayName = "CustomLinkAdapter";
11
+ const customTheme = createTheme({
12
+ custom: {
13
+ LinkAdapter: CustomLinkAdapater,
14
+ },
15
+ });
16
+ const meta = {
17
+ title: "smoot-design/ThemeProvider",
18
+ component: ThemeProvider,
19
+ argTypes: {
20
+ theme: {
21
+ options: ["Default", "Custom Link Adapter"],
22
+ mapping: {
23
+ Default: undefined,
24
+ "Custom Link Adapter": customTheme,
25
+ },
26
+ },
27
+ children: {
28
+ table: { disable: true },
29
+ },
30
+ },
31
+ id: "smoot-design/ThemeProvider",
32
+ };
33
+ /**
34
+ * `ThemeProvider` must wrap all components from `smoot`-design, and allows
35
+ * styling any component via [`styled`](https://emotion.sh/docs/styled).
36
+ *
37
+ * In general, most useful theme properties are exposed on `theme.custom`. (Root
38
+ * `theme` properties are used internally by MUI.) See typescript definitions
39
+ * for more information about `theme.custom`.
40
+ *
41
+ * ## Further Customized Theme with `createTheme`
42
+ * Consuming applications can customize `smoot-design`'s default theme by creating
43
+ * a theme instance with `createTheme` and passing it to `ThemeProvider`:
44
+ *
45
+ * ```tsx
46
+ * const customTheme = createTheme({...})
47
+ *
48
+ * <ThemeProvider theme={customTheme}>
49
+ * {children}
50
+ * </ThemeProvider>
51
+ * ```
52
+ *
53
+ * ### Custom Link Adapter
54
+ * One particularly notable property is `theme.custom.LinkAdapter`. Some `smoot-design`
55
+ * components render links. These links are native anchor tags by default. In
56
+ * order to use these components with custom routing libraries (e.g. `react-router`
57
+ * or `next/link`), you can provide a custom link adapter.
58
+ *
59
+ * Components such as `ButtonLink` will:
60
+ * - use `Component` on `ButtonLink` if specified (`<ButtonLink Component={Link} />`)
61
+ * - else, use `theme.custom.LinkAdapter` if specified,
62
+ * - else, use `a` tag.
63
+ *
64
+ * For example, to use `next/link` as the default link implementation:
65
+ *
66
+ * ```tsx
67
+ * import Link from "next/link"
68
+ * const theme = createTheme({ LinkAdapter: Link })
69
+ * ```
70
+ *
71
+ * You can use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
72
+ * to add the custom props to relevant components. For example, to expose
73
+ * `next/link`'s `scroll` prop on `ButtonLink`:
74
+ *
75
+ * ```ts
76
+ * // Add scroll prop to all components using LinkAdapter
77
+ * declare module "@mitodl/smoot-design" {
78
+ * interface LinkAdapterPropsOverrides {
79
+ * scroll?: boolean
80
+ * }
81
+ * }
82
+ * ```
83
+ *
84
+ * ### ImageAdapter
85
+ * Similarly, `theme.custom.ImageAdapter` can be used to customize the image
86
+ * component used by `smoot-design`. By default, `ImageAdapter` uses a simple `img`
87
+ * tag. Interface `ImageAdapterPropsOverrides` is similarly available for
88
+ * augmentation.
89
+ */
90
+ export const LinkAdapterOverride = {
91
+ args: {
92
+ theme: customTheme,
93
+ },
94
+ render: (args) => {
95
+ return (React.createElement(ThemeProvider, { theme: args.theme },
96
+ React.createElement(ButtonLink, { href: "https://mit.edu" }, args.theme ? "Custom theme in use" : "Default theme in use")));
97
+ },
98
+ };
99
+ export default meta;
@@ -0,0 +1,39 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import Typography from "@mui/material/Typography";
3
+ /**
4
+ * Typography styles can be controlled via the `theme.typography` object when
5
+ * using the `styled` helper or via the `<Tyopgraphy variant="..." />` component.
6
+ *
7
+ * For the `Typography` component, see [MUI's documentation](https://mui.com/material-ui/react-typography/).
8
+ *
9
+ * ```tsx
10
+ * const MyHeading = styled(({ theme }) => ({
11
+ * ...theme.typography.h2,
12
+ * [theme.breakpoints.down("sm")]: {
13
+ * ...theme.typography.h3,
14
+ * },
15
+ * }))
16
+ *
17
+ * // or:
18
+ * <Typography component="h1" typography={
19
+ * {
20
+ * xs: "h3", // above xs
21
+ * sm: "h2" // above sm
22
+ * }
23
+ * }>
24
+ * Hello, world!
25
+ * </Typography>
26
+ * ```
27
+ *
28
+ */
29
+ declare const meta: Meta<typeof Typography>;
30
+ export default meta;
31
+ type Story = StoryObj<typeof Typography>;
32
+ /**
33
+ * Typography variants are shown below.
34
+ *
35
+ * **Note:** The typography variant is not related to the HTML element used. A
36
+ * `variant="h1"` component does not automatically render an `<h1>` element.
37
+ *
38
+ */
39
+ export declare const Variants: Story;
@@ -0,0 +1,62 @@
1
+ import * as React from "react";
2
+ import Stack from "@mui/material/Stack";
3
+ import Typography from "@mui/material/Typography";
4
+ /**
5
+ * Typography styles can be controlled via the `theme.typography` object when
6
+ * using the `styled` helper or via the `<Tyopgraphy variant="..." />` component.
7
+ *
8
+ * For the `Typography` component, see [MUI's documentation](https://mui.com/material-ui/react-typography/).
9
+ *
10
+ * ```tsx
11
+ * const MyHeading = styled(({ theme }) => ({
12
+ * ...theme.typography.h2,
13
+ * [theme.breakpoints.down("sm")]: {
14
+ * ...theme.typography.h3,
15
+ * },
16
+ * }))
17
+ *
18
+ * // or:
19
+ * <Typography component="h1" typography={
20
+ * {
21
+ * xs: "h3", // above xs
22
+ * sm: "h2" // above sm
23
+ * }
24
+ * }>
25
+ * Hello, world!
26
+ * </Typography>
27
+ * ```
28
+ *
29
+ */
30
+ const meta = {
31
+ title: "smoot-design/Typography",
32
+ component: Typography,
33
+ };
34
+ export default meta;
35
+ const text = "The quick brown fox jumps over the lazy dog. ".repeat(10);
36
+ const INSTANCES = [
37
+ { variant: "h1", children: "Heading level 1" },
38
+ { variant: "h2", children: "Heading level 2" },
39
+ { variant: "h3", children: "Heading level 3" },
40
+ { variant: "h4", children: "Heading level 4" },
41
+ { variant: "h5", children: "Heading level 5" },
42
+ { variant: "subtitle1", children: "Subtitle level 1" },
43
+ { variant: "subtitle2", children: "Subtitle level 2" },
44
+ { variant: "subtitle3", children: "Subtitle level 3" },
45
+ { variant: "subtitle4", children: "Subtitle level 4" },
46
+ { variant: "body1", children: `body level 1... ${text}` },
47
+ { variant: "body2", children: `body level 2... ${text}` },
48
+ { variant: "body3", children: `body level 3... ${text}` },
49
+ { variant: "body4", children: `body level 4... ${text}` },
50
+ ];
51
+ /**
52
+ * Typography variants are shown below.
53
+ *
54
+ * **Note:** The typography variant is not related to the HTML element used. A
55
+ * `variant="h1"` component does not automatically render an `<h1>` element.
56
+ *
57
+ */
58
+ export const Variants = {
59
+ render: () => {
60
+ return (React.createElement(Stack, { gap: "1rem" }, INSTANCES.map((props) => (React.createElement(Typography, Object.assign({ key: props.variant }, props))))));
61
+ },
62
+ };
@@ -0,0 +1,4 @@
1
+ import type { ThemeOptions } from "@mui/material/styles";
2
+ declare const BREAKPOINT_VALUES: ThemeOptions["breakpoints"];
3
+ declare const breakpoints: import("@mui/material/styles").Breakpoints;
4
+ export { BREAKPOINT_VALUES, breakpoints };
@@ -0,0 +1,15 @@
1
+ import { createTheme } from "@mui/material/styles";
2
+ const BREAKPOINT_VALUES = {
3
+ values: {
4
+ xs: 0,
5
+ sm: 600,
6
+ md: 900,
7
+ lg: 1280,
8
+ xl: 1536,
9
+ },
10
+ };
11
+ const { breakpoints } = createTheme({
12
+ breakpoints: BREAKPOINT_VALUES,
13
+ custom: {},
14
+ });
15
+ export { BREAKPOINT_VALUES, breakpoints };
@@ -0,0 +1,7 @@
1
+ import type { ThemeOptions } from "@mui/material/styles";
2
+ /**
3
+ * We don't use MUI's button directly, but ButtonBase does get used internally
4
+ * by some MUI components, so we override a few styles.
5
+ */
6
+ declare const buttonBaseComponent: NonNullable<ThemeOptions["components"]>["MuiButtonBase"];
7
+ export { buttonBaseComponent };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * We don't use MUI's button directly, but ButtonBase does get used internally
3
+ * by some MUI components, so we override a few styles.
4
+ */
5
+ const buttonBaseComponent = {
6
+ defaultProps: {
7
+ disableRipple: true,
8
+ },
9
+ styleOverrides: {
10
+ root: {
11
+ ":focus-visible": {
12
+ outline: "revert",
13
+ },
14
+ },
15
+ },
16
+ };
17
+ export { buttonBaseComponent };
@@ -0,0 +1,3 @@
1
+ import type { ThemeOptions } from "@mui/material/styles";
2
+ declare const chipComponent: NonNullable<ThemeOptions["components"]>["MuiChip"];
3
+ export { chipComponent };
@@ -0,0 +1,151 @@
1
+ import * as React from "react";
2
+ import { colors } from "./colors";
3
+ import { RiCloseLine } from "@remixicon/react";
4
+ const chipComponent = {
5
+ defaultProps: {
6
+ size: "medium",
7
+ color: "default",
8
+ variant: "outlined",
9
+ deleteIcon: React.createElement(RiCloseLine, { "aria-hidden": "true" }),
10
+ },
11
+ styleOverrides: {
12
+ root: {
13
+ borderRadius: "100vh",
14
+ borderWidth: "1px",
15
+ },
16
+ deleteIcon: {
17
+ "&:hover": {
18
+ color: "inherit",
19
+ },
20
+ "&.MuiChip-deleteIconLarge": {
21
+ width: "16px",
22
+ height: "16px",
23
+ },
24
+ "&.MuiChip-deleteIconMedium": {
25
+ width: "14px",
26
+ height: "14px",
27
+ },
28
+ margin: "0 -2px 0 8px",
29
+ color: "inherit",
30
+ },
31
+ icon: {
32
+ margin: "0 8px 0 -2px",
33
+ color: "inherit",
34
+ "&.MuiChip-iconLarge": {
35
+ width: "16px",
36
+ height: "16px",
37
+ },
38
+ "&.MuiChip-iconMedium": {
39
+ width: "14px",
40
+ height: "14px",
41
+ },
42
+ },
43
+ },
44
+ variants: [
45
+ {
46
+ props: { size: "medium" },
47
+ style: ({ theme }) => (Object.assign(Object.assign({}, theme.typography.body3), { boxSizing: "border-box", height: "24px", paddingRight: "12px", paddingLeft: "12px", ".MuiChip-label": {
48
+ paddingLeft: "0px",
49
+ paddingRight: "0px",
50
+ } })),
51
+ },
52
+ {
53
+ props: { size: "large" },
54
+ style: ({ theme }) => (Object.assign(Object.assign({}, theme.typography.body2), { height: "32px", paddingLeft: "16px", paddingRight: "16px", ".MuiChip-label": {
55
+ paddingLeft: "0px",
56
+ paddingRight: "0px",
57
+ } })),
58
+ },
59
+ {
60
+ props: { variant: "outlined" },
61
+ style: {
62
+ borderColor: colors.silverGrayLight,
63
+ color: colors.darkGray1,
64
+ "&.Mui-focusVisible": {
65
+ backgroundColor: "transparent",
66
+ },
67
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
68
+ color: colors.darkGray1,
69
+ borderColor: colors.silverGrayDark,
70
+ backgroundColor: "transparent", // mui has a default background color for hover
71
+ },
72
+ },
73
+ },
74
+ {
75
+ props: { variant: "outlinedWhite" },
76
+ style: {
77
+ backgroundColor: "white",
78
+ border: "1px solid",
79
+ borderColor: colors.silverGrayLight,
80
+ color: colors.darkGray1,
81
+ "&.Mui-focusVisible": {
82
+ backgroundColor: "white",
83
+ },
84
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
85
+ color: colors.darkGray1,
86
+ borderColor: colors.silverGrayDark,
87
+ backgroundColor: "white", // mui has a default background color hover
88
+ },
89
+ },
90
+ },
91
+ {
92
+ props: { variant: "gray" },
93
+ style: {
94
+ backgroundColor: colors.lightGray2,
95
+ border: "none",
96
+ color: colors.darkGray2,
97
+ "&.Mui-focusVisible": {
98
+ backgroundColor: colors.lightGray2,
99
+ },
100
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
101
+ color: colors.darkGray1,
102
+ backgroundColor: colors.silverGrayLight,
103
+ },
104
+ },
105
+ },
106
+ {
107
+ props: { variant: "dark" },
108
+ style: {
109
+ backgroundColor: colors.silverGrayDark,
110
+ border: "none",
111
+ color: colors.white,
112
+ "&.Mui-focusVisible": {
113
+ backgroundColor: colors.silverGrayDark,
114
+ },
115
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
116
+ backgroundColor: colors.darkGray1,
117
+ },
118
+ },
119
+ },
120
+ {
121
+ props: { variant: "darker" },
122
+ style: {
123
+ backgroundColor: colors.darkGray2,
124
+ border: `1px solid ${colors.darkGray1}`,
125
+ color: colors.white,
126
+ "&.Mui-focusVisible": {
127
+ backgroundColor: colors.darkGray2,
128
+ },
129
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
130
+ backgroundColor: colors.black,
131
+ border: `1px solid ${colors.silverGray}`,
132
+ },
133
+ },
134
+ },
135
+ {
136
+ props: { variant: "filled" },
137
+ style: {
138
+ backgroundColor: colors.mitRed,
139
+ border: "none",
140
+ color: colors.white,
141
+ "&.Mui-focusVisible": {
142
+ backgroundColor: colors.mitRed,
143
+ },
144
+ "&.MuiChip-clickable:hover, &.MuiChip-deletable:hover": {
145
+ backgroundColor: colors.red,
146
+ },
147
+ },
148
+ },
149
+ ],
150
+ };
151
+ export { chipComponent };
@@ -0,0 +1,32 @@
1
+ declare const colors: {
2
+ mitRed: string;
3
+ brightRed: string;
4
+ black: string;
5
+ white: string;
6
+ darkGray2: string;
7
+ darkGray1: string;
8
+ silverGrayDark: string;
9
+ silverGray: string;
10
+ silverGrayLight: string;
11
+ lightGray2: string;
12
+ lightGray1: string;
13
+ navGray: string;
14
+ darkPink: string;
15
+ pink: string;
16
+ lightPink: string;
17
+ darkPurple: string;
18
+ purple: string;
19
+ lightPurple: string;
20
+ darkBlue: string;
21
+ blue: string;
22
+ lightBlue: string;
23
+ darkGreen: string;
24
+ green: string;
25
+ lightGreen: string;
26
+ darkRed: string;
27
+ red: string;
28
+ lightRed: string;
29
+ orange: string;
30
+ yellow: string;
31
+ };
32
+ export { colors };