|
1 |
| -import '@/styles/sdk.scss' |
2 | 1 | import { getRootFontSize, toRem } from '@/helpers/rem'
|
3 | 2 |
|
4 | 3 | // Colors are for internal use in our theme currently
|
5 | 4 | // We don't export them for partner use or overrides
|
6 |
| -const colors = { |
| 5 | +const baseColors = { |
7 | 6 | neutral: {
|
8 | 7 | 100: '#FFFFFF',
|
9 | 8 | 200: '#FBFAFA',
|
@@ -40,71 +39,99 @@ const colors = {
|
40 | 39 | },
|
41 | 40 | }
|
42 | 41 |
|
43 |
| -export const gustoSDKTheme = { |
44 |
| - // Colors |
45 |
| - colorBody: colors.neutral[100], |
46 |
| - colorBodyContent: colors.neutral[1000], |
47 |
| - colorPrimary: colors.neutral[1000], |
48 |
| - colorPrimaryAccent: colors.neutral[900], |
49 |
| - colorPrimaryContent: colors.neutral[100], |
50 |
| - colorSecondary: colors.neutral[100], |
51 |
| - colorSecondaryAccent: colors.neutral[400], |
52 |
| - colorSecondaryContent: colors.neutral[1000], |
53 |
| - colorInfo: colors.info[100], |
54 |
| - colorInfoAccent: colors.info[500], |
55 |
| - colorInfoContent: colors.info[800], |
56 |
| - colorWarning: colors.warning[100], |
57 |
| - colorWarningAccent: colors.warning[500], |
58 |
| - colorWarningContent: colors.warning[800], |
59 |
| - colorError: colors.error[100], |
60 |
| - colorErrorAccent: colors.error[500], |
61 |
| - colorErrorContent: colors.error[800], |
62 |
| - colorSuccess: colors.success[100], |
63 |
| - colorSuccessAccent: colors.success[500], |
64 |
| - colorSuccessContent: colors.success[800], |
65 |
| - // Input Colors |
66 |
| - inputBackgroundColor: colors.neutral[100], |
67 |
| - inputBorderColor: colors.neutral[500], |
68 |
| - inputContentColor: colors.neutral[1000], |
69 |
| - inputBorderWidth: '1px', |
70 |
| - inputPlaceholderColor: colors.neutral[800], |
71 |
| - inputAdornmentColor: colors.neutral[800], |
72 |
| - inputDisabledBackgroundColor: colors.neutral[300], |
73 |
| - // Field Colors |
74 |
| - inputLabelColor: colors.neutral[1000], |
75 |
| - inputLabelFontSize: toRem(16), |
76 |
| - inputLabelFontWeight: '500', |
77 |
| - inputDescriptionColor: colors.neutral[900], |
78 |
| - inputErrorColor: colors.error[500], |
79 |
| - // Radius |
80 |
| - inputRadius: toRem(8), |
81 |
| - buttonRadius: toRem(8), |
82 |
| - badgeRadius: toRem(16), |
83 |
| - // Font |
84 |
| - fontSizeRoot: getRootFontSize(), |
85 |
| - fontFamily: 'Geist', |
86 |
| - fontLineHeight: toRem(24), |
87 |
| - fontSizeSmall: toRem(14), |
88 |
| - fontSizeRegular: toRem(16), |
89 |
| - fontSizeLarge: toRem(18), |
90 |
| - fontSizeHeading1: toRem(32), |
91 |
| - fontSizeHeading2: toRem(24), |
92 |
| - fontSizeHeading3: toRem(20), |
93 |
| - fontSizeHeading4: toRem(18), |
94 |
| - fontSizeHeading5: toRem(16), |
95 |
| - fontSizeHeading6: toRem(14), |
96 |
| - fontWeightRegular: '400', |
97 |
| - fontWeightMedium: '500', |
98 |
| - fontWeightSemibold: '600', |
99 |
| - fontWeightBold: '700', |
100 |
| - // Transitions |
101 |
| - transitionDuration: '200ms', |
102 |
| - // Shadows |
103 |
| - shadowResting: '0px 1px 2px 0px rgba(10, 13, 18, 0.05)', |
104 |
| - shadowTopmost: '0px 4px 6px 0px rgba(28, 28, 28, 0.05), 0px 10px 15px 0px rgba(28, 28, 28, 0.10)', |
105 |
| - // Focus |
106 |
| - focusRingColor: colors.neutral[1000], |
107 |
| - focusRingWidth: '2px', |
| 42 | +const defaultThemeColors = { |
| 43 | + colorBody: baseColors.neutral[100], |
| 44 | + colorBodyContent: baseColors.neutral[1000], |
| 45 | + colorPrimary: baseColors.neutral[1000], |
| 46 | + colorPrimaryAccent: baseColors.neutral[900], |
| 47 | + colorPrimaryContent: baseColors.neutral[100], |
| 48 | + colorSecondary: baseColors.neutral[100], |
| 49 | + colorSecondaryAccent: baseColors.neutral[400], |
| 50 | + colorSecondaryContent: baseColors.neutral[1000], |
| 51 | + colorInfo: baseColors.info[100], |
| 52 | + colorInfoAccent: baseColors.info[500], |
| 53 | + colorInfoContent: baseColors.info[800], |
| 54 | + colorWarning: baseColors.warning[100], |
| 55 | + colorWarningAccent: baseColors.warning[500], |
| 56 | + colorWarningContent: baseColors.warning[800], |
| 57 | + colorError: baseColors.error[100], |
| 58 | + colorErrorAccent: baseColors.error[500], |
| 59 | + colorErrorContent: baseColors.error[800], |
| 60 | + colorSuccess: baseColors.success[100], |
| 61 | + colorSuccessAccent: baseColors.success[500], |
| 62 | + colorSuccessContent: baseColors.success[800], |
108 | 63 | }
|
109 | 64 |
|
110 |
| -export type GustoSDKTheme = Partial<typeof gustoSDKTheme> |
| 65 | +export type GustoSDKThemeColors = Partial<typeof defaultThemeColors> |
| 66 | + |
| 67 | +export const createTheme = (colors: GustoSDKThemeColors = {}) => { |
| 68 | + return { |
| 69 | + // Colors |
| 70 | + ...defaultThemeColors, |
| 71 | + ...colors, |
| 72 | + // Input Colors |
| 73 | + inputBackgroundColor: colors.colorBody, |
| 74 | + inputBorderColor: baseColors.neutral[500], |
| 75 | + inputContentColor: colors.colorBodyContent, |
| 76 | + inputBorderWidth: '1px', |
| 77 | + inputPlaceholderColor: baseColors.neutral[800], |
| 78 | + inputAdornmentColor: baseColors.neutral[800], |
| 79 | + inputDisabledBackgroundColor: baseColors.neutral[300], |
| 80 | + // Field Colors |
| 81 | + inputLabelColor: colors.colorBodyContent, |
| 82 | + inputLabelFontSize: toRem(16), |
| 83 | + inputLabelFontWeight: '500', |
| 84 | + inputDescriptionColor: baseColors.neutral[900], |
| 85 | + inputErrorColor: colors.colorErrorAccent, |
| 86 | + // Radius |
| 87 | + inputRadius: toRem(8), |
| 88 | + buttonRadius: toRem(8), |
| 89 | + badgeRadius: toRem(16), |
| 90 | + // Font |
| 91 | + fontSizeRoot: getRootFontSize(), |
| 92 | + fontFamily: 'Geist', |
| 93 | + fontLineHeight: toRem(24), |
| 94 | + fontSizeSmall: toRem(14), |
| 95 | + fontSizeRegular: toRem(16), |
| 96 | + fontSizeLarge: toRem(18), |
| 97 | + fontSizeHeading1: toRem(32), |
| 98 | + fontSizeHeading2: toRem(24), |
| 99 | + fontSizeHeading3: toRem(20), |
| 100 | + fontSizeHeading4: toRem(18), |
| 101 | + fontSizeHeading5: toRem(16), |
| 102 | + fontSizeHeading6: toRem(14), |
| 103 | + fontWeightRegular: '400', |
| 104 | + fontWeightMedium: '500', |
| 105 | + fontWeightSemibold: '600', |
| 106 | + fontWeightBold: '700', |
| 107 | + // Transitions |
| 108 | + transitionDuration: '200ms', |
| 109 | + // Shadows |
| 110 | + shadowResting: '0px 1px 2px 0px rgba(10, 13, 18, 0.05)', |
| 111 | + shadowTopmost: |
| 112 | + '0px 4px 6px 0px rgba(28, 28, 28, 0.05), 0px 10px 15px 0px rgba(28, 28, 28, 0.10)', |
| 113 | + // Focus |
| 114 | + focusRingColor: colors.colorPrimary, |
| 115 | + focusRingWidth: '2px', |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +export type GustoSDKTheme = Partial<ReturnType<typeof createTheme>> |
| 120 | + |
| 121 | +export const mergePartnerTheme = (partnerTheme: GustoSDKTheme): GustoSDKTheme => { |
| 122 | + const colors = Object.entries(defaultThemeColors).reduce( |
| 123 | + (acc: GustoSDKThemeColors, [key, value]) => { |
| 124 | + acc[key as keyof typeof defaultThemeColors] = |
| 125 | + partnerTheme[key as keyof typeof defaultThemeColors] || value |
| 126 | + return acc |
| 127 | + }, |
| 128 | + {}, |
| 129 | + ) |
| 130 | + |
| 131 | + const theme = createTheme(colors) |
| 132 | + |
| 133 | + return { |
| 134 | + ...theme, |
| 135 | + ...partnerTheme, |
| 136 | + } |
| 137 | +} |
0 commit comments