-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy paththeme.ts
More file actions
117 lines (101 loc) · 4.25 KB
/
theme.ts
File metadata and controls
117 lines (101 loc) · 4.25 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 - present Instructure, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* Global variables (colors, typography, spacing, etc.) are defined in lib/themes */
import { makeThemeVars } from '@instructure/emotion'
import type { Theme, ThemeSpecificStyle } from '@instructure/ui-themes'
import { ViewTheme } from '@instructure/shared-types'
/**
* Generates the theme object for the component from the theme and provided additional information
* @param {Object} theme The actual theme object.
* @return {Object} The final theme object with the overrides and component variables
*/
const generateComponentTheme = (theme: Theme): ViewTheme => {
const {
colors,
typography,
borders,
breakpoints,
spacing,
shadows,
stacking,
key: themeName
} = theme
const themeSpecificStyle: ThemeSpecificStyle<ViewTheme> = {
canvas: {
color: theme['ic-brand-font-color-dark'],
focusColorInfo: theme['ic-brand-primary'],
backgroundBrand: theme['ic-brand-primary'],
backgroundInfo: theme['ic-brand-primary'],
borderColorBrand: theme['ic-brand-primary'],
borderColorInfo: theme['ic-brand-primary']
}
}
const componentVariables: ViewTheme = {
fontFamily: typography?.fontFamily,
color: colors?.contrasts?.grey125125,
colorPrimaryInverse: colors?.contrasts?.white1010,
borderColorPrimary: colors?.contrasts?.grey1424,
borderColorSecondary: colors?.contrasts?.grey3045,
borderColorSuccess: colors?.contrasts?.green4570,
borderColorBrand: colors?.contrasts?.blue4570,
borderColorInfo: colors?.contrasts?.blue4570,
borderColorAlert: colors?.contrasts?.blue4570,
borderColorWarning: colors?.contrasts?.orange4570,
borderColorDanger: colors?.contrasts?.red4570,
borderColorTransparent: 'transparent',
debugOutlineColor: colors?.contrasts?.red4570,
backgroundPrimary: colors?.contrasts?.white1010,
backgroundSecondary: colors?.contrasts?.grey1111,
backgroundPrimaryInverse: colors?.contrasts?.grey125125,
backgroundBrand: colors?.contrasts?.blue4570,
backgroundInfo: colors?.contrasts?.blue4570,
backgroundAlert: colors?.contrasts?.blue4570,
backgroundSuccess: colors?.contrasts?.green4570,
backgroundDanger: colors?.contrasts?.red4570,
backgroundWarning: colors?.contrasts?.orange4570,
arrowSize: '0.5rem',
focusOutlineStyle: borders?.style,
focusOutlineWidth: borders?.widthMedium,
focusOutlineOffset: '0.3125rem',
focusOutlineInset: '0rem', // do not use unitless zero (for CSS calc())
focusColorInfo: colors?.contrasts?.blue4570,
focusColorDanger: colors?.contrasts?.red4570,
focusColorSuccess: colors?.contrasts?.green4570,
focusColorInverse: colors?.contrasts?.white1010,
xSmallMaxWidth: breakpoints?.xSmall,
smallMaxWidth: breakpoints?.small,
mediumMaxWidth: breakpoints?.medium,
largeMaxWidth: breakpoints?.large,
...makeThemeVars('margin', spacing),
...makeThemeVars('padding', spacing),
...makeThemeVars('shadow', shadows),
...makeThemeVars('stacking', stacking),
...makeThemeVars('border', borders)
}
return {
...componentVariables,
...themeSpecificStyle[themeName]
}
}
export default generateComponentTheme