@nulogy/components 16.0.1 → 16.0.3
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/dist/main.js +46 -59
- package/dist/main.js.map +1 -1
- package/dist/main.module.js +46 -59
- package/dist/main.module.js.map +1 -1
- package/dist/src/Alert/Alert.story.d.ts +1 -1
- package/dist/src/Alert/Alert.story.js +11 -0
- package/dist/src/AppTag/stories/AppTag.story.d.ts +2 -2
- package/dist/src/AppTag/stories/AppTag.story.js +6 -4
- package/dist/src/AppTag/stories/AppTag.usecases.story.d.ts +13 -10
- package/dist/src/AppTag/stories/AppTag.usecases.story.js +71 -51
- package/dist/src/AsyncSelect/AsyncSelect.story.d.ts +17 -13
- package/dist/src/AsyncSelect/AsyncSelect.story.js +46 -23
- package/dist/src/BottomSheet/BottomSheet.parts.d.ts +2 -2
- package/dist/src/BottomSheet/BottomSheet.styled.d.ts +10 -6
- package/dist/src/BottomSheet/stories/BottomSheet.actions.story.d.ts +8 -1
- package/dist/src/BottomSheet/stories/BottomSheet.actions.story.js +22 -3
- package/dist/src/BottomSheet/stories/BottomSheet.features.story.d.ts +9 -2
- package/dist/src/BottomSheet/stories/BottomSheet.features.story.js +27 -12
- package/dist/src/BottomSheet/stories/BottomSheet.story.d.ts +7 -1
- package/dist/src/BottomSheet/stories/BottomSheet.story.js +20 -3
- package/dist/src/Box/Box.d.ts +12 -13
- package/dist/src/Box/Box.story.d.ts +22 -44
- package/dist/src/Box/Box.story.js +30 -30
- package/dist/src/BrandedNavBar/DesktopMenu.d.ts +3 -1
- package/dist/src/BrandedNavBar/NavBar.js +2 -2
- package/dist/src/BrandedNavBar/NavBar.story.d.ts +16 -28
- package/dist/src/BrandedNavBar/NavBar.story.js +41 -35
- package/dist/src/BrandedNavBar/SmallNavBar.story.d.ts +1 -1
- package/dist/src/Breadcrumbs/Breadcrumbs.story.d.ts +4 -8
- package/dist/src/Breadcrumbs/Breadcrumbs.story.js +4 -4
- package/dist/src/Button/Button.story.d.ts +14 -28
- package/dist/src/Button/Button.story.js +14 -14
- package/dist/src/Button/ControlIcon.story.js +1 -1
- package/dist/src/Button/DangerButton.d.ts +3 -1
- package/dist/src/Button/IconicButton.story.d.ts +23 -45
- package/dist/src/Button/IconicButton.story.js +27 -25
- package/dist/src/Button/PrimaryButton.d.ts +3 -1
- package/dist/src/Button/QuietButton.d.ts +3 -1
- package/dist/src/ButtonGroup/ButtonGroup.story.d.ts +13 -23
- package/dist/src/ButtonGroup/ButtonGroup.story.js +10 -10
- package/dist/src/Card/Card.story.d.ts +3 -5
- package/dist/src/Card/Card.story.js +9 -7
- package/dist/src/Checkbox/Checkbox.story.d.ts +18 -34
- package/dist/src/Checkbox/Checkbox.story.js +28 -24
- package/dist/src/Checkbox/CheckboxGroup.story.d.ts +10 -20
- package/dist/src/Checkbox/CheckboxGroup.story.js +10 -10
- package/dist/src/DatePickers/stories/DatePicker.story.d.ts +9 -2
- package/dist/src/DatePickers/stories/DatePicker.story.js +43 -2
- package/dist/src/DatePickers/stories/MonthPicker.story.d.ts +8 -1
- package/dist/src/DatePickers/stories/MonthPicker.story.js +21 -2
- package/dist/src/DatePickers/stories/WeekPicker.story.d.ts +32 -4
- package/dist/src/DatePickers/stories/WeekPicker.story.js +57 -8
- package/dist/src/DateRange/DateRange.story.d.ts +16 -2
- package/dist/src/DateRange/DateRange.story.js +41 -3
- package/dist/src/DateRange/EndTime.d.ts +5 -7
- package/dist/src/DateRange/StartTime.d.ts +5 -7
- package/dist/src/DescriptionList/stories/DescriptionList.column.story.d.ts +1 -1
- package/dist/src/DescriptionList/stories/DescriptionList.column.story.js +10 -8
- package/dist/src/DescriptionList/stories/DescriptionList.group-min-width.story.d.ts +1 -1
- package/dist/src/DescriptionList/stories/DescriptionList.layout.story.d.ts +1 -1
- package/dist/src/DescriptionList/stories/DescriptionList.layout.story.js +12 -10
- package/dist/src/DescriptionList/stories/DescriptionList.playground.story.d.ts +1 -1
- package/dist/src/DescriptionList/stories/DescriptionList.story.d.ts +1 -0
- package/dist/src/DescriptionList/stories/DescriptionList.story.js +3 -0
- package/dist/src/DescriptionList/stories/fixtures.d.ts +2 -2
- package/dist/src/DropdownMenu/DropdownMenu.story.d.ts +32 -32
- package/dist/src/DropdownMenu/DropdownMenu.story.js +58 -16
- package/dist/src/DropdownMenu/DropdownMenuContainer.d.ts +1 -1
- package/dist/src/DropdownMenu/DropdownText.d.ts +1 -1
- package/dist/src/FieldLabel/FieldLabel.story.d.ts +2 -4
- package/dist/src/FieldLabel/FieldLabel.story.js +2 -2
- package/dist/src/FieldLabel/HelpText.d.ts +1 -1
- package/dist/src/Flex/Flex.story.d.ts +34 -68
- package/dist/src/Flex/Flex.story.js +36 -36
- package/dist/src/Form/Form.story.d.ts +8 -16
- package/dist/src/Form/Form.story.js +8 -8
- package/dist/src/Icon/Icon.d.ts +6 -2
- package/dist/src/Icon/Icon.story.d.ts +12 -24
- package/dist/src/Icon/Icon.story.js +15 -15
- package/dist/src/Input/Input.story.d.ts +16 -32
- package/dist/src/Input/Input.story.js +23 -23
- package/dist/src/Layout/Page.applicationFrame.story.d.ts +1 -1
- package/dist/src/Layout/Page.story.d.ts +1 -1
- package/dist/src/Layout/Sidebar.story.d.ts +1 -1
- package/dist/src/Link/Link.story.d.ts +16 -32
- package/dist/src/Link/Link.story.js +16 -17
- package/dist/src/List/List.story.d.ts +8 -16
- package/dist/src/List/List.story.js +8 -8
- package/dist/src/LoadingAnimation/LoadingAnimation.story.d.ts +4 -8
- package/dist/src/LoadingAnimation/LoadingAnimation.story.js +4 -4
- package/dist/src/MaybeTooltip/MaybeTooltip.story.d.ts +1 -1
- package/dist/src/Modal/Modal.d.ts +5 -3
- package/dist/src/Modal/Modal.js +2 -2
- package/dist/src/Modal/Modal.story.d.ts +2 -24
- package/dist/src/Modal/ModalCloseButton.d.ts +4 -2
- package/dist/src/Modal/ModalContent.d.ts +1 -1
- package/dist/src/Navigation/components/AppSwitcher/parts/Item.d.ts +3 -1
- package/dist/src/Navigation/components/AppSwitcher/parts/index.d.ts +15 -7
- package/dist/src/Navigation/components/DesktopNav/parts/MoreMenuItem.d.ts +5 -1
- package/dist/src/Navigation/components/MenuSubItem/parts/styled.d.ts +17 -5
- package/dist/src/Navigation/components/MobileNav/parts/styled.d.ts +10 -4
- package/dist/src/Navigation/components/UserMenu/UserMenu.d.ts +5 -1
- package/dist/src/Navigation/components/UserMenu/parts/styled.d.ts +6 -2
- package/dist/src/Navigation/components/shared/NavigationMenuContent.d.ts +5 -1
- package/dist/src/Navigation/components/shared/NavigationMenuItem.d.ts +3 -1
- package/dist/src/Navigation/components/shared/components.d.ts +35 -9
- package/dist/src/Navigation/stories/Navigation.appSwitcher.story.d.ts +8 -1
- package/dist/src/Navigation/stories/Navigation.appSwitcher.story.js +19 -1
- package/dist/src/Navigation/stories/Navigation.logos.story.d.ts +2 -4
- package/dist/src/Navigation/stories/Navigation.logos.story.js +4 -4
- package/dist/src/Navigation/stories/Navigation.story.d.ts +7 -1
- package/dist/src/Navigation/stories/Navigation.story.js +145 -136
- package/dist/src/Navigation/stories/Navigation.userMenu.story.d.ts +8 -1
- package/dist/src/Navigation/stories/Navigation.userMenu.story.js +22 -1
- package/dist/src/Overlay/Overlay.story.d.ts +2 -4
- package/dist/src/Overlay/Overlay.story.js +2 -2
- package/dist/src/Pagination/Pagination.story.d.ts +14 -13
- package/dist/src/Pagination/Pagination.story.js +32 -11
- package/dist/src/Radio/Radio.story.d.ts +13 -15
- package/dist/src/Radio/Radio.story.js +44 -1
- package/dist/src/Radio/RadioGroup.story.d.ts +29 -21
- package/dist/src/Radio/RadioGroup.story.js +67 -14
- package/dist/src/RangeContainer/RangeContainer.story.d.ts +2 -4
- package/dist/src/RangeContainer/RangeContainer.story.js +2 -2
- package/dist/src/Select/Select.story.d.ts +37 -65
- package/dist/src/Select/Select.story.js +93 -49
- package/dist/src/StatusIndicator/StatusIndicator.story.d.ts +4 -8
- package/dist/src/StatusIndicator/StatusIndicator.story.js +4 -4
- package/dist/src/Summary/Summary.d.ts +1 -2
- package/dist/src/Summary/Summary.js +2 -2
- package/dist/src/Summary/SummaryContext.d.ts +3 -1
- package/dist/src/Summary/SummaryContext.js +2 -2
- package/dist/src/Summary/SummaryItem.d.ts +1 -1
- package/dist/src/Summary/SummaryItem.js +2 -2
- package/dist/src/Switcher/Switcher.d.ts +2 -2
- package/dist/src/Switcher/Switcher.js +2 -2
- package/dist/src/Switcher/Switcher.story.d.ts +8 -1
- package/dist/src/Switcher/Switcher.story.js +13 -1
- package/dist/src/Table/stories/BaseTable.story.d.ts +1 -1
- package/dist/src/Table/stories/BaseTable.story.js +1 -1
- package/dist/src/Table/stories/CustomContent.story.js +1 -1
- package/dist/src/Table/stories/Density.story.d.ts +4 -8
- package/dist/src/Table/stories/Density.story.js +4 -4
- package/dist/src/Table/stories/SortingColumnHeader.story.d.ts +1 -1
- package/dist/src/Table/stories/SortingColumnHeader.story.js +1 -1
- package/dist/src/Table/stories/Table.story.d.ts +1 -1
- package/dist/src/Table/stories/Table.story.js +37 -1
- package/dist/src/Table/stories/TableWithCustomSorting.story.d.ts +2 -4
- package/dist/src/Table/stories/TableWithCustomSorting.story.js +2 -2
- package/dist/src/Table/stories/TableWithExpandableRows.story.d.ts +4 -8
- package/dist/src/Table/stories/TableWithExpandableRows.story.js +5 -5
- package/dist/src/Table/stories/TableWithFiltering.story.d.ts +8 -8
- package/dist/src/Table/stories/TableWithFiltering.story.js +15 -4
- package/dist/src/Table/stories/TableWithSelectableRows.story.d.ts +8 -8
- package/dist/src/Table/stories/TableWithSelectableRows.story.js +22 -5
- package/dist/src/Table/stories/TableWithServerSidePagination.story.d.ts +2 -4
- package/dist/src/Table/stories/TableWithServerSidePagination.story.js +2 -2
- package/dist/src/Tabs/TabScrollIndicator.d.ts +1 -1
- package/dist/src/Tabs/TabScrollIndicator.js +2 -2
- package/dist/src/Tabs/Tabs.story.d.ts +33 -33
- package/dist/src/Tabs/Tabs.story.js +52 -16
- package/dist/src/Textarea/Textarea.story.js +1 -1
- package/dist/src/TimePicker/TimePicker.d.ts +1 -1
- package/dist/src/TimePicker/TimePicker.js +2 -0
- package/dist/src/TimePicker/TimePicker.story.d.ts +24 -40
- package/dist/src/TimePicker/TimePicker.story.js +40 -27
- package/dist/src/TimePicker/TimePickerInput.d.ts +3 -1
- package/dist/src/TimeRange/TimeRange.d.ts +3 -2
- package/dist/src/TimeRange/TimeRange.story.d.ts +14 -20
- package/dist/src/TimeRange/TimeRange.story.js +34 -20
- package/dist/src/Toast/Toast.story.d.ts +24 -25
- package/dist/src/Toast/Toast.story.js +170 -142
- package/dist/src/ToastContainer/ToastContainer.story.d.ts +8 -1
- package/dist/src/ToastContainer/ToastContainer.story.js +13 -1
- package/dist/src/ToastContainer/ToastFunction.js +2 -2
- package/dist/src/Toggle/Toggle.story.d.ts +25 -15
- package/dist/src/Toggle/Toggle.story.js +77 -43
- package/dist/src/Toggle/ToggleButton.js +2 -2
- package/dist/src/Tooltip/Tooltip.story.d.ts +1 -1
- package/dist/src/Tooltip/Tooltip.story.js +16 -0
- package/dist/src/TopBar/TopBar.styled.d.ts +16 -15
- package/dist/src/TopBar/components/BackLink.d.ts +3 -1
- package/dist/src/TopBar/components/MenuItemLink.d.ts +3 -1
- package/dist/src/TopBar/stories/TopBar.backButton.story.js +1 -1
- package/dist/src/TopBar/stories/TopBar.menu.story.js +1 -1
- package/dist/src/TopBar/stories/TopBar.story.d.ts +7 -1
- package/dist/src/TopBar/stories/TopBar.story.js +18 -1
- package/dist/src/TruncatedText/TruncatedText.story.d.ts +29 -34
- package/dist/src/TruncatedText/TruncatedText.story.js +46 -19
- package/dist/src/Type/Headings.d.ts +4 -4
- package/dist/src/Type/Text.story.d.ts +10 -20
- package/dist/src/Type/Text.story.js +10 -10
- package/dist/src/Validation/InlineValidation.story.d.ts +6 -12
- package/dist/src/Validation/InlineValidation.story.js +6 -6
- package/dist/src/VisualTests/Select.story.d.ts +12 -24
- package/dist/src/VisualTests/Select.story.js +19 -19
- package/dist/src/pages/ErrorPage.story.d.ts +3 -5
- package/dist/src/pages/ErrorPage.story.js +10 -10
- package/dist/src/pages/LoginPage.story.d.ts +8 -16
- package/dist/src/pages/LoginPage.story.js +8 -8
- package/dist/src/utils/story/dashed.d.ts +1 -3
- package/dist/src/utils/story/resizable.d.ts +4 -2
- package/dist/src/utils/ts/FocusManager.d.ts +1 -1
- package/dist/src/utils/ts/FocusManager.js +2 -2
- package/package.json +25 -34
|
@@ -1,99 +1,147 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import { expect, screen, userEvent, waitFor, within } from "storybook/test";
|
|
3
4
|
import { Button, DangerButton, IconicButton, Modal, PrimaryButton, Flex, Toast } from "../index";
|
|
4
5
|
export default {
|
|
5
6
|
title: "Components/Toast",
|
|
6
7
|
};
|
|
7
|
-
export const _Toast =
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export const _Toast = {
|
|
9
|
+
render: () => {
|
|
10
|
+
const ToastWithTrigger = () => {
|
|
11
|
+
const [triggered, setTriggered] = useState(false);
|
|
12
|
+
const triggerToast = () => {
|
|
13
|
+
setTriggered(!triggered);
|
|
14
|
+
};
|
|
15
|
+
const onHideHandler = () => {
|
|
16
|
+
setTriggered(false);
|
|
17
|
+
};
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, children: "Saved" })] }));
|
|
12
19
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
return _jsx(ToastWithTrigger, {});
|
|
21
|
+
},
|
|
22
|
+
name: "Toast",
|
|
23
|
+
play: async ({ canvasElement, step }) => {
|
|
24
|
+
const canvas = within(canvasElement);
|
|
25
|
+
await step("is hidden by default", async () => {
|
|
26
|
+
await expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
await step("shows toast when triggered", async () => {
|
|
29
|
+
await userEvent.click(canvas.getByText("Save Changes"));
|
|
30
|
+
await waitFor(() => expect(screen.getByRole("alert")).toBeVisible());
|
|
31
|
+
});
|
|
32
|
+
},
|
|
19
33
|
};
|
|
20
|
-
export const _MultipleToastsExample =
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
export const _MultipleToastsExample = {
|
|
35
|
+
render: () => {
|
|
36
|
+
const MultipleToastsExample = () => {
|
|
37
|
+
const [currentToast, setCurrentToast] = useState(undefined);
|
|
38
|
+
const triggerToast = (toastName) => {
|
|
39
|
+
setCurrentToast(toastName);
|
|
40
|
+
};
|
|
41
|
+
/* Alternate trigger toast fn adds a delay between toasts
|
|
42
|
+
const triggerToast = toastName => {
|
|
43
|
+
if (!currentToast) {
|
|
44
|
+
setCurrentToast(toastName);
|
|
45
|
+
} else {
|
|
46
|
+
// adds a delay between toasts
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
setCurrentToast(toastName);
|
|
49
|
+
}, 200);
|
|
50
|
+
}
|
|
51
|
+
}; */
|
|
52
|
+
const onHideHandler = (toastName) => {
|
|
53
|
+
if (currentToast === toastName) {
|
|
54
|
+
setCurrentToast(undefined);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const TOAST_ACTIONS = {
|
|
58
|
+
SAVE: "save",
|
|
59
|
+
RESET: "reset",
|
|
60
|
+
DELETE: "delete",
|
|
61
|
+
ERROR: "error",
|
|
62
|
+
};
|
|
63
|
+
const TOASTS = [
|
|
64
|
+
{
|
|
65
|
+
action: TOAST_ACTIONS.SAVE,
|
|
66
|
+
message: "Saved all your changes",
|
|
67
|
+
type: "success",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
action: TOAST_ACTIONS.RESET,
|
|
71
|
+
message: "Reset all your changes",
|
|
72
|
+
type: "success",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
action: TOAST_ACTIONS.DELETE,
|
|
76
|
+
message: "Ok, it's deleted",
|
|
77
|
+
type: "success",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
action: TOAST_ACTIONS.ERROR,
|
|
81
|
+
message: "An error occurred, please retry",
|
|
82
|
+
type: "danger",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { alignItems: "center", children: [_jsx(PrimaryButton, { onClick: () => triggerToast(TOAST_ACTIONS.SAVE), mr: "x2", children: "Save Changes" }), _jsx(Button, { onClick: () => triggerToast(TOAST_ACTIONS.RESET), mr: "x2", children: "Reset" }), _jsx(DangerButton, { onClick: () => triggerToast(TOAST_ACTIONS.ERROR), mr: "x2", children: "Trigger Error" }), _jsx(IconicButton, { icon: "delete", onClick: () => triggerToast(TOAST_ACTIONS.DELETE), children: "Delete" })] }), TOASTS.map((toast) => {
|
|
86
|
+
return (_jsx(Toast, { triggered: currentToast === toast.action, onHide: () => onHideHandler(toast.action), type: toast.type, children: toast.message }, toast.action));
|
|
87
|
+
})] }));
|
|
41
88
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
RESET: "reset",
|
|
45
|
-
DELETE: "delete",
|
|
46
|
-
ERROR: "error",
|
|
47
|
-
};
|
|
48
|
-
const TOASTS = [
|
|
49
|
-
{
|
|
50
|
-
action: TOAST_ACTIONS.SAVE,
|
|
51
|
-
message: "Saved all your changes",
|
|
52
|
-
type: "success",
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
action: TOAST_ACTIONS.RESET,
|
|
56
|
-
message: "Reset all your changes",
|
|
57
|
-
type: "success",
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
action: TOAST_ACTIONS.DELETE,
|
|
61
|
-
message: "Ok, it's deleted",
|
|
62
|
-
type: "success",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
action: TOAST_ACTIONS.ERROR,
|
|
66
|
-
message: "An error occurred, please retry",
|
|
67
|
-
type: "danger",
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { alignItems: "center", children: [_jsx(PrimaryButton, { onClick: () => triggerToast(TOAST_ACTIONS.SAVE), mr: "x2", children: "Save Changes" }), _jsx(Button, { onClick: () => triggerToast(TOAST_ACTIONS.RESET), mr: "x2", children: "Reset" }), _jsx(DangerButton, { onClick: () => triggerToast(TOAST_ACTIONS.ERROR), mr: "x2", children: "Trigger Error" }), _jsx(IconicButton, { icon: "delete", onClick: () => triggerToast(TOAST_ACTIONS.DELETE), children: "Delete" })] }), TOASTS.map((toast) => {
|
|
71
|
-
return (_jsx(Toast, { triggered: currentToast === toast.action, onHide: () => onHideHandler(toast.action), type: toast.type, children: toast.message }, toast.action));
|
|
72
|
-
})] }));
|
|
73
|
-
};
|
|
74
|
-
return _jsx(MultipleToastsExample, {});
|
|
75
|
-
};
|
|
76
|
-
_MultipleToastsExample.story = {
|
|
89
|
+
return _jsx(MultipleToastsExample, {});
|
|
90
|
+
},
|
|
77
91
|
name: "multiple toasts example",
|
|
78
92
|
};
|
|
79
|
-
export const CustomizeLengthOfTimeToastIsVisible =
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
export const CustomizeLengthOfTimeToastIsVisible = {
|
|
94
|
+
render: () => {
|
|
95
|
+
const ToastWithTrigger = () => {
|
|
96
|
+
const [triggered, setTriggered] = useState(false);
|
|
97
|
+
const triggerToast = () => {
|
|
98
|
+
setTriggered(!triggered);
|
|
99
|
+
};
|
|
100
|
+
const onHideHandler = () => {
|
|
101
|
+
setTriggered(false);
|
|
102
|
+
};
|
|
103
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, showDuration: 5000, children: "Saved" })] }));
|
|
84
104
|
};
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
return _jsx(ToastWithTrigger, {});
|
|
106
|
+
},
|
|
107
|
+
name: "customize length of time toast is visible",
|
|
108
|
+
};
|
|
109
|
+
export const WithCloseButton = {
|
|
110
|
+
render: () => {
|
|
111
|
+
const ToastWithTrigger = () => {
|
|
112
|
+
const [triggered, setTriggered] = useState(false);
|
|
113
|
+
const triggerToast = () => {
|
|
114
|
+
setTriggered(!triggered);
|
|
115
|
+
};
|
|
116
|
+
const onHideHandler = () => {
|
|
117
|
+
setTriggered(false);
|
|
118
|
+
};
|
|
119
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, isCloseable: true, children: "An error occurred while saving results. Please try again" })] }));
|
|
87
120
|
};
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
121
|
+
return _jsx(ToastWithTrigger, {});
|
|
122
|
+
},
|
|
123
|
+
name: "with close button",
|
|
124
|
+
play: async ({ canvasElement, step }) => {
|
|
125
|
+
const canvas = within(canvasElement);
|
|
126
|
+
await step("is hidden by default", async () => {
|
|
127
|
+
await expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
|
128
|
+
});
|
|
129
|
+
await step("shows toast when triggered", async () => {
|
|
130
|
+
await userEvent.click(canvas.getByText("Save Changes"));
|
|
131
|
+
await waitFor(() => expect(screen.getByRole("alert")).toBeVisible());
|
|
132
|
+
});
|
|
133
|
+
await step("hides toast when close button is clicked", async () => {
|
|
134
|
+
await userEvent.click(screen.getByLabelText("Close"));
|
|
135
|
+
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
|
|
136
|
+
});
|
|
137
|
+
},
|
|
91
138
|
};
|
|
92
|
-
|
|
93
|
-
|
|
139
|
+
export const WithModal = {
|
|
140
|
+
render: () => (_jsxs(_Fragment, { children: [_jsx(Toast, { triggered: true, type: "danger", isCloseable: true, zIndex: 1001, children: "Something went wrong. Try again." }), _jsx(Modal, { title: "Modal Title", onRequestClose: () => { }, maxWidth: "456px", children: "Modal Body" })] })),
|
|
141
|
+
name: "with a modal",
|
|
94
142
|
};
|
|
95
|
-
export const
|
|
96
|
-
|
|
143
|
+
export const CloseableWithMultiLineMessage = {
|
|
144
|
+
render: () => {
|
|
97
145
|
const [triggered, setTriggered] = useState(false);
|
|
98
146
|
const triggerToast = () => {
|
|
99
147
|
setTriggered(!triggered);
|
|
@@ -101,69 +149,49 @@ export const WithCloseButton = () => {
|
|
|
101
149
|
const onHideHandler = () => {
|
|
102
150
|
setTriggered(false);
|
|
103
151
|
};
|
|
104
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, isCloseable: true, children: "
|
|
105
|
-
}
|
|
106
|
-
return _jsx(ToastWithTrigger, {});
|
|
107
|
-
};
|
|
108
|
-
WithCloseButton.story = {
|
|
109
|
-
name: "with close button",
|
|
110
|
-
};
|
|
111
|
-
export const WithModal = () => (_jsxs(_Fragment, { children: [_jsx(Toast, { triggered: true, type: "danger", isCloseable: true, zIndex: 1001, children: "Something went wrong. Try again." }), _jsx(Modal, { title: "Modal Title", onRequestClose: () => { }, maxWidth: "456px", children: "Modal Body" })] }));
|
|
112
|
-
WithModal.story = {
|
|
113
|
-
name: "with a modal",
|
|
114
|
-
};
|
|
115
|
-
export const CloseableWithMultiLineMessage = () => {
|
|
116
|
-
const [triggered, setTriggered] = useState(false);
|
|
117
|
-
const triggerToast = () => {
|
|
118
|
-
setTriggered(!triggered);
|
|
119
|
-
};
|
|
120
|
-
const onHideHandler = () => {
|
|
121
|
-
setTriggered(false);
|
|
122
|
-
};
|
|
123
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, type: "danger", isCloseable: true, children: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorum quidem eveniet, repellat accusamus error reiciendis libero. Totam autem distinctio vo" })] }));
|
|
124
|
-
};
|
|
125
|
-
CloseableWithMultiLineMessage.story = {
|
|
152
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: triggerToast, children: "Save Changes" }), _jsx(Toast, { triggered: triggered, onHide: onHideHandler, type: "danger", isCloseable: true, children: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorum quidem eveniet, repellat accusamus error reiciendis libero. Totam autem distinctio vo" })] }));
|
|
153
|
+
},
|
|
126
154
|
name: "closeable with a 150 character long multi-line message",
|
|
127
155
|
};
|
|
128
|
-
export const MultipleCloseableToastsExample =
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
export const MultipleCloseableToastsExample = {
|
|
157
|
+
render: () => {
|
|
158
|
+
const MultipleToastsExample = () => {
|
|
159
|
+
const [currentToasts, setCurrentToasts] = useState([]);
|
|
160
|
+
const triggerToast = (toastName) => {
|
|
161
|
+
setCurrentToasts([...currentToasts, toastName]);
|
|
162
|
+
};
|
|
163
|
+
const onHideHandler = (toastName) => {
|
|
164
|
+
setCurrentToasts(currentToasts.filter((toast) => toast !== toastName));
|
|
165
|
+
};
|
|
166
|
+
const TOAST_ACTIONS = {
|
|
167
|
+
SAVE: "save",
|
|
168
|
+
RESET: "reset",
|
|
169
|
+
DELETE: "delete",
|
|
170
|
+
ERROR: "error",
|
|
171
|
+
};
|
|
172
|
+
const TOASTS = [
|
|
173
|
+
{
|
|
174
|
+
action: TOAST_ACTIONS.SAVE,
|
|
175
|
+
message: "Error saving all your changes",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
action: TOAST_ACTIONS.RESET,
|
|
179
|
+
message: "Error: changes were reset",
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
action: TOAST_ACTIONS.DELETE,
|
|
183
|
+
message: "An error occurred, could not deleted",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
action: TOAST_ACTIONS.ERROR,
|
|
187
|
+
message: "An error occurred, please retry",
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { alignItems: "center", children: [_jsx(PrimaryButton, { onClick: () => triggerToast(TOAST_ACTIONS.SAVE), mr: "x2", children: "Save Changes" }), _jsx(Button, { onClick: () => triggerToast(TOAST_ACTIONS.RESET), mr: "x2", children: "Reset" }), _jsx(DangerButton, { onClick: () => triggerToast(TOAST_ACTIONS.ERROR), mr: "x2", children: "Trigger Error" }), _jsx(IconicButton, { icon: "delete", onClick: () => triggerToast(TOAST_ACTIONS.DELETE), children: "Delete" })] }), TOASTS.map((toast) => {
|
|
191
|
+
return (_jsx(Toast, { triggered: currentToasts.includes(toast.action), onHide: () => onHideHandler(toast.action), type: "danger", isCloseable: true, children: toast.message }, toast.action));
|
|
192
|
+
})] }));
|
|
133
193
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
const TOAST_ACTIONS = {
|
|
138
|
-
SAVE: "save",
|
|
139
|
-
RESET: "reset",
|
|
140
|
-
DELETE: "delete",
|
|
141
|
-
ERROR: "error",
|
|
142
|
-
};
|
|
143
|
-
const TOASTS = [
|
|
144
|
-
{
|
|
145
|
-
action: TOAST_ACTIONS.SAVE,
|
|
146
|
-
message: "Error saving all your changes",
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
action: TOAST_ACTIONS.RESET,
|
|
150
|
-
message: "Error: changes were reset",
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
action: TOAST_ACTIONS.DELETE,
|
|
154
|
-
message: "An error occurred, could not deleted",
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
action: TOAST_ACTIONS.ERROR,
|
|
158
|
-
message: "An error occurred, please retry",
|
|
159
|
-
},
|
|
160
|
-
];
|
|
161
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Flex, { alignItems: "center", children: [_jsx(PrimaryButton, { onClick: () => triggerToast(TOAST_ACTIONS.SAVE), mr: "x2", children: "Save Changes" }), _jsx(Button, { onClick: () => triggerToast(TOAST_ACTIONS.RESET), mr: "x2", children: "Reset" }), _jsx(DangerButton, { onClick: () => triggerToast(TOAST_ACTIONS.ERROR), mr: "x2", children: "Trigger Error" }), _jsx(IconicButton, { icon: "delete", onClick: () => triggerToast(TOAST_ACTIONS.DELETE), children: "Delete" })] }), TOASTS.map((toast) => {
|
|
162
|
-
return (_jsx(Toast, { triggered: currentToasts.includes(toast.action), onHide: () => onHideHandler(toast.action), type: "danger", isCloseable: true, children: toast.message }, toast.action));
|
|
163
|
-
})] }));
|
|
164
|
-
};
|
|
165
|
-
return _jsx(MultipleToastsExample, {});
|
|
166
|
-
};
|
|
167
|
-
MultipleCloseableToastsExample.story = {
|
|
194
|
+
return _jsx(MultipleToastsExample, {});
|
|
195
|
+
},
|
|
168
196
|
name: "multiple closeable toasts example",
|
|
169
197
|
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export declare const WithEverything:
|
|
1
|
+
export declare const WithEverything: {
|
|
2
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
name: string;
|
|
4
|
+
play: ({ canvasElement, step }: {
|
|
5
|
+
canvasElement: any;
|
|
6
|
+
step: any;
|
|
7
|
+
}) => Promise<void>;
|
|
8
|
+
};
|
|
2
9
|
declare const _default: {
|
|
3
10
|
title: string;
|
|
4
11
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import { expect, screen, userEvent, waitFor, within } from "storybook/test";
|
|
3
4
|
import { PrimaryButton } from "../Button";
|
|
4
5
|
import { Input } from "../Input";
|
|
5
6
|
import { Flex } from "../Flex";
|
|
@@ -11,7 +12,7 @@ const getToastFunctionTemplate = ({ isClosable = false, toastType = "informative
|
|
|
11
12
|
title: "This is a '${toastType}' type toast title",
|
|
12
13
|
isCloseable: ${isClosable},
|
|
13
14
|
})`;
|
|
14
|
-
|
|
15
|
+
const WithEverythingComponent = () => {
|
|
15
16
|
const [behavior, setBehavior] = useState("random");
|
|
16
17
|
const [position, setPosition] = useState("bottom-center");
|
|
17
18
|
const [type, setType] = useState("random");
|
|
@@ -53,6 +54,17 @@ export const WithEverything = () => {
|
|
|
53
54
|
});
|
|
54
55
|
}, children: "Trigger toast" })] })] }), _jsx(ToastContainer, { position: position, toastOptions: { duration }, maxVisibleToasts: maxVisibleToasts })] })] }));
|
|
55
56
|
};
|
|
57
|
+
export const WithEverything = {
|
|
58
|
+
render: () => _jsx(WithEverythingComponent, {}),
|
|
59
|
+
name: "With Everything",
|
|
60
|
+
play: async ({ canvasElement, step }) => {
|
|
61
|
+
const canvas = within(canvasElement);
|
|
62
|
+
await step("triggers a toast", async () => {
|
|
63
|
+
await userEvent.click(canvas.getByText("Trigger toast"));
|
|
64
|
+
await waitFor(() => expect(screen.getAllByRole("alert")[0]).toBeVisible());
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
56
68
|
export default {
|
|
57
69
|
title: "Components/ToastContainer",
|
|
58
70
|
};
|
|
@@ -4,12 +4,12 @@ import { toast as _toast } from "react-hot-toast";
|
|
|
4
4
|
import { Alert } from "../Alert";
|
|
5
5
|
import { AnimatedBox } from "../Box";
|
|
6
6
|
import { toastAnimationConfig } from "../Toast/Toast";
|
|
7
|
-
|
|
7
|
+
function CustomToast({ isVisible, id, children, ...props }) {
|
|
8
8
|
const handleClose = () => {
|
|
9
9
|
_toast.dismiss(id);
|
|
10
10
|
};
|
|
11
11
|
return (_jsx(AnimatePresence, { children: isVisible && (_jsx(AnimatedBox, { role: "alert", ...toastAnimationConfig, children: _jsx(Alert, { controlled: true, onClose: handleClose, ...props, children: children }) }, "notification")) }));
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
const toast = {
|
|
14
14
|
danger: (children, props = {}, options = {}) => _toast.custom((t) => (_jsx(CustomToast, { id: t.id, isVisible: t.visible, type: "danger", ...props, children: children })), { duration: props.isCloseable ? Infinity : options.duration, ...options }),
|
|
15
15
|
informative: (children, props = {}, options = {}) => _toast.custom((t) => (_jsx(CustomToast, { id: t.id, isVisible: t.visible, type: "informative", ...props, children: children })), { duration: props.isCloseable ? Infinity : options.duration, ...options }),
|
|
@@ -2,32 +2,42 @@ declare const _default: {
|
|
|
2
2
|
title: string;
|
|
3
3
|
};
|
|
4
4
|
export default _default;
|
|
5
|
-
export declare const _Toggle:
|
|
5
|
+
export declare const _Toggle: {
|
|
6
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
play: ({ canvasElement, step }: {
|
|
8
|
+
canvasElement: any;
|
|
9
|
+
step: any;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
};
|
|
6
12
|
export declare const ToggleWithAllProps: {
|
|
7
|
-
()
|
|
8
|
-
|
|
13
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
name: string;
|
|
9
15
|
};
|
|
10
16
|
export declare const ToggleSetToDisabled: {
|
|
11
|
-
()
|
|
12
|
-
|
|
17
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
name: string;
|
|
19
|
+
play: ({ canvasElement, step }: {
|
|
20
|
+
canvasElement: any;
|
|
21
|
+
step: any;
|
|
22
|
+
}) => Promise<void>;
|
|
13
23
|
};
|
|
14
24
|
export declare const WithCustomId: {
|
|
15
|
-
()
|
|
16
|
-
|
|
25
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
name: string;
|
|
17
27
|
};
|
|
18
28
|
export declare const WithText: {
|
|
19
|
-
()
|
|
20
|
-
|
|
29
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
name: string;
|
|
21
31
|
};
|
|
22
32
|
export declare const WithLongText: {
|
|
23
|
-
()
|
|
24
|
-
|
|
33
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
name: string;
|
|
25
35
|
};
|
|
26
36
|
export declare const WithContraintWidth: {
|
|
27
|
-
()
|
|
28
|
-
|
|
37
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
name: string;
|
|
29
39
|
};
|
|
30
40
|
export declare const UsingRefToControlFocus: {
|
|
31
|
-
()
|
|
32
|
-
|
|
41
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
name: string;
|
|
33
43
|
};
|
|
@@ -1,51 +1,85 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useRef, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { expect, userEvent, within } from "storybook/test";
|
|
4
|
+
import { action } from "storybook/actions";
|
|
4
5
|
import { Toggle, Button, Box } from "../index";
|
|
5
6
|
import { dashed } from "../utils/story/dashed";
|
|
6
7
|
const DashedBox = dashed(Box);
|
|
7
8
|
export default {
|
|
8
9
|
title: "Components/Toggle",
|
|
9
10
|
};
|
|
10
|
-
export const _Toggle =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
11
|
+
export const _Toggle = {
|
|
12
|
+
render: () => {
|
|
13
|
+
const [toggled, setToggled] = useState(false);
|
|
14
|
+
return _jsx(Toggle, { "data-testid": "toggle-example", toggled: toggled, onChange: (e) => setToggled(e.target.checked) });
|
|
15
|
+
},
|
|
16
|
+
play: async ({ canvasElement, step }) => {
|
|
17
|
+
const canvas = within(canvasElement);
|
|
18
|
+
await step("changes the value on click", async () => {
|
|
19
|
+
const input = canvasElement.querySelector("[data-testid='toggle-example'] input");
|
|
20
|
+
await expect(input).not.toBeChecked();
|
|
21
|
+
await userEvent.click(canvas.getByTestId("toggle-example"));
|
|
22
|
+
await expect(input).toBeChecked();
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const ToggleWithAllProps = {
|
|
27
|
+
render: () => {
|
|
28
|
+
const [toggled, setToggled] = useState(true);
|
|
29
|
+
return (_jsx(Toggle, { labelText: "Toggle", helpText: "Turns setting on/off", onText: "on", offText: "off", toggled: toggled, required: true, requirementText: "(Required)", onChange: (e) => setToggled(e.target.checked) }));
|
|
30
|
+
},
|
|
31
|
+
name: "Toggle with all props",
|
|
32
|
+
};
|
|
33
|
+
export const ToggleSetToDisabled = {
|
|
34
|
+
render: () => {
|
|
35
|
+
return (_jsxs(_Fragment, { children: [_jsx(Toggle, { labelText: "Toggle", disabled: true, onText: "on", offText: "off", onChange: action("on change"), "data-testid": "toggle-example" }), _jsx(Toggle, { id: "toggle-2", disabled: true, onText: "on", offText: "off", toggled: true, labelText: "Toggle", onChange: action("on change") })] }));
|
|
36
|
+
},
|
|
37
|
+
name: "Toggle set to disabled",
|
|
38
|
+
play: async ({ canvasElement, step }) => {
|
|
39
|
+
const canvas = within(canvasElement);
|
|
40
|
+
await step("disabled toggle does not change on click", async () => {
|
|
41
|
+
const input = canvas.getByTestId("toggle-example").querySelector("input");
|
|
42
|
+
await expect(input).toBeDisabled();
|
|
43
|
+
await expect(input).not.toBeChecked();
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export const WithCustomId = {
|
|
48
|
+
render: () => {
|
|
49
|
+
const [toggled, setToggled] = useState(true);
|
|
50
|
+
return (_jsx(Toggle, { id: "my-custom-id", labelText: "Toggle", onText: "on", offText: "off", toggled: toggled, onChange: (e) => setToggled(e.target.checked) }));
|
|
51
|
+
},
|
|
52
|
+
name: "With custom id",
|
|
53
|
+
};
|
|
54
|
+
export const WithText = {
|
|
55
|
+
render: () => {
|
|
56
|
+
const [toggled, setToggled] = useState(true);
|
|
57
|
+
return (_jsx(Toggle, { labelText: "Toggle", onText: "on", offText: "off", toggled: toggled, onChange: (e) => setToggled(e.target.checked) }));
|
|
58
|
+
},
|
|
59
|
+
name: "With text",
|
|
60
|
+
};
|
|
61
|
+
export const WithLongText = {
|
|
62
|
+
render: () => {
|
|
63
|
+
const [toggled, setToggled] = useState(true);
|
|
64
|
+
return (_jsx(Toggle, { labelText: "Toggle", toggled: toggled, onText: "this state has a very long text label to explain it's state", offText: "not this one", onChange: (e) => setToggled(e.target.checked) }));
|
|
65
|
+
},
|
|
66
|
+
name: "With long text",
|
|
67
|
+
};
|
|
68
|
+
export const WithContraintWidth = {
|
|
69
|
+
render: () => {
|
|
70
|
+
const [toggled, setToggled] = useState(true);
|
|
71
|
+
return (_jsx(DashedBox, { width: "200px", padding: "x2", children: _jsx(Toggle, { labelText: "Toggle", onText: "This is a long On label for the toggle component.", offText: "This is a long Off label for the toggle component.", toggled: toggled, onChange: (e) => setToggled(e.target.checked) }) }));
|
|
72
|
+
},
|
|
73
|
+
name: "With constraint width",
|
|
74
|
+
};
|
|
75
|
+
export const UsingRefToControlFocus = {
|
|
76
|
+
render: () => {
|
|
77
|
+
const [toggled, setToggled] = useState(true);
|
|
78
|
+
const ref = useRef(null);
|
|
79
|
+
const handleClick = () => {
|
|
80
|
+
ref.current.focus();
|
|
81
|
+
};
|
|
82
|
+
return (_jsxs(_Fragment, { children: [_jsx(Toggle, { id: "my-custom-id", labelText: "Toggle", onText: "on", offText: "off", toggled: toggled, onChange: (e) => setToggled(e.target.checked), ref: ref }), _jsx(Button, { onClick: handleClick, children: "Focus the Toggle" })] }));
|
|
83
|
+
},
|
|
84
|
+
name: "Using ref to control focus",
|
|
85
|
+
};
|
|
@@ -18,7 +18,7 @@ function Switch({ children, disabled, checked }) {
|
|
|
18
18
|
const componentVariant = useComponentVariant();
|
|
19
19
|
return (_jsx(AnimatedBox, { marginTop: componentVariant === "touch" ? "x0_25" : "none", position: "relative", flexShrink: 0, height: "24px", width: "48px", bg: disabled ? "grey" : getSwitchBackground(checked), borderRadius: "20px", padding: "2px", boxShadow: "small", animate: checked ? "toggled" : "initial", whileHover: "active", whileFocus: "active", children: children }));
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
function Slider({ disabled, children }) {
|
|
22
22
|
const theme = useTheme();
|
|
23
23
|
return (_jsx(motion.div, { className: "slider", initial: false, variants: {
|
|
24
24
|
active: {
|
|
@@ -37,7 +37,7 @@ const Slider = ({ disabled, children }) => {
|
|
|
37
37
|
borderRadius: "50%",
|
|
38
38
|
backgroundColor: disabled ? theme.colors.whiteGrey : theme.colors.white,
|
|
39
39
|
}, children: children }));
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
const ToggleInput = styled.input(({ disabled, theme }) => ({
|
|
42
42
|
width: "1px",
|
|
43
43
|
height: "1px",
|