This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.tsx
87 lines (79 loc) · 2.32 KB
/
theme.tsx
1
2
3
4
5
6
7
8
9
10
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
CreateCSSProperties,
CSSProperties,
makeStyles,
PropsFunc
} from "@material-ui/styles";
import React from "react";
export const colors = {
primary: "#19aeff",
dark: "#005c94",
text: "#ffffff",
neutral: "#cccccc"
};
export function addPropsClassName<P extends { className?: string }>(
base: string,
props: P
) {
return {
...props,
className: base + (props.className ? " " + props.className : "")
};
}
type BaseStyledComponentProps = { className?: string };
type StyledComponentConstraint =
| keyof JSX.IntrinsicElements
| React.ElementType<BaseStyledComponentProps>;
export function styled<
AdditionalProps extends {} = {},
// This shouldn't ever need to fall back to the default but I might as well provide a sensible value
Component extends StyledComponentConstraint = "div"
>(
component: Component,
styles:
| CSSProperties
| CreateCSSProperties<{}>
| PropsFunc<{}, CreateCSSProperties<{}>>,
overrideProps?:
| Partial<React.ComponentPropsWithRef<Component>>
| {
(
props: React.ComponentPropsWithRef<Component> &
AdditionalProps
): React.ComponentPropsWithRef<Component>;
}
) {
const useStyles = makeStyles(() => ({
root: styles
}));
return React.forwardRef((
props: React.ComponentPropsWithRef<Component> & AdditionalProps,
ref
) => {
const styles = useStyles();
const styleAddedProps = addPropsClassName(styles.root, props);
return React.createElement(component, {
ref,
...styleAddedProps,
...(typeof overrideProps === "function"
? overrideProps(styleAddedProps)
: overrideProps)
});
});
}
const useStyles = makeStyles(() => ({
root: {
fontFamily: "Supply Mono Light, sans-serif",
minWidth: "calc(100vw - 4rem)",
minHeight: "100vh",
padding: "2rem",
backgroundColor: colors.primary,
"& button, input": {
fontFamily: "Supply Mono Regular"
}
}
}));
export default function ThemeProvider(props: { children: React.ReactNode }) {
const styles = useStyles();
return <div className={styles.root}>{props.children}</div>;
}