@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,74 @@
|
|
|
1
|
+
import { fade } from "@material-ui/core/styles";
|
|
2
|
+
import type { Overrides } from "@material-ui/core/styles/overrides";
|
|
3
|
+
|
|
4
|
+
import { SaleorThemeColors } from "../types";
|
|
5
|
+
|
|
6
|
+
export const tableOverrides = (
|
|
7
|
+
colors: SaleorThemeColors,
|
|
8
|
+
fontFamily: string
|
|
9
|
+
): Overrides => ({
|
|
10
|
+
MuiTable: {
|
|
11
|
+
root: {
|
|
12
|
+
fontFamily,
|
|
13
|
+
fontFeatureSettings: '"tnum"',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
MuiTableCell: {
|
|
17
|
+
body: {
|
|
18
|
+
fontSize: "1.6rem",
|
|
19
|
+
},
|
|
20
|
+
head: {
|
|
21
|
+
fontSize: "1.4rem",
|
|
22
|
+
fontWeight: 400,
|
|
23
|
+
color: colors.font.textDisabled,
|
|
24
|
+
},
|
|
25
|
+
paddingCheckbox: {
|
|
26
|
+
"&:first-child": {
|
|
27
|
+
padding: "0 12px",
|
|
28
|
+
width: 72,
|
|
29
|
+
},
|
|
30
|
+
"&:not(first-child)": {
|
|
31
|
+
padding: 0,
|
|
32
|
+
width: 52,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
root: {
|
|
36
|
+
"&:first-child": {
|
|
37
|
+
"&:not($paddingCheckbox)": {
|
|
38
|
+
paddingLeft: 24 + "px",
|
|
39
|
+
textAlign: "left" as "left",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
borderBottomColor: colors.paperBorder,
|
|
43
|
+
padding: "16px 24px",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
MuiTablePagination: {
|
|
47
|
+
input: {
|
|
48
|
+
color: colors.primary,
|
|
49
|
+
fontSize: "1.4rem",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
MuiTableRow: {
|
|
53
|
+
footer: {
|
|
54
|
+
"$root$hover&:hover": {
|
|
55
|
+
background: "none",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
head: {
|
|
59
|
+
"$root$hover&:hover": {
|
|
60
|
+
background: "none",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
hover: {
|
|
64
|
+
"$root&:hover": {
|
|
65
|
+
backgroundColor: fade(colors.primary, 0.3),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
root: {
|
|
69
|
+
"&$selected": {
|
|
70
|
+
backgroundColor: fade(colors.primary, 0.05),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SaleorPaletteOptions, SaleorThemeColors } from "./types";
|
|
2
|
+
|
|
3
|
+
export const createPalette = (
|
|
4
|
+
colors: SaleorThemeColors
|
|
5
|
+
): SaleorPaletteOptions => ({
|
|
6
|
+
action: {
|
|
7
|
+
active: colors.checkbox.default,
|
|
8
|
+
},
|
|
9
|
+
alert: colors.alert,
|
|
10
|
+
background: colors.background,
|
|
11
|
+
divider: colors.divider,
|
|
12
|
+
error: {
|
|
13
|
+
main: colors.error,
|
|
14
|
+
},
|
|
15
|
+
primary: {
|
|
16
|
+
contrastText: "#ffffff",
|
|
17
|
+
dark: colors.font.textDisabled,
|
|
18
|
+
main: colors.primary,
|
|
19
|
+
},
|
|
20
|
+
secondary: {
|
|
21
|
+
contrastText: "#ffffff",
|
|
22
|
+
main: colors.secondary,
|
|
23
|
+
},
|
|
24
|
+
success: {
|
|
25
|
+
main: colors.success,
|
|
26
|
+
},
|
|
27
|
+
text: {
|
|
28
|
+
disabled: colors.font.gray,
|
|
29
|
+
hint: colors.font.gray,
|
|
30
|
+
primary: colors.font.default,
|
|
31
|
+
secondary: colors.font.gray,
|
|
32
|
+
},
|
|
33
|
+
textHighlighted: {
|
|
34
|
+
active: colors.primary,
|
|
35
|
+
inactive: colors.highlightInactive.default,
|
|
36
|
+
},
|
|
37
|
+
type: colors.theme,
|
|
38
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Shadows } from "@material-ui/core/styles/shadows";
|
|
2
|
+
|
|
3
|
+
const createShadow = (
|
|
4
|
+
pv: number,
|
|
5
|
+
pb: number,
|
|
6
|
+
ps: number,
|
|
7
|
+
uv: number,
|
|
8
|
+
ub: number,
|
|
9
|
+
us: number,
|
|
10
|
+
av: number,
|
|
11
|
+
ab: number,
|
|
12
|
+
as: number
|
|
13
|
+
) =>
|
|
14
|
+
[
|
|
15
|
+
`0 ${pv}px ${pb}px ${ps}px rgba(0, 0, 0, 0.2)`,
|
|
16
|
+
`0 ${uv}px ${ub}px ${us}px rgba(0, 0, 0, 0.14)`,
|
|
17
|
+
`0 ${av}px ${ab}px ${as}px rgba(0, 0, 0, 0.12)`,
|
|
18
|
+
].join(",");
|
|
19
|
+
|
|
20
|
+
export const shadows: Shadows = [
|
|
21
|
+
"none",
|
|
22
|
+
createShadow(1, 1, 0, 2, 1, -2, 1, 3, 0),
|
|
23
|
+
createShadow(2, 2, 0, 3, 1, -2, 1, 5, 0),
|
|
24
|
+
createShadow(3, 4, 0, 3, 3, -2, 1, 8, 0),
|
|
25
|
+
createShadow(4, 5, 0, 1, 10, 0, 2, 4, -1),
|
|
26
|
+
createShadow(5, 8, 0, 1, 14, 0, 3, 4, -1),
|
|
27
|
+
createShadow(6, 10, 0, 1, 18, 0, 3, 5, -1),
|
|
28
|
+
createShadow(7, 10, 0, 2, 16, 1, 4, 5, -2),
|
|
29
|
+
createShadow(8, 10, 1, 3, 14, 2, 5, 5, -3),
|
|
30
|
+
createShadow(9, 12, 1, 3, 16, 3, 5, 6, -4),
|
|
31
|
+
createShadow(10, 14, 1, 4, 18, 3, 6, 7, -4),
|
|
32
|
+
createShadow(11, 16, 1, 4, 20, 3, 6, 7, -4),
|
|
33
|
+
createShadow(12, 17, 1, 5, 22, 4, 7, 8, -4),
|
|
34
|
+
createShadow(13, 19, 1, 5, 24, 4, 7, 8, -4),
|
|
35
|
+
createShadow(14, 21, 1, 5, 26, 4, 7, 9, -5),
|
|
36
|
+
createShadow(15, 22, 1, 5, 28, 4, 7, 9, -5),
|
|
37
|
+
createShadow(16, 24, 2, 6, 30, 5, 8, 10, -5),
|
|
38
|
+
createShadow(15, 27, 3, 7, 28, 3, 10, 14, -4),
|
|
39
|
+
createShadow(14, 30, 4, 8, 26, 1, 12, 17, -3),
|
|
40
|
+
createShadow(13, 33, 4, 8, 24, -1, 14, 20, -1),
|
|
41
|
+
createShadow(12, 36, 5, 9, 22, -2, 16, 24, 1),
|
|
42
|
+
createShadow(11, 39, 6, 10, 20, -4, 18, 28, 1),
|
|
43
|
+
createShadow(10, 41, 7, 10, 18, -5, 20, 31, 2),
|
|
44
|
+
createShadow(9, 44, 7, 11, 16, -6, 22, 35, 2),
|
|
45
|
+
createShadow(9, 46, 8, 11, 15, -7, 24, 38, 3),
|
|
46
|
+
];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
2
|
+
import type { Theme } from "@material-ui/core/styles";
|
|
3
|
+
import type { ThemeOptions } from "@material-ui/core/styles/createMuiTheme";
|
|
4
|
+
import type {
|
|
5
|
+
Palette,
|
|
6
|
+
PaletteOptions,
|
|
7
|
+
} from "@material-ui/core/styles/createPalette";
|
|
8
|
+
|
|
9
|
+
export type AlertPalette = Record<
|
|
10
|
+
"success" | "error" | "warning" | "info",
|
|
11
|
+
string
|
|
12
|
+
>;
|
|
13
|
+
export type AlertColors = Record<"paper" | "icon", AlertPalette>;
|
|
14
|
+
interface ExtraPalette {
|
|
15
|
+
alert: AlertColors;
|
|
16
|
+
textHighlighted: {
|
|
17
|
+
active: string;
|
|
18
|
+
inactive: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
type ExtraPaletteOptions = Partial<ExtraPalette>;
|
|
22
|
+
|
|
23
|
+
export interface SaleorPalette extends Palette, ExtraPalette {}
|
|
24
|
+
|
|
25
|
+
export interface SaleorPaletteOptions
|
|
26
|
+
extends PaletteOptions,
|
|
27
|
+
ExtraPaletteOptions {}
|
|
28
|
+
|
|
29
|
+
export interface SaleorSpacing {
|
|
30
|
+
(): string;
|
|
31
|
+
(value: number): string;
|
|
32
|
+
(topBottom: number, rightLeft: number): string;
|
|
33
|
+
(top: number, rightLeft: number, bottom: number): string;
|
|
34
|
+
(top: number, right: number, bottom: number, left: number): string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SaleorTheme extends Omit<Theme, "spacing"> {
|
|
38
|
+
palette: SaleorPalette;
|
|
39
|
+
spacing: SaleorSpacing;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SaleorThemeOptions extends ThemeOptions {
|
|
43
|
+
palette: SaleorPaletteOptions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type ThemeType = "light" | "dark";
|
|
47
|
+
|
|
48
|
+
export type SaleorThemeColors = Record<
|
|
49
|
+
"primary" | "secondary" | "error" | "paperBorder" | "autofill" | "success",
|
|
50
|
+
string
|
|
51
|
+
> & {
|
|
52
|
+
highlightInactive: Record<"default", string>;
|
|
53
|
+
} & {
|
|
54
|
+
background: Record<"default" | "paper", string>;
|
|
55
|
+
} & {
|
|
56
|
+
checkbox: Record<"default", string>;
|
|
57
|
+
} & {
|
|
58
|
+
divider: string;
|
|
59
|
+
} & {
|
|
60
|
+
font: Record<
|
|
61
|
+
"default" | "gray" | "button" | "textButton" | "textDisabled",
|
|
62
|
+
string
|
|
63
|
+
>;
|
|
64
|
+
} & {
|
|
65
|
+
gray: Record<"default" | "disabled", string>;
|
|
66
|
+
} & {
|
|
67
|
+
input: Record<
|
|
68
|
+
| "default"
|
|
69
|
+
| "border"
|
|
70
|
+
| "disabled"
|
|
71
|
+
| "disabledBackground"
|
|
72
|
+
| "disabledText"
|
|
73
|
+
| "error"
|
|
74
|
+
| "text"
|
|
75
|
+
| "textHover",
|
|
76
|
+
string
|
|
77
|
+
>;
|
|
78
|
+
} & {
|
|
79
|
+
alert: AlertColors;
|
|
80
|
+
} & {
|
|
81
|
+
theme: ThemeType;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type Themes = Record<ThemeType, SaleorThemeColors>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeStyles as muiMakeStyles,
|
|
3
|
+
useTheme as useMuiTheme,
|
|
4
|
+
} from "@material-ui/core/styles";
|
|
5
|
+
import type {
|
|
6
|
+
ClassNameMap,
|
|
7
|
+
Styles,
|
|
8
|
+
WithStylesOptions,
|
|
9
|
+
} from "@material-ui/styles/withStyles";
|
|
10
|
+
import { useContext } from "react";
|
|
11
|
+
|
|
12
|
+
import { ThemeContext } from "./context";
|
|
13
|
+
import { SaleorTheme } from "./createSaleorTheme/types";
|
|
14
|
+
import type { SaleorThemeContext } from "./types";
|
|
15
|
+
|
|
16
|
+
export function makeStyles<
|
|
17
|
+
Props extends Record<string, any> = {},
|
|
18
|
+
ClassKey extends string = string
|
|
19
|
+
>(
|
|
20
|
+
styles: Styles<SaleorTheme, Props, ClassKey>,
|
|
21
|
+
options?: Omit<WithStylesOptions<SaleorTheme>, "withTheme">
|
|
22
|
+
): keyof Props extends never
|
|
23
|
+
? (props?: any) => ClassNameMap<ClassKey>
|
|
24
|
+
: (props: Props) => ClassNameMap<ClassKey> {
|
|
25
|
+
return muiMakeStyles(styles, options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useTheme(): SaleorTheme & SaleorThemeContext {
|
|
29
|
+
const saleorTheme = useMuiTheme<SaleorTheme>();
|
|
30
|
+
const themeInfo = useContext(ThemeContext);
|
|
31
|
+
|
|
32
|
+
if (themeInfo === undefined || saleorTheme === undefined) {
|
|
33
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...saleorTheme,
|
|
38
|
+
...themeInfo,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SaleorThemeColors } from "./createSaleorTheme";
|
|
2
|
+
|
|
3
|
+
export const dark: SaleorThemeColors = {
|
|
4
|
+
alert: {
|
|
5
|
+
paper: {
|
|
6
|
+
error: "#E0444E",
|
|
7
|
+
info: "#2E2F31",
|
|
8
|
+
success: "#5DC292",
|
|
9
|
+
warning: "#E29A2E",
|
|
10
|
+
},
|
|
11
|
+
icon: {
|
|
12
|
+
error: "#FE6E76",
|
|
13
|
+
info: "#FAFAFA",
|
|
14
|
+
success: "#5DC292",
|
|
15
|
+
warning: "#FFB84E",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
highlightInactive: {
|
|
19
|
+
default: "#78797A",
|
|
20
|
+
},
|
|
21
|
+
autofill: "#5D5881",
|
|
22
|
+
background: {
|
|
23
|
+
default: "#1D1E1F",
|
|
24
|
+
paper: "#2E2F31",
|
|
25
|
+
},
|
|
26
|
+
checkbox: {
|
|
27
|
+
default: "#FFFFFF",
|
|
28
|
+
},
|
|
29
|
+
divider: "#252728",
|
|
30
|
+
error: "#C22D74",
|
|
31
|
+
font: {
|
|
32
|
+
button: "#202124",
|
|
33
|
+
default: "#FCFCFC",
|
|
34
|
+
gray: "#9E9D9D",
|
|
35
|
+
textButton: "#FFFFFF",
|
|
36
|
+
textDisabled: "#FCFCFC",
|
|
37
|
+
},
|
|
38
|
+
gray: {
|
|
39
|
+
default: "#202124",
|
|
40
|
+
disabled: "rgba(32, 33, 36, 0.6)",
|
|
41
|
+
},
|
|
42
|
+
input: {
|
|
43
|
+
border: "#9d9d9d",
|
|
44
|
+
default: "#25262A",
|
|
45
|
+
disabled: "#393939",
|
|
46
|
+
disabledBackground: "#292A2D",
|
|
47
|
+
disabledText: "#9D9D9D",
|
|
48
|
+
error: "#8C2054",
|
|
49
|
+
text: "#FCFCFC",
|
|
50
|
+
textHover: "#616161",
|
|
51
|
+
},
|
|
52
|
+
paperBorder: "#252728",
|
|
53
|
+
primary: "#13BEBB",
|
|
54
|
+
secondary: "#21125E",
|
|
55
|
+
success: "#5DC292",
|
|
56
|
+
theme: "dark",
|
|
57
|
+
};
|
|
58
|
+
export const light: SaleorThemeColors = {
|
|
59
|
+
alert: {
|
|
60
|
+
paper: {
|
|
61
|
+
error: "#FFD6D9",
|
|
62
|
+
info: "#FFFFFF",
|
|
63
|
+
success: "#DFF3E9",
|
|
64
|
+
warning: "#FFF4E4",
|
|
65
|
+
},
|
|
66
|
+
icon: {
|
|
67
|
+
error: "#FE6E76",
|
|
68
|
+
info: "#28234A",
|
|
69
|
+
success: "#5DC292",
|
|
70
|
+
warning: "#FFB84E",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
highlightInactive: {
|
|
74
|
+
default: "#C8C8C8",
|
|
75
|
+
},
|
|
76
|
+
autofill: "#f4f6c5",
|
|
77
|
+
background: {
|
|
78
|
+
default: "#EFF5F8",
|
|
79
|
+
paper: "#FFFFFF",
|
|
80
|
+
},
|
|
81
|
+
checkbox: {
|
|
82
|
+
default: "#616161",
|
|
83
|
+
},
|
|
84
|
+
divider: "#EAEAEA",
|
|
85
|
+
error: "#FE6D76",
|
|
86
|
+
font: {
|
|
87
|
+
button: "#FFFFFF",
|
|
88
|
+
default: "#3D3D3D",
|
|
89
|
+
gray: "#616161",
|
|
90
|
+
textButton: "#06847B",
|
|
91
|
+
textDisabled: "#616161",
|
|
92
|
+
},
|
|
93
|
+
gray: {
|
|
94
|
+
default: "#C8C8C8",
|
|
95
|
+
disabled: "rgba(216, 216, 216, 0.3)",
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
input: {
|
|
99
|
+
border: "#BDBDBD",
|
|
100
|
+
default: "#FFFFFF",
|
|
101
|
+
disabled: "#EAEAEA",
|
|
102
|
+
disabledBackground: "#F4F4F4",
|
|
103
|
+
disabledText: "#9D9D9D",
|
|
104
|
+
error: "#8C2054",
|
|
105
|
+
text: "#3D3D3D",
|
|
106
|
+
textHover: "#616161",
|
|
107
|
+
},
|
|
108
|
+
paperBorder: "#EAEAEA",
|
|
109
|
+
primary: "#06847B",
|
|
110
|
+
secondary: "#21125E",
|
|
111
|
+
success: "#5DC292",
|
|
112
|
+
theme: "light",
|
|
113
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { changeColorMeta } from "./utils";
|
|
2
|
+
|
|
3
|
+
describe("Changing color meta tag", () => {
|
|
4
|
+
it("works properly if no tag is present", () => {
|
|
5
|
+
// Given
|
|
6
|
+
document.head.innerHTML = `
|
|
7
|
+
<meta name="tag1" content="value1" />
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
// When
|
|
11
|
+
changeColorMeta("#FF0000");
|
|
12
|
+
|
|
13
|
+
// Then
|
|
14
|
+
expect(
|
|
15
|
+
document.querySelector(`head meta[name="tag1"]`)?.getAttribute("content")
|
|
16
|
+
).toBe("value1");
|
|
17
|
+
expect(
|
|
18
|
+
document
|
|
19
|
+
.querySelector(`head meta[name="theme-color"]`)
|
|
20
|
+
?.getAttribute("content")
|
|
21
|
+
).toBe("#FF0000");
|
|
22
|
+
});
|
|
23
|
+
it("works properly if tag is present", () => {
|
|
24
|
+
// Given
|
|
25
|
+
document.head.innerHTML = `
|
|
26
|
+
<meta name="tag1" content="value1" />
|
|
27
|
+
<meta name="theme-color" content="#00FF00" />
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
// When
|
|
31
|
+
changeColorMeta("#FF0000");
|
|
32
|
+
|
|
33
|
+
// Then
|
|
34
|
+
expect(
|
|
35
|
+
document.querySelector(`head meta[name="tag1"]`)?.getAttribute("content")
|
|
36
|
+
).toBe("value1");
|
|
37
|
+
expect(
|
|
38
|
+
document
|
|
39
|
+
.querySelector(`head meta[name="theme-color"]`)
|
|
40
|
+
?.getAttribute("content")
|
|
41
|
+
).toBe("#FF0000");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function changeColorMeta(color: string) {
|
|
2
|
+
const themeColorTag = document.createElement("meta");
|
|
3
|
+
themeColorTag.setAttribute("content", color);
|
|
4
|
+
themeColorTag.setAttribute("name", "theme-color");
|
|
5
|
+
|
|
6
|
+
const existingColorTag = document.head.querySelector(
|
|
7
|
+
`meta[name="theme-color"]`
|
|
8
|
+
);
|
|
9
|
+
if (existingColorTag) {
|
|
10
|
+
existingColorTag.remove();
|
|
11
|
+
}
|
|
12
|
+
document.head.appendChild(themeColorTag);
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copied directly from
|
|
2
|
+
// https://github.com/dance2die/react-use-localstorage/blob/master/src/index.ts
|
|
3
|
+
// to avoid cjs and esm confusion in jest transformators
|
|
4
|
+
|
|
5
|
+
import { useCallback, useEffect, useState } from "react";
|
|
6
|
+
|
|
7
|
+
// FIXME: We also had to tweak return signature because tuples were bugging
|
|
8
|
+
// typescript parser
|
|
9
|
+
// https://stackoverflow.com/questions/62079477/line-0-parsing-error-cannot-read-property-map-of-undefined
|
|
10
|
+
// tsdx issue
|
|
11
|
+
// https://github.com/formium/tsdx/issues/926
|
|
12
|
+
export interface UseLocalStorage {
|
|
13
|
+
value: string;
|
|
14
|
+
setValue: (value: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export default function useLocalStorage(
|
|
17
|
+
key: string,
|
|
18
|
+
initialValue: string = ""
|
|
19
|
+
): UseLocalStorage {
|
|
20
|
+
const [value, setValue] = useState(
|
|
21
|
+
() => window.localStorage.getItem(key) || initialValue
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const setItem = (newValue: string) => {
|
|
25
|
+
setValue(newValue);
|
|
26
|
+
window.localStorage.setItem(key, newValue);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const newValue = window.localStorage.getItem(key);
|
|
32
|
+
if (value !== newValue) {
|
|
33
|
+
setValue(newValue || initialValue);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const handleStorage = useCallback(
|
|
38
|
+
(event: StorageEvent) => {
|
|
39
|
+
if (event.key === key && event.newValue !== value) {
|
|
40
|
+
setValue(event.newValue || initialValue);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
[value, key]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
window.addEventListener("storage", handleStorage);
|
|
49
|
+
return () => window.removeEventListener("storage", handleStorage);
|
|
50
|
+
}, [handleStorage]);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
value,
|
|
54
|
+
setValue: setItem,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// It's only optimized for esm, cjs will remain fat blob
|
|
2
|
+
// Ref https://github.com/formium/tsdx/issues/763
|
|
3
|
+
import { throttle } from "lodash";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
|
|
6
|
+
function getPosition() {
|
|
7
|
+
return {
|
|
8
|
+
x: window.pageXOffset,
|
|
9
|
+
y: window.pageYOffset,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function useWindowScroll() {
|
|
14
|
+
const [scroll, setScroll] = useState(getPosition);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const handleScroll = throttle(() => setScroll(getPosition()), 100);
|
|
18
|
+
|
|
19
|
+
window.addEventListener("scroll", handleScroll);
|
|
20
|
+
|
|
21
|
+
return () => window.removeEventListener("scroll", handleScroll);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return scroll;
|
|
25
|
+
}
|
|
26
|
+
export default useWindowScroll;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Card, CardContent } from "@material-ui/core";
|
|
2
|
+
import { StoryFn } from "@storybook/addons";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
import { ThemeProvider } from "../theme";
|
|
6
|
+
|
|
7
|
+
export const Decorator = (storyFn: StoryFn<React.ReactNode>) => (
|
|
8
|
+
<ThemeProvider>
|
|
9
|
+
<div
|
|
10
|
+
style={{
|
|
11
|
+
padding: 24,
|
|
12
|
+
}}
|
|
13
|
+
>
|
|
14
|
+
{storyFn()}
|
|
15
|
+
</div>
|
|
16
|
+
</ThemeProvider>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const GuideDecorator = (storyFn: StoryFn<React.ReactNode>) => (
|
|
20
|
+
<Card style={{ margin: "auto", width: 600 }}>
|
|
21
|
+
<CardContent>{storyFn()}</CardContent>
|
|
22
|
+
</Card>
|
|
23
|
+
);
|