@mitodl/smoot-design 0.0.0-355a925

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 (247) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +35 -0
  3. package/dist/bundles/remoteTutorDrawer.es.js +38364 -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 +9 -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 +56 -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 +284 -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 +226 -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/AiChatContext.d.ts +22 -0
  24. package/dist/cjs/components/AiChat/AiChatContext.js +105 -0
  25. package/dist/cjs/components/AiChat/AiChatContext.stories.d.ts +14 -0
  26. package/dist/cjs/components/AiChat/AiChatContext.stories.js +75 -0
  27. package/dist/cjs/components/AiChat/ChatTitle.d.ts +8 -0
  28. package/dist/cjs/components/AiChat/ChatTitle.js +43 -0
  29. package/dist/cjs/components/AiChat/EntryScreen.d.ts +11 -0
  30. package/dist/cjs/components/AiChat/EntryScreen.js +123 -0
  31. package/dist/cjs/components/AiChat/TimLogo.d.ts +5 -0
  32. package/dist/cjs/components/AiChat/TimLogo.js +15 -0
  33. package/dist/cjs/components/AiChat/test-utils/api.d.ts +2 -0
  34. package/dist/cjs/components/AiChat/test-utils/api.js +125 -0
  35. package/dist/cjs/components/AiChat/types.d.ts +86 -0
  36. package/dist/cjs/components/AiChat/types.js +3 -0
  37. package/dist/cjs/components/Alert/Alert.d.ts +15 -0
  38. package/dist/cjs/components/Alert/Alert.js +62 -0
  39. package/dist/cjs/components/Alert/Alert.stories.d.ts +8 -0
  40. package/dist/cjs/components/Alert/Alert.stories.js +53 -0
  41. package/dist/cjs/components/Button/ActionButton.d.ts +30 -0
  42. package/dist/cjs/components/Button/ActionButton.js +73 -0
  43. package/dist/cjs/components/Button/ActionButton.stories.d.ts +15 -0
  44. package/dist/cjs/components/Button/ActionButton.stories.js +113 -0
  45. package/dist/cjs/components/Button/Button.d.ts +54 -0
  46. package/dist/cjs/components/Button/Button.js +240 -0
  47. package/dist/cjs/components/Button/Button.stories.d.ts +17 -0
  48. package/dist/cjs/components/Button/Button.stories.js +135 -0
  49. package/dist/cjs/components/Button/Button.test.d.ts +1 -0
  50. package/dist/cjs/components/Button/Button.test.js +46 -0
  51. package/dist/cjs/components/ImageAdapter/ImageAdapter.d.ts +23 -0
  52. package/dist/cjs/components/ImageAdapter/ImageAdapter.js +30 -0
  53. package/dist/cjs/components/Input/Input.d.ts +116 -0
  54. package/dist/cjs/components/Input/Input.js +237 -0
  55. package/dist/cjs/components/Input/Input.stories.d.ts +19 -0
  56. package/dist/cjs/components/Input/Input.stories.js +135 -0
  57. package/dist/cjs/components/Input/Input.test.d.ts +1 -0
  58. package/dist/cjs/components/Input/Input.test.js +32 -0
  59. package/dist/cjs/components/LinkAdapter/LinkAdapter.d.ts +23 -0
  60. package/dist/cjs/components/LinkAdapter/LinkAdapter.js +34 -0
  61. package/dist/cjs/components/ScrollSnap/ScrollSnap.d.ts +19 -0
  62. package/dist/cjs/components/ScrollSnap/ScrollSnap.js +59 -0
  63. package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
  64. package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.js +43 -0
  65. package/dist/cjs/components/ScrollSnap/useScrollSnap.d.ts +6 -0
  66. package/dist/cjs/components/ScrollSnap/useScrollSnap.js +36 -0
  67. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
  68. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.js +43 -0
  69. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
  70. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.js +44 -0
  71. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
  72. package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.js +62 -0
  73. package/dist/cjs/components/TabButtons/TabButtonList.d.ts +25 -0
  74. package/dist/cjs/components/TabButtons/TabButtonList.js +97 -0
  75. package/dist/cjs/components/TabButtons/TabButtonList.stories.d.ts +24 -0
  76. package/dist/cjs/components/TabButtons/TabButtonList.stories.js +139 -0
  77. package/dist/cjs/components/TextField/TextField.d.ts +29 -0
  78. package/dist/cjs/components/TextField/TextField.js +33 -0
  79. package/dist/cjs/components/TextField/TextField.stories.d.ts +10 -0
  80. package/dist/cjs/components/TextField/TextField.stories.js +136 -0
  81. package/dist/cjs/components/TextField/TextField.test.d.ts +1 -0
  82. package/dist/cjs/components/TextField/TextField.test.js +77 -0
  83. package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +21 -0
  84. package/dist/cjs/components/ThemeProvider/ThemeProvider.js +86 -0
  85. package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
  86. package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.js +102 -0
  87. package/dist/cjs/components/ThemeProvider/Typography.stories.d.ts +39 -0
  88. package/dist/cjs/components/ThemeProvider/Typography.stories.js +65 -0
  89. package/dist/cjs/components/ThemeProvider/breakpoints.d.ts +4 -0
  90. package/dist/cjs/components/ThemeProvider/breakpoints.js +19 -0
  91. package/dist/cjs/components/ThemeProvider/buttons.d.ts +7 -0
  92. package/dist/cjs/components/ThemeProvider/buttons.js +20 -0
  93. package/dist/cjs/components/ThemeProvider/chips.d.ts +3 -0
  94. package/dist/cjs/components/ThemeProvider/chips.js +154 -0
  95. package/dist/cjs/components/ThemeProvider/colors.d.ts +32 -0
  96. package/dist/cjs/components/ThemeProvider/colors.js +35 -0
  97. package/dist/cjs/components/ThemeProvider/typography.d.ts +18 -0
  98. package/dist/cjs/components/ThemeProvider/typography.js +173 -0
  99. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
  100. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js +33 -0
  101. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
  102. package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.js +13 -0
  103. package/dist/cjs/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
  104. package/dist/cjs/components/internal/FormHelpers/FormHelpers.js +78 -0
  105. package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
  106. package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.js +93 -0
  107. package/dist/cjs/index.d.ts +16 -0
  108. package/dist/cjs/index.js +30 -0
  109. package/dist/cjs/jest-setup.d.ts +1 -0
  110. package/dist/cjs/jest-setup.js +18 -0
  111. package/dist/cjs/jsdom-extended.d.ts +6 -0
  112. package/dist/cjs/jsdom-extended.js +14 -0
  113. package/dist/cjs/story-utils/index.d.ts +6 -0
  114. package/dist/cjs/story-utils/index.js +17 -0
  115. package/dist/cjs/utils/composeRefs.d.ts +7 -0
  116. package/dist/cjs/utils/composeRefs.js +20 -0
  117. package/dist/cjs/utils/composeRefs.test.d.ts +1 -0
  118. package/dist/cjs/utils/composeRefs.test.js +19 -0
  119. package/dist/cjs/utils/useDevCheckStable.d.ts +8 -0
  120. package/dist/cjs/utils/useDevCheckStable.js +29 -0
  121. package/dist/cjs/utils/useInterval.d.ts +7 -0
  122. package/dist/cjs/utils/useInterval.js +25 -0
  123. package/dist/esm/ai.d.ts +3 -0
  124. package/dist/esm/ai.js +2 -0
  125. package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
  126. package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.js +83 -0
  127. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +56 -0
  128. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +273 -0
  129. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +16 -0
  130. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +281 -0
  131. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
  132. package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +239 -0
  133. package/dist/esm/bundles/remoteTutorDrawer.d.ts +7 -0
  134. package/dist/esm/bundles/remoteTutorDrawer.js +37 -0
  135. package/dist/esm/components/AiChat/AiChat.d.ts +5 -0
  136. package/dist/esm/components/AiChat/AiChat.js +222 -0
  137. package/dist/esm/components/AiChat/AiChat.stories.d.ts +21 -0
  138. package/dist/esm/components/AiChat/AiChat.stories.js +240 -0
  139. package/dist/esm/components/AiChat/AiChat.test.d.ts +1 -0
  140. package/dist/esm/components/AiChat/AiChat.test.js +209 -0
  141. package/dist/esm/components/AiChat/AiChatContext.d.ts +22 -0
  142. package/dist/esm/components/AiChat/AiChatContext.js +101 -0
  143. package/dist/esm/components/AiChat/AiChatContext.stories.d.ts +14 -0
  144. package/dist/esm/components/AiChat/AiChatContext.stories.js +72 -0
  145. package/dist/esm/components/AiChat/ChatTitle.d.ts +8 -0
  146. package/dist/esm/components/AiChat/ChatTitle.js +40 -0
  147. package/dist/esm/components/AiChat/EntryScreen.d.ts +11 -0
  148. package/dist/esm/components/AiChat/EntryScreen.js +120 -0
  149. package/dist/esm/components/AiChat/TimLogo.d.ts +5 -0
  150. package/dist/esm/components/AiChat/TimLogo.js +13 -0
  151. package/dist/esm/components/AiChat/test-utils/api.d.ts +2 -0
  152. package/dist/esm/components/AiChat/test-utils/api.js +122 -0
  153. package/dist/esm/components/AiChat/types.d.ts +86 -0
  154. package/dist/esm/components/AiChat/types.js +2 -0
  155. package/dist/esm/components/Alert/Alert.d.ts +15 -0
  156. package/dist/esm/components/Alert/Alert.js +59 -0
  157. package/dist/esm/components/Alert/Alert.stories.d.ts +8 -0
  158. package/dist/esm/components/Alert/Alert.stories.js +50 -0
  159. package/dist/esm/components/Button/ActionButton.d.ts +30 -0
  160. package/dist/esm/components/Button/ActionButton.js +68 -0
  161. package/dist/esm/components/Button/ActionButton.stories.d.ts +15 -0
  162. package/dist/esm/components/Button/ActionButton.stories.js +110 -0
  163. package/dist/esm/components/Button/Button.d.ts +54 -0
  164. package/dist/esm/components/Button/Button.js +232 -0
  165. package/dist/esm/components/Button/Button.stories.d.ts +17 -0
  166. package/dist/esm/components/Button/Button.stories.js +132 -0
  167. package/dist/esm/components/Button/Button.test.d.ts +1 -0
  168. package/dist/esm/components/Button/Button.test.js +44 -0
  169. package/dist/esm/components/ImageAdapter/ImageAdapter.d.ts +23 -0
  170. package/dist/esm/components/ImageAdapter/ImageAdapter.js +27 -0
  171. package/dist/esm/components/Input/Input.d.ts +116 -0
  172. package/dist/esm/components/Input/Input.js +232 -0
  173. package/dist/esm/components/Input/Input.stories.d.ts +19 -0
  174. package/dist/esm/components/Input/Input.stories.js +132 -0
  175. package/dist/esm/components/Input/Input.test.d.ts +1 -0
  176. package/dist/esm/components/Input/Input.test.js +30 -0
  177. package/dist/esm/components/LinkAdapter/LinkAdapter.d.ts +23 -0
  178. package/dist/esm/components/LinkAdapter/LinkAdapter.js +31 -0
  179. package/dist/esm/components/ScrollSnap/ScrollSnap.d.ts +19 -0
  180. package/dist/esm/components/ScrollSnap/ScrollSnap.js +56 -0
  181. package/dist/esm/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
  182. package/dist/esm/components/ScrollSnap/ScrollSnap.stories.js +40 -0
  183. package/dist/esm/components/ScrollSnap/useScrollSnap.d.ts +6 -0
  184. package/dist/esm/components/ScrollSnap/useScrollSnap.js +33 -0
  185. package/dist/esm/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
  186. package/dist/esm/components/SrAnnouncer/SrAnnouncer.js +40 -0
  187. package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
  188. package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.js +41 -0
  189. package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
  190. package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.js +60 -0
  191. package/dist/esm/components/TabButtons/TabButtonList.d.ts +25 -0
  192. package/dist/esm/components/TabButtons/TabButtonList.js +92 -0
  193. package/dist/esm/components/TabButtons/TabButtonList.stories.d.ts +24 -0
  194. package/dist/esm/components/TabButtons/TabButtonList.stories.js +136 -0
  195. package/dist/esm/components/TextField/TextField.d.ts +29 -0
  196. package/dist/esm/components/TextField/TextField.js +30 -0
  197. package/dist/esm/components/TextField/TextField.stories.d.ts +10 -0
  198. package/dist/esm/components/TextField/TextField.stories.js +133 -0
  199. package/dist/esm/components/TextField/TextField.test.d.ts +1 -0
  200. package/dist/esm/components/TextField/TextField.test.js +75 -0
  201. package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +21 -0
  202. package/dist/esm/components/ThemeProvider/ThemeProvider.js +82 -0
  203. package/dist/esm/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
  204. package/dist/esm/components/ThemeProvider/ThemeProvider.stories.js +99 -0
  205. package/dist/esm/components/ThemeProvider/Typography.stories.d.ts +39 -0
  206. package/dist/esm/components/ThemeProvider/Typography.stories.js +62 -0
  207. package/dist/esm/components/ThemeProvider/breakpoints.d.ts +4 -0
  208. package/dist/esm/components/ThemeProvider/breakpoints.js +15 -0
  209. package/dist/esm/components/ThemeProvider/buttons.d.ts +7 -0
  210. package/dist/esm/components/ThemeProvider/buttons.js +17 -0
  211. package/dist/esm/components/ThemeProvider/chips.d.ts +3 -0
  212. package/dist/esm/components/ThemeProvider/chips.js +151 -0
  213. package/dist/esm/components/ThemeProvider/colors.d.ts +32 -0
  214. package/dist/esm/components/ThemeProvider/colors.js +32 -0
  215. package/dist/esm/components/ThemeProvider/typography.d.ts +18 -0
  216. package/dist/esm/components/ThemeProvider/typography.js +167 -0
  217. package/dist/esm/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
  218. package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +30 -0
  219. package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
  220. package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.js +10 -0
  221. package/dist/esm/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
  222. package/dist/esm/components/internal/FormHelpers/FormHelpers.js +73 -0
  223. package/dist/esm/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
  224. package/dist/esm/components/internal/FormHelpers/FormHelpers.test.js +91 -0
  225. package/dist/esm/index.d.ts +16 -0
  226. package/dist/esm/index.js +11 -0
  227. package/dist/esm/jest-setup.d.ts +1 -0
  228. package/dist/esm/jest-setup.js +16 -0
  229. package/dist/esm/jsdom-extended.d.ts +6 -0
  230. package/dist/esm/jsdom-extended.js +12 -0
  231. package/dist/esm/story-utils/index.d.ts +6 -0
  232. package/dist/esm/story-utils/index.js +13 -0
  233. package/dist/esm/utils/composeRefs.d.ts +7 -0
  234. package/dist/esm/utils/composeRefs.js +17 -0
  235. package/dist/esm/utils/composeRefs.test.d.ts +1 -0
  236. package/dist/esm/utils/composeRefs.test.js +17 -0
  237. package/dist/esm/utils/useDevCheckStable.d.ts +8 -0
  238. package/dist/esm/utils/useDevCheckStable.js +26 -0
  239. package/dist/esm/utils/useInterval.d.ts +7 -0
  240. package/dist/esm/utils/useInterval.js +22 -0
  241. package/dist/tsconfig.tsbuildinfo +1 -0
  242. package/dist/type-augmentation/TypescriptDocs.mdx +17 -0
  243. package/dist/type-augmentation/imports.d.ts +3 -0
  244. package/dist/type-augmentation/index.d.ts +3 -0
  245. package/dist/type-augmentation/theme.d.ts +105 -0
  246. package/dist/type-augmentation/typography.d.ts +54 -0
  247. package/package.json +155 -0
@@ -0,0 +1,116 @@
1
+ import * as React from "react";
2
+ import type { InputBaseProps } from "@mui/material/InputBase";
3
+ import type { Theme } from "@mui/material/styles";
4
+ type Size = "small" | "medium" | "large" | "chat" | "hero";
5
+ type CustomInputProps = {
6
+ /**
7
+ * If true, the input will display one size smaller at mobile breakpoint.
8
+ */
9
+ responsive?: boolean;
10
+ };
11
+ type MuiDocOverride = {
12
+ size?: Size;
13
+ /**
14
+ * Slot for icon adornments.
15
+ *
16
+ * If the icon is a button, use `AdornmentButton` component.
17
+ */
18
+ startAdornment?: React.ReactNode;
19
+ /**
20
+ * Slot for icon adornments.
21
+ *
22
+ * If the icon is a button, use `AdornmentButton` component.
23
+ */
24
+ endAdornment?: React.ReactNode;
25
+ };
26
+ type InputProps = CustomInputProps & MuiDocOverride & Omit<InputBaseProps, "color" | keyof MuiDocOverride>;
27
+ /**
28
+ * Base styles for Input and Select components. Includes border, color, hover effects.
29
+ */
30
+ declare const baseInputStyles: (theme: Theme) => {
31
+ backgroundColor: string;
32
+ color: string;
33
+ borderColor: string;
34
+ borderWidth: string;
35
+ borderStyle: string;
36
+ borderRadius: string;
37
+ overflow: string;
38
+ "&.Mui-disabled": {
39
+ backgroundColor: string;
40
+ };
41
+ "&:hover:not(.Mui-disabled):not(.Mui-focused)": {
42
+ borderColor: string;
43
+ };
44
+ "&.Mui-focused": {
45
+ /**
46
+ * When change border width, it affects either the elements outside of it or
47
+ * inside based on the border-box setting.
48
+ *
49
+ * Instead of changing the border width, we hide the border and change width
50
+ * using outline.
51
+ */
52
+ borderColor: string;
53
+ outline: string;
54
+ outlineOffset: string;
55
+ };
56
+ "&.Mui-error": {
57
+ borderColor: string;
58
+ outlineColor: string;
59
+ };
60
+ "& input::placeholder, textarea::placeholder": {
61
+ color: string;
62
+ opacity: number;
63
+ };
64
+ "& input:placeholder-shown, textarea:placeholder-shown": {
65
+ textOverflow: string;
66
+ };
67
+ "& textarea": {
68
+ paddingTop: string;
69
+ paddingBottom: string;
70
+ };
71
+ "&.MuiInputBase-adornedStart": {
72
+ paddingLeft: string;
73
+ input: {
74
+ paddingLeft: string;
75
+ };
76
+ };
77
+ "&.MuiInputBase-adornedEnd": {
78
+ paddingRight: string;
79
+ input: {
80
+ paddingRight: string;
81
+ };
82
+ };
83
+ };
84
+ /**
85
+ * Use `Input` for a visually unlabelled input field. If used, it should still
86
+ * have an accessible label, e.g., provided via `aria-label`.
87
+ * For a labeled input field, use `TextField`. instead.
88
+ *
89
+ * **Note:** This component is a styled version of MUI's `InputBase`. See
90
+ * MUI's documentation for full info.
91
+ *
92
+ * - [Smoot Design Input Documentation](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-input--docs)
93
+ * - [InputBase Documentation](https://mui.com/api/input-base/)
94
+ */
95
+ declare const Input: React.FC<InputProps>;
96
+ declare const AdornmentButtonStyled: import("@emotion/styled").StyledComponent<{
97
+ theme?: import("@emotion/react").Theme;
98
+ as?: React.ElementType;
99
+ }, React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
100
+ type AdornmentButtonProps = React.ComponentProps<typeof AdornmentButtonStyled>;
101
+ /**
102
+ * Button to be used with `startAdornment` and `endAdornment` props on Input and
103
+ * TextField components. AdornmentButton takes care of positioning and other
104
+ * styling concerns.
105
+ *
106
+ * NOTES:
107
+ * - It is generally expected that the content of the AdornmentButton is a
108
+ * Remix Icon component. https://remixicon.com/
109
+ * - By default, the AdornmentButton calls `preventDefault` on `mouseDown`
110
+ * events. This prevents the button from stealing focus from the input on
111
+ * click. The button is still focusable via keyboard events. You can override
112
+ * this behavior by passing your own `onMouseDown` handler.
113
+ */
114
+ declare const AdornmentButton: React.FC<AdornmentButtonProps>;
115
+ export { AdornmentButton, Input, baseInputStyles };
116
+ export type { InputProps, AdornmentButtonProps };
@@ -0,0 +1,232 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import * as React from "react";
13
+ import styled from "@emotion/styled";
14
+ import { css } from "@emotion/react";
15
+ import InputBase from "@mui/material/InputBase";
16
+ import classnames from "classnames";
17
+ const defaultProps = {
18
+ size: "medium",
19
+ multiline: false,
20
+ };
21
+ const responsiveSize = {
22
+ small: "small",
23
+ medium: "small",
24
+ large: "medium",
25
+ chat: "chat",
26
+ hero: "large",
27
+ };
28
+ const sizeStyles = ({ size, theme, multiline }) => css([
29
+ (size === "small" || size === "medium") && Object.assign({}, theme.typography.body2),
30
+ (size === "large" || size === "chat" || size === "hero") && Object.assign({ ".remixicon": {
31
+ width: "24px",
32
+ height: "24px",
33
+ } }, theme.typography.body1),
34
+ size === "medium" && {
35
+ paddingLeft: "12px",
36
+ paddingRight: "12px",
37
+ },
38
+ size === "small" &&
39
+ !multiline && {
40
+ height: "32px",
41
+ },
42
+ size === "medium" &&
43
+ !multiline && {
44
+ height: "40px",
45
+ },
46
+ size === "large" &&
47
+ !multiline && {
48
+ height: "48px",
49
+ },
50
+ size === "chat" &&
51
+ !multiline && {
52
+ height: "56px",
53
+ },
54
+ size === "hero" &&
55
+ !multiline && {
56
+ height: "72px",
57
+ },
58
+ size === "small" && {
59
+ padding: "0 8px",
60
+ ".Mit-AdornmentButton": {
61
+ width: "32px",
62
+ ".remixicon": {
63
+ width: "16px",
64
+ height: "16px",
65
+ },
66
+ },
67
+ },
68
+ size === "medium" && {
69
+ padding: "0 12px",
70
+ ".Mit-AdornmentButton": {
71
+ width: "40px",
72
+ ".remixicon": {
73
+ width: "20px",
74
+ height: "20px",
75
+ },
76
+ },
77
+ },
78
+ size === "large" && {
79
+ padding: "0 16px",
80
+ ".Mit-AdornmentButton": {
81
+ width: "48px",
82
+ },
83
+ },
84
+ size === "chat" && {
85
+ padding: "0 16px",
86
+ borderRadius: "8px",
87
+ borderColor: theme.custom.colors.silverGrayLight,
88
+ backgroundColor: theme.custom.colors.white,
89
+ ".Mit-AdornmentButton": {
90
+ padding: "0 16px",
91
+ },
92
+ },
93
+ size === "hero" && {
94
+ padding: "0 24px",
95
+ ".Mit-AdornmentButton": {
96
+ width: "72px",
97
+ },
98
+ },
99
+ ]);
100
+ /**
101
+ * Base styles for Input and Select components. Includes border, color, hover effects.
102
+ */
103
+ const baseInputStyles = (theme) => ({
104
+ backgroundColor: "white",
105
+ color: theme.custom.colors.darkGray2,
106
+ borderColor: theme.custom.colors.silverGrayLight,
107
+ borderWidth: "1px",
108
+ borderStyle: "solid",
109
+ borderRadius: "4px",
110
+ overflow: "hidden",
111
+ "&.Mui-disabled": {
112
+ backgroundColor: theme.custom.colors.lightGray1,
113
+ },
114
+ "&:hover:not(.Mui-disabled):not(.Mui-focused)": {
115
+ borderColor: theme.custom.colors.darkGray2,
116
+ },
117
+ "&.Mui-focused": {
118
+ /**
119
+ * When change border width, it affects either the elements outside of it or
120
+ * inside based on the border-box setting.
121
+ *
122
+ * Instead of changing the border width, we hide the border and change width
123
+ * using outline.
124
+ */
125
+ borderColor: "transparent",
126
+ outline: "2px solid currentcolor",
127
+ outlineOffset: "-2px",
128
+ },
129
+ "&.Mui-error": {
130
+ borderColor: theme.custom.colors.red,
131
+ outlineColor: theme.custom.colors.red,
132
+ },
133
+ "& input::placeholder, textarea::placeholder": {
134
+ color: theme.custom.colors.silverGrayDark,
135
+ opacity: 1, // some browsers apply opacity to placeholder text
136
+ },
137
+ "& input:placeholder-shown, textarea:placeholder-shown": {
138
+ textOverflow: "ellipsis",
139
+ },
140
+ "& textarea": {
141
+ paddingTop: "8px",
142
+ paddingBottom: "8px",
143
+ },
144
+ "&.MuiInputBase-adornedStart": {
145
+ paddingLeft: "0",
146
+ input: {
147
+ paddingLeft: "8px",
148
+ },
149
+ },
150
+ "&.MuiInputBase-adornedEnd": {
151
+ paddingRight: "0",
152
+ input: {
153
+ paddingRight: "8px",
154
+ },
155
+ },
156
+ });
157
+ const noForward = Object.keys({
158
+ responsive: true,
159
+ });
160
+ /**
161
+ * Use `Input` for a visually unlabelled input field. If used, it should still
162
+ * have an accessible label, e.g., provided via `aria-label`.
163
+ * For a labeled input field, use `TextField`. instead.
164
+ *
165
+ * **Note:** This component is a styled version of MUI's `InputBase`. See
166
+ * MUI's documentation for full info.
167
+ *
168
+ * - [Smoot Design Input Documentation](https://mitodl.github.io/smoot-design/?path=/docs/smoot-design-input--docs)
169
+ * - [InputBase Documentation](https://mui.com/api/input-base/)
170
+ */
171
+ const Input = styled(InputBase, {
172
+ shouldForwardProp: (prop) => !noForward.includes(prop),
173
+ })(({ theme, size = defaultProps.size, multiline, responsive }) => [
174
+ baseInputStyles(theme),
175
+ sizeStyles({ size, theme, multiline }),
176
+ responsive && {
177
+ [theme.breakpoints.down("sm")]: sizeStyles({
178
+ size: responsiveSize[size],
179
+ theme,
180
+ multiline,
181
+ }),
182
+ },
183
+ ]);
184
+ const AdornmentButtonStyled = styled.button(({ theme, disabled }) => (Object.assign(Object.assign({}, theme.typography.button), {
185
+ // display
186
+ display: "flex", flexShrink: 0, justifyContent: "center", alignItems: "center",
187
+ // background and border
188
+ border: "none", background: "transparent", transition: `background ${theme.transitions.duration.short}ms`,
189
+ // cursor
190
+ cursor: disabled ? "default" : "pointer", ":disabled": {
191
+ cursor: "default",
192
+ svg: {
193
+ fill: theme.custom.colors.silverGray,
194
+ },
195
+ }, ":hover": {
196
+ background: disabled ? "inherit" : "rgba(0, 0, 0, 0.06)",
197
+ }, color: theme.custom.colors.silverGray, ".MuiInputBase-root:hover &": {
198
+ color: "inherit",
199
+ }, ".MuiInputBase-root.Mui-focused &": {
200
+ color: "inherit",
201
+ }, ".MuiInputBase-root.Mui-disabled &": {
202
+ color: "inherit",
203
+ }, height: "100%" })));
204
+ const noFocus = (e) => e.preventDefault();
205
+ /**
206
+ * Button to be used with `startAdornment` and `endAdornment` props on Input and
207
+ * TextField components. AdornmentButton takes care of positioning and other
208
+ * styling concerns.
209
+ *
210
+ * NOTES:
211
+ * - It is generally expected that the content of the AdornmentButton is a
212
+ * Remix Icon component. https://remixicon.com/
213
+ * - By default, the AdornmentButton calls `preventDefault` on `mouseDown`
214
+ * events. This prevents the button from stealing focus from the input on
215
+ * click. The button is still focusable via keyboard events. You can override
216
+ * this behavior by passing your own `onMouseDown` handler.
217
+ */
218
+ const AdornmentButton = (_a) => {
219
+ var { className } = _a, others = __rest(_a, ["className"]);
220
+ return (React.createElement(AdornmentButtonStyled
221
+ /**
222
+ * If the input is focused and user clicks the AdornmentButton, we don't
223
+ * want to steal focus from the input.
224
+ */
225
+ , Object.assign({
226
+ /**
227
+ * If the input is focused and user clicks the AdornmentButton, we don't
228
+ * want to steal focus from the input.
229
+ */
230
+ onMouseDown: noFocus, className: classnames("Mit-AdornmentButton", className) }, others)));
231
+ };
232
+ export { AdornmentButton, Input, baseInputStyles };
@@ -0,0 +1,19 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { Input } from "./Input";
3
+ declare const meta: Meta<typeof Input>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Input>;
6
+ export declare const Sizes: Story;
7
+ /**
8
+ * **Note:** Adornments should be wrapped in an `AdornmentButton` component.
9
+ *
10
+ * ```tsx
11
+ * <Input startAdornment={
12
+ * <AdornmentButton>
13
+ * <RiSearchLine />
14
+ * </AdornmentButton>
15
+ * } {...otherProps} />
16
+ * ```
17
+ */
18
+ export declare const Adornments: Story;
19
+ export declare const States: Story;
@@ -0,0 +1,132 @@
1
+ import * as React from "react";
2
+ import { Input, AdornmentButton } from "./Input";
3
+ import Stack from "@mui/material/Stack";
4
+ import Grid from "@mui/material/Grid2";
5
+ import { RiCalendarLine, RiCloseLine, RiSearchLine } from "@remixicon/react";
6
+ import { fn } from "@storybook/test";
7
+ import { enumValues } from "../../story-utils";
8
+ import Typography from "@mui/material/Typography";
9
+ const SIZES = enumValues({
10
+ small: true,
11
+ medium: true,
12
+ large: true,
13
+ chat: true,
14
+ hero: true,
15
+ });
16
+ const ADORNMENTS = {
17
+ None: undefined,
18
+ SearchIcon: (React.createElement(AdornmentButton, null,
19
+ React.createElement(RiSearchLine, null))),
20
+ CalendarTodayIcon: (React.createElement(AdornmentButton, null,
21
+ React.createElement(RiCalendarLine, null))),
22
+ CloseIcon: (React.createElement(AdornmentButton, null,
23
+ React.createElement(RiCloseLine, null))),
24
+ "Close and Calendar": (React.createElement(React.Fragment, null,
25
+ React.createElement(AdornmentButton, null,
26
+ React.createElement(RiCloseLine, null)),
27
+ React.createElement(AdornmentButton, null,
28
+ React.createElement(RiCalendarLine, null)))),
29
+ };
30
+ const meta = {
31
+ title: "smoot-design/Input",
32
+ component: Input,
33
+ argTypes: {
34
+ startAdornment: {
35
+ options: Object.keys(ADORNMENTS),
36
+ mapping: ADORNMENTS,
37
+ control: { type: "select" },
38
+ },
39
+ endAdornment: {
40
+ options: Object.keys(ADORNMENTS),
41
+ mapping: ADORNMENTS,
42
+ control: { type: "select" },
43
+ },
44
+ },
45
+ args: {
46
+ onChange: fn(),
47
+ value: "some value",
48
+ placeholder: "placeholder",
49
+ },
50
+ };
51
+ export default meta;
52
+ export const Sizes = {
53
+ render: (args) => {
54
+ return (React.createElement(Stack, { direction: "row", gap: 1 },
55
+ React.createElement(Input, Object.assign({ size: "small" }, args)),
56
+ React.createElement(Input, Object.assign({ size: "medium" }, args)),
57
+ React.createElement(Input, Object.assign({ size: "large" }, args)),
58
+ React.createElement(Input, Object.assign({ size: "hero" }, args))));
59
+ },
60
+ };
61
+ /**
62
+ * **Note:** Adornments should be wrapped in an `AdornmentButton` component.
63
+ *
64
+ * ```tsx
65
+ * <Input startAdornment={
66
+ * <AdornmentButton>
67
+ * <RiSearchLine />
68
+ * </AdornmentButton>
69
+ * } {...otherProps} />
70
+ * ```
71
+ */
72
+ export const Adornments = {
73
+ render: (args) => {
74
+ const adornments = [
75
+ { startAdornment: ADORNMENTS.SearchIcon },
76
+ { endAdornment: ADORNMENTS.CloseIcon },
77
+ {
78
+ startAdornment: ADORNMENTS.SearchIcon,
79
+ endAdornment: ADORNMENTS["Close and Calendar"],
80
+ },
81
+ ];
82
+ return (React.createElement(Grid, { container: true, maxWidth: "1400px", spacing: 2 }, Object.values(adornments).flatMap((props, i) => SIZES.map((size) => {
83
+ return (React.createElement(Grid, { size: { xs: 3 }, key: `${i}-${size}` },
84
+ React.createElement(Input, Object.assign({}, args, { size: size }, props))));
85
+ }))));
86
+ },
87
+ argTypes: {
88
+ startAdornment: { table: { disable: true } },
89
+ endAdornment: { table: { disable: true } },
90
+ },
91
+ };
92
+ export const States = {
93
+ render: (args) => {
94
+ return (React.createElement(Grid, { container: true, spacing: 2, alignItems: "center", maxWidth: "400px" },
95
+ React.createElement(Grid, { size: { xs: 4 } },
96
+ React.createElement(Typography, null, "Placeholder")),
97
+ React.createElement(Grid, { size: { xs: 8 } },
98
+ React.createElement(Input, Object.assign({}, args, { value: "" }))),
99
+ React.createElement(Grid, { size: { xs: 4 } },
100
+ React.createElement(Typography, null, "Default")),
101
+ React.createElement(Grid, { size: { xs: 8 } },
102
+ React.createElement(Input, Object.assign({}, args))),
103
+ React.createElement(Grid, { size: { xs: 4 } },
104
+ React.createElement(Typography, null, "Initially Focused")),
105
+ React.createElement(Grid, { size: { xs: 8 } },
106
+ React.createElement(Input
107
+ // This is a story just demonstrating the autofocus prop
108
+ // eslint-disable-next-line jsx-a11y/no-autofocus
109
+ , Object.assign({
110
+ // This is a story just demonstrating the autofocus prop
111
+ // eslint-disable-next-line jsx-a11y/no-autofocus
112
+ autoFocus: true }, args))),
113
+ React.createElement(Grid, { size: { xs: 4 } },
114
+ React.createElement(Typography, null, "Error")),
115
+ React.createElement(Grid, { size: { xs: 8 } },
116
+ React.createElement(Input, Object.assign({}, args, { error: true }))),
117
+ React.createElement(Grid, { size: { xs: 4 } },
118
+ React.createElement(Typography, null, "Disabled")),
119
+ React.createElement(Grid, { size: { xs: 8 } },
120
+ React.createElement(Input, Object.assign({}, args, { disabled: true })))));
121
+ },
122
+ args: {
123
+ placeholder: "This is placeholder text.",
124
+ value: "Some value",
125
+ },
126
+ argTypes: {
127
+ placeholder: { table: { disable: true } },
128
+ value: { table: { disable: true } },
129
+ error: { table: { disable: true } },
130
+ disabled: { table: { disable: true } },
131
+ },
132
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
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 { Input, AdornmentButton } from "./Input";
14
+ import { ThemeProvider } from "../ThemeProvider/ThemeProvider";
15
+ describe("AdornmentButton", () => {
16
+ it("Does not steal focus from input when clicked", () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const onClick = jest.fn();
18
+ render(React.createElement(Input, { endAdornment: React.createElement(AdornmentButton, { onClick: onClick }, "Test") }), { wrapper: ThemeProvider });
19
+ const input = screen.getByRole("textbox");
20
+ const button = screen.getByRole("button", { name: "Test" });
21
+ yield user.click(input);
22
+ expect(input).toHaveFocus();
23
+ yield user.click(button);
24
+ expect(input).toHaveFocus();
25
+ expect(onClick).toHaveBeenCalledTimes(1);
26
+ // But it should still be focusable via keyboard
27
+ yield user.tab();
28
+ expect(button).toHaveFocus();
29
+ }));
30
+ });
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ /**
3
+ * LinkAdapterPropsOverrides can be used with module augmentation to provide
4
+ * extra props to ButtonLink.
5
+ *
6
+ * For example, in a NextJS App, you might set `next/link` as your default
7
+ * Link implementation, and use LinkAdapterPropsOverrides to provide
8
+ * `next/link`-specific props.
9
+ */
10
+ interface LinkAdapterPropsOverrides {
11
+ }
12
+ type LinkAdapterProps = React.ComponentProps<"a"> & {
13
+ Component?: React.ElementType;
14
+ } & LinkAdapterPropsOverrides;
15
+ /**
16
+ * Overrideable link component.
17
+ * - If `Component` is provided, renders as `Component`
18
+ * - else, if `theme.custom.LinkAdapter` is provided, renders as `theme.custom.LinkAdapter`
19
+ * - else, renders as `a` tag
20
+ */
21
+ declare const LinkAdapter: React.ForwardRefExoticComponent<Omit<LinkAdapterProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
22
+ export { LinkAdapter };
23
+ export type { LinkAdapterPropsOverrides, LinkAdapterProps };
@@ -0,0 +1,31 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import * as React from "react";
13
+ import { useTheme } from "@emotion/react";
14
+ import styled from "@emotion/styled";
15
+ const PlainLink = styled.a({
16
+ color: "inherit",
17
+ textDecoration: "none",
18
+ });
19
+ /**
20
+ * Overrideable link component.
21
+ * - If `Component` is provided, renders as `Component`
22
+ * - else, if `theme.custom.LinkAdapter` is provided, renders as `theme.custom.LinkAdapter`
23
+ * - else, renders as `a` tag
24
+ */
25
+ const LinkAdapter = React.forwardRef(function LinkAdapter(_a, ref) {
26
+ var { Component } = _a, props = __rest(_a, ["Component"]);
27
+ const theme = useTheme();
28
+ const LinkComponent = Component !== null && Component !== void 0 ? Component : theme.custom.LinkAdapter;
29
+ return React.createElement(PlainLink, Object.assign({ as: LinkComponent, ref: ref }, props));
30
+ });
31
+ export { LinkAdapter };
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ type ScrollSnapProps = {
3
+ /**
4
+ * Tolerance within which scroll will be considered "at the bottom" of the element.
5
+ */
6
+ threshold?: number;
7
+ /**
8
+ * Content to be displayed
9
+ */
10
+ children: React.ReactNode;
11
+ className?: string;
12
+ };
13
+ /**
14
+ * Component that automatically scrolls to the bottom of the element when new
15
+ * content is added, unless the user has scrolled up.
16
+ */
17
+ declare const ScrollSnap: React.ForwardRefExoticComponent<ScrollSnapProps & React.RefAttributes<HTMLDivElement>>;
18
+ export { ScrollSnap };
19
+ export type { ScrollSnapProps };
@@ -0,0 +1,56 @@
1
+ import { composeRefs } from "../../utils/composeRefs";
2
+ import styled from "@emotion/styled";
3
+ import * as React from "react";
4
+ /**
5
+ * Returns the distance between visible content and the bottom of the element.
6
+ */
7
+ const distanceFromBottom = (el) => {
8
+ return el.scrollHeight - el.clientHeight - el.scrollTop;
9
+ };
10
+ /**
11
+ * Scrolls to the bottom of the element.
12
+ */
13
+ const scrollToBottom = (el) => {
14
+ el.scrollTop = el.scrollHeight;
15
+ };
16
+ const Scroller = styled.div({
17
+ overflow: "auto",
18
+ });
19
+ /**
20
+ * Component that automatically scrolls to the bottom of the element when new
21
+ * content is added, unless the user has scrolled up.
22
+ */
23
+ const ScrollSnap = React.forwardRef(function ScrollSnap({ children, threshold = 2, className }, ref) {
24
+ const el = React.useRef(null);
25
+ // `content` a delayed version of children to allow measuring scroll position
26
+ // using the old children.
27
+ const [content, setContent] = React.useState(children);
28
+ const wasAtBottom = React.useRef(null);
29
+ /**
30
+ * The next two effects:
31
+ * 1. Check if the element is at the bottom.
32
+ * 2. Then set children -> content
33
+ * 3. Then scroll to bottom (if needed)
34
+ *
35
+ * In this way, we can measure the scroll position before the new content is set.
36
+ *
37
+ * In React 19, this started requiring useLayoutEffect.
38
+ */
39
+ React.useLayoutEffect(() => {
40
+ if (!el.current)
41
+ return;
42
+ wasAtBottom.current = distanceFromBottom(el.current) < threshold;
43
+ setContent(children);
44
+ }, [children, threshold]);
45
+ React.useLayoutEffect(() => {
46
+ if (!el.current)
47
+ return;
48
+ const atBottom = distanceFromBottom(el.current) < threshold;
49
+ if (wasAtBottom.current && !atBottom) {
50
+ scrollToBottom(el.current);
51
+ wasAtBottom.current = null;
52
+ }
53
+ }, [content, threshold]);
54
+ return (React.createElement(Scroller, { className: className, ref: composeRefs(el, ref) }, content));
55
+ });
56
+ export { ScrollSnap };
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { ScrollSnap } from "./ScrollSnap";
3
+ declare const meta: Meta<typeof ScrollSnap>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof ScrollSnap>;
6
+ export declare const Chat: Story;