@instructure/emotion 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +84 -0
  3. package/es/__old-tests__/getComponentThemeOverride.test.js +128 -0
  4. package/es/__old-tests__/useStyle.test.js +226 -0
  5. package/es/__old-tests__/useTheme.test.js +484 -0
  6. package/es/__old-tests__/withStyle.test.js +327 -0
  7. package/es/styleUtils/__old-tests__/getShorthandPropValue.test.js +85 -0
  8. package/es/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
  9. package/es/styleUtils/__old-tests__/mirrorShorthand.test.js +66 -0
  10. package/lib/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +86 -0
  11. package/lib/__old-tests__/getComponentThemeOverride.test.js +131 -0
  12. package/lib/__old-tests__/useStyle.test.js +228 -0
  13. package/lib/__old-tests__/useTheme.test.js +488 -0
  14. package/lib/__old-tests__/withStyle.test.js +329 -0
  15. package/lib/styleUtils/__old-tests__/getShorthandPropValue.test.js +87 -0
  16. package/lib/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
  17. package/lib/styleUtils/__old-tests__/mirrorShorthand.test.js +68 -0
  18. package/package.json +11 -11
  19. package/src/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.tsx +82 -0
  20. package/src/__old-tests__/getComponentThemeOverride.test.ts +182 -0
  21. package/src/__old-tests__/useStyle.test.tsx +272 -0
  22. package/src/__old-tests__/useTheme.test.tsx +510 -0
  23. package/src/__old-tests__/withStyle.test.tsx +389 -0
  24. package/src/styleUtils/__old-tests__/getShorthandPropValue.test.ts +96 -0
  25. package/src/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.tsx → styleUtils/__old-tests__/makeThemeVars.test.ts} +19 -14
  26. package/src/styleUtils/__old-tests__/mirrorShorthand.test.ts +77 -0
  27. package/tsconfig.build.tsbuildinfo +1 -1
  28. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts +2 -0
  29. package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts.map +1 -0
  30. package/types/__old-tests__/getComponentThemeOverride.test.d.ts +2 -0
  31. package/types/__old-tests__/getComponentThemeOverride.test.d.ts.map +1 -0
  32. package/types/__old-tests__/useStyle.test.d.ts +2 -0
  33. package/types/__old-tests__/useStyle.test.d.ts.map +1 -0
  34. package/types/__old-tests__/useTheme.test.d.ts +2 -0
  35. package/types/__old-tests__/useTheme.test.d.ts.map +1 -0
  36. package/types/__old-tests__/withStyle.test.d.ts +2 -0
  37. package/types/__old-tests__/withStyle.test.d.ts.map +1 -0
  38. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts +2 -0
  39. package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts.map +1 -0
  40. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts +2 -0
  41. package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts.map +1 -0
  42. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts +2 -0
  43. package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts.map +1 -0
  44. package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts +0 -2
  45. package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts.map +0 -1
@@ -0,0 +1,182 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { expect } from '@instructure/ui-test-utils'
26
+ import canvas from '@instructure/ui-themes'
27
+
28
+ import { getComponentThemeOverride } from '../getComponentThemeOverride'
29
+
30
+ const componentName = 'ExampleComponent'
31
+ const componentId = 'Example.Component'
32
+
33
+ describe('@getComponentThemeOverride', async () => {
34
+ describe('should return empty object', async () => {
35
+ it('if there is no theme set', async () => {
36
+ const override = getComponentThemeOverride(
37
+ {},
38
+ componentName,
39
+ componentId,
40
+ {}
41
+ )
42
+
43
+ expect(override).to.deep.equal({})
44
+ })
45
+
46
+ it('if there is no override set', async () => {
47
+ const override = getComponentThemeOverride(
48
+ canvas,
49
+ componentName,
50
+ componentId,
51
+ {}
52
+ )
53
+
54
+ expect(override).to.deep.equal({})
55
+ })
56
+ })
57
+
58
+ describe('should return the correct override', async () => {
59
+ it('if there is `themeOverride` set on the props', async () => {
60
+ const componentOverride = {
61
+ componentColor: 'rgb(150, 0, 0)'
62
+ }
63
+ const override = getComponentThemeOverride(
64
+ canvas,
65
+ componentName,
66
+ componentId,
67
+ {
68
+ themeOverride: componentOverride
69
+ }
70
+ )
71
+
72
+ expect(override).to.deep.equal(componentOverride)
73
+ })
74
+
75
+ it('if the `themeOverride` prop is a function', async () => {
76
+ const theme = {
77
+ backgroundGreen: 'rgb(0, 150, 0)',
78
+ backgroundBlue: 'rgb(0, 0, 150)',
79
+ backgroundDark: 'rgb(0, 0, 0)'
80
+ }
81
+
82
+ const override = getComponentThemeOverride(
83
+ canvas,
84
+ componentName,
85
+ componentId,
86
+ {
87
+ themeOverride: (componentTheme, currentTheme) => ({
88
+ backgroundBlue: componentTheme.backgroundGreen,
89
+ backgroundDark: currentTheme.colors.contrasts.white1010
90
+ })
91
+ },
92
+ theme
93
+ )
94
+
95
+ expect(override).to.deep.equal({
96
+ backgroundBlue: 'rgb(0, 150, 0)',
97
+ backgroundDark: '#FFFFFF'
98
+ })
99
+ })
100
+
101
+ it('if `themeOverride` and `componentOverrides` are both set', async () => {
102
+ const override = getComponentThemeOverride(
103
+ {
104
+ ...canvas,
105
+ componentOverrides: {
106
+ [componentName]: {
107
+ componentColor: 'rgb(0, 0, 150)'
108
+ }
109
+ }
110
+ },
111
+ componentName,
112
+ componentId,
113
+ {
114
+ themeOverride: {
115
+ componentColor: 'rgb(0, 150, 0)'
116
+ }
117
+ }
118
+ )
119
+
120
+ expect(override).to.deep.equal({
121
+ componentColor: 'rgb(0, 150, 0)'
122
+ })
123
+ })
124
+
125
+ describe('if there is `componentOverrides` set on the theme', async () => {
126
+ it('with the displayName', async () => {
127
+ const componentOverride = {
128
+ componentColor: 'rgb(0, 0, 150)'
129
+ }
130
+ const override = getComponentThemeOverride(
131
+ {
132
+ ...canvas,
133
+ componentOverrides: {
134
+ [componentName]: componentOverride
135
+ }
136
+ },
137
+ componentName,
138
+ componentId,
139
+ {}
140
+ )
141
+
142
+ expect(override).to.deep.equal(componentOverride)
143
+ })
144
+
145
+ it('with the componentId', async () => {
146
+ const componentOverride = {
147
+ componentColor: 'rgb(0, 150, 150)'
148
+ }
149
+ const override = getComponentThemeOverride(
150
+ {
151
+ ...canvas,
152
+ componentOverrides: {
153
+ [componentId]: componentOverride
154
+ }
155
+ },
156
+ componentName,
157
+ componentId,
158
+ {}
159
+ )
160
+
161
+ expect(override).to.deep.equal(componentOverride)
162
+ })
163
+
164
+ it('with both the displayName and componentId (displayName takes precedence)', async () => {
165
+ const override = getComponentThemeOverride(
166
+ {
167
+ ...canvas,
168
+ componentOverrides: {
169
+ [componentName]: { componentColor: 'rgb(150, 150, 150)' },
170
+ [componentId]: { componentColor: 'rgb(150, 150, 0)' }
171
+ }
172
+ },
173
+ componentName,
174
+ componentId,
175
+ {}
176
+ )
177
+
178
+ expect(override).to.deep.equal({ componentColor: 'rgb(150, 150, 150)' })
179
+ })
180
+ })
181
+ })
182
+ })
@@ -0,0 +1,272 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { useState } from 'react'
26
+
27
+ import { expect, mount, stub, within } from '@instructure/ui-test-utils'
28
+ import { InstUISettingsProvider, WithStyleProps, useStyle } from '../index'
29
+
30
+ type Props = {
31
+ inverse?: boolean
32
+ } & WithStyleProps<ComponentTheme>
33
+
34
+ type Theme = {
35
+ key: string
36
+ colors: {
37
+ contrasts: {
38
+ grey1111: string
39
+ green4570: string
40
+ blue4570: string
41
+ }
42
+ }
43
+ }
44
+
45
+ type ComponentTheme = {
46
+ textColor: string
47
+ textColorInverse: string
48
+ backgroundColor: string
49
+ }
50
+
51
+ describe('useStyle', async () => {
52
+ const grey1111 = 'rgb(0, 128, 0)'
53
+ const green4570 = 'rgb(10, 10, 10)'
54
+ const blue4570 = 'rgb(255, 255, 0)'
55
+ const exampleTheme: Theme = {
56
+ key: 'exampleTheme',
57
+ colors: {
58
+ contrasts: {
59
+ grey1111,
60
+ green4570,
61
+ blue4570
62
+ }
63
+ }
64
+ }
65
+
66
+ const generateComponentTheme = function (theme: Theme): ComponentTheme {
67
+ const { colors } = theme
68
+ return {
69
+ textColor: colors.contrasts.grey1111,
70
+ textColorInverse: colors.contrasts.green4570,
71
+ backgroundColor: colors.contrasts.blue4570
72
+ }
73
+ }
74
+
75
+ type StyleParams = {
76
+ inverse: boolean
77
+ clearBackground: boolean
78
+ themeOverride: Props['themeOverride']
79
+ }
80
+
81
+ const generateStyle = function (
82
+ componentTheme: ComponentTheme,
83
+ params: StyleParams
84
+ ) {
85
+ const { inverse, clearBackground } = params
86
+
87
+ return {
88
+ exampleComponent: {
89
+ label: 'exampleComponent',
90
+ color: componentTheme.textColor,
91
+ background: componentTheme.backgroundColor,
92
+ insetInlineStart: '8px',
93
+ ...(inverse && { color: componentTheme.textColorInverse }),
94
+ ...(clearBackground && { background: 'transparent' })
95
+ }
96
+ }
97
+ }
98
+
99
+ const ThemedComponent = ({ inverse = false, themeOverride }: Props) => {
100
+ const [clearBackground, setClearBackground] = useState(false)
101
+
102
+ const styles = useStyle({
103
+ generateStyle,
104
+ generateComponentTheme,
105
+ componentId: 'ThemedComponent',
106
+ params: { inverse, clearBackground, themeOverride }
107
+ })
108
+
109
+ const handleClick = () => {
110
+ setClearBackground(true)
111
+ }
112
+
113
+ return (
114
+ <div css={styles!.exampleComponent}>
115
+ <p>Hello World</p>
116
+ <button onClick={handleClick}>Button</button>
117
+ </div>
118
+ )
119
+ }
120
+
121
+ describe('with theme provided by InstUISettingsProvider', async () => {
122
+ it('should add css class suffixed with label', async () => {
123
+ const subject = await mount(
124
+ <InstUISettingsProvider theme={exampleTheme}>
125
+ <ThemedComponent />
126
+ </InstUISettingsProvider>
127
+ )
128
+ const emotionClassRegex = new RegExp(/^css-.+-exampleComponent$/)
129
+
130
+ expect(subject.getDOMNode().classList[0]).to.match(emotionClassRegex)
131
+ })
132
+
133
+ it('should apply correct css props', async () => {
134
+ const subject = await mount(
135
+ <InstUISettingsProvider theme={exampleTheme}>
136
+ <ThemedComponent />
137
+ </InstUISettingsProvider>
138
+ )
139
+ const component = subject.getDOMNode()
140
+ const computedStyle = getComputedStyle(component)
141
+
142
+ expect(computedStyle.color).to.equal('rgb(0, 128, 0)')
143
+ expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)')
144
+ })
145
+
146
+ describe('should allow configuration through the themeOverride prop', async () => {
147
+ it('when it is an object', async () => {
148
+ const subject = await mount(
149
+ <InstUISettingsProvider theme={exampleTheme}>
150
+ <ThemedComponent
151
+ themeOverride={{
152
+ textColor: 'rgb(128, 0, 128)'
153
+ }}
154
+ />
155
+ </InstUISettingsProvider>
156
+ )
157
+ const component = subject.getDOMNode()
158
+ const computedStyle = getComputedStyle(component)
159
+
160
+ expect(computedStyle.color).to.equal('rgb(128, 0, 128)')
161
+ expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)')
162
+ })
163
+
164
+ it('when it is a function', async () => {
165
+ const subject = await mount(
166
+ <InstUISettingsProvider theme={exampleTheme}>
167
+ <ThemedComponent
168
+ themeOverride={(componentTheme) => ({
169
+ textColor: componentTheme.backgroundColor
170
+ })}
171
+ />
172
+ </InstUISettingsProvider>
173
+ )
174
+ const component = subject.getDOMNode()
175
+ const computedStyle = getComputedStyle(component)
176
+
177
+ expect(computedStyle.color).to.equal('rgb(255, 255, 0)')
178
+ expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)')
179
+ })
180
+ })
181
+
182
+ it('should ignore empty themeOverride props', async () => {
183
+ const subject = await mount(
184
+ <InstUISettingsProvider theme={exampleTheme}>
185
+ <ThemedComponent themeOverride={{}} />
186
+ </InstUISettingsProvider>
187
+ )
188
+ const component = subject.getDOMNode()
189
+ const computedStyle = getComputedStyle(component)
190
+
191
+ expect(computedStyle.color).to.equal('rgb(0, 128, 0)')
192
+ expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)')
193
+ })
194
+ })
195
+
196
+ describe('should update css props', async () => {
197
+ it('when props are updated', async () => {
198
+ // `setProps` can be called on the outer component,
199
+ // so have to add the theme ad themeOverride here, and suppress the error
200
+ stub(console, 'warn') // suppress "no theme provided error"
201
+
202
+ const subject = await mount(
203
+ <ThemedComponent
204
+ inverse={false}
205
+ themeOverride={{
206
+ textColor: grey1111,
207
+ textColorInverse: blue4570,
208
+ backgroundColor: green4570
209
+ }}
210
+ />
211
+ )
212
+ const component = subject.getDOMNode()
213
+
214
+ expect(getComputedStyle(component).color).to.equal(grey1111)
215
+
216
+ await subject.setProps({ inverse: true })
217
+
218
+ expect(getComputedStyle(component).color).to.equal(blue4570)
219
+ })
220
+
221
+ it('when state is updated', async () => {
222
+ const subject = await mount(
223
+ <InstUISettingsProvider theme={exampleTheme}>
224
+ <ThemedComponent />
225
+ </InstUISettingsProvider>
226
+ )
227
+ const main = within(subject.getDOMNode())
228
+ const clearBackgroundButton = await main.find('button')
229
+ const component = main.getDOMNode()
230
+
231
+ expect(getComputedStyle(component).backgroundColor).to.equal(
232
+ 'rgb(255, 255, 0)'
233
+ )
234
+
235
+ await clearBackgroundButton.click()
236
+
237
+ expect(getComputedStyle(component).backgroundColor).to.equal(
238
+ 'rgba(0, 0, 0, 0)'
239
+ )
240
+ })
241
+ })
242
+
243
+ describe('should apply bi-directional polyfill on styles object', async () => {
244
+ it('in default "ltr" mode', async () => {
245
+ const subject = await mount(
246
+ <InstUISettingsProvider theme={exampleTheme}>
247
+ <ThemedComponent />
248
+ </InstUISettingsProvider>
249
+ )
250
+ const component = subject.getDOMNode()
251
+ const computedStyle = getComputedStyle(component)
252
+
253
+ // `inset-inline-start` should be transformed to 'left' in 'ltr' mode
254
+ expect(computedStyle.left).to.equal('8px')
255
+ expect(computedStyle.right).to.equal('auto')
256
+ })
257
+
258
+ it('in "rtl" mode', async () => {
259
+ const subject = await mount(
260
+ <InstUISettingsProvider theme={exampleTheme} dir="rtl">
261
+ <ThemedComponent />
262
+ </InstUISettingsProvider>
263
+ )
264
+ const component = subject.getDOMNode().firstElementChild
265
+ const computedStyle = getComputedStyle(component!)
266
+
267
+ // `inset-inline-start` should be transformed to 'right' in 'rtl' mode
268
+ expect(computedStyle.left).to.equal('auto')
269
+ expect(computedStyle.right).to.equal('8px')
270
+ })
271
+ })
272
+ })