@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.
- package/CHANGELOG.md +1 -1
- package/es/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +84 -0
- package/es/__old-tests__/getComponentThemeOverride.test.js +128 -0
- package/es/__old-tests__/useStyle.test.js +226 -0
- package/es/__old-tests__/useTheme.test.js +484 -0
- package/es/__old-tests__/withStyle.test.js +327 -0
- package/es/styleUtils/__old-tests__/getShorthandPropValue.test.js +85 -0
- package/es/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
- package/es/styleUtils/__old-tests__/mirrorShorthand.test.js +66 -0
- package/lib/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.js +86 -0
- package/lib/__old-tests__/getComponentThemeOverride.test.js +131 -0
- package/lib/__old-tests__/useStyle.test.js +228 -0
- package/lib/__old-tests__/useTheme.test.js +488 -0
- package/lib/__old-tests__/withStyle.test.js +329 -0
- package/lib/styleUtils/__old-tests__/getShorthandPropValue.test.js +87 -0
- package/lib/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.js → styleUtils/__old-tests__/makeThemeVars.test.js} +19 -16
- package/lib/styleUtils/__old-tests__/mirrorShorthand.test.js +68 -0
- package/package.json +11 -11
- package/src/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.tsx +82 -0
- package/src/__old-tests__/getComponentThemeOverride.test.ts +182 -0
- package/src/__old-tests__/useStyle.test.tsx +272 -0
- package/src/__old-tests__/useTheme.test.tsx +510 -0
- package/src/__old-tests__/withStyle.test.tsx +389 -0
- package/src/styleUtils/__old-tests__/getShorthandPropValue.test.ts +96 -0
- package/src/{InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.tsx → styleUtils/__old-tests__/makeThemeVars.test.ts} +19 -14
- package/src/styleUtils/__old-tests__/mirrorShorthand.test.ts +77 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts +2 -0
- package/types/InstUISettingsProvider/__old-tests__/InstUISettingProvider.test.d.ts.map +1 -0
- package/types/__old-tests__/getComponentThemeOverride.test.d.ts +2 -0
- package/types/__old-tests__/getComponentThemeOverride.test.d.ts.map +1 -0
- package/types/__old-tests__/useStyle.test.d.ts +2 -0
- package/types/__old-tests__/useStyle.test.d.ts.map +1 -0
- package/types/__old-tests__/useTheme.test.d.ts +2 -0
- package/types/__old-tests__/useTheme.test.d.ts.map +1 -0
- package/types/__old-tests__/withStyle.test.d.ts +2 -0
- package/types/__old-tests__/withStyle.test.d.ts.map +1 -0
- package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts +2 -0
- package/types/styleUtils/__old-tests__/getShorthandPropValue.test.d.ts.map +1 -0
- package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts +2 -0
- package/types/styleUtils/__old-tests__/makeThemeVars.test.d.ts.map +1 -0
- package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts +2 -0
- package/types/styleUtils/__old-tests__/mirrorShorthand.test.d.ts.map +1 -0
- package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts +0 -2
- package/types/InstUISettingsProvider/__new-tests__/InstUISettingsProvider.test.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [10.19.2-snapshot-
|
|
6
|
+
## [10.19.2-snapshot-4](https://github.com/instructure/instructure-ui/compare/v10.19.1...v10.19.2-snapshot-4) (2025-06-12)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/emotion
|
|
9
9
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var _dec, _class, _TextDirAwareComponent, _InstUISettingsProvid, _InstUISettingsProvid2, _InstUISettingsProvid3;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Component } from 'react';
|
|
27
|
+
import { expect, mount, spy } from '@instructure/ui-test-utils';
|
|
28
|
+
import canvas from '@instructure/ui-themes';
|
|
29
|
+
import { InstUISettingsProvider } from '../index';
|
|
30
|
+
import { textDirectionContextConsumer } from '@instructure/ui-i18n';
|
|
31
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
|
+
let TextDirAwareComponent = (_dec = textDirectionContextConsumer(), _dec(_class = (_TextDirAwareComponent = class TextDirAwareComponent extends Component {
|
|
33
|
+
render() {
|
|
34
|
+
return _jsx("div", {
|
|
35
|
+
"data-dir": this.props.dir,
|
|
36
|
+
children: "hello world"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, _TextDirAwareComponent.displayName = "TextDirAwareComponent", _TextDirAwareComponent)) || _class);
|
|
40
|
+
describe('InstUISettingsProvider', async () => {
|
|
41
|
+
it('can handle nested text direction setting changes', async () => {
|
|
42
|
+
const subject = await mount(_InstUISettingsProvid || (_InstUISettingsProvid = _jsx(InstUISettingsProvider, {
|
|
43
|
+
theme: canvas,
|
|
44
|
+
dir: "rtl",
|
|
45
|
+
children: _jsx(InstUISettingsProvider, {
|
|
46
|
+
children: _jsx(TextDirAwareComponent, {})
|
|
47
|
+
})
|
|
48
|
+
})));
|
|
49
|
+
let element = subject.getDOMNode().firstElementChild;
|
|
50
|
+
expect(element.getAttribute('data-dir')).to.equal('rtl');
|
|
51
|
+
await subject.setProps({
|
|
52
|
+
dir: 'ltr'
|
|
53
|
+
});
|
|
54
|
+
element = subject.getDOMNode().firstElementChild;
|
|
55
|
+
expect(element.getAttribute('data-dir')).to.equal('ltr');
|
|
56
|
+
});
|
|
57
|
+
it('can handle text direction on native HTML elements', async () => {
|
|
58
|
+
const subject = await mount(_InstUISettingsProvid2 || (_InstUISettingsProvid2 = _jsx(InstUISettingsProvider, {
|
|
59
|
+
dir: "rtl",
|
|
60
|
+
children: _jsx("div", {
|
|
61
|
+
children: "Should be RTL"
|
|
62
|
+
})
|
|
63
|
+
})));
|
|
64
|
+
let element = subject.getDOMNode();
|
|
65
|
+
expect(element.getAttribute('dir')).to.equal('rtl');
|
|
66
|
+
await subject.setProps({
|
|
67
|
+
dir: 'ltr'
|
|
68
|
+
});
|
|
69
|
+
element = subject.getDOMNode();
|
|
70
|
+
expect(element.getAttribute('dir')).to.equal('ltr');
|
|
71
|
+
});
|
|
72
|
+
it('warns when "as" property is used without using the "dir" property', async () => {
|
|
73
|
+
const consoleWarning = spy(console, 'warn');
|
|
74
|
+
const warningMessage = "The 'as' property should be used in conjunction with the 'dir' property!";
|
|
75
|
+
await mount(//@ts-expect-error div is required
|
|
76
|
+
_InstUISettingsProvid3 || (_InstUISettingsProvid3 = _jsx(InstUISettingsProvider, {
|
|
77
|
+
as: "div",
|
|
78
|
+
children: _jsx("div", {
|
|
79
|
+
children: "text"
|
|
80
|
+
})
|
|
81
|
+
})));
|
|
82
|
+
expect(consoleWarning).to.has.been.calledWith(warningMessage);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
import { getComponentThemeOverride } from '../getComponentThemeOverride';
|
|
28
|
+
const componentName = 'ExampleComponent';
|
|
29
|
+
const componentId = 'Example.Component';
|
|
30
|
+
describe('@getComponentThemeOverride', async () => {
|
|
31
|
+
describe('should return empty object', async () => {
|
|
32
|
+
it('if there is no theme set', async () => {
|
|
33
|
+
const override = getComponentThemeOverride({}, componentName, componentId, {});
|
|
34
|
+
expect(override).to.deep.equal({});
|
|
35
|
+
});
|
|
36
|
+
it('if there is no override set', async () => {
|
|
37
|
+
const override = getComponentThemeOverride(canvas, componentName, componentId, {});
|
|
38
|
+
expect(override).to.deep.equal({});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('should return the correct override', async () => {
|
|
42
|
+
it('if there is `themeOverride` set on the props', async () => {
|
|
43
|
+
const componentOverride = {
|
|
44
|
+
componentColor: 'rgb(150, 0, 0)'
|
|
45
|
+
};
|
|
46
|
+
const override = getComponentThemeOverride(canvas, componentName, componentId, {
|
|
47
|
+
themeOverride: componentOverride
|
|
48
|
+
});
|
|
49
|
+
expect(override).to.deep.equal(componentOverride);
|
|
50
|
+
});
|
|
51
|
+
it('if the `themeOverride` prop is a function', async () => {
|
|
52
|
+
const theme = {
|
|
53
|
+
backgroundGreen: 'rgb(0, 150, 0)',
|
|
54
|
+
backgroundBlue: 'rgb(0, 0, 150)',
|
|
55
|
+
backgroundDark: 'rgb(0, 0, 0)'
|
|
56
|
+
};
|
|
57
|
+
const override = getComponentThemeOverride(canvas, componentName, componentId, {
|
|
58
|
+
themeOverride: (componentTheme, currentTheme) => ({
|
|
59
|
+
backgroundBlue: componentTheme.backgroundGreen,
|
|
60
|
+
backgroundDark: currentTheme.colors.contrasts.white1010
|
|
61
|
+
})
|
|
62
|
+
}, theme);
|
|
63
|
+
expect(override).to.deep.equal({
|
|
64
|
+
backgroundBlue: 'rgb(0, 150, 0)',
|
|
65
|
+
backgroundDark: '#FFFFFF'
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('if `themeOverride` and `componentOverrides` are both set', async () => {
|
|
69
|
+
const override = getComponentThemeOverride({
|
|
70
|
+
...canvas,
|
|
71
|
+
componentOverrides: {
|
|
72
|
+
[componentName]: {
|
|
73
|
+
componentColor: 'rgb(0, 0, 150)'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, componentName, componentId, {
|
|
77
|
+
themeOverride: {
|
|
78
|
+
componentColor: 'rgb(0, 150, 0)'
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
expect(override).to.deep.equal({
|
|
82
|
+
componentColor: 'rgb(0, 150, 0)'
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('if there is `componentOverrides` set on the theme', async () => {
|
|
86
|
+
it('with the displayName', async () => {
|
|
87
|
+
const componentOverride = {
|
|
88
|
+
componentColor: 'rgb(0, 0, 150)'
|
|
89
|
+
};
|
|
90
|
+
const override = getComponentThemeOverride({
|
|
91
|
+
...canvas,
|
|
92
|
+
componentOverrides: {
|
|
93
|
+
[componentName]: componentOverride
|
|
94
|
+
}
|
|
95
|
+
}, componentName, componentId, {});
|
|
96
|
+
expect(override).to.deep.equal(componentOverride);
|
|
97
|
+
});
|
|
98
|
+
it('with the componentId', async () => {
|
|
99
|
+
const componentOverride = {
|
|
100
|
+
componentColor: 'rgb(0, 150, 150)'
|
|
101
|
+
};
|
|
102
|
+
const override = getComponentThemeOverride({
|
|
103
|
+
...canvas,
|
|
104
|
+
componentOverrides: {
|
|
105
|
+
[componentId]: componentOverride
|
|
106
|
+
}
|
|
107
|
+
}, componentName, componentId, {});
|
|
108
|
+
expect(override).to.deep.equal(componentOverride);
|
|
109
|
+
});
|
|
110
|
+
it('with both the displayName and componentId (displayName takes precedence)', async () => {
|
|
111
|
+
const override = getComponentThemeOverride({
|
|
112
|
+
...canvas,
|
|
113
|
+
componentOverrides: {
|
|
114
|
+
[componentName]: {
|
|
115
|
+
componentColor: 'rgb(150, 150, 150)'
|
|
116
|
+
},
|
|
117
|
+
[componentId]: {
|
|
118
|
+
componentColor: 'rgb(150, 150, 0)'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, componentName, componentId, {});
|
|
122
|
+
expect(override).to.deep.equal({
|
|
123
|
+
componentColor: 'rgb(150, 150, 150)'
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
var _p;
|
|
3
|
+
/*
|
|
4
|
+
* The MIT License (MIT)
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { useState } from 'react';
|
|
28
|
+
import { expect, mount, stub, within } from '@instructure/ui-test-utils';
|
|
29
|
+
import { InstUISettingsProvider, useStyle } from '../index';
|
|
30
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
31
|
+
describe('useStyle', async () => {
|
|
32
|
+
var _InstUISettingsProvid, _InstUISettingsProvid2, _InstUISettingsProvid3, _InstUISettingsProvid4, _InstUISettingsProvid5;
|
|
33
|
+
const grey1111 = 'rgb(0, 128, 0)';
|
|
34
|
+
const green4570 = 'rgb(10, 10, 10)';
|
|
35
|
+
const blue4570 = 'rgb(255, 255, 0)';
|
|
36
|
+
const exampleTheme = {
|
|
37
|
+
key: 'exampleTheme',
|
|
38
|
+
colors: {
|
|
39
|
+
contrasts: {
|
|
40
|
+
grey1111,
|
|
41
|
+
green4570,
|
|
42
|
+
blue4570
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const generateComponentTheme = function (theme) {
|
|
47
|
+
const colors = theme.colors;
|
|
48
|
+
return {
|
|
49
|
+
textColor: colors.contrasts.grey1111,
|
|
50
|
+
textColorInverse: colors.contrasts.green4570,
|
|
51
|
+
backgroundColor: colors.contrasts.blue4570
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const generateStyle = function (componentTheme, params) {
|
|
55
|
+
const inverse = params.inverse,
|
|
56
|
+
clearBackground = params.clearBackground;
|
|
57
|
+
return {
|
|
58
|
+
exampleComponent: {
|
|
59
|
+
label: 'exampleComponent',
|
|
60
|
+
color: componentTheme.textColor,
|
|
61
|
+
background: componentTheme.backgroundColor,
|
|
62
|
+
insetInlineStart: '8px',
|
|
63
|
+
...(inverse && {
|
|
64
|
+
color: componentTheme.textColorInverse
|
|
65
|
+
}),
|
|
66
|
+
...(clearBackground && {
|
|
67
|
+
background: 'transparent'
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const ThemedComponent = ({
|
|
73
|
+
inverse = false,
|
|
74
|
+
themeOverride
|
|
75
|
+
}) => {
|
|
76
|
+
const _useState = useState(false),
|
|
77
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
78
|
+
clearBackground = _useState2[0],
|
|
79
|
+
setClearBackground = _useState2[1];
|
|
80
|
+
const styles = useStyle({
|
|
81
|
+
generateStyle,
|
|
82
|
+
generateComponentTheme,
|
|
83
|
+
componentId: 'ThemedComponent',
|
|
84
|
+
params: {
|
|
85
|
+
inverse,
|
|
86
|
+
clearBackground,
|
|
87
|
+
themeOverride
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const handleClick = () => {
|
|
91
|
+
setClearBackground(true);
|
|
92
|
+
};
|
|
93
|
+
return _jsxs("div", {
|
|
94
|
+
css: styles.exampleComponent,
|
|
95
|
+
children: [_p || (_p = _jsx("p", {
|
|
96
|
+
children: "Hello World"
|
|
97
|
+
})), _jsx("button", {
|
|
98
|
+
onClick: handleClick,
|
|
99
|
+
children: "Button"
|
|
100
|
+
})]
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
describe('with theme provided by InstUISettingsProvider', async () => {
|
|
104
|
+
it('should add css class suffixed with label', async () => {
|
|
105
|
+
const subject = await mount(_InstUISettingsProvid || (_InstUISettingsProvid = _jsx(InstUISettingsProvider, {
|
|
106
|
+
theme: exampleTheme,
|
|
107
|
+
children: _jsx(ThemedComponent, {})
|
|
108
|
+
})));
|
|
109
|
+
const emotionClassRegex = new RegExp(/^css-.+-exampleComponent$/);
|
|
110
|
+
expect(subject.getDOMNode().classList[0]).to.match(emotionClassRegex);
|
|
111
|
+
});
|
|
112
|
+
it('should apply correct css props', async () => {
|
|
113
|
+
const subject = await mount(_InstUISettingsProvid2 || (_InstUISettingsProvid2 = _jsx(InstUISettingsProvider, {
|
|
114
|
+
theme: exampleTheme,
|
|
115
|
+
children: _jsx(ThemedComponent, {})
|
|
116
|
+
})));
|
|
117
|
+
const component = subject.getDOMNode();
|
|
118
|
+
const computedStyle = getComputedStyle(component);
|
|
119
|
+
expect(computedStyle.color).to.equal('rgb(0, 128, 0)');
|
|
120
|
+
expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
|
|
121
|
+
});
|
|
122
|
+
describe('should allow configuration through the themeOverride prop', async () => {
|
|
123
|
+
it('when it is an object', async () => {
|
|
124
|
+
const subject = await mount(_jsx(InstUISettingsProvider, {
|
|
125
|
+
theme: exampleTheme,
|
|
126
|
+
children: _jsx(ThemedComponent, {
|
|
127
|
+
themeOverride: {
|
|
128
|
+
textColor: 'rgb(128, 0, 128)'
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
}));
|
|
132
|
+
const component = subject.getDOMNode();
|
|
133
|
+
const computedStyle = getComputedStyle(component);
|
|
134
|
+
expect(computedStyle.color).to.equal('rgb(128, 0, 128)');
|
|
135
|
+
expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
|
|
136
|
+
});
|
|
137
|
+
it('when it is a function', async () => {
|
|
138
|
+
const subject = await mount(_jsx(InstUISettingsProvider, {
|
|
139
|
+
theme: exampleTheme,
|
|
140
|
+
children: _jsx(ThemedComponent, {
|
|
141
|
+
themeOverride: componentTheme => ({
|
|
142
|
+
textColor: componentTheme.backgroundColor
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
}));
|
|
146
|
+
const component = subject.getDOMNode();
|
|
147
|
+
const computedStyle = getComputedStyle(component);
|
|
148
|
+
expect(computedStyle.color).to.equal('rgb(255, 255, 0)');
|
|
149
|
+
expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
it('should ignore empty themeOverride props', async () => {
|
|
153
|
+
const subject = await mount(_jsx(InstUISettingsProvider, {
|
|
154
|
+
theme: exampleTheme,
|
|
155
|
+
children: _jsx(ThemedComponent, {
|
|
156
|
+
themeOverride: {}
|
|
157
|
+
})
|
|
158
|
+
}));
|
|
159
|
+
const component = subject.getDOMNode();
|
|
160
|
+
const computedStyle = getComputedStyle(component);
|
|
161
|
+
expect(computedStyle.color).to.equal('rgb(0, 128, 0)');
|
|
162
|
+
expect(computedStyle.backgroundColor).to.equal('rgb(255, 255, 0)');
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('should update css props', async () => {
|
|
166
|
+
it('when props are updated', async () => {
|
|
167
|
+
// `setProps` can be called on the outer component,
|
|
168
|
+
// so have to add the theme ad themeOverride here, and suppress the error
|
|
169
|
+
stub(console, 'warn'); // suppress "no theme provided error"
|
|
170
|
+
|
|
171
|
+
const subject = await mount(_jsx(ThemedComponent, {
|
|
172
|
+
inverse: false,
|
|
173
|
+
themeOverride: {
|
|
174
|
+
textColor: grey1111,
|
|
175
|
+
textColorInverse: blue4570,
|
|
176
|
+
backgroundColor: green4570
|
|
177
|
+
}
|
|
178
|
+
}));
|
|
179
|
+
const component = subject.getDOMNode();
|
|
180
|
+
expect(getComputedStyle(component).color).to.equal(grey1111);
|
|
181
|
+
await subject.setProps({
|
|
182
|
+
inverse: true
|
|
183
|
+
});
|
|
184
|
+
expect(getComputedStyle(component).color).to.equal(blue4570);
|
|
185
|
+
});
|
|
186
|
+
it('when state is updated', async () => {
|
|
187
|
+
const subject = await mount(_InstUISettingsProvid3 || (_InstUISettingsProvid3 = _jsx(InstUISettingsProvider, {
|
|
188
|
+
theme: exampleTheme,
|
|
189
|
+
children: _jsx(ThemedComponent, {})
|
|
190
|
+
})));
|
|
191
|
+
const main = within(subject.getDOMNode());
|
|
192
|
+
const clearBackgroundButton = await main.find('button');
|
|
193
|
+
const component = main.getDOMNode();
|
|
194
|
+
expect(getComputedStyle(component).backgroundColor).to.equal('rgb(255, 255, 0)');
|
|
195
|
+
await clearBackgroundButton.click();
|
|
196
|
+
expect(getComputedStyle(component).backgroundColor).to.equal('rgba(0, 0, 0, 0)');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('should apply bi-directional polyfill on styles object', async () => {
|
|
200
|
+
it('in default "ltr" mode', async () => {
|
|
201
|
+
const subject = await mount(_InstUISettingsProvid4 || (_InstUISettingsProvid4 = _jsx(InstUISettingsProvider, {
|
|
202
|
+
theme: exampleTheme,
|
|
203
|
+
children: _jsx(ThemedComponent, {})
|
|
204
|
+
})));
|
|
205
|
+
const component = subject.getDOMNode();
|
|
206
|
+
const computedStyle = getComputedStyle(component);
|
|
207
|
+
|
|
208
|
+
// `inset-inline-start` should be transformed to 'left' in 'ltr' mode
|
|
209
|
+
expect(computedStyle.left).to.equal('8px');
|
|
210
|
+
expect(computedStyle.right).to.equal('auto');
|
|
211
|
+
});
|
|
212
|
+
it('in "rtl" mode', async () => {
|
|
213
|
+
const subject = await mount(_InstUISettingsProvid5 || (_InstUISettingsProvid5 = _jsx(InstUISettingsProvider, {
|
|
214
|
+
theme: exampleTheme,
|
|
215
|
+
dir: "rtl",
|
|
216
|
+
children: _jsx(ThemedComponent, {})
|
|
217
|
+
})));
|
|
218
|
+
const component = subject.getDOMNode().firstElementChild;
|
|
219
|
+
const computedStyle = getComputedStyle(component);
|
|
220
|
+
|
|
221
|
+
// `inset-inline-start` should be transformed to 'right' in 'rtl' mode
|
|
222
|
+
expect(computedStyle.left).to.equal('auto');
|
|
223
|
+
expect(computedStyle.right).to.equal('8px');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|