@mitodl/smoot-design 0.0.0-1967631
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.
- package/LICENSE +28 -0
- package/README.md +35 -0
- package/dist/bundles/remoteTutorDrawer.es.js +38609 -0
- package/dist/bundles/remoteTutorDrawer.es.js.map +1 -0
- package/dist/bundles/remoteTutorDrawer.umd.js +241 -0
- package/dist/bundles/remoteTutorDrawer.umd.js.map +1 -0
- package/dist/cjs/VERSION.d.ts +6 -0
- package/dist/cjs/VERSION.js +9 -0
- package/dist/cjs/ai.d.ts +3 -0
- package/dist/cjs/ai.js +9 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.js +87 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +56 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +283 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +17 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +302 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +247 -0
- package/dist/cjs/bundles/remoteTutorDrawer.d.ts +7 -0
- package/dist/cjs/bundles/remoteTutorDrawer.js +43 -0
- package/dist/cjs/components/AiChat/AiChat.d.ts +5 -0
- package/dist/cjs/components/AiChat/AiChat.js +233 -0
- package/dist/cjs/components/AiChat/AiChat.stories.d.ts +21 -0
- package/dist/cjs/components/AiChat/AiChat.stories.js +257 -0
- package/dist/cjs/components/AiChat/AiChat.test.d.ts +1 -0
- package/dist/cjs/components/AiChat/AiChat.test.js +211 -0
- package/dist/cjs/components/AiChat/AiChatContext.d.ts +26 -0
- package/dist/cjs/components/AiChat/AiChatContext.js +105 -0
- package/dist/cjs/components/AiChat/AiChatContext.stories.d.ts +14 -0
- package/dist/cjs/components/AiChat/AiChatContext.stories.js +75 -0
- package/dist/cjs/components/AiChat/ChatTitle.d.ts +8 -0
- package/dist/cjs/components/AiChat/ChatTitle.js +43 -0
- package/dist/cjs/components/AiChat/EntryScreen.d.ts +11 -0
- package/dist/cjs/components/AiChat/EntryScreen.js +123 -0
- package/dist/cjs/components/AiChat/Markdown.d.ts +7 -0
- package/dist/cjs/components/AiChat/Markdown.js +14 -0
- package/dist/cjs/components/AiChat/TimLogo.d.ts +5 -0
- package/dist/cjs/components/AiChat/TimLogo.js +15 -0
- package/dist/cjs/components/AiChat/test-utils/api.d.ts +2 -0
- package/dist/cjs/components/AiChat/test-utils/api.js +164 -0
- package/dist/cjs/components/AiChat/types.d.ts +91 -0
- package/dist/cjs/components/AiChat/types.js +3 -0
- package/dist/cjs/components/AiChat/utils.d.ts +9 -0
- package/dist/cjs/components/AiChat/utils.js +41 -0
- package/dist/cjs/components/Alert/Alert.d.ts +15 -0
- package/dist/cjs/components/Alert/Alert.js +62 -0
- package/dist/cjs/components/Alert/Alert.stories.d.ts +8 -0
- package/dist/cjs/components/Alert/Alert.stories.js +53 -0
- package/dist/cjs/components/Button/ActionButton.d.ts +30 -0
- package/dist/cjs/components/Button/ActionButton.js +73 -0
- package/dist/cjs/components/Button/ActionButton.stories.d.ts +15 -0
- package/dist/cjs/components/Button/ActionButton.stories.js +113 -0
- package/dist/cjs/components/Button/Button.d.ts +54 -0
- package/dist/cjs/components/Button/Button.js +240 -0
- package/dist/cjs/components/Button/Button.stories.d.ts +17 -0
- package/dist/cjs/components/Button/Button.stories.js +135 -0
- package/dist/cjs/components/Button/Button.test.d.ts +1 -0
- package/dist/cjs/components/Button/Button.test.js +46 -0
- package/dist/cjs/components/ImageAdapter/ImageAdapter.d.ts +23 -0
- package/dist/cjs/components/ImageAdapter/ImageAdapter.js +30 -0
- package/dist/cjs/components/Input/Input.d.ts +116 -0
- package/dist/cjs/components/Input/Input.js +237 -0
- package/dist/cjs/components/Input/Input.stories.d.ts +19 -0
- package/dist/cjs/components/Input/Input.stories.js +135 -0
- package/dist/cjs/components/Input/Input.test.d.ts +1 -0
- package/dist/cjs/components/Input/Input.test.js +32 -0
- package/dist/cjs/components/LinkAdapter/LinkAdapter.d.ts +23 -0
- package/dist/cjs/components/LinkAdapter/LinkAdapter.js +34 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.d.ts +19 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.js +59 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.js +43 -0
- package/dist/cjs/components/ScrollSnap/useScrollSnap.d.ts +6 -0
- package/dist/cjs/components/ScrollSnap/useScrollSnap.js +36 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.js +43 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.js +44 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.js +62 -0
- package/dist/cjs/components/TabButtons/TabButtonList.d.ts +25 -0
- package/dist/cjs/components/TabButtons/TabButtonList.js +97 -0
- package/dist/cjs/components/TabButtons/TabButtonList.stories.d.ts +24 -0
- package/dist/cjs/components/TabButtons/TabButtonList.stories.js +139 -0
- package/dist/cjs/components/TextField/TextField.d.ts +29 -0
- package/dist/cjs/components/TextField/TextField.js +33 -0
- package/dist/cjs/components/TextField/TextField.stories.d.ts +10 -0
- package/dist/cjs/components/TextField/TextField.stories.js +136 -0
- package/dist/cjs/components/TextField/TextField.test.d.ts +1 -0
- package/dist/cjs/components/TextField/TextField.test.js +77 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +21 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.js +86 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.js +102 -0
- package/dist/cjs/components/ThemeProvider/Typography.stories.d.ts +39 -0
- package/dist/cjs/components/ThemeProvider/Typography.stories.js +65 -0
- package/dist/cjs/components/ThemeProvider/breakpoints.d.ts +4 -0
- package/dist/cjs/components/ThemeProvider/breakpoints.js +19 -0
- package/dist/cjs/components/ThemeProvider/buttons.d.ts +7 -0
- package/dist/cjs/components/ThemeProvider/buttons.js +20 -0
- package/dist/cjs/components/ThemeProvider/chips.d.ts +3 -0
- package/dist/cjs/components/ThemeProvider/chips.js +154 -0
- package/dist/cjs/components/ThemeProvider/colors.d.ts +32 -0
- package/dist/cjs/components/ThemeProvider/colors.js +35 -0
- package/dist/cjs/components/ThemeProvider/typography.d.ts +18 -0
- package/dist/cjs/components/ThemeProvider/typography.js +173 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js +33 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.js +13 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.js +78 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.js +93 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/jest-setup.d.ts +1 -0
- package/dist/cjs/jest-setup.js +18 -0
- package/dist/cjs/jsdom-extended.d.ts +6 -0
- package/dist/cjs/jsdom-extended.js +14 -0
- package/dist/cjs/story-utils/index.d.ts +6 -0
- package/dist/cjs/story-utils/index.js +17 -0
- package/dist/cjs/utils/composeRefs.d.ts +7 -0
- package/dist/cjs/utils/composeRefs.js +20 -0
- package/dist/cjs/utils/composeRefs.test.d.ts +1 -0
- package/dist/cjs/utils/composeRefs.test.js +19 -0
- package/dist/cjs/utils/useDevCheckStable.d.ts +8 -0
- package/dist/cjs/utils/useDevCheckStable.js +29 -0
- package/dist/cjs/utils/useInterval.d.ts +7 -0
- package/dist/cjs/utils/useInterval.js +25 -0
- package/dist/esm/VERSION.d.ts +6 -0
- package/dist/esm/VERSION.js +6 -0
- package/dist/esm/ai.d.ts +3 -0
- package/dist/esm/ai.js +2 -0
- package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
- package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.js +83 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +56 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +280 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +17 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +299 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +245 -0
- package/dist/esm/bundles/remoteTutorDrawer.d.ts +7 -0
- package/dist/esm/bundles/remoteTutorDrawer.js +40 -0
- package/dist/esm/components/AiChat/AiChat.d.ts +5 -0
- package/dist/esm/components/AiChat/AiChat.js +229 -0
- package/dist/esm/components/AiChat/AiChat.stories.d.ts +21 -0
- package/dist/esm/components/AiChat/AiChat.stories.js +254 -0
- package/dist/esm/components/AiChat/AiChat.test.d.ts +1 -0
- package/dist/esm/components/AiChat/AiChat.test.js +209 -0
- package/dist/esm/components/AiChat/AiChatContext.d.ts +26 -0
- package/dist/esm/components/AiChat/AiChatContext.js +101 -0
- package/dist/esm/components/AiChat/AiChatContext.stories.d.ts +14 -0
- package/dist/esm/components/AiChat/AiChatContext.stories.js +72 -0
- package/dist/esm/components/AiChat/ChatTitle.d.ts +8 -0
- package/dist/esm/components/AiChat/ChatTitle.js +40 -0
- package/dist/esm/components/AiChat/EntryScreen.d.ts +11 -0
- package/dist/esm/components/AiChat/EntryScreen.js +120 -0
- package/dist/esm/components/AiChat/Markdown.d.ts +7 -0
- package/dist/esm/components/AiChat/Markdown.js +12 -0
- package/dist/esm/components/AiChat/TimLogo.d.ts +5 -0
- package/dist/esm/components/AiChat/TimLogo.js +13 -0
- package/dist/esm/components/AiChat/test-utils/api.d.ts +2 -0
- package/dist/esm/components/AiChat/test-utils/api.js +161 -0
- package/dist/esm/components/AiChat/types.d.ts +91 -0
- package/dist/esm/components/AiChat/types.js +2 -0
- package/dist/esm/components/AiChat/utils.d.ts +9 -0
- package/dist/esm/components/AiChat/utils.js +38 -0
- package/dist/esm/components/Alert/Alert.d.ts +15 -0
- package/dist/esm/components/Alert/Alert.js +59 -0
- package/dist/esm/components/Alert/Alert.stories.d.ts +8 -0
- package/dist/esm/components/Alert/Alert.stories.js +50 -0
- package/dist/esm/components/Button/ActionButton.d.ts +30 -0
- package/dist/esm/components/Button/ActionButton.js +68 -0
- package/dist/esm/components/Button/ActionButton.stories.d.ts +15 -0
- package/dist/esm/components/Button/ActionButton.stories.js +110 -0
- package/dist/esm/components/Button/Button.d.ts +54 -0
- package/dist/esm/components/Button/Button.js +232 -0
- package/dist/esm/components/Button/Button.stories.d.ts +17 -0
- package/dist/esm/components/Button/Button.stories.js +132 -0
- package/dist/esm/components/Button/Button.test.d.ts +1 -0
- package/dist/esm/components/Button/Button.test.js +44 -0
- package/dist/esm/components/ImageAdapter/ImageAdapter.d.ts +23 -0
- package/dist/esm/components/ImageAdapter/ImageAdapter.js +27 -0
- package/dist/esm/components/Input/Input.d.ts +116 -0
- package/dist/esm/components/Input/Input.js +232 -0
- package/dist/esm/components/Input/Input.stories.d.ts +19 -0
- package/dist/esm/components/Input/Input.stories.js +132 -0
- package/dist/esm/components/Input/Input.test.d.ts +1 -0
- package/dist/esm/components/Input/Input.test.js +30 -0
- package/dist/esm/components/LinkAdapter/LinkAdapter.d.ts +23 -0
- package/dist/esm/components/LinkAdapter/LinkAdapter.js +31 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.d.ts +19 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.js +56 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.stories.js +40 -0
- package/dist/esm/components/ScrollSnap/useScrollSnap.d.ts +6 -0
- package/dist/esm/components/ScrollSnap/useScrollSnap.js +33 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.js +40 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.js +41 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.js +60 -0
- package/dist/esm/components/TabButtons/TabButtonList.d.ts +25 -0
- package/dist/esm/components/TabButtons/TabButtonList.js +92 -0
- package/dist/esm/components/TabButtons/TabButtonList.stories.d.ts +24 -0
- package/dist/esm/components/TabButtons/TabButtonList.stories.js +136 -0
- package/dist/esm/components/TextField/TextField.d.ts +29 -0
- package/dist/esm/components/TextField/TextField.js +30 -0
- package/dist/esm/components/TextField/TextField.stories.d.ts +10 -0
- package/dist/esm/components/TextField/TextField.stories.js +133 -0
- package/dist/esm/components/TextField/TextField.test.d.ts +1 -0
- package/dist/esm/components/TextField/TextField.test.js +75 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +21 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.js +82 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.stories.js +99 -0
- package/dist/esm/components/ThemeProvider/Typography.stories.d.ts +39 -0
- package/dist/esm/components/ThemeProvider/Typography.stories.js +62 -0
- package/dist/esm/components/ThemeProvider/breakpoints.d.ts +4 -0
- package/dist/esm/components/ThemeProvider/breakpoints.js +15 -0
- package/dist/esm/components/ThemeProvider/buttons.d.ts +7 -0
- package/dist/esm/components/ThemeProvider/buttons.js +17 -0
- package/dist/esm/components/ThemeProvider/chips.d.ts +3 -0
- package/dist/esm/components/ThemeProvider/chips.js +151 -0
- package/dist/esm/components/ThemeProvider/colors.d.ts +32 -0
- package/dist/esm/components/ThemeProvider/colors.js +32 -0
- package/dist/esm/components/ThemeProvider/typography.d.ts +18 -0
- package/dist/esm/components/ThemeProvider/typography.js +167 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +30 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.js +10 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.js +73 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.test.js +91 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/jest-setup.d.ts +1 -0
- package/dist/esm/jest-setup.js +16 -0
- package/dist/esm/jsdom-extended.d.ts +6 -0
- package/dist/esm/jsdom-extended.js +12 -0
- package/dist/esm/story-utils/index.d.ts +6 -0
- package/dist/esm/story-utils/index.js +13 -0
- package/dist/esm/utils/composeRefs.d.ts +7 -0
- package/dist/esm/utils/composeRefs.js +17 -0
- package/dist/esm/utils/composeRefs.test.d.ts +1 -0
- package/dist/esm/utils/composeRefs.test.js +17 -0
- package/dist/esm/utils/useDevCheckStable.d.ts +8 -0
- package/dist/esm/utils/useDevCheckStable.js +26 -0
- package/dist/esm/utils/useInterval.d.ts +7 -0
- package/dist/esm/utils/useInterval.js +22 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type-augmentation/TypescriptDocs.mdx +17 -0
- package/dist/type-augmentation/imports.d.ts +3 -0
- package/dist/type-augmentation/index.d.ts +3 -0
- package/dist/type-augmentation/theme.d.ts +105 -0
- package/dist/type-augmentation/typography.d.ts +54 -0
- package/package.json +158 -0
|
@@ -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), props.children));
|
|
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,40 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ScrollSnap } from "./ScrollSnap";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { faker } from "@faker-js/faker/locale/en";
|
|
5
|
+
import { useInterval } from "../../utils/useInterval";
|
|
6
|
+
import Slider from "@mui/material/Slider";
|
|
7
|
+
import Stack from "@mui/material/Stack";
|
|
8
|
+
import Typography from "@mui/material/Typography";
|
|
9
|
+
import { Button } from "../Button/Button";
|
|
10
|
+
const Scroller = styled(ScrollSnap)({
|
|
11
|
+
width: "200px",
|
|
12
|
+
height: "350px",
|
|
13
|
+
border: "1pt solid black",
|
|
14
|
+
});
|
|
15
|
+
const meta = {
|
|
16
|
+
title: "smoot-design/ScrollSnap",
|
|
17
|
+
component: ScrollSnap,
|
|
18
|
+
render: function Render(args) {
|
|
19
|
+
const MAX = 3000;
|
|
20
|
+
const [updateInterval, setUpdateInterval] = React.useState(MAX);
|
|
21
|
+
const [children, setChildren] = React.useState(faker.lorem.sentence());
|
|
22
|
+
const appendText = () => setChildren((current) => {
|
|
23
|
+
return `${current} ${faker.lorem.sentence()}`;
|
|
24
|
+
});
|
|
25
|
+
useInterval(() => {
|
|
26
|
+
appendText();
|
|
27
|
+
}, updateInterval === MAX ? null : updateInterval);
|
|
28
|
+
return (React.createElement(Stack, { gap: "12px", alignItems: "start" },
|
|
29
|
+
React.createElement(Typography, null, "Update interval (ms)"),
|
|
30
|
+
React.createElement(Slider, { sx: { width: "350px" }, marks: [
|
|
31
|
+
{ value: 100, label: "0.1s" },
|
|
32
|
+
{ value: 2000, label: "2s" },
|
|
33
|
+
{ value: MAX, label: "off" },
|
|
34
|
+
], value: updateInterval, min: 100, max: MAX, onChange: (_e, val) => setUpdateInterval(val) }),
|
|
35
|
+
React.createElement(Scroller, Object.assign({}, args), children),
|
|
36
|
+
React.createElement(Button, { onClick: appendText }, "Append Sentence")));
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export default meta;
|
|
40
|
+
export const Chat = {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the distance between visible content and the bottom of the element.
|
|
4
|
+
*/
|
|
5
|
+
const distanceFromBottom = (el) => {
|
|
6
|
+
return el.scrollHeight - el.clientHeight - el.scrollTop;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Scrolls to the bottom of the element.
|
|
10
|
+
*/
|
|
11
|
+
const scrollToBottom = (el) => {
|
|
12
|
+
el.scrollTop = el.scrollHeight;
|
|
13
|
+
};
|
|
14
|
+
const useScrollSnap = ({ scrollElement, contentElement, threshold = 2, }) => {
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const onGrow = () => {
|
|
17
|
+
if (!scrollElement)
|
|
18
|
+
return;
|
|
19
|
+
if (distanceFromBottom(scrollElement) < threshold) {
|
|
20
|
+
scrollToBottom(scrollElement);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
onGrow();
|
|
24
|
+
const resizeObserver = new ResizeObserver(onGrow);
|
|
25
|
+
if (contentElement) {
|
|
26
|
+
resizeObserver.observe(contentElement);
|
|
27
|
+
}
|
|
28
|
+
return () => {
|
|
29
|
+
resizeObserver.disconnect();
|
|
30
|
+
};
|
|
31
|
+
}, [scrollElement, contentElement, threshold]);
|
|
32
|
+
};
|
|
33
|
+
export { useScrollSnap };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type SrAnnouncerProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Message text to be read to user.
|
|
5
|
+
*
|
|
6
|
+
* Cannot contain HTML elements—only text.
|
|
7
|
+
*/
|
|
8
|
+
message: string;
|
|
9
|
+
/**
|
|
10
|
+
* Messages to display while the component is in a loading state.
|
|
11
|
+
*
|
|
12
|
+
* Identical consecutive messages may not be read on some screen readers.
|
|
13
|
+
*/
|
|
14
|
+
loadingMessages?: {
|
|
15
|
+
delay: number;
|
|
16
|
+
text: string;
|
|
17
|
+
}[];
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A component that announces messages to screen readers as they come in.
|
|
22
|
+
*/
|
|
23
|
+
declare const SrAnnouncer: React.FC<SrAnnouncerProps>;
|
|
24
|
+
export { SrAnnouncer };
|
|
25
|
+
export type { SrAnnouncerProps };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { useDevCheckStable } from "../../utils/useDevCheckStable";
|
|
5
|
+
const DEFAULT_PROPS = {
|
|
6
|
+
loadingMessages: [
|
|
7
|
+
{ delay: 1500, text: "Loading" },
|
|
8
|
+
{ delay: 4000, text: "Still loading" },
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A component that announces messages to screen readers as they come in.
|
|
13
|
+
*/
|
|
14
|
+
const SrAnnouncer = ({ message, isLoading, loadingMessages = DEFAULT_PROPS.loadingMessages, }) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const [loadingMsgIndex, setLoadingMsgIndex] = React.useState(-1);
|
|
17
|
+
/**
|
|
18
|
+
* If loadingMessages changes, the timeouts are reset.
|
|
19
|
+
* Desirable if the change is real, undesirable if it's a mistake (e.g., by
|
|
20
|
+
* passing an array literal as a prop).
|
|
21
|
+
*/
|
|
22
|
+
useDevCheckStable(loadingMessages, "SrAnnouncer: loadingMessages changed (by ===) unexpectedly. This may interfere with loading message visibility");
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setLoadingMsgIndex(-1);
|
|
25
|
+
}, [isLoading, loadingMessages]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const next = loadingMessages[loadingMsgIndex + 1];
|
|
28
|
+
if (!isLoading || !next)
|
|
29
|
+
return () => { };
|
|
30
|
+
const id = setTimeout(() => {
|
|
31
|
+
setLoadingMsgIndex(loadingMsgIndex + 1);
|
|
32
|
+
}, next.delay);
|
|
33
|
+
return () => {
|
|
34
|
+
clearTimeout(id);
|
|
35
|
+
};
|
|
36
|
+
}, [isLoading, loadingMsgIndex, loadingMessages]);
|
|
37
|
+
const loadingTxt = (_a = loadingMessages[loadingMsgIndex]) === null || _a === void 0 ? void 0 : _a.text;
|
|
38
|
+
return (React.createElement(VisuallyHidden, { "aria-atomic": "true", "aria-live": "polite" }, isLoading ? loadingTxt : message));
|
|
39
|
+
};
|
|
40
|
+
export { SrAnnouncer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { SrAnnouncer } from "./SrAnnouncer";
|
|
3
|
+
declare const meta: Meta<typeof SrAnnouncer>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof SrAnnouncer>;
|
|
6
|
+
export declare const ScreenreaderAnnouncements: Story;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { SrAnnouncer } from "./SrAnnouncer";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
const Container = styled.div(({ forceVisible }) => [
|
|
5
|
+
forceVisible && {
|
|
6
|
+
width: "100% !important",
|
|
7
|
+
height: "100px !important",
|
|
8
|
+
"& > *:first-of-type": {
|
|
9
|
+
width: "unset !important",
|
|
10
|
+
height: "unset !important",
|
|
11
|
+
clipPath: "none !important",
|
|
12
|
+
clip: "unset !important",
|
|
13
|
+
position: "unset !important",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
const meta = {
|
|
18
|
+
title: "smoot-design/ScreenreaderAnnouncer",
|
|
19
|
+
component: SrAnnouncer,
|
|
20
|
+
decorators: function Decorator(Story) {
|
|
21
|
+
const [forceVisible, setForceVisible] = React.useState(true);
|
|
22
|
+
return (React.createElement(React.Fragment, null,
|
|
23
|
+
React.createElement("label", null,
|
|
24
|
+
"Force Visible:",
|
|
25
|
+
React.createElement("input", { type: "checkbox", checked: forceVisible, onChange: (e) => setForceVisible(e.target.checked) }),
|
|
26
|
+
React.createElement("p", null, "By default, the content of this story is visually hidden.")),
|
|
27
|
+
React.createElement("hr", null),
|
|
28
|
+
React.createElement(Container, { forceVisible: forceVisible },
|
|
29
|
+
React.createElement(Story, null))));
|
|
30
|
+
},
|
|
31
|
+
args: {
|
|
32
|
+
message: "A message to read to user",
|
|
33
|
+
isLoading: true,
|
|
34
|
+
loadingMessages: [
|
|
35
|
+
{ delay: 1000, text: "Loading" },
|
|
36
|
+
{ delay: 3000, text: "Still loading" },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export default meta;
|
|
41
|
+
export const ScreenreaderAnnouncements = {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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, act } from "@testing-library/react";
|
|
12
|
+
import { SrAnnouncer } from "./SrAnnouncer";
|
|
13
|
+
const sleep = (ms) => {
|
|
14
|
+
act(() => {
|
|
15
|
+
jest.advanceTimersByTime(ms);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
describe("SrAnnouncer", () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.useFakeTimers();
|
|
21
|
+
jest.clearAllTimers();
|
|
22
|
+
});
|
|
23
|
+
test("Renders a message when not loading", () => {
|
|
24
|
+
const { container } = render(React.createElement(SrAnnouncer, { message: "Hello, world!", isLoading: false }));
|
|
25
|
+
expect(container.textContent).toBe("Hello, world!");
|
|
26
|
+
});
|
|
27
|
+
test("Renders a loading message when loading", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const loadingMessages = [
|
|
29
|
+
{ delay: 100, text: "Loading 1" },
|
|
30
|
+
{ delay: 200, text: "Loading 2" },
|
|
31
|
+
];
|
|
32
|
+
const { container, rerender } = render(React.createElement(SrAnnouncer, { message: "Hello, world!", loadingMessages: loadingMessages, isLoading: true }));
|
|
33
|
+
expect(container.textContent).toBe("");
|
|
34
|
+
sleep(100);
|
|
35
|
+
expect(container.textContent).toBe("Loading 1");
|
|
36
|
+
sleep(100);
|
|
37
|
+
expect(container.textContent).toBe("Loading 1");
|
|
38
|
+
sleep(100);
|
|
39
|
+
expect(container.textContent).toBe("Loading 2");
|
|
40
|
+
sleep(1000);
|
|
41
|
+
expect(container.textContent).toBe("Loading 2");
|
|
42
|
+
rerender(React.createElement(SrAnnouncer, { message: "Hello, world!", loadingMessages: loadingMessages, isLoading: false }));
|
|
43
|
+
expect(container.textContent).toBe("Hello, world!");
|
|
44
|
+
rerender(React.createElement(SrAnnouncer, { message: "Hello, world!", loadingMessages: loadingMessages, isLoading: true }));
|
|
45
|
+
expect(container.textContent).toBe("");
|
|
46
|
+
sleep(100);
|
|
47
|
+
expect(container.textContent).toBe("Loading 1");
|
|
48
|
+
sleep(100);
|
|
49
|
+
expect(container.textContent).toBe("Loading 1");
|
|
50
|
+
sleep(100);
|
|
51
|
+
expect(container.textContent).toBe("Loading 2");
|
|
52
|
+
}));
|
|
53
|
+
test("Warns if loadingMessages changes unexpectedly", () => {
|
|
54
|
+
const error = jest.spyOn(console, "error").mockImplementation(() => { });
|
|
55
|
+
const { rerender } = render(React.createElement(SrAnnouncer, { message: "Hello, world!", isLoading: true }));
|
|
56
|
+
rerender(React.createElement(SrAnnouncer, { message: "Hello, world!", isLoading: true, loadingMessages: [{ delay: 100, text: "Loading" }] }));
|
|
57
|
+
expect(error).toHaveBeenCalled();
|
|
58
|
+
error.mockRestore();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TabProps } from "@mui/material/Tab";
|
|
3
|
+
import type { TabListProps } from "@mui/lab/TabList";
|
|
4
|
+
import type { ButtonLinkProps } from "../Button/Button";
|
|
5
|
+
type StyleVariant = "chat";
|
|
6
|
+
type TabButtonListProps = TabListProps & {
|
|
7
|
+
styleVariant?: StyleVariant;
|
|
8
|
+
};
|
|
9
|
+
declare const TabButtonList: React.FC<TabButtonListProps>;
|
|
10
|
+
declare const TabLinkInner: React.ForwardRefExoticComponent<Omit<ButtonLinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
11
|
+
type TabButtonProps = Omit<TabProps<"button">, "color"> & {
|
|
12
|
+
styleVariant?: StyleVariant;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Wrapper around [MUI Tab](https://mui.com/material-ui/api/tab/) using our
|
|
16
|
+
* Button as the `component` implementation.
|
|
17
|
+
*/
|
|
18
|
+
declare const TabButton: (props: TabButtonProps) => React.JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Wrapper around [MUI Tab](https://mui.com/material-ui/api/tab/) using our
|
|
21
|
+
* ButtonLink as the `component` implementation.
|
|
22
|
+
*/
|
|
23
|
+
declare const TabButtonLink: ({ ...props }: TabProps<typeof TabLinkInner>) => React.JSX.Element;
|
|
24
|
+
export { TabButtonList, TabButton, TabButtonLink };
|
|
25
|
+
export type { TabButtonListProps, TabButtonProps };
|