@instructure/ui-color-picker 8.33.1 → 8.33.2-snapshot-5
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 +8 -0
- package/es/ColorContrast/ColorContrastLocator.js +3 -3
- package/es/ColorContrast/index.js +15 -34
- package/es/ColorContrast/props.js +1 -0
- package/es/ColorContrast/styles.js +0 -2
- package/es/ColorContrast/theme.js +5 -5
- package/es/ColorIndicator/ColorIndicatorLocator.js +3 -4
- package/es/ColorIndicator/index.js +1 -10
- package/es/ColorIndicator/props.js +1 -0
- package/es/ColorIndicator/styles.js +2 -5
- package/es/ColorIndicator/theme.js +6 -5
- package/es/ColorMixer/ColorMixerLocator.js +2 -7
- package/es/ColorMixer/ColorPalette/index.js +9 -50
- package/es/ColorMixer/ColorPalette/props.js +1 -0
- package/es/ColorMixer/ColorPalette/styles.js +2 -3
- package/es/ColorMixer/ColorPalette/theme.js +6 -5
- package/es/ColorMixer/RGBAInput/index.js +7 -19
- package/es/ColorMixer/RGBAInput/props.js +1 -0
- package/es/ColorMixer/RGBAInput/styles.js +0 -1
- package/es/ColorMixer/RGBAInput/theme.js +3 -3
- package/es/ColorMixer/Slider/index.js +7 -37
- package/es/ColorMixer/Slider/props.js +1 -0
- package/es/ColorMixer/Slider/styles.js +0 -2
- package/es/ColorMixer/Slider/theme.js +6 -5
- package/es/ColorMixer/index.js +25 -34
- package/es/ColorMixer/props.js +1 -0
- package/es/ColorMixer/styles.js +0 -1
- package/es/ColorMixer/utils/shallowCompare.js +1 -2
- package/es/ColorPicker/ColorPickerLocator.js +10 -23
- package/es/ColorPicker/index.js +24 -77
- package/es/ColorPicker/props.js +1 -0
- package/es/ColorPicker/styles.js +4 -5
- package/es/ColorPicker/theme.js +7 -6
- package/es/ColorPreset/ColorPresetLocator.js +7 -10
- package/es/ColorPreset/index.js +4 -28
- package/es/ColorPreset/props.js +1 -0
- package/es/ColorPreset/styles.js +0 -1
- package/es/ColorPreset/theme.js +4 -4
- package/lib/ColorContrast/ColorContrastLocator.js +1 -6
- package/lib/ColorContrast/index.js +14 -47
- package/lib/ColorContrast/props.js +1 -3
- package/lib/ColorContrast/styles.js +0 -3
- package/lib/ColorContrast/theme.js +5 -6
- package/lib/ColorIndicator/ColorIndicatorLocator.js +2 -7
- package/lib/ColorIndicator/index.js +0 -18
- package/lib/ColorIndicator/props.js +1 -3
- package/lib/ColorIndicator/styles.js +2 -6
- package/lib/ColorIndicator/theme.js +6 -7
- package/lib/ColorMixer/ColorMixerLocator.js +3 -11
- package/lib/ColorMixer/ColorPalette/index.js +8 -61
- package/lib/ColorMixer/ColorPalette/props.js +1 -3
- package/lib/ColorMixer/ColorPalette/styles.js +0 -4
- package/lib/ColorMixer/ColorPalette/theme.js +4 -6
- package/lib/ColorMixer/RGBAInput/index.js +6 -29
- package/lib/ColorMixer/RGBAInput/props.js +1 -3
- package/lib/ColorMixer/RGBAInput/styles.js +0 -2
- package/lib/ColorMixer/RGBAInput/theme.js +3 -4
- package/lib/ColorMixer/Slider/index.js +6 -46
- package/lib/ColorMixer/Slider/props.js +1 -3
- package/lib/ColorMixer/Slider/styles.js +0 -3
- package/lib/ColorMixer/Slider/theme.js +4 -6
- package/lib/ColorMixer/index.js +24 -46
- package/lib/ColorMixer/props.js +1 -3
- package/lib/ColorMixer/styles.js +0 -2
- package/lib/ColorMixer/utils/shallowCompare.js +1 -3
- package/lib/ColorPicker/ColorPickerLocator.js +10 -29
- package/lib/ColorPicker/index.js +24 -102
- package/lib/ColorPicker/props.js +1 -3
- package/lib/ColorPicker/styles.js +4 -6
- package/lib/ColorPicker/theme.js +5 -7
- package/lib/ColorPreset/ColorPresetLocator.js +3 -12
- package/lib/ColorPreset/index.js +3 -49
- package/lib/ColorPreset/props.js +1 -3
- package/lib/ColorPreset/styles.js +0 -2
- package/lib/ColorPreset/theme.js +4 -5
- package/lib/index.js +0 -5
- package/package.json +25 -25
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [8.33.2-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2-snapshot-5) (2023-01-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-color-picker
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-color-picker
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
25
|
import { find } from '@instructure/ui-test-queries';
|
|
26
|
+
|
|
26
27
|
/* eslint-disable no-restricted-imports */
|
|
27
28
|
// @ts-expect-error bypass no type definition found error
|
|
28
|
-
|
|
29
29
|
import { PillLocator } from '@instructure/ui-pill/es/Pill/PillLocator';
|
|
30
30
|
/* eslint-enable no-restricted-imports */
|
|
31
31
|
|
|
32
|
-
import { ColorContrast } from './index';
|
|
32
|
+
import { ColorContrast } from './index';
|
|
33
33
|
|
|
34
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
34
35
|
export const ColorContrastLocator = locator(ColorContrast.selector, {
|
|
35
36
|
findPreview: function () {
|
|
36
37
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
37
38
|
args[_key] = arguments[_key];
|
|
38
39
|
}
|
|
39
|
-
|
|
40
40
|
return find('[class$=-colorContrast__colorPreview]', ...args);
|
|
41
41
|
},
|
|
42
42
|
findNormalTextCheckPill: async () => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _dec2, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -25,7 +24,6 @@ var _dec, _dec2, _class, _class2;
|
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
26
|
/** @jsx jsx */
|
|
28
|
-
|
|
29
27
|
/** @jsxFrag React.Fragment */
|
|
30
28
|
import React, { Component } from 'react';
|
|
31
29
|
import { omitProps } from '@instructure/ui-react-utils';
|
|
@@ -39,32 +37,29 @@ import ColorIndicator from '../ColorIndicator';
|
|
|
39
37
|
import { propTypes, allowedProps } from './props';
|
|
40
38
|
import generateStyle from './styles';
|
|
41
39
|
import generateComponentTheme from './theme';
|
|
40
|
+
|
|
42
41
|
/**
|
|
43
42
|
---
|
|
44
43
|
category: components
|
|
45
44
|
---
|
|
46
45
|
@tsProps
|
|
47
46
|
**/
|
|
48
|
-
|
|
49
47
|
let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class ColorContrast extends Component {
|
|
50
48
|
constructor(props) {
|
|
51
49
|
super(props);
|
|
52
50
|
this.ref = null;
|
|
53
|
-
|
|
54
51
|
this.handleRef = el => {
|
|
55
52
|
const elementRef = this.props.elementRef;
|
|
56
53
|
this.ref = el;
|
|
57
|
-
|
|
58
54
|
if (typeof elementRef === 'function') {
|
|
59
55
|
elementRef(el);
|
|
60
56
|
}
|
|
61
57
|
};
|
|
62
|
-
|
|
63
58
|
this.renderStatus = (pass, description) => {
|
|
64
59
|
const _this$props = this.props,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
successLabel = _this$props.successLabel,
|
|
61
|
+
failureLabel = _this$props.failureLabel,
|
|
62
|
+
styles = _this$props.styles;
|
|
68
63
|
return jsx("div", {
|
|
69
64
|
css: styles === null || styles === void 0 ? void 0 : styles.statusWrapper
|
|
70
65
|
}, jsx("div", {
|
|
@@ -75,10 +70,8 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
75
70
|
color: pass ? 'success' : 'danger'
|
|
76
71
|
}, pass ? successLabel : failureLabel)));
|
|
77
72
|
};
|
|
78
|
-
|
|
79
73
|
this.renderColorIndicator = (color, label) => {
|
|
80
74
|
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
81
|
-
|
|
82
75
|
return jsx(React.Fragment, null, jsx("div", null, jsx("div", {
|
|
83
76
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
|
|
84
77
|
}, jsx(ColorIndicator, {
|
|
@@ -89,7 +82,6 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
89
82
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.pickedColorHex
|
|
90
83
|
}, color)));
|
|
91
84
|
};
|
|
92
|
-
|
|
93
85
|
this.calcBlendedColor = (c1, c2) => {
|
|
94
86
|
const alpha = 1 - (1 - c1.a) * (1 - c2.a);
|
|
95
87
|
return {
|
|
@@ -100,36 +92,28 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
100
92
|
};
|
|
101
93
|
};
|
|
102
94
|
}
|
|
103
|
-
|
|
104
95
|
componentDidMount() {
|
|
105
96
|
var _this$props$makeStyle, _this$props2;
|
|
106
|
-
|
|
107
97
|
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
108
98
|
}
|
|
109
|
-
|
|
110
99
|
componentDidUpdate() {
|
|
111
100
|
var _this$props$makeStyle2, _this$props3;
|
|
112
|
-
|
|
113
101
|
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
114
102
|
}
|
|
115
|
-
|
|
116
103
|
renderPreview() {
|
|
117
104
|
const _this$props4 = this.props,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
105
|
+
styles = _this$props4.styles,
|
|
106
|
+
withoutColorPreview = _this$props4.withoutColorPreview,
|
|
107
|
+
firstColor = _this$props4.firstColor,
|
|
108
|
+
secondColor = _this$props4.secondColor,
|
|
109
|
+
firstColorLabel = _this$props4.firstColorLabel,
|
|
110
|
+
secondColorLabel = _this$props4.secondColorLabel;
|
|
125
111
|
if (withoutColorPreview) {
|
|
126
112
|
return null;
|
|
127
113
|
}
|
|
128
|
-
|
|
129
114
|
if (!firstColorLabel || !secondColorLabel) {
|
|
130
115
|
error(false, 'When `withoutColorPreview` is not set to true, the properties `firstColorLabel` and `secondColorLabel` are required!');
|
|
131
116
|
}
|
|
132
|
-
|
|
133
117
|
return !withoutColorPreview && jsx("div", {
|
|
134
118
|
css: styles === null || styles === void 0 ? void 0 : styles.colorPreview
|
|
135
119
|
}, jsx("div", {
|
|
@@ -138,7 +122,6 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
138
122
|
css: styles === null || styles === void 0 ? void 0 : styles.secondColorPreview
|
|
139
123
|
}, this.renderColorIndicator(secondColor, secondColorLabel || '')));
|
|
140
124
|
}
|
|
141
|
-
|
|
142
125
|
//We project the firstColor onto an opaque white background, then we project the secondColor onto
|
|
143
126
|
//the projected first color. We calculate the contrast of these two, projected colors.
|
|
144
127
|
get calcContrast() {
|
|
@@ -153,14 +136,13 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
153
136
|
const c2OnC1OnWhite = this.calcBlendedColor(c1OnWhite, c2RGBA);
|
|
154
137
|
return getContrast(colorToHex8(c1OnWhite), colorToHex8(c2OnC1OnWhite), 2);
|
|
155
138
|
}
|
|
156
|
-
|
|
157
139
|
render() {
|
|
158
140
|
const _this$props5 = this.props,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
141
|
+
styles = _this$props5.styles,
|
|
142
|
+
label = _this$props5.label,
|
|
143
|
+
normalTextLabel = _this$props5.normalTextLabel,
|
|
144
|
+
largeTextLabel = _this$props5.largeTextLabel,
|
|
145
|
+
graphicsTextLabel = _this$props5.graphicsTextLabel;
|
|
164
146
|
const contrast = this.calcContrast;
|
|
165
147
|
return jsx("div", Object.assign({}, omitProps(this.props, ColorContrast.allowedProps), {
|
|
166
148
|
ref: this.handleRef,
|
|
@@ -174,7 +156,6 @@ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _d
|
|
|
174
156
|
size: "x-large"
|
|
175
157
|
}, contrast, ":1"), this.renderPreview(), this.renderStatus(contrast >= 4.5, normalTextLabel), this.renderStatus(contrast >= 3, largeTextLabel), this.renderStatus(contrast >= 3, graphicsTextLabel));
|
|
176
158
|
}
|
|
177
|
-
|
|
178
159
|
}, _class2.displayName = "ColorContrast", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorContrast', _class2.defaultProps = {
|
|
179
160
|
withoutColorPreview: false
|
|
180
161
|
}, _class2)) || _class) || _class);
|
|
@@ -38,7 +38,6 @@ const generateStyle = componentTheme => {
|
|
|
38
38
|
flex: 1,
|
|
39
39
|
color: pass ? componentTheme.successColor : componentTheme.failureColor
|
|
40
40
|
});
|
|
41
|
-
|
|
42
41
|
return {
|
|
43
42
|
colorContrast: {
|
|
44
43
|
label: 'colorContrast',
|
|
@@ -95,5 +94,4 @@ const generateStyle = componentTheme => {
|
|
|
95
94
|
}
|
|
96
95
|
};
|
|
97
96
|
};
|
|
98
|
-
|
|
99
97
|
export default generateStyle;
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
31
|
const colors = theme.colors,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
typography = theme.typography,
|
|
33
|
+
spacing = theme.spacing,
|
|
34
|
+
borders = theme.borders;
|
|
35
35
|
const componentVariables = {
|
|
36
36
|
width: '17rem',
|
|
37
37
|
fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
|
|
@@ -48,8 +48,8 @@ const generateComponentTheme = theme => {
|
|
|
48
48
|
failureColor: colors.crimson,
|
|
49
49
|
pickedHexColor: colors.ash
|
|
50
50
|
};
|
|
51
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
...componentVariables
|
|
52
53
|
};
|
|
53
54
|
};
|
|
54
|
-
|
|
55
55
|
export default generateComponentTheme;
|
|
@@ -23,17 +23,16 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
25
|
import { ColorIndicator } from './index';
|
|
26
|
-
import { colorToRGB } from '@instructure/ui-color-utils';
|
|
26
|
+
import { colorToRGB } from '@instructure/ui-color-utils';
|
|
27
27
|
|
|
28
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
28
29
|
export const ColorIndicatorLocator = locator(ColorIndicator.selector, {
|
|
29
30
|
getColorRGBA: element => {
|
|
30
31
|
const _getComputedStyle = getComputedStyle(element),
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
boxShadow = _getComputedStyle.boxShadow;
|
|
33
33
|
if (boxShadow === 'none') {
|
|
34
34
|
return boxShadow;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
const shadowColor = /rgba?\(\d+,\s\d+,\s\d+(,\s.+)?\)/.exec(boxShadow)[0];
|
|
38
37
|
return colorToRGB(shadowColor);
|
|
39
38
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _dec2, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -32,40 +31,33 @@ import { withStyle, jsx } from '@instructure/emotion';
|
|
|
32
31
|
import generateStyle from './styles';
|
|
33
32
|
import generateComponentTheme from './theme';
|
|
34
33
|
import { propTypes, allowedProps } from './props';
|
|
34
|
+
|
|
35
35
|
/**
|
|
36
36
|
---
|
|
37
37
|
category: components
|
|
38
38
|
---
|
|
39
39
|
@tsProps
|
|
40
40
|
**/
|
|
41
|
-
|
|
42
41
|
let ColorIndicator = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class ColorIndicator extends Component {
|
|
43
42
|
constructor() {
|
|
44
43
|
super(...arguments);
|
|
45
44
|
this.ref = null;
|
|
46
|
-
|
|
47
45
|
this.handleRef = el => {
|
|
48
46
|
const elementRef = this.props.elementRef;
|
|
49
47
|
this.ref = el;
|
|
50
|
-
|
|
51
48
|
if (typeof elementRef === 'function') {
|
|
52
49
|
elementRef(el);
|
|
53
50
|
}
|
|
54
51
|
};
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
componentDidMount() {
|
|
58
54
|
var _this$props$makeStyle, _this$props;
|
|
59
|
-
|
|
60
55
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
61
56
|
}
|
|
62
|
-
|
|
63
57
|
componentDidUpdate() {
|
|
64
58
|
var _this$props$makeStyle2, _this$props2;
|
|
65
|
-
|
|
66
59
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
67
60
|
}
|
|
68
|
-
|
|
69
61
|
render() {
|
|
70
62
|
const styles = this.props.styles;
|
|
71
63
|
return jsx("div", Object.assign({}, omitProps(this.props, ColorIndicator.allowedProps), {
|
|
@@ -73,7 +65,6 @@ let ColorIndicator = (_dec = withStyle(generateStyle, generateComponentTheme), _
|
|
|
73
65
|
css: styles === null || styles === void 0 ? void 0 : styles.colorIndicator
|
|
74
66
|
}));
|
|
75
67
|
}
|
|
76
|
-
|
|
77
68
|
}, _class2.displayName = "ColorIndicator", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorIndicator', _class2.defaultProps = {
|
|
78
69
|
shape: 'circle'
|
|
79
70
|
}, _class2)) || _class) || _class);
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { colorToRGB, isValid } from '@instructure/ui-color-utils';
|
|
25
24
|
|
|
25
|
+
import { colorToRGB, isValid } from '@instructure/ui-color-utils';
|
|
26
26
|
const calcBlendedColor = (c1, c2) => {
|
|
27
27
|
// 0.4 as decided by design
|
|
28
28
|
const c2Alpha = c2.a * 0.4;
|
|
@@ -44,11 +44,9 @@ const calcBlendedColor = (c1, c2) => {
|
|
|
44
44
|
* @param {Object} state the state of the component, the style is applied to
|
|
45
45
|
* @return {Object} The final style object, which will be used in the component
|
|
46
46
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
47
|
const generateStyle = (componentTheme, props) => {
|
|
50
48
|
const color = props.color,
|
|
51
|
-
|
|
49
|
+
shape = props.shape;
|
|
52
50
|
return {
|
|
53
51
|
colorIndicator: {
|
|
54
52
|
label: 'colorIndicator',
|
|
@@ -66,5 +64,4 @@ const generateStyle = (componentTheme, props) => {
|
|
|
66
64
|
}
|
|
67
65
|
};
|
|
68
66
|
};
|
|
69
|
-
|
|
70
67
|
export default generateStyle;
|
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
export const colorIndicatorBorderColor = '#384A5899';
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* Generates the theme object for the component from the theme and provided additional information
|
|
27
29
|
* @param {Object} theme The actual theme object.
|
|
28
30
|
* @return {Object} The final theme object with the overrides and component variables
|
|
29
31
|
*/
|
|
30
|
-
|
|
31
32
|
const generateComponentTheme = theme => {
|
|
32
33
|
const colors = theme.colors,
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
borders = theme.borders,
|
|
35
|
+
spacing = theme.spacing;
|
|
35
36
|
const componentVariables = {
|
|
36
37
|
borderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall,
|
|
37
38
|
backgroundImage: `linear-gradient(45deg, ${colors.tiara} 25%, transparent 25%),
|
|
@@ -46,8 +47,8 @@ const generateComponentTheme = theme => {
|
|
|
46
47
|
rectangularIndicatorBorderRadius: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
|
|
47
48
|
rectangularIndicatorBorderWidth: borders === null || borders === void 0 ? void 0 : borders.widthSmall
|
|
48
49
|
};
|
|
49
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
...componentVariables
|
|
50
52
|
};
|
|
51
53
|
};
|
|
52
|
-
|
|
53
54
|
export default generateComponentTheme;
|
|
@@ -29,37 +29,32 @@ const customMethos = {
|
|
|
29
29
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
30
|
args[_key] = arguments[_key];
|
|
31
31
|
}
|
|
32
|
-
|
|
33
32
|
return find('[id^=TextInput_]', ...args);
|
|
34
33
|
},
|
|
35
34
|
findColorPalette: function () {
|
|
36
35
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
37
36
|
args[_key2] = arguments[_key2];
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
return find('[aria-label*="color palette"]', ...args);
|
|
41
39
|
},
|
|
42
40
|
findColorSlider: function () {
|
|
43
41
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
44
42
|
args[_key3] = arguments[_key3];
|
|
45
43
|
}
|
|
46
|
-
|
|
47
44
|
return find('[aria-label*="color slider"]', ...args);
|
|
48
45
|
},
|
|
49
46
|
findAlphaSlider: function () {
|
|
50
47
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
51
48
|
args[_key4] = arguments[_key4];
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
return find('[aria-label*="alpha slider"]', ...args);
|
|
55
51
|
},
|
|
56
52
|
findIndicator: function () {
|
|
57
53
|
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
58
54
|
args[_key5] = arguments[_key5];
|
|
59
55
|
}
|
|
60
|
-
|
|
61
56
|
return find('[clas*=__indicator]', ...args);
|
|
62
57
|
}
|
|
63
|
-
};
|
|
64
|
-
|
|
58
|
+
};
|
|
59
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
65
60
|
export const ColorMixerLocator = locator(ColorMixer.selector, customMethos);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -34,50 +33,41 @@ import { propTypes, allowedProps } from './props';
|
|
|
34
33
|
import generateStyle from './styles';
|
|
35
34
|
import generateComponentTheme from './theme';
|
|
36
35
|
import { px } from '@instructure/ui-utils';
|
|
36
|
+
|
|
37
37
|
/**
|
|
38
38
|
---
|
|
39
39
|
private: true
|
|
40
40
|
---
|
|
41
41
|
@tsProps
|
|
42
42
|
**/
|
|
43
|
-
|
|
44
43
|
let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_class2 = class ColorPalette extends Component {
|
|
45
44
|
constructor(props) {
|
|
46
45
|
var _this$props$styles;
|
|
47
|
-
|
|
48
46
|
super(props);
|
|
49
47
|
this.ref = null;
|
|
50
48
|
this._paletteRef = null;
|
|
51
49
|
this._mouseMoveListener = void 0;
|
|
52
50
|
this._mouseUpListener = void 0;
|
|
53
51
|
this._paletteOffset = px((_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.paletteOffset);
|
|
54
|
-
|
|
55
52
|
this.handleRef = el => {
|
|
56
53
|
const elementRef = this.props.elementRef;
|
|
57
54
|
this.ref = el;
|
|
58
|
-
|
|
59
55
|
if (typeof elementRef === 'function') {
|
|
60
56
|
elementRef(el);
|
|
61
57
|
}
|
|
62
58
|
};
|
|
63
|
-
|
|
64
59
|
this.calcSaturation = position => Math.round(position / this.paletteWidth * 100) / 100;
|
|
65
|
-
|
|
66
60
|
this.calcLuminance = position => Math.round((this.paletteHeight - position) / this.paletteHeight * 100) / 100;
|
|
67
|
-
|
|
68
61
|
this.handleMouseUp = () => {
|
|
69
62
|
this.removeEventListeners();
|
|
70
63
|
};
|
|
71
|
-
|
|
72
64
|
this.handleChange = e => {
|
|
73
65
|
if (this.props.disabled) return;
|
|
74
66
|
const clientX = e.clientX,
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
clientY = e.clientY;
|
|
77
68
|
const _this$calcColorPositi = this.calcColorPosition(clientX, clientY),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
newXPosition = _this$calcColorPositi.newXPosition,
|
|
70
|
+
newYPosition = _this$calcColorPositi.newYPosition;
|
|
81
71
|
this.setState({
|
|
82
72
|
colorPosition: {
|
|
83
73
|
x: newXPosition,
|
|
@@ -90,7 +80,6 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
90
80
|
v: this.calcLuminance(newYPosition)
|
|
91
81
|
});
|
|
92
82
|
};
|
|
93
|
-
|
|
94
83
|
this.state = {
|
|
95
84
|
colorPosition: {
|
|
96
85
|
x: 0,
|
|
@@ -98,43 +87,34 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
98
87
|
}
|
|
99
88
|
};
|
|
100
89
|
}
|
|
101
|
-
|
|
102
90
|
componentDidMount() {
|
|
103
91
|
var _this$props$makeStyle, _this$props;
|
|
104
|
-
|
|
105
92
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.state);
|
|
106
93
|
this.setState({
|
|
107
94
|
colorPosition: this.calcPositionFromColor(this.props.color)
|
|
108
95
|
});
|
|
109
96
|
}
|
|
110
|
-
|
|
111
97
|
componentDidUpdate(prevProps) {
|
|
112
98
|
var _this$props$makeStyle2, _this$props2;
|
|
113
|
-
|
|
114
99
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.state);
|
|
115
|
-
|
|
116
100
|
if (shallowCompare(prevProps.color, this.props.color)) {
|
|
117
101
|
this.setState({
|
|
118
102
|
colorPosition: this.calcPositionFromColor(this.props.color)
|
|
119
103
|
});
|
|
120
104
|
}
|
|
121
105
|
}
|
|
122
|
-
|
|
123
106
|
componentWillUnmount() {
|
|
124
107
|
this.removeEventListeners();
|
|
125
108
|
}
|
|
126
|
-
|
|
127
109
|
get paletteWidth() {
|
|
128
110
|
return this._paletteRef.getBoundingClientRect().width - this._paletteOffset;
|
|
129
111
|
}
|
|
130
|
-
|
|
131
112
|
get paletteHeight() {
|
|
132
113
|
return this._paletteRef.getBoundingClientRect().height - this._paletteOffset;
|
|
133
114
|
}
|
|
134
|
-
|
|
135
115
|
calcPositionFromColor(hsv) {
|
|
136
116
|
const s = hsv.s,
|
|
137
|
-
|
|
117
|
+
v = hsv.v;
|
|
138
118
|
const x = s * this.paletteWidth;
|
|
139
119
|
const y = (1 - v) * this.paletteHeight;
|
|
140
120
|
return {
|
|
@@ -142,54 +122,42 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
142
122
|
y
|
|
143
123
|
};
|
|
144
124
|
}
|
|
145
|
-
|
|
146
125
|
handlePaletteMouseDown(e) {
|
|
147
126
|
this.handleChange(e);
|
|
148
127
|
this._mouseMoveListener = addEventListener(window, 'mousemove', this.handleChange);
|
|
149
128
|
this._mouseUpListener = addEventListener(window, 'mouseup', this.handleMouseUp);
|
|
150
129
|
}
|
|
151
|
-
|
|
152
130
|
removeEventListeners() {
|
|
153
131
|
var _this$_mouseMoveListe, _this$_mouseUpListene;
|
|
154
|
-
|
|
155
132
|
(_this$_mouseMoveListe = this._mouseMoveListener) === null || _this$_mouseMoveListe === void 0 ? void 0 : _this$_mouseMoveListe.remove();
|
|
156
133
|
(_this$_mouseUpListene = this._mouseUpListener) === null || _this$_mouseUpListene === void 0 ? void 0 : _this$_mouseUpListene.remove();
|
|
157
134
|
}
|
|
158
|
-
|
|
159
135
|
calcColorPosition(clientX, clientY) {
|
|
160
136
|
const _getBoundingClientRec = this._paletteRef.getBoundingClientRect(),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
x = _getBoundingClientRec.x,
|
|
138
|
+
y = _getBoundingClientRec.y;
|
|
164
139
|
return this.applyBoundaries(clientX - x, clientY - y);
|
|
165
140
|
}
|
|
166
|
-
|
|
167
141
|
applyBoundaries(x, y) {
|
|
168
142
|
let newXPosition = x;
|
|
169
143
|
let newYPosition = y;
|
|
170
|
-
|
|
171
144
|
if (x > this.paletteWidth) {
|
|
172
145
|
newXPosition = this.paletteWidth;
|
|
173
146
|
}
|
|
174
|
-
|
|
175
147
|
if (x < 0) {
|
|
176
148
|
newXPosition = 0;
|
|
177
149
|
}
|
|
178
|
-
|
|
179
150
|
if (y > this.paletteHeight) {
|
|
180
151
|
newYPosition = this.paletteHeight;
|
|
181
152
|
}
|
|
182
|
-
|
|
183
153
|
if (y < 0) {
|
|
184
154
|
newYPosition = 0;
|
|
185
155
|
}
|
|
186
|
-
|
|
187
156
|
return {
|
|
188
157
|
newXPosition,
|
|
189
158
|
newYPosition
|
|
190
159
|
};
|
|
191
160
|
}
|
|
192
|
-
|
|
193
161
|
handleKeyDown(e) {
|
|
194
162
|
if (this.props.disabled) return;
|
|
195
163
|
const key = e.key;
|
|
@@ -197,27 +165,21 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
197
165
|
e.preventDefault();
|
|
198
166
|
let deltaX = 0;
|
|
199
167
|
let deltaY = 0;
|
|
200
|
-
|
|
201
168
|
if (key === 'ArrowLeft' || key === 'a') {
|
|
202
169
|
deltaX = -2;
|
|
203
170
|
}
|
|
204
|
-
|
|
205
171
|
if (key === 'ArrowRight' || key === 'd') {
|
|
206
172
|
deltaX = 2;
|
|
207
173
|
}
|
|
208
|
-
|
|
209
174
|
if (key === 'ArrowUp' || key === 'w') {
|
|
210
175
|
deltaY = -2;
|
|
211
176
|
}
|
|
212
|
-
|
|
213
177
|
if (key === 'ArrowDown' || key === 's') {
|
|
214
178
|
deltaY = 2;
|
|
215
179
|
}
|
|
216
|
-
|
|
217
180
|
const _this$applyBoundaries = this.applyBoundaries(this.state.colorPosition.x + deltaX, this.state.colorPosition.y + deltaY),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
181
|
+
newXPosition = _this$applyBoundaries.newXPosition,
|
|
182
|
+
newYPosition = _this$applyBoundaries.newYPosition;
|
|
221
183
|
this.setState({
|
|
222
184
|
colorPosition: {
|
|
223
185
|
x: newXPosition,
|
|
@@ -230,10 +192,8 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
230
192
|
v: this.calcLuminance(newYPosition)
|
|
231
193
|
});
|
|
232
194
|
}
|
|
233
|
-
|
|
234
195
|
render() {
|
|
235
196
|
var _this$props$styles2, _this$props$styles3, _this$props$styles4;
|
|
236
|
-
|
|
237
197
|
return jsx(View, {
|
|
238
198
|
elementRef: this.handleRef,
|
|
239
199
|
disabled: this.props.disabled,
|
|
@@ -259,6 +219,5 @@ let ColorPalette = (_dec = withStyle(generateStyle, generateComponentTheme), _de
|
|
|
259
219
|
}
|
|
260
220
|
}));
|
|
261
221
|
}
|
|
262
|
-
|
|
263
222
|
}, _class2.displayName = "ColorPalette", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorMixer.Palette', _class2)) || _class);
|
|
264
223
|
export default ColorPalette;
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { px } from '@instructure/ui-utils';
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* ---
|
|
27
29
|
* private: true
|
|
@@ -32,10 +34,8 @@ import { px } from '@instructure/ui-utils';
|
|
|
32
34
|
* @param {Object} state the state of the component, the style is applied to
|
|
33
35
|
* @return {Object} The final style object, which will be used in the component
|
|
34
36
|
*/
|
|
35
|
-
|
|
36
37
|
const generateStyle = (componentTheme, props, state) => {
|
|
37
38
|
var _state$colorPosition, _state$colorPosition2;
|
|
38
|
-
|
|
39
39
|
return {
|
|
40
40
|
ColorPalette: {
|
|
41
41
|
label: 'ColorPalette'
|
|
@@ -78,5 +78,4 @@ const generateStyle = (componentTheme, props, state) => {
|
|
|
78
78
|
paletteOffset: componentTheme.paletteOffset
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
|
-
|
|
82
81
|
export default generateStyle;
|