@saleor/macaw-ui 0.2.4
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/README.md +40 -0
- package/dist/ActionBar/ActionBar.d.ts +8 -0
- package/dist/ActionBar/context.d.ts +9 -0
- package/dist/ActionBar/index.d.ts +2 -0
- package/dist/ActionBar/styles.d.ts +2 -0
- package/dist/Alert/Alert.d.ts +9 -0
- package/dist/Alert/index.d.ts +1 -0
- package/dist/Alert/styles.d.ts +2 -0
- package/dist/Backlink/Backlink.d.ts +6 -0
- package/dist/Backlink/context.d.ts +5 -0
- package/dist/Backlink/index.d.ts +2 -0
- package/dist/Backlink/styles.d.ts +2 -0
- package/dist/ConfirmButton/ConfirmButton.d.ts +11 -0
- package/dist/ConfirmButton/index.d.ts +1 -0
- package/dist/ConfirmButton/styles.d.ts +2 -0
- package/dist/Notification/Notification.d.ts +3 -0
- package/dist/Notification/index.d.ts +2 -0
- package/dist/Notification/styles.d.ts +2 -0
- package/dist/Notification/types.d.ts +16 -0
- package/dist/ResponsiveTable/ResponsiveTable.d.ts +8 -0
- package/dist/ResponsiveTable/index.d.ts +1 -0
- package/dist/ResponsiveTable/styles.d.ts +2 -0
- package/dist/Savebar/ButtonTooltipDecorator.d.ts +6 -0
- package/dist/Savebar/Savebar.d.ts +14 -0
- package/dist/Savebar/index.d.ts +1 -0
- package/dist/Savebar/styles.d.ts +2 -0
- package/dist/Sidebar/ExpandButton.d.ts +6 -0
- package/dist/Sidebar/MenuItem.d.ts +11 -0
- package/dist/Sidebar/Sidebar.d.ts +6 -0
- package/dist/Sidebar/fixtures.d.ts +2 -0
- package/dist/Sidebar/index.d.ts +4 -0
- package/dist/Sidebar/types.d.ts +16 -0
- package/dist/SidebarDrawer/MenuItemBtn.d.ts +7 -0
- package/dist/SidebarDrawer/SidebarDrawer.d.ts +4 -0
- package/dist/SidebarDrawer/index.d.ts +2 -0
- package/dist/SidebarDrawer/styles.d.ts +2 -0
- package/dist/SquareButton/SquareButton.d.ts +3 -0
- package/dist/SquareButton/index.d.ts +1 -0
- package/dist/Tooltip/Tooltip.d.ts +6 -0
- package/dist/Tooltip/index.d.ts +1 -0
- package/dist/Tooltip/styles.d.ts +3 -0
- package/dist/UserChipMenu/UserChipMenu.d.ts +8 -0
- package/dist/UserChipMenu/UserChipMenuItem.d.ts +6 -0
- package/dist/UserChipMenu/context.d.ts +4 -0
- package/dist/UserChipMenu/index.d.ts +2 -0
- package/dist/UserChipMenu/styles.d.ts +2 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/sendMessage.d.ts +3 -0
- package/dist/extensions/types.d.ts +22 -0
- package/dist/extensions/useExtensionMessage.d.ts +2 -0
- package/dist/icons/ArrowDropdownIcon.d.ts +2 -0
- package/dist/icons/CheckboxCheckedIcon.d.ts +1 -0
- package/dist/icons/CheckboxIcon.d.ts +1 -0
- package/dist/icons/CheckboxIndeterminateIcon.d.ts +1 -0
- package/dist/icons/CompleteIcon.d.ts +2 -0
- package/dist/icons/InfoIcon.d.ts +2 -0
- package/dist/icons/Logo.d.ts +2 -0
- package/dist/icons/NotAllowedIcon.d.ts +2 -0
- package/dist/icons/NotAllowedInvertedIcon.d.ts +2 -0
- package/dist/icons/WarningIcon.d.ts +2 -0
- package/dist/icons/index.d.ts +9 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +8 -0
- package/dist/localStorageKeys.d.ts +4 -0
- package/dist/macaw-ui.cjs.development.js +2582 -0
- package/dist/macaw-ui.cjs.development.js.map +1 -0
- package/dist/macaw-ui.cjs.production.min.js +2 -0
- package/dist/macaw-ui.cjs.production.min.js.map +1 -0
- package/dist/macaw-ui.esm.js +2536 -0
- package/dist/macaw-ui.esm.js.map +1 -0
- package/dist/theme/Baseline.d.ts +2 -0
- package/dist/theme/ThemeProvider.d.ts +17 -0
- package/dist/theme/context.d.ts +3 -0
- package/dist/theme/createSaleorTheme/createSaleorTheme.d.ts +3 -0
- package/dist/theme/createSaleorTheme/index.d.ts +2 -0
- package/dist/theme/createSaleorTheme/overrides/buttons.d.ts +3 -0
- package/dist/theme/createSaleorTheme/overrides/index.d.ts +3 -0
- package/dist/theme/createSaleorTheme/overrides/inputs.d.ts +3 -0
- package/dist/theme/createSaleorTheme/overrides/tables.d.ts +3 -0
- package/dist/theme/createSaleorTheme/palette.d.ts +2 -0
- package/dist/theme/createSaleorTheme/shadows.d.ts +2 -0
- package/dist/theme/createSaleorTheme/types.d.ts +53 -0
- package/dist/theme/index.d.ts +4 -0
- package/dist/theme/styles.d.ts +5 -0
- package/dist/theme/themes.d.ts +3 -0
- package/dist/theme/types.d.ts +6 -0
- package/dist/theme/utils.d.ts +1 -0
- package/dist/tools/useLocalStorage.d.ts +5 -0
- package/dist/tools/useWindowScroll.d.ts +5 -0
- package/dist/utils/Decorator.d.ts +4 -0
- package/package.json +117 -0
- package/src/ActionBar/ActionBar.stories.tsx +34 -0
- package/src/ActionBar/ActionBar.tsx +58 -0
- package/src/ActionBar/context.tsx +32 -0
- package/src/ActionBar/index.ts +2 -0
- package/src/ActionBar/styles.ts +27 -0
- package/src/Alert/Alert.stories.tsx +30 -0
- package/src/Alert/Alert.tsx +86 -0
- package/src/Alert/index.ts +1 -0
- package/src/Alert/styles.ts +46 -0
- package/src/Backlink/Backlink.stories.tsx +51 -0
- package/src/Backlink/Backlink.tsx +40 -0
- package/src/Backlink/context.tsx +27 -0
- package/src/Backlink/index.ts +2 -0
- package/src/Backlink/styles.ts +41 -0
- package/src/ConfirmButton/ConfirmButton.stories.tsx +72 -0
- package/src/ConfirmButton/ConfirmButton.tsx +119 -0
- package/src/ConfirmButton/index.ts +1 -0
- package/src/ConfirmButton/styles.ts +44 -0
- package/src/Notification/Notification.stories.tsx +42 -0
- package/src/Notification/Notification.tsx +98 -0
- package/src/Notification/index.ts +2 -0
- package/src/Notification/styles.ts +74 -0
- package/src/Notification/types.ts +18 -0
- package/src/ResponsiveTable/ResponsiveTable.tsx +24 -0
- package/src/ResponsiveTable/index.ts +1 -0
- package/src/ResponsiveTable/styles.ts +23 -0
- package/src/Savebar/ButtonTooltipDecorator.tsx +22 -0
- package/src/Savebar/Savebar.stories.tsx +57 -0
- package/src/Savebar/Savebar.tsx +79 -0
- package/src/Savebar/index.ts +1 -0
- package/src/Savebar/styles.ts +25 -0
- package/src/Sidebar/ExpandButton.tsx +44 -0
- package/src/Sidebar/MenuItem.tsx +217 -0
- package/src/Sidebar/Sidebar.stories.tsx +21 -0
- package/src/Sidebar/Sidebar.tsx +88 -0
- package/src/Sidebar/fixtures.ts +39 -0
- package/src/Sidebar/index.ts +4 -0
- package/src/Sidebar/types.ts +18 -0
- package/src/SidebarDrawer/MenuItemBtn.tsx +40 -0
- package/src/SidebarDrawer/SidebarDrawer.stories.tsx +13 -0
- package/src/SidebarDrawer/SidebarDrawer.tsx +113 -0
- package/src/SidebarDrawer/index.ts +2 -0
- package/src/SidebarDrawer/styles.ts +69 -0
- package/src/SquareButton/SquareButton.stories.tsx +15 -0
- package/src/SquareButton/SquareButton.tsx +35 -0
- package/src/SquareButton/index.ts +1 -0
- package/src/Tooltip/Tooltip.stories.tsx +19 -0
- package/src/Tooltip/Tooltip.tsx +25 -0
- package/src/Tooltip/index.ts +1 -0
- package/src/Tooltip/styles.ts +28 -0
- package/src/UserChipMenu/UserChipMenu.stories.tsx +40 -0
- package/src/UserChipMenu/UserChipMenu.tsx +113 -0
- package/src/UserChipMenu/UserChipMenuItem.tsx +33 -0
- package/src/UserChipMenu/context.ts +19 -0
- package/src/UserChipMenu/index.ts +2 -0
- package/src/UserChipMenu/styles.ts +65 -0
- package/src/assets/placeholder_64x64.png +0 -0
- package/src/extensions/index.ts +3 -0
- package/src/extensions/sendMessage.ts +23 -0
- package/src/extensions/types.ts +26 -0
- package/src/extensions/useExtensionMessage.ts +13 -0
- package/src/icons/ArrowDropdownIcon.tsx +11 -0
- package/src/icons/CheckboxCheckedIcon.tsx +15 -0
- package/src/icons/CheckboxIcon.tsx +7 -0
- package/src/icons/CheckboxIndeterminateIcon.tsx +17 -0
- package/src/icons/CompleteIcon.tsx +25 -0
- package/src/icons/InfoIcon.tsx +23 -0
- package/src/icons/Logo.tsx +32 -0
- package/src/icons/NotAllowedIcon.tsx +25 -0
- package/src/icons/NotAllowedInvertedIcon.tsx +25 -0
- package/src/icons/WarningIcon.tsx +23 -0
- package/src/icons/index.ts +9 -0
- package/src/index.tsx +15 -0
- package/src/localStorageKeys.ts +4 -0
- package/src/theme/Baseline.tsx +30 -0
- package/src/theme/ThemeProvider.tsx +84 -0
- package/src/theme/context.ts +8 -0
- package/src/theme/createSaleorTheme/createSaleorTheme.ts +267 -0
- package/src/theme/createSaleorTheme/index.ts +2 -0
- package/src/theme/createSaleorTheme/overrides/buttons.ts +94 -0
- package/src/theme/createSaleorTheme/overrides/index.ts +15 -0
- package/src/theme/createSaleorTheme/overrides/inputs.ts +149 -0
- package/src/theme/createSaleorTheme/overrides/tables.ts +74 -0
- package/src/theme/createSaleorTheme/palette.ts +38 -0
- package/src/theme/createSaleorTheme/shadows.ts +46 -0
- package/src/theme/createSaleorTheme/types.ts +84 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/styles.ts +40 -0
- package/src/theme/themes.ts +113 -0
- package/src/theme/types.ts +7 -0
- package/src/theme/utils.test.ts +43 -0
- package/src/theme/utils.ts +13 -0
- package/src/tools/useLocalStorage.ts +56 -0
- package/src/tools/useWindowScroll.ts +26 -0
- package/src/utils/Decorator.tsx +23 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import Button, { ButtonProps } from "@material-ui/core/Button";
|
|
2
|
+
import CircularProgress from "@material-ui/core/CircularProgress";
|
|
3
|
+
import CheckIcon from "@material-ui/icons/Check";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import React from "react";
|
|
6
|
+
|
|
7
|
+
import useStyles from "./styles";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_NOTIFICATION_SHOW_TIME = 3000;
|
|
10
|
+
export type ConfirmButtonTransitionState =
|
|
11
|
+
| "loading"
|
|
12
|
+
| "success"
|
|
13
|
+
| "error"
|
|
14
|
+
| "default";
|
|
15
|
+
|
|
16
|
+
export type ConfirmButtonLabels = Record<"confirm" | "error", string>;
|
|
17
|
+
export interface ConfirmButtonProps extends Omit<ButtonProps, "classes"> {
|
|
18
|
+
labels: ConfirmButtonLabels;
|
|
19
|
+
noTransition?: boolean;
|
|
20
|
+
transitionState: ConfirmButtonTransitionState;
|
|
21
|
+
onTransitionToDefault?: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ConfirmButton: React.FC<ConfirmButtonProps> = ({
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
disabled,
|
|
28
|
+
labels,
|
|
29
|
+
noTransition,
|
|
30
|
+
transitionState,
|
|
31
|
+
onClick,
|
|
32
|
+
onTransitionToDefault,
|
|
33
|
+
...props
|
|
34
|
+
}) => {
|
|
35
|
+
const classes = useStyles();
|
|
36
|
+
const [
|
|
37
|
+
displayCompletedActionState,
|
|
38
|
+
setDisplayCompletedActionState,
|
|
39
|
+
] = React.useState(false);
|
|
40
|
+
const timeout = React.useRef<number>();
|
|
41
|
+
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!noTransition && transitionState === "loading") {
|
|
44
|
+
setDisplayCompletedActionState(true);
|
|
45
|
+
}
|
|
46
|
+
}, [transitionState, noTransition]);
|
|
47
|
+
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
if (
|
|
50
|
+
!noTransition &&
|
|
51
|
+
(["error", "success"] as ConfirmButtonTransitionState[]).includes(
|
|
52
|
+
transitionState
|
|
53
|
+
)
|
|
54
|
+
) {
|
|
55
|
+
timeout.current = (setTimeout(() => {
|
|
56
|
+
setDisplayCompletedActionState(false);
|
|
57
|
+
if (onTransitionToDefault) {
|
|
58
|
+
onTransitionToDefault();
|
|
59
|
+
}
|
|
60
|
+
}, DEFAULT_NOTIFICATION_SHOW_TIME) as unknown) as number;
|
|
61
|
+
} else if (transitionState === "loading") {
|
|
62
|
+
clearTimeout(timeout.current);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return () => {
|
|
66
|
+
if (timeout.current) {
|
|
67
|
+
clearTimeout(timeout.current);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, [noTransition, transitionState, onTransitionToDefault]);
|
|
71
|
+
|
|
72
|
+
const isCompleted = noTransition
|
|
73
|
+
? transitionState !== "default"
|
|
74
|
+
: displayCompletedActionState;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Button
|
|
78
|
+
variant="contained"
|
|
79
|
+
onClick={transitionState === "loading" ? undefined : onClick}
|
|
80
|
+
color="primary"
|
|
81
|
+
className={clsx(className, {
|
|
82
|
+
[classes.error]: transitionState === "error" && isCompleted,
|
|
83
|
+
[classes.success]: transitionState === "success" && isCompleted,
|
|
84
|
+
})}
|
|
85
|
+
disabled={!isCompleted && disabled}
|
|
86
|
+
data-test-state={isCompleted ? transitionState : "default"}
|
|
87
|
+
{...props}
|
|
88
|
+
>
|
|
89
|
+
<CircularProgress
|
|
90
|
+
size={24}
|
|
91
|
+
color="inherit"
|
|
92
|
+
className={clsx({
|
|
93
|
+
[classes.progress]: true,
|
|
94
|
+
[classes.invisible]: transitionState !== "loading",
|
|
95
|
+
})}
|
|
96
|
+
/>
|
|
97
|
+
<CheckIcon
|
|
98
|
+
className={clsx({
|
|
99
|
+
[classes.icon]: true,
|
|
100
|
+
[classes.invisible]: !(transitionState === "success" && isCompleted),
|
|
101
|
+
})}
|
|
102
|
+
/>
|
|
103
|
+
<span
|
|
104
|
+
className={clsx({
|
|
105
|
+
[classes.label]: true,
|
|
106
|
+
[classes.invisible]:
|
|
107
|
+
(transitionState === "loading" || transitionState === "success") &&
|
|
108
|
+
isCompleted,
|
|
109
|
+
})}
|
|
110
|
+
>
|
|
111
|
+
{transitionState === "error" && isCompleted
|
|
112
|
+
? labels.error
|
|
113
|
+
: children || labels.confirm}
|
|
114
|
+
</span>
|
|
115
|
+
</Button>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
ConfirmButton.displayName = "ConfirmButton";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ConfirmButton";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { makeStyles } from "../theme";
|
|
2
|
+
|
|
3
|
+
const useStyles = makeStyles(
|
|
4
|
+
(theme) => ({
|
|
5
|
+
error: {
|
|
6
|
+
"&:hover": {
|
|
7
|
+
backgroundColor: theme.palette.error.main,
|
|
8
|
+
},
|
|
9
|
+
backgroundColor: theme.palette.error.main,
|
|
10
|
+
color: theme.palette.error.contrastText,
|
|
11
|
+
},
|
|
12
|
+
icon: {
|
|
13
|
+
marginLeft: "0 !important",
|
|
14
|
+
position: "absolute",
|
|
15
|
+
transitionDuration: theme.transitions.duration.standard + "ms",
|
|
16
|
+
},
|
|
17
|
+
invisible: {
|
|
18
|
+
opacity: 0,
|
|
19
|
+
},
|
|
20
|
+
label: {
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
display: "flex",
|
|
23
|
+
transitionDuration: theme.transitions.duration.standard + "ms",
|
|
24
|
+
},
|
|
25
|
+
progress: {
|
|
26
|
+
"& svg": {
|
|
27
|
+
color: theme.palette.common.white,
|
|
28
|
+
margin: 0,
|
|
29
|
+
},
|
|
30
|
+
position: "absolute",
|
|
31
|
+
transitionDuration: theme.transitions.duration.standard + "ms",
|
|
32
|
+
},
|
|
33
|
+
success: {
|
|
34
|
+
"&:hover": {
|
|
35
|
+
backgroundColor: theme.palette.primary.main,
|
|
36
|
+
},
|
|
37
|
+
backgroundColor: theme.palette.primary.main,
|
|
38
|
+
color: theme.palette.primary.contrastText,
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
{ name: "ConfirmButton" }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export default useStyles;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import { Notification } from "./Notification";
|
|
5
|
+
import type { NotificationProps } from "./types";
|
|
6
|
+
|
|
7
|
+
const props: NotificationProps = {
|
|
8
|
+
title: "Title",
|
|
9
|
+
onClose: () => undefined,
|
|
10
|
+
type: "info",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const Info: Story = () => <Notification {...props} />;
|
|
14
|
+
export const Warn: Story = () => <Notification {...props} type="warning" />;
|
|
15
|
+
export const Success: Story = () => <Notification {...props} type="success" />;
|
|
16
|
+
export const Error: Story = () => <Notification {...props} type="error" />;
|
|
17
|
+
export const WithAction: Story = () => (
|
|
18
|
+
<Notification
|
|
19
|
+
{...props}
|
|
20
|
+
action={{
|
|
21
|
+
label: "Action",
|
|
22
|
+
onClick: () => undefined,
|
|
23
|
+
}}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
export const WithContent: Story = () => (
|
|
27
|
+
<Notification {...props} content="Some notification content" />
|
|
28
|
+
);
|
|
29
|
+
export const WithActionAndContent: Story = () => (
|
|
30
|
+
<Notification
|
|
31
|
+
{...props}
|
|
32
|
+
content="Some notification content"
|
|
33
|
+
action={{
|
|
34
|
+
label: "Action",
|
|
35
|
+
onClick: () => undefined,
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
title: "Notification",
|
|
42
|
+
} as Meta;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Button from "@material-ui/core/Button";
|
|
2
|
+
import IconButton from "@material-ui/core/IconButton";
|
|
3
|
+
import SnackbarContent from "@material-ui/core/SnackbarContent";
|
|
4
|
+
import Typography from "@material-ui/core/Typography";
|
|
5
|
+
import CloseIcon from "@material-ui/icons/Close";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import React from "react";
|
|
8
|
+
|
|
9
|
+
import { CompleteIcon, InfoIcon, NotAllowedIcon, WarningIcon } from "../icons";
|
|
10
|
+
import useStyles from "./styles";
|
|
11
|
+
import type { NotificationProps, NotificationType } from "./types";
|
|
12
|
+
|
|
13
|
+
function getIcon(variant: NotificationType): React.ReactElement {
|
|
14
|
+
switch (variant) {
|
|
15
|
+
case "error":
|
|
16
|
+
return <NotAllowedIcon />;
|
|
17
|
+
case "success":
|
|
18
|
+
return <CompleteIcon />;
|
|
19
|
+
case "warning":
|
|
20
|
+
return <WarningIcon />;
|
|
21
|
+
}
|
|
22
|
+
return <InfoIcon />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Notification: React.FC<NotificationProps> = ({
|
|
26
|
+
onClose,
|
|
27
|
+
title,
|
|
28
|
+
type,
|
|
29
|
+
action,
|
|
30
|
+
content,
|
|
31
|
+
className,
|
|
32
|
+
...rest
|
|
33
|
+
}) => {
|
|
34
|
+
const classes = useStyles();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
className={clsx(classes.snackbarContainer, className)}
|
|
39
|
+
data-test="notification"
|
|
40
|
+
data-test-type={type}
|
|
41
|
+
{...rest}
|
|
42
|
+
>
|
|
43
|
+
<SnackbarContent
|
|
44
|
+
aria-describedby="client-snackbar"
|
|
45
|
+
classes={{
|
|
46
|
+
action: classes.snackbarAction,
|
|
47
|
+
message: classes.messageContainer,
|
|
48
|
+
}}
|
|
49
|
+
className={clsx(classes.snackbar, {
|
|
50
|
+
[classes.info]: type === "info",
|
|
51
|
+
[classes.error]: type === "error",
|
|
52
|
+
[classes.success]: type === "success",
|
|
53
|
+
[classes.warning]: type === "warning",
|
|
54
|
+
})}
|
|
55
|
+
message={
|
|
56
|
+
<div className={classes.container}>
|
|
57
|
+
<div>{getIcon(type)}</div>
|
|
58
|
+
<div>
|
|
59
|
+
<div className={classes.title}>
|
|
60
|
+
<Typography variant="h5">{title}</Typography>
|
|
61
|
+
</div>
|
|
62
|
+
<Typography variant="body1">{content}</Typography>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
}
|
|
66
|
+
action={[
|
|
67
|
+
<div key="actions">
|
|
68
|
+
{!!action && (
|
|
69
|
+
<Button
|
|
70
|
+
className={classes.actionBtn}
|
|
71
|
+
key="action"
|
|
72
|
+
color="default"
|
|
73
|
+
size="small"
|
|
74
|
+
onClick={action.onClick}
|
|
75
|
+
data-test="button-action"
|
|
76
|
+
>
|
|
77
|
+
{action.label}
|
|
78
|
+
</Button>
|
|
79
|
+
)}
|
|
80
|
+
</div>,
|
|
81
|
+
<IconButton
|
|
82
|
+
key="close"
|
|
83
|
+
aria-label="Close"
|
|
84
|
+
color="inherit"
|
|
85
|
+
onClick={onClose}
|
|
86
|
+
className={clsx(classes.closeBtn, {
|
|
87
|
+
[classes.closeBtnInfo]: type === "info",
|
|
88
|
+
})}
|
|
89
|
+
data-test="close"
|
|
90
|
+
>
|
|
91
|
+
<CloseIcon />
|
|
92
|
+
</IconButton>,
|
|
93
|
+
]}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
Notification.displayName = "Notification";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { makeStyles } from "../theme";
|
|
2
|
+
|
|
3
|
+
const iconWidth = 40;
|
|
4
|
+
|
|
5
|
+
const useStyles = makeStyles(
|
|
6
|
+
(theme) => ({
|
|
7
|
+
actionBtn: {
|
|
8
|
+
left: -4,
|
|
9
|
+
position: "relative",
|
|
10
|
+
minWidth: "unset",
|
|
11
|
+
},
|
|
12
|
+
closeBtn: {
|
|
13
|
+
"& svg": {
|
|
14
|
+
maxHeight: 20,
|
|
15
|
+
maxWidth: 20,
|
|
16
|
+
},
|
|
17
|
+
padding: 10,
|
|
18
|
+
position: "absolute",
|
|
19
|
+
right: 5,
|
|
20
|
+
top: 7,
|
|
21
|
+
},
|
|
22
|
+
closeBtnInfo: {
|
|
23
|
+
color: theme.palette.text.primary,
|
|
24
|
+
},
|
|
25
|
+
error: {
|
|
26
|
+
backgroundColor: theme.palette.alert.paper.error,
|
|
27
|
+
},
|
|
28
|
+
hiddenText: {
|
|
29
|
+
maxHeight: 0,
|
|
30
|
+
},
|
|
31
|
+
info: {},
|
|
32
|
+
snackbar: {
|
|
33
|
+
borderRadius: 4,
|
|
34
|
+
padding: theme.spacing(0, 6, 1, 2),
|
|
35
|
+
position: "relative",
|
|
36
|
+
},
|
|
37
|
+
snackbarContainer: {
|
|
38
|
+
marginBottom: theme.spacing(2),
|
|
39
|
+
maxWidth: 450,
|
|
40
|
+
position: "relative",
|
|
41
|
+
},
|
|
42
|
+
snackbarAction: {
|
|
43
|
+
paddingLeft: `calc(${iconWidth}px + ${theme.spacing(2)})`,
|
|
44
|
+
},
|
|
45
|
+
success: {
|
|
46
|
+
backgroundColor: theme.palette.alert.paper.success,
|
|
47
|
+
},
|
|
48
|
+
text: {
|
|
49
|
+
fontWeight: 400,
|
|
50
|
+
paddingTop: 5,
|
|
51
|
+
},
|
|
52
|
+
warning: {
|
|
53
|
+
backgroundColor: theme.palette.alert.paper.warning,
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
messageContainer: {
|
|
57
|
+
paddingTop: theme.spacing(2),
|
|
58
|
+
position: "relative",
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
container: {
|
|
62
|
+
columnGap: theme.spacing(2),
|
|
63
|
+
display: "grid",
|
|
64
|
+
gridTemplateColumns: `${iconWidth}px 1fr`,
|
|
65
|
+
},
|
|
66
|
+
title: {
|
|
67
|
+
marginTop: 6,
|
|
68
|
+
marginBottom: theme.spacing(0.5),
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
{ name: "Notification" }
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export default useStyles;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
export type NotificationType = "info" | "success" | "error" | "warning";
|
|
4
|
+
export interface NotificationAction {
|
|
5
|
+
label: string;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface NotificationData {
|
|
9
|
+
content?: ReactNode;
|
|
10
|
+
title: string;
|
|
11
|
+
action?: NotificationAction;
|
|
12
|
+
type: NotificationType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NotificationProps extends NotificationData {
|
|
16
|
+
className?: string;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Table from "@material-ui/core/Table";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import useStyles from "./styles";
|
|
5
|
+
|
|
6
|
+
interface ResponsiveTableProps {
|
|
7
|
+
children: React.ReactNode | React.ReactNodeArray;
|
|
8
|
+
className?: string;
|
|
9
|
+
key?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ResponsiveTable: React.FC<ResponsiveTableProps> = (props) => {
|
|
13
|
+
const { children, className } = props;
|
|
14
|
+
|
|
15
|
+
const classes = useStyles(props);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className={classes.root}>
|
|
19
|
+
<Table className={className}>{children}</Table>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
ResponsiveTable.displayName = "ResponsiveTable";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ResponsiveTable";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeStyles } from "../theme";
|
|
2
|
+
|
|
3
|
+
const useStyles = makeStyles(
|
|
4
|
+
(theme) => ({
|
|
5
|
+
root: {
|
|
6
|
+
[theme.breakpoints.up("md")]: {
|
|
7
|
+
"&& table": {
|
|
8
|
+
tableLayout: "fixed",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
"& table": {
|
|
12
|
+
tableLayout: "auto",
|
|
13
|
+
},
|
|
14
|
+
overflowX: "auto",
|
|
15
|
+
width: "100%",
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
{
|
|
19
|
+
name: "ResponsiveTable",
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default useStyles;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Tooltip from "@material-ui/core/Tooltip";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
interface ButtonTooltipDecoratorProps {
|
|
5
|
+
tooltip?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ButtonTooltipDecorator: React.FC<ButtonTooltipDecoratorProps> = ({
|
|
9
|
+
tooltip,
|
|
10
|
+
children,
|
|
11
|
+
}) => {
|
|
12
|
+
if (tooltip) {
|
|
13
|
+
return (
|
|
14
|
+
<Tooltip title={tooltip} placement="top">
|
|
15
|
+
<span>{children}</span>
|
|
16
|
+
</Tooltip>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return <>{children}</>;
|
|
21
|
+
};
|
|
22
|
+
ButtonTooltipDecorator.displayName = "ButtonTooltipDecorator";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Meta, Story } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import { useActionBar } from "../ActionBar";
|
|
5
|
+
import {
|
|
6
|
+
Savebar,
|
|
7
|
+
SavebarLabels,
|
|
8
|
+
SavebarProps,
|
|
9
|
+
SavebarTooltips,
|
|
10
|
+
} from "./Savebar";
|
|
11
|
+
|
|
12
|
+
const Wrapper: React.FC = ({ children }) => {
|
|
13
|
+
const { anchor } = useActionBar();
|
|
14
|
+
|
|
15
|
+
return <div ref={anchor}>{children}</div>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const labels: SavebarLabels = {
|
|
19
|
+
confirm: "Confirm",
|
|
20
|
+
error: "Error",
|
|
21
|
+
cancel: "Cancel",
|
|
22
|
+
delete: "Delete",
|
|
23
|
+
};
|
|
24
|
+
const tooltips: SavebarTooltips = {
|
|
25
|
+
confirm: "Confirm text",
|
|
26
|
+
cancel: "Cancel text",
|
|
27
|
+
delete: "Delete text",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const props: SavebarProps = {
|
|
31
|
+
labels,
|
|
32
|
+
disabled: false,
|
|
33
|
+
onCancel: () => undefined,
|
|
34
|
+
onSubmit: () => undefined,
|
|
35
|
+
state: "default",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Default: Story = () => <Savebar {...props} />;
|
|
39
|
+
export const WithDelete: Story = () => (
|
|
40
|
+
<Savebar {...props} onDelete={() => undefined} />
|
|
41
|
+
);
|
|
42
|
+
export const WithTooltips: Story = () => (
|
|
43
|
+
<div style={{ paddingTop: 50 }}>
|
|
44
|
+
<Savebar {...props} onDelete={() => undefined} tooltips={tooltips} />
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
title: "Savebar",
|
|
50
|
+
decorators: [
|
|
51
|
+
(Story) => (
|
|
52
|
+
<Wrapper>
|
|
53
|
+
<Story />
|
|
54
|
+
</Wrapper>
|
|
55
|
+
),
|
|
56
|
+
],
|
|
57
|
+
} as Meta;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Button from "@material-ui/core/Button";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import { useActionBar } from "../ActionBar";
|
|
5
|
+
import { ActionBar } from "../ActionBar/ActionBar";
|
|
6
|
+
import {
|
|
7
|
+
ConfirmButton,
|
|
8
|
+
ConfirmButtonLabels,
|
|
9
|
+
ConfirmButtonTransitionState,
|
|
10
|
+
} from "../ConfirmButton";
|
|
11
|
+
import { ButtonTooltipDecorator } from "./ButtonTooltipDecorator";
|
|
12
|
+
import useStyles from "./styles";
|
|
13
|
+
|
|
14
|
+
export type SavebarLabels = ConfirmButtonLabels &
|
|
15
|
+
Record<"delete" | "cancel", string>;
|
|
16
|
+
export type SavebarTooltips = Partial<
|
|
17
|
+
Record<"confirm" | "delete" | "cancel", string>
|
|
18
|
+
>;
|
|
19
|
+
export interface SavebarProps {
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
state: ConfirmButtonTransitionState;
|
|
22
|
+
labels: SavebarLabels;
|
|
23
|
+
tooltips?: SavebarTooltips;
|
|
24
|
+
onCancel: () => void;
|
|
25
|
+
onDelete?: () => void;
|
|
26
|
+
onSubmit: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const Savebar: React.FC<SavebarProps> = ({
|
|
30
|
+
disabled,
|
|
31
|
+
labels,
|
|
32
|
+
tooltips,
|
|
33
|
+
state,
|
|
34
|
+
onCancel,
|
|
35
|
+
onDelete,
|
|
36
|
+
onSubmit,
|
|
37
|
+
}) => {
|
|
38
|
+
const classes = useStyles();
|
|
39
|
+
const { setDocked } = useActionBar();
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<ActionBar state={state} disabled={disabled}>
|
|
43
|
+
{!!onDelete && (
|
|
44
|
+
<ButtonTooltipDecorator tooltip={tooltips?.delete}>
|
|
45
|
+
<Button
|
|
46
|
+
variant="contained"
|
|
47
|
+
onClick={onDelete}
|
|
48
|
+
className={classes.deleteButton}
|
|
49
|
+
data-test="button-bar-delete"
|
|
50
|
+
>
|
|
51
|
+
{labels.delete}
|
|
52
|
+
</Button>
|
|
53
|
+
</ButtonTooltipDecorator>
|
|
54
|
+
)}
|
|
55
|
+
<div className={classes.spacer} />
|
|
56
|
+
<ButtonTooltipDecorator tooltip={tooltips?.cancel}>
|
|
57
|
+
<Button
|
|
58
|
+
className={classes.cancelButton}
|
|
59
|
+
variant="text"
|
|
60
|
+
onClick={onCancel}
|
|
61
|
+
data-test="button-bar-cancel"
|
|
62
|
+
>
|
|
63
|
+
{labels.cancel}
|
|
64
|
+
</Button>
|
|
65
|
+
</ButtonTooltipDecorator>
|
|
66
|
+
<ButtonTooltipDecorator tooltip={tooltips?.confirm}>
|
|
67
|
+
<ConfirmButton
|
|
68
|
+
disabled={disabled}
|
|
69
|
+
labels={labels}
|
|
70
|
+
onClick={onSubmit}
|
|
71
|
+
transitionState={state}
|
|
72
|
+
data-test="button-bar-confirm"
|
|
73
|
+
onTransitionToDefault={() => setDocked(true)}
|
|
74
|
+
/>
|
|
75
|
+
</ButtonTooltipDecorator>
|
|
76
|
+
</ActionBar>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
Savebar.displayName = "Savebar";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Savebar";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { makeStyles } from "../theme";
|
|
2
|
+
|
|
3
|
+
const useStyles = makeStyles(
|
|
4
|
+
(theme) => ({
|
|
5
|
+
button: {
|
|
6
|
+
marginRight: theme.spacing(1),
|
|
7
|
+
},
|
|
8
|
+
cancelButton: {
|
|
9
|
+
marginRight: theme.spacing(2),
|
|
10
|
+
},
|
|
11
|
+
deleteButton: {
|
|
12
|
+
"&:hover": {
|
|
13
|
+
backgroundColor: theme.palette.error.dark,
|
|
14
|
+
},
|
|
15
|
+
backgroundColor: theme.palette.error.main,
|
|
16
|
+
color: theme.palette.error.contrastText,
|
|
17
|
+
},
|
|
18
|
+
spacer: {
|
|
19
|
+
flex: "1",
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
{ name: "Savebar" }
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export default useStyles;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ButtonProps } from "@material-ui/core/Button";
|
|
2
|
+
import ArrowIcon from "@material-ui/icons/ArrowBack";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
import { SquareButton } from "../SquareButton";
|
|
7
|
+
import { makeStyles } from "../theme";
|
|
8
|
+
|
|
9
|
+
const useStyles = makeStyles(
|
|
10
|
+
(theme) => ({
|
|
11
|
+
arrow: {
|
|
12
|
+
transition: theme.transitions.duration.shortest + "ms",
|
|
13
|
+
},
|
|
14
|
+
shrunk: {
|
|
15
|
+
transform: "scaleX(-1)",
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
{
|
|
19
|
+
name: "ExpandButton",
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export interface ExpandButtonProps extends ButtonProps {
|
|
24
|
+
isShrunk: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const ExpandButton: React.FC<ExpandButtonProps> = ({
|
|
28
|
+
isShrunk,
|
|
29
|
+
...rest
|
|
30
|
+
}) => {
|
|
31
|
+
const classes = useStyles({});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<SquareButton {...rest}>
|
|
35
|
+
<ArrowIcon
|
|
36
|
+
className={clsx(classes.arrow, {
|
|
37
|
+
[classes.shrunk]: isShrunk,
|
|
38
|
+
})}
|
|
39
|
+
/>
|
|
40
|
+
</SquareButton>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
ExpandButton.displayName = "ExpandButton";
|