Skip to content

Commit 0768bda

Browse files
committed
chore: update fork
Signed-off-by: Antonette Caldwell <[email protected]>
1 parent 6d36228 commit 0768bda

17 files changed

+572
-31
lines changed

packages/components/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
},
2020
"devDependencies": {
2121
"@mui/material": "^5.14.10",
22+
"@types/ramda": "^0.29.3",
2223
"@types/react": "^18.2.15",
2324
"@types/react-dom": "^18.2.7",
2425
"@typescript-eslint/eslint-plugin": "^6.0.0",
2526
"@typescript-eslint/parser": "^6.0.0",
2627
"@vitejs/plugin-react-swc": "^3.3.2",
2728
"eslint": "^8.45.0",
2829
"eslint-plugin-react": "^7.33.2",
30+
"io-ts": "^2.2.20",
31+
"ramda": "^0.29.0",
2932
"react-error-boundary": "^4.0.11",
3033
"typescript": "^5.0.2",
3134
"vite": "^4.4.5",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { EmotionCache } from '@emotion/react';
2+
import { ThemeProvider } from '@mui/material';
3+
import { ReactNode, createContext, useContext } from 'react';
4+
import { DEFAULT_THEME } from './defaultTheme';
5+
import { SistentTheme, SistentThemeOverride } from './types/SistentTheme';
6+
import { mergeThemeWithFn } from './utils/mergeTheme';
7+
8+
type SistentProviderContextType = {
9+
theme: SistentTheme;
10+
emotionCache?: EmotionCache;
11+
};
12+
13+
const SistentProviderContext = createContext<SistentProviderContextType>({
14+
theme: DEFAULT_THEME
15+
});
16+
17+
export function useSistentTheme() {
18+
return useContext(SistentProviderContext)?.theme || DEFAULT_THEME;
19+
}
20+
21+
export function useSistentProviderStyles(component: string | string[]) {
22+
const theme = useSistentTheme();
23+
24+
const getStyles = (name: string) => ({});
25+
26+
if (Array.isArray(component)) {
27+
return component.map(getStyles);
28+
}
29+
30+
return [getStyles(component)];
31+
}
32+
33+
export function useSistentEmotionCache() {
34+
return useContext(SistentProviderContext)?.emotionCache;
35+
}
36+
37+
export type SistentProviderProps = {
38+
theme?: SistentThemeOverride;
39+
emotionCache?: EmotionCache;
40+
children: ReactNode;
41+
inherit?: boolean;
42+
};
43+
44+
export function SistentProvider({
45+
theme,
46+
emotionCache,
47+
children,
48+
inherit = false
49+
}: SistentProviderProps) {
50+
const ctx = useContext(SistentProviderContext);
51+
52+
const mergedTheme = mergeThemeWithFn(DEFAULT_THEME, inherit ? { ...ctx.theme, ...theme } : theme);
53+
54+
return (
55+
<ThemeProvider theme={mergedTheme}>
56+
<SistentProviderContext.Provider value={{ theme: mergedTheme, emotionCache }}>
57+
{children}
58+
</SistentProviderContext.Provider>
59+
</ThemeProvider>
60+
);
61+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { SistentThemeBase } from './types/SistentTheme';
2+
import { DEFAULT_COLORS } from './utils/defaultColors';
3+
4+
export const DEFAULT_THEME: SistentThemeBase = {
5+
dir: 'ltr',
6+
colorScheme: 'light',
7+
white: '#FFF',
8+
black: '#000',
9+
primaryColor: 'green',
10+
fontFamily: undefined,
11+
lineHeight: undefined,
12+
primaryShade: 0,
13+
other: {},
14+
components: {},
15+
colors: DEFAULT_COLORS,
16+
fontSizes: {
17+
xs: '',
18+
sm: '',
19+
md: '',
20+
lg: '',
21+
xl: ''
22+
},
23+
radius: {
24+
xs: '',
25+
sm: '',
26+
md: '',
27+
lg: '',
28+
xl: ''
29+
},
30+
spacing: {
31+
xs: '',
32+
sm: '',
33+
md: '',
34+
lg: '',
35+
xl: ''
36+
},
37+
breakpoints: {
38+
xs: '0',
39+
sm: '600',
40+
md: '960',
41+
lg: '1280',
42+
xl: '1920'
43+
},
44+
shadows: {
45+
xs: '',
46+
sm: '',
47+
md: '',
48+
lg: '',
49+
xl: ''
50+
},
51+
headings: {
52+
fontFamily: undefined,
53+
fontWeight: undefined,
54+
sizes: {
55+
h1: {
56+
fontSize: '',
57+
fontWeight: undefined,
58+
lineHeight: undefined
59+
},
60+
h2: {
61+
fontSize: '',
62+
fontWeight: undefined,
63+
lineHeight: undefined
64+
},
65+
h3: {
66+
fontSize: '',
67+
fontWeight: undefined,
68+
lineHeight: undefined
69+
},
70+
h4: {
71+
fontSize: '',
72+
fontWeight: undefined,
73+
lineHeight: undefined
74+
},
75+
h5: {
76+
fontSize: '',
77+
fontWeight: undefined,
78+
lineHeight: undefined
79+
},
80+
h6: {
81+
fontSize: '',
82+
fontWeight: undefined,
83+
lineHeight: undefined
84+
}
85+
}
86+
}
87+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { SistentProvider, useSistentTheme } from './SistentProvider';
2+
export type { SistentProviderProps } from './SistentProvider';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as t from 'io-ts';
2+
3+
export const ColorSchemeType = t.string;
4+
export type ColorScheme = 'ight' | 'dark';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type DeepPartial<T> = {
2+
[P in keyof T]?: T[P] extends (...args: infer Args) => infer Return
3+
? (...args: Args) => DeepPartial<Return>
4+
: T[P] extends object
5+
? DeepPartial<T[P]>
6+
: T[P];
7+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as t from 'io-ts';
2+
import { TupleCodec } from './Tuple';
3+
4+
const DefaultSistentColorType = t.union([
5+
t.literal('dark'),
6+
t.literal('gray'),
7+
t.literal('red'),
8+
t.literal('pink'),
9+
t.literal('grape'),
10+
t.literal('violet'),
11+
t.literal('indigo'),
12+
t.literal('blue'),
13+
t.literal('cyan'),
14+
t.literal('green'),
15+
t.literal('lime'),
16+
t.literal('yellow'),
17+
t.literal('orange'),
18+
t.literal('teal'),
19+
t.string
20+
]);
21+
22+
export type DefaultSistentColor = t.TypeOf<typeof DefaultSistentColorType>;
23+
24+
const SistentThemeColorsOverrideType = t.record(t.string, TupleCodec(t.string, 10));
25+
26+
export type SistentThemeColorsOverride = t.TypeOf<typeof SistentThemeColorsOverrideType>;
27+
28+
export const SistentThemeColorsType = t.union([
29+
SistentThemeColorsOverrideType,
30+
t.record(DefaultSistentColorType, TupleCodec(t.string, 10))
31+
]);
32+
33+
export type SistentThemeColors = t.TypeOf<typeof SistentThemeColorsType>;
34+
35+
export type SistentColor = keyof SistentThemeColors;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as t from 'io-ts';
2+
3+
export const SistentSizeType = t.union([
4+
t.literal('xs'),
5+
t.literal('sm'),
6+
t.literal('md'),
7+
t.literal('lg'),
8+
t.literal('xl'),
9+
t.string
10+
]);
11+
12+
export type SistentSize = t.TypeOf<typeof SistentSizeType>;
13+
14+
export const SistentNumberSizeType = t.union([SistentSizeType, t.number]);
15+
16+
export type SistentNumberSize = t.TypeOf<typeof SistentNumberSizeType>;
17+
18+
// Create a Keyof codec for known keys
19+
const knownSizes = t.keyof({
20+
xs: null,
21+
sm: null,
22+
md: null,
23+
lg: null,
24+
xl: null
25+
});
26+
27+
// Create the SistentSizesType using the known keys
28+
export const SistentSizesType = t.record(knownSizes, t.string);
29+
30+
export type SistentSizes = t.TypeOf<typeof SistentSizesType>;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import * as t from 'io-ts';
2+
import { ColorSchemeType } from './ColorTheme';
3+
import { DeepPartial } from './DeepPartial';
4+
import { SistentThemeColorsType } from './SistentColor';
5+
import { SistentSizesType } from './SistentSizes';
6+
7+
const SISTENT_SIZES = {
8+
xs: null,
9+
sm: null,
10+
md: null,
11+
lg: null,
12+
xl: null
13+
};
14+
15+
type ThemeComponent = {};
16+
17+
export type SistentThemeOther = Record<string, any>;
18+
export type SistentThemeComponents = Record<string, ThemeComponent>;
19+
20+
/*
21+
export type HeadingStyle = {
22+
fontSize: string;
23+
fontWeight: CSSProperties['fontWeight'];
24+
lineHeight: CSSProperties['lineHeight'];
25+
}
26+
*/
27+
28+
const HeadingStyleType = t.type({
29+
fontSize: t.string,
30+
fontWeight: t.string,
31+
lineHeight: t.string
32+
});
33+
34+
const HeadingsType = t.type({
35+
fontFamily: t.string,
36+
fontWeight: t.string,
37+
sizes: t.type({
38+
h1: HeadingStyleType,
39+
h2: HeadingStyleType,
40+
h3: HeadingStyleType,
41+
h4: HeadingStyleType,
42+
h5: HeadingStyleType,
43+
h6: HeadingStyleType
44+
})
45+
});
46+
47+
const ShadeType = t.keyof({
48+
'0': null,
49+
'1': null,
50+
'2': null,
51+
'3': null,
52+
'4': null,
53+
'5': null,
54+
'6': null,
55+
'7': null,
56+
'8': null,
57+
'9': null
58+
});
59+
60+
type Shade = t.TypeOf<typeof ShadeType>;
61+
/**
62+
* type Shade = keyof typeof allowedShades;
63+
const allowedShades = {
64+
0: true, 1: true, 2: true, 3: true, 4: true,
65+
5: true, 6: true, 7: true, 8: true, 9: true,
66+
};
67+
68+
type FontFamilyType = CSSProperties['fontFamily'];
69+
type LineHeightType = CSSProperties['lineHeight'];
70+
*/
71+
72+
const SistentPrimaryShade = t.type({
73+
light: ShadeType,
74+
dark: ShadeType
75+
});
76+
77+
const SistentThemeType = t.type({
78+
dir: t.union([t.literal('ltr'), t.literal('rtl')]),
79+
fontFamily: t.string,
80+
lineHeight: t.string,
81+
primaryShade: t.union([ShadeType, SistentPrimaryShade]),
82+
other: t.record(t.string, t.any),
83+
white: t.string,
84+
black: t.string,
85+
components: t.record(t.string, t.unknown),
86+
colors: t.record(t.string, t.tuple([t.string, t.number])),
87+
primaryColor: t.keyof(SistentThemeColorsType),
88+
colorScheme: ColorSchemeType,
89+
fontSizes: SistentSizesType,
90+
radius: SistentSizesType,
91+
spacing: SistentSizesType,
92+
breakpoints: SistentSizesType,
93+
shadows: t.record(t.keyof(SISTENT_SIZES), t.string),
94+
headings: HeadingsType
95+
});
96+
97+
export type SistentTheme = t.TypeOf<typeof SistentThemeType>;
98+
99+
export type SistentThemeBase = Omit<SistentTheme, 'fn'>;
100+
101+
export type SistentThemeOverride = DeepPartial<Omit<SistentThemeBase, 'other' | 'components'>> &
102+
Partial<Pick<SistentThemeBase, 'other' | 'components'>>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as t from 'io-ts';
2+
3+
export function TupleCodec<T extends t.Mixed>(itemCodec: T, length: number): t.Type<T[]> {
4+
return new t.Type(
5+
`Tuple<${itemCodec.name}, ${length}>`,
6+
(input: unknown): input is T[] => {
7+
if (Array.isArray(input) && input.length === length) {
8+
return input.every((item) => itemCodec.is(item));
9+
}
10+
return false;
11+
},
12+
(input, context) => {
13+
if (Array.isArray(input) && input.length === length) {
14+
return t.success(input);
15+
}
16+
return t.failure(input, context);
17+
},
18+
t.identity
19+
);
20+
}

0 commit comments

Comments
 (0)