@instructure/ui-buttons 9.5.2-snapshot-7 → 9.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,19 +22,109 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import type { Theme } from '@instructure/ui-themes'
25
+ import { alpha, darken } from '@instructure/ui-color-utils'
26
+ import type { Theme, ThemeSpecificStyle } from '@instructure/ui-themes'
26
27
  import { BaseButtonTheme } from '@instructure/shared-types'
27
- import { alpha } from '@instructure/ui-color-utils'
28
28
 
29
29
  const activeShadow = 'inset 0 0 0.1875rem 0.0625rem'
30
30
 
31
+ type Variants =
32
+ | 'primary'
33
+ | 'secondary'
34
+ | 'success'
35
+ | 'danger'
36
+ | 'primaryInverse'
37
+
38
+ type VariantValues =
39
+ | 'Color'
40
+ | 'BorderColor'
41
+ | 'Background'
42
+ | 'HoverBackground'
43
+ | 'ActiveBackground'
44
+ | 'ActiveBoxShadow'
45
+ | 'GhostColor'
46
+ | 'GhostBorderColor'
47
+ | 'GhostBackground'
48
+ | 'GhostHoverBackground'
49
+ | 'GhostActiveBackground'
50
+ | 'GhostActiveBoxShadow'
51
+
52
+ type VariantMap<Variant extends Variants> = Record<
53
+ `${Variant}${VariantValues}`,
54
+ string
55
+ >
56
+
57
+ const generateButtonThemeVars = <Variant extends Variants>({
58
+ style,
59
+ textColor,
60
+ ghostTextColor,
61
+ backgroundColor,
62
+ borderColor,
63
+ ghostBorderColor = borderColor
64
+ }: {
65
+ style: Variant
66
+ textColor: string
67
+ ghostTextColor: string
68
+ backgroundColor: string
69
+ borderColor: string
70
+ ghostBorderColor?: string
71
+ }) =>
72
+ ({
73
+ [`${style}Color`]: textColor,
74
+ [`${style}BorderColor`]: darken(borderColor, 10),
75
+ [`${style}Background`]: backgroundColor,
76
+ [`${style}HoverBackground`]: darken(backgroundColor, 10),
77
+ [`${style}ActiveBackground`]: darken(backgroundColor, 10),
78
+ [`${style}ActiveBoxShadow`]: `${activeShadow} ${darken(borderColor, 20)}`,
79
+
80
+ [`${style}GhostColor`]: ghostTextColor,
81
+ [`${style}GhostBorderColor`]: ghostBorderColor,
82
+ [`${style}GhostBackground`]: 'transparent',
83
+ [`${style}GhostHoverBackground`]: alpha(ghostTextColor, 10),
84
+ [`${style}GhostActiveBackground`]: 'transparent',
85
+ [`${style}GhostActiveBoxShadow`]: `${activeShadow} ${alpha(
86
+ ghostBorderColor,
87
+ 28
88
+ )}`
89
+ } as VariantMap<Variant>)
90
+
31
91
  /**
32
92
  * Generates the theme object for the component from the theme and provided additional information
33
93
  * @param {Object} theme The actual theme object.
34
94
  * @return {Object} The final theme object with the overrides and component variables
35
95
  */
36
96
  const generateComponentTheme = (theme: Theme): BaseButtonTheme => {
37
- const { borders, colors, forms, spacing, typography } = theme
97
+ const { borders, colors, forms, spacing, typography, key: themeName } = theme
98
+
99
+ const themeSpecificStyle: ThemeSpecificStyle<BaseButtonTheme> = {
100
+ canvas: {
101
+ ...generateButtonThemeVars({
102
+ style: 'primary',
103
+ backgroundColor: theme['ic-brand-button--primary-bgd']!,
104
+ borderColor: theme['ic-brand-button--primary-bgd']!,
105
+ textColor: theme['ic-brand-button--primary-text']!,
106
+ ghostTextColor: theme['ic-brand-button--primary-bgd']!
107
+ }),
108
+ primaryGhostHoverBackground: alpha(
109
+ theme['ic-brand-button--primary-bgd']!,
110
+ 10
111
+ )
112
+ },
113
+ 'canvas-high-contrast': {
114
+ secondaryBorderColor: colors?.borderMedium,
115
+ primaryInverseBorderColor: colors?.borderMedium
116
+ },
117
+ instructure: {
118
+ borderRadius: '999em',
119
+ smallPaddingTop: '0.5rem',
120
+ smallPaddingBottom: '0.4375rem',
121
+ mediumPaddingTop: '0.75rem',
122
+ mediumPaddingBottom: '0.75rem',
123
+ largePaddingTop: '1rem',
124
+ largePaddingBottom: '1rem',
125
+ largeFontSize: '1.125rem'
126
+ }
127
+ }
38
128
 
39
129
  const componentVariables: BaseButtonTheme = {
40
130
  transform: 'none',
@@ -73,89 +163,63 @@ const generateComponentTheme = (theme: Theme): BaseButtonTheme => {
73
163
  iconTextGap: spacing.xSmall,
74
164
  iconTextGapCondensed: spacing.xxSmall,
75
165
 
76
- primaryColor: colors?.contrasts?.white1010,
77
- primaryBorderColor: colors?.contrasts?.blue5782,
78
- primaryBackground: colors?.contrasts?.blue4570,
79
- primaryHoverBackground: colors?.contrasts?.blue5782,
80
- primaryActiveBackground: colors?.contrasts?.blue5782,
81
- primaryActiveBoxShadow: `${activeShadow} ${colors?.contrasts?.white1010}`,
82
- primaryGhostColor: colors?.contrasts?.blue4570,
83
- primaryGhostBorderColor: colors?.contrasts?.blue4570,
84
- primaryGhostBackground: 'transparent',
85
- primaryGhostHoverBackground: alpha(colors?.contrasts?.blue4570, 10),
86
- primaryGhostActiveBackground: 'transparent',
87
- primaryGhostActiveBoxShadow: `${activeShadow} ${alpha(
88
- colors?.contrasts?.blue1212,
89
- 28
90
- )}`,
91
-
92
- secondaryColor: colors?.contrasts?.grey125125,
93
- secondaryBorderColor: colors?.contrasts?.grey1214,
94
- secondaryBackground: colors?.contrasts?.grey1111,
95
- secondaryHoverBackground: colors?.contrasts?.grey1214,
96
- secondaryActiveBackground: colors?.contrasts?.grey1214,
97
- secondaryActiveBoxShadow: `${activeShadow} ${colors?.contrasts?.white1010}`,
98
- secondaryGhostColor: colors?.contrasts?.grey125125,
99
- secondaryGhostBorderColor: colors?.contrasts?.grey125125,
100
- secondaryGhostBackground: 'transparent',
101
- secondaryGhostHoverBackground: alpha(colors?.contrasts?.grey125125, 10),
102
- secondaryGhostActiveBackground: 'transparent',
103
- secondaryGhostActiveBoxShadow: `${activeShadow} ${alpha(
104
- colors?.contrasts?.grey125125,
105
- 28
106
- )}`,
107
-
108
- successColor: colors?.contrasts?.white1010,
109
- successBorderColor: colors?.contrasts?.green5782,
110
- successBackground: colors?.contrasts?.green4570,
111
- successHoverBackground: colors?.contrasts?.green5782,
112
- successActiveBackground: colors?.contrasts?.green5782,
113
- successActiveBoxShadow: `${activeShadow} ${colors?.contrasts?.white1010}`,
114
- successGhostColor: colors?.contrasts?.green4570,
115
- successGhostBorderColor: colors?.contrasts?.green4570,
116
- successGhostBackground: 'transparent',
117
- successGhostHoverBackground: alpha(colors?.contrasts?.green4570, 10),
118
- successGhostActiveBackground: 'transparent',
119
- successGhostActiveBoxShadow: `${activeShadow} ${alpha(
120
- colors?.contrasts?.green4570,
121
- 28
122
- )}`,
123
-
124
- dangerColor: colors?.contrasts?.white1010,
125
- dangerBorderColor: colors?.contrasts?.red5782,
126
- dangerBackground: colors?.contrasts?.red4570,
127
- dangerHoverBackground: colors?.contrasts?.red5782,
128
- dangerActiveBackground: colors?.contrasts?.red5782,
129
- dangerActiveBoxShadow: `${activeShadow} ${colors?.contrasts?.white1010}`,
130
- dangerGhostColor: colors?.contrasts?.red4570,
131
- dangerGhostBorderColor: colors?.contrasts?.red4570,
132
- dangerGhostBackground: 'transparent',
133
- dangerGhostHoverBackground: alpha(colors?.contrasts?.red4570, 10),
134
- dangerGhostActiveBackground: 'transparent',
135
- dangerGhostActiveBoxShadow: `${activeShadow} ${alpha(
136
- colors?.contrasts?.red4570,
137
- 28
166
+ ...generateButtonThemeVars({
167
+ style: 'primary',
168
+ backgroundColor: colors?.backgroundBrand,
169
+ borderColor: colors?.borderBrand,
170
+ textColor: colors?.textLightest,
171
+ ghostTextColor: colors?.textBrand
172
+ }),
173
+
174
+ ...generateButtonThemeVars({
175
+ style: 'secondary',
176
+ backgroundColor: colors?.backgroundLight,
177
+ borderColor: colors?.borderLight,
178
+ ghostBorderColor: colors?.borderDarkest,
179
+ textColor: colors?.textDarkest,
180
+ ghostTextColor: colors?.textDarkest
181
+ }),
182
+
183
+ ...generateButtonThemeVars({
184
+ style: 'success',
185
+ backgroundColor: colors?.backgroundSuccess,
186
+ borderColor: colors?.borderSuccess,
187
+ textColor: colors?.textLightest,
188
+ ghostTextColor: colors?.textSuccess
189
+ }),
190
+
191
+ ...generateButtonThemeVars({
192
+ style: 'danger',
193
+ backgroundColor: colors?.backgroundDanger,
194
+ borderColor: colors?.borderDanger,
195
+ textColor: colors?.textLightest,
196
+ ghostTextColor: colors?.textDanger
197
+ }),
198
+
199
+ ...generateButtonThemeVars({
200
+ style: 'primaryInverse',
201
+ backgroundColor: colors?.backgroundLightest,
202
+ borderColor: colors?.borderLightest,
203
+ textColor: colors?.textDarkest,
204
+ ghostTextColor: colors?.textLightest
205
+ }),
206
+
207
+ // Overrides for primary-inverse to match what was previously the `light` button variant
208
+ primaryInverseBorderColor: darken(colors?.borderLight, 10),
209
+ primaryInverseHoverBackground: darken(colors?.backgroundLightest, 5),
210
+ primaryInverseActiveBackground: colors?.backgroundLightest,
211
+ primaryInverseActiveBoxShadow: `${activeShadow} ${darken(
212
+ colors?.borderLightest,
213
+ 25
138
214
  )}`,
139
215
 
140
- primaryInverseColor: colors?.contrasts?.grey125125,
141
- primaryInverseBorderColor: colors?.contrasts?.grey1214,
142
- primaryInverseBackground: colors?.contrasts?.white1010,
143
- primaryInverseHoverBackground: colors?.contrasts?.grey1111,
144
- primaryInverseActiveBackground: colors?.contrasts?.white1010,
145
- primaryInverseActiveBoxShadow: `${activeShadow} ${colors?.contrasts?.white1010}`,
146
- primaryInverseGhostColor: colors?.contrasts?.white1010,
147
- primaryInverseGhostBorderColor: colors?.contrasts?.white1010,
148
- primaryInverseGhostBackground: 'transparent',
149
- primaryInverseGhostHoverBackground: alpha(colors?.contrasts?.white1010, 10),
150
- primaryInverseGhostActiveBackground: 'transparent',
151
- primaryInverseGhostActiveBoxShadow: `${activeShadow} ${alpha(
152
- colors?.contrasts?.white1010,
153
- 28
154
- )}`
216
+ // Overrides for ghost hover states to ensure correct color contrast for a11y
217
+ successGhostHoverBackground: alpha(colors?.textSuccess, 1)
155
218
  }
156
219
 
157
220
  return {
158
- ...componentVariables
221
+ ...componentVariables,
222
+ ...themeSpecificStyle[themeName]
159
223
  }
160
224
  }
161
225