saleor-dashboard/src/theme.ts

577 lines
14 KiB
TypeScript
Raw Normal View History

2019-09-30 16:46:48 +00:00
import Card from "@material-ui/core/Card";
2020-08-17 11:42:37 +00:00
import Checkbox from "@material-ui/core/Checkbox";
2019-06-19 14:40:52 +00:00
import { createMuiTheme, Theme } from "@material-ui/core/styles";
2019-09-16 02:16:49 +00:00
import { darken, fade } from "@material-ui/core/styles/colorManipulator";
2019-06-19 14:40:52 +00:00
import TextField from "@material-ui/core/TextField";
2019-10-30 14:34:24 +00:00
import Typography from "@material-ui/core/Typography";
2020-08-17 14:44:40 +00:00
import { createElement } from "react";
2019-06-19 14:40:52 +00:00
2019-11-04 13:36:25 +00:00
import { IThemeColors } from "./components/Theme/themes";
2020-08-17 14:44:40 +00:00
import CheckboxIcon from "./icons/Checkbox";
import CheckboxCheckedIcon from "./icons/CheckboxChecked";
import CheckboxIndeterminateIcon from "./icons/CheckboxIndeterminate";
2019-11-04 13:36:25 +00:00
2019-06-19 14:40:52 +00:00
const createShadow = (pv, pb, ps, uv, ub, us, av, ab, as) =>
[
`0 ${pv}px ${pb}px ${ps}px rgba(0, 0, 0, 0.2)`,
`0 ${uv}px ${ub}px ${us}px rgba(0, 0, 0, 0.14)`,
`0 ${av}px ${ab}px ${as}px rgba(0, 0, 0, 0.12)`
].join(",");
export const ICONBUTTON_SIZE = 48;
const fontFamily = '"Inter", "roboto", "sans-serif"';
export default (colors: IThemeColors): Theme =>
createMuiTheme({
overrides: {
MuiButton: {
contained: {
"&$disabled": {
backgroundColor: fade(colors.primary, 0.12)
2019-10-28 16:16:49 +00:00
},
"&:active": {
boxShadow: null
},
"&:hover": {
boxShadow: null
},
boxShadow: null
2019-06-19 14:40:52 +00:00
},
containedPrimary: {
2019-10-28 16:16:49 +00:00
"&:active": {
backgroundColor: darken(colors.primary, 0.4)
},
"&:hover": {
backgroundColor: darken(colors.primary, 0.1)
}
},
2019-06-19 14:40:52 +00:00
label: {
2019-08-09 11:14:35 +00:00
color: colors.font.button,
2019-06-19 14:40:52 +00:00
fontWeight: 600
},
root: {
"& svg": {
marginLeft: 8
},
2019-08-09 11:14:35 +00:00
borderRadius: 4
2019-10-28 16:16:49 +00:00
},
text: {
"& span": {
color: colors.font.default
}
},
textPrimary: {
"& span": {
color: colors.primary
}
2019-06-19 14:40:52 +00:00
}
},
MuiCard: {
root: {
borderColor: colors.paperBorder,
borderRadius: 8,
2019-08-09 11:14:35 +00:00
borderStyle: "solid",
borderWidth: 1,
overflow: "visible"
2019-06-19 14:40:52 +00:00
}
},
MuiCardActions: {
root: {
flexDirection: "row-reverse" as "row-reverse"
}
},
2019-09-02 11:27:23 +00:00
MuiCardContent: {
root: {
padding: "24px"
}
},
2019-10-30 14:34:24 +00:00
MuiChip: {
avatar: {
height: 32,
left: -5,
position: "relative",
width: 32
}
},
2019-11-04 13:36:25 +00:00
MuiDialogActions: {
root: {
borderTop: `1px solid ${colors.divider}`,
padding: `16px 24px`
}
},
2019-08-09 11:14:35 +00:00
MuiDialogContent: {
2019-06-19 14:40:52 +00:00
root: {
2019-10-22 09:57:04 +00:00
"& label": {
2019-10-23 14:42:51 +00:00
overflowX: "hidden"
2019-10-22 09:57:04 +00:00
},
2019-11-04 13:36:25 +00:00
padding: 24
2019-08-09 11:14:35 +00:00
}
},
2019-11-04 13:36:25 +00:00
MuiDialogContentText: {
2019-09-09 09:28:06 +00:00
root: {
2019-11-04 13:36:25 +00:00
"&:last-child": {
marginBottom: 0
}
}
},
MuiDialogTitle: {
root: {
borderBottom: `1px solid ${colors.divider}`
}
},
MuiFormControlLabel: {
label: {
marginLeft: 4
2019-09-09 09:28:06 +00:00
}
},
2019-08-09 11:14:35 +00:00
MuiFormLabel: {
filled: {
2019-09-26 14:51:28 +00:00
"&&:not($error)": {
color: colors.primary
}
},
root: {
"&&$focused:not($error)": {
color: colors.font.gray
}
2019-06-19 14:40:52 +00:00
}
},
MuiIconButton: {
root: {
"&:hover": {
backgroundColor: fade(colors.primary, 0.12)
}
}
},
MuiInput: {
input: {
"&:-webkit-autofill": {
WebkitTextFillColor: colors.font.default,
boxShadow: `inset 0 0 0px 9999px ${colors.autofill}`
},
"&::placeholder": {
2019-08-09 11:14:35 +00:00
opacity: "1 !important" as any
2020-05-07 11:04:44 +00:00
},
color: colors.font.default
2019-06-19 14:40:52 +00:00
},
underline: {
"&:after": {
borderBottomColor: colors.primary
}
}
},
MuiInputBase: {
input: {
2019-09-11 10:47:38 +00:00
"&$disabled": {
color: colors.input.disabledText
},
2019-06-19 14:40:52 +00:00
"&::placeholder": {
2019-08-09 11:14:35 +00:00
color: colors.font.gray,
opacity: "1 !important" as any
2019-09-11 09:47:39 +00:00
},
2019-11-04 13:36:25 +00:00
zIndex: 2
2019-06-19 14:40:52 +00:00
}
},
MuiInputLabel: {
2019-11-04 13:36:25 +00:00
filled: {
zIndex: 2
2019-09-26 14:23:51 +00:00
},
2019-06-19 14:40:52 +00:00
formControl: {
transform: "translate(0, 1.5px) scale(0.75)",
transformOrigin: "top left" as "top left",
width: "100%"
},
2019-08-09 11:14:35 +00:00
outlined: {
"&$shrink": {
2019-10-28 16:16:49 +00:00
transform: "translate(12px, 9px) scale(0.75)"
2019-08-09 11:14:35 +00:00
},
2019-10-28 16:16:49 +00:00
transform: "translate(14px, 18px) scale(1)",
zIndex: 9
2019-08-09 11:14:35 +00:00
},
2019-06-19 14:40:52 +00:00
root: {
2019-09-03 11:45:23 +00:00
"&$disabled": {
color: `${fade(colors.primary, 0.4)} !important` as any
},
2019-11-04 13:36:25 +00:00
"&$error": {
"&$focused": {
2019-09-26 14:51:28 +00:00
color: colors.error
},
2019-11-04 13:36:25 +00:00
color: colors.error
},
"&&$focused": {
2019-09-26 14:51:28 +00:00
"&:not($error)": {
color: colors.primary
}
2019-09-11 10:27:15 +00:00
},
2020-05-07 11:04:44 +00:00
color: fade(colors.input.text, 0.6)
2019-06-19 14:40:52 +00:00
},
shrink: {
// Negates x0.75 scale
width: "133%"
}
},
MuiList: {
root: {
display: "grid",
gridRowGap: 8 + "px",
padding: "8px !important"
}
},
MuiListItem: {
button: {
"&:focus": {
backgroundColor: colors.input.default
}
},
root: {
"&$selected": {
"&:hover": {
backgroundColor: colors.input.default
},
backgroundColor: colors.input.default
}
}
},
MuiMenu: {
paper: {
borderRadius: 8
}
},
MuiMenuItem: {
root: {
2019-10-28 16:16:49 +00:00
"&$selected, &$selected:focus, &$selected:hover": {
backgroundColor: [colors.background.default, "!important"] as any,
color: colors.primary,
fontWeight: 700
},
"&:hover": {
backgroundColor: [colors.background.default, "!important"] as any,
color: colors.font.default,
fontWeight: 400
2019-06-19 14:40:52 +00:00
},
borderRadius: 4
}
2019-06-19 14:40:52 +00:00
},
2019-08-09 11:14:35 +00:00
MuiOutlinedInput: {
input: {
"&:-webkit-autofill": {
2019-10-28 16:16:49 +00:00
borderRadius: 4,
boxShadow: `0 0 0px 1000px rgba(19, 190, 187, 0.1) inset`,
zIndex: 0
},
2019-08-09 11:14:35 +00:00
"&::placeholder": {
opacity: [[0], "!important"] as any
},
color: colors.input.text,
2019-10-28 16:16:49 +00:00
padding: "23px 12px 10px 12px"
2019-08-09 11:14:35 +00:00
},
inputMultiline: {
left: -2,
padding: "10px 0",
position: "relative"
},
root: {
"& fieldset": {
2019-09-26 14:51:28 +00:00
"&&:not($error)": {
borderColor: colors.input.border
2019-10-28 16:16:49 +00:00
},
top: 0,
zIndex: 1
2019-08-09 11:14:35 +00:00
},
"& legend": {
display: "none"
},
"&$disabled": {
"& fieldset": {
2019-09-03 11:29:40 +00:00
backgroundColor: colors.input.disabledBackground,
borderColor: [[colors.input.disabled], "!important"] as any
2019-08-09 11:14:35 +00:00
},
"& input": {
2019-09-03 11:29:40 +00:00
color: colors.input.disabledText,
2019-08-09 11:14:35 +00:00
zIndex: 2
}
},
2019-11-04 13:36:25 +00:00
"&$error": {
"&$focused": {
"& fieldset": {
borderColor: colors.error
},
"& input": {
color: colors.error,
zIndex: 2
}
},
"&:hover": {
"& fieldset": {
borderColor: colors.error
},
"& input": {
color: colors.error,
zIndex: 2
}
}
},
2019-08-09 11:14:35 +00:00
"&$focused": {
"& input": {
2019-11-04 13:36:25 +00:00
"& fieldset": {
borderColor: colors.primary
},
2019-08-09 11:14:35 +00:00
"&::placeholder": {
opacity: [[1], "!important"] as any
},
2019-10-28 16:16:49 +00:00
color: colors.font.default
2019-08-09 11:14:35 +00:00
}
},
"&:hover": {
"& input": {
2019-10-28 16:16:49 +00:00
color: colors.font.default
2019-09-26 14:51:28 +00:00
},
"&&&": {
"& fieldset": {
borderColor: colors.primary
},
"&$error fieldset": {
borderColor: colors.input.error
}
2019-08-09 11:14:35 +00:00
}
},
2019-12-17 14:20:54 +00:00
backgroundColor: colors.background.paper,
2019-10-28 16:16:49 +00:00
borderColor: colors.input.border,
top: 0
2019-09-03 09:48:20 +00:00
}
},
MuiSnackbarContent: {
action: {
"& $MuiIconButton": {
"& svg": {
color: colors.font.default
}
2019-11-25 16:23:52 +00:00
},
2020-06-23 11:47:30 +00:00
display: "block",
paddingBottom: 10,
paddingLeft: 0,
paddingRight: 45
},
2019-11-12 12:31:05 +00:00
message: {
fontSize: 16
},
root: {
backgroundColor: colors.background.paper,
2019-09-10 13:47:20 +00:00
boxShadow:
2019-09-11 09:47:39 +00:00
"0 6px 10px 0px rgba(0, 0, 0, 0.15), 0 1px 18px 0px rgba(0, 0, 0, 0.12), 0 3px 5px -1px rgba(0, 0, 0, 0.10)",
2019-11-25 16:23:52 +00:00
color: colors.font.default,
2020-06-23 11:47:30 +00:00
display: "block",
2020-06-24 14:17:56 +00:00
maxWidth: 480
}
},
2019-06-19 14:40:52 +00:00
MuiSwitch: {
2019-10-30 14:34:24 +00:00
colorPrimary: {
"&$checked": {
color: colors.background.paper
}
2019-06-19 14:40:52 +00:00
},
root: {
"&$disabled": {
"&$switchBase": {
2019-11-04 13:36:25 +00:00
"& + $thumb": {
2019-06-19 14:40:52 +00:00
backgroundColor: colors.gray.disabled
}
}
2019-10-30 14:34:24 +00:00
},
height: 48,
width: 72
},
switchBase: {
"&$checked": {
transform: "translateX(23px)"
},
boxShadow: "none",
left: 1,
marginLeft: 4,
top: 5
},
thumb: {
boxShadow: "none"
},
track: {
"$colorPrimary$checked + &": {
backgroundColor: colors.primary
},
backgroundColor: colors.gray.default,
borderRadius: 12,
height: 24,
opacity: [["1"], "!important"] as any,
width: 48
2019-06-19 14:40:52 +00:00
}
},
MuiTable: {
root: {
fontFamily,
fontFeatureSettings: '"tnum"'
}
},
MuiTableCell: {
body: {
2019-11-12 12:21:37 +00:00
fontSize: "1rem",
2019-06-19 14:40:52 +00:00
paddingBottom: 8,
paddingTop: 8
},
head: {
2019-11-12 12:21:37 +00:00
fontSize: "1rem"
2019-06-19 14:40:52 +00:00
},
paddingCheckbox: {
2019-08-09 11:14:35 +00:00
"&:first-child": {
padding: "0 12px",
width: 72
},
"&:not(first-child)": {
padding: 0,
width: 52
}
2019-06-19 14:40:52 +00:00
},
root: {
"&:first-child": {
"&:not($paddingCheckbox)": {
paddingLeft: 24 + "px",
textAlign: "left" as "left"
}
},
borderBottomColor: colors.paperBorder,
height: 56,
2019-09-02 08:44:26 +00:00
padding: "4px 24px"
2019-06-19 14:40:52 +00:00
}
},
MuiTableRow: {
footer: {
"$root$hover&:hover": {
background: "none"
}
},
head: {
"$root$hover&:hover": {
background: "none"
}
},
hover: {
"$root&:hover": {
2019-09-10 13:37:36 +00:00
backgroundColor: fade(colors.primary, 0.3)
2019-06-19 14:40:52 +00:00
}
},
root: {
"&$selected": {
backgroundColor: fade(colors.primary, 0.05)
}
}
},
MuiTouchRipple: {
child: {
backgroundColor: fade(colors.primary, 0.2)
},
childLeaving: {
backgroundColor: fade(colors.primary, 0.2)
},
ripple: {
"&$rippleVisible": {
backgroundColor: fade(colors.primary, 0.2)
2019-10-10 12:45:25 +00:00
},
borderRadius: "100%"
2019-06-19 14:40:52 +00:00
}
}
},
palette: {
2019-09-11 09:47:39 +00:00
action: {
active: colors.checkbox.default
},
2019-06-19 14:40:52 +00:00
background: colors.background,
2019-09-10 16:43:34 +00:00
divider: colors.divider,
2019-06-19 14:40:52 +00:00
error: {
main: colors.error
},
primary: {
contrastText: "#ffffff",
2019-09-10 16:23:59 +00:00
dark: colors.font.textDisabled,
2019-06-19 14:40:52 +00:00
main: colors.primary
},
secondary: {
contrastText: "#ffffff",
main: colors.secondary
},
text: {
disabled: colors.font.gray,
hint: colors.font.gray,
primary: colors.font.default,
secondary: colors.font.gray
2019-10-28 16:16:49 +00:00
},
type: colors.theme
2019-06-19 14:40:52 +00:00
},
props: {
MuiFormControl: {
variant: "filled"
}
},
shadows: [
"none",
createShadow(1, 1, 0, 2, 1, -2, 1, 3, 0),
createShadow(2, 2, 0, 3, 1, -2, 1, 5, 0),
createShadow(3, 4, 0, 3, 3, -2, 1, 8, 0),
createShadow(4, 5, 0, 1, 10, 0, 2, 4, -1),
createShadow(5, 8, 0, 1, 14, 0, 3, 4, -1),
createShadow(6, 10, 0, 1, 18, 0, 3, 5, -1),
createShadow(7, 10, 0, 2, 16, 1, 4, 5, -2),
createShadow(8, 10, 1, 3, 14, 2, 5, 5, -3),
createShadow(9, 12, 1, 3, 16, 3, 5, 6, -4),
createShadow(10, 14, 1, 4, 18, 3, 6, 7, -4),
createShadow(11, 16, 1, 4, 20, 3, 6, 7, -4),
createShadow(12, 17, 1, 5, 22, 4, 7, 8, -4),
createShadow(13, 19, 1, 5, 24, 4, 7, 8, -4),
createShadow(14, 21, 1, 5, 26, 4, 7, 9, -5),
createShadow(15, 22, 1, 5, 28, 4, 7, 9, -5),
createShadow(16, 24, 2, 6, 30, 5, 8, 10, -5),
createShadow(15, 27, 3, 7, 28, 3, 10, 14, -4),
createShadow(14, 30, 4, 8, 26, 1, 12, 17, -3),
createShadow(13, 33, 4, 8, 24, -1, 14, 20, -1),
createShadow(12, 36, 5, 9, 22, -2, 16, 24, 1),
createShadow(11, 39, 6, 10, 20, -4, 18, 28, 1),
createShadow(10, 41, 7, 10, 18, -5, 20, 31, 2),
createShadow(9, 44, 7, 11, 16, -6, 22, 35, 2),
createShadow(9, 46, 8, 11, 15, -7, 24, 38, 3)
],
typography: {
allVariants: {
fontFamily
},
body1: {
2019-10-28 16:16:49 +00:00
color: colors.font.default
2019-06-19 14:40:52 +00:00
},
2019-10-16 15:18:29 +00:00
fontFamily,
2019-06-19 14:40:52 +00:00
h4: {
color: colors.font.default
},
h5: {
fontSize: "1.3125rem"
2019-10-28 16:16:49 +00:00
}
2019-06-19 14:40:52 +00:00
}
});
TextField.defaultProps = {
...TextField.defaultProps,
2019-08-09 11:14:35 +00:00
variant: "outlined"
2019-06-19 14:40:52 +00:00
};
2019-09-30 16:46:48 +00:00
Card.defaultProps = {
...Card.defaultProps,
elevation: 0
};
2019-10-30 14:34:24 +00:00
Typography.defaultProps = {
2019-11-04 13:36:25 +00:00
component: "div"
2019-10-30 14:34:24 +00:00
};
2020-08-17 11:42:37 +00:00
Checkbox.defaultProps = {
2020-08-17 14:44:40 +00:00
checkedIcon: createElement(CheckboxCheckedIcon),
color: "primary",
icon: createElement(CheckboxIcon),
indeterminateIcon: createElement(CheckboxIndeterminateIcon)
2020-08-17 11:42:37 +00:00
};