@instructure/ui-color-picker 8.25.1-snapshot-20
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 +17 -0
- package/README.md +46 -0
- package/es/ColorContrast/ColorContrastLocator.js +54 -0
- package/es/ColorContrast/index.js +174 -0
- package/es/ColorContrast/props.js +40 -0
- package/es/ColorContrast/styles.js +99 -0
- package/es/ColorContrast/theme.js +55 -0
- package/es/ColorIndicator/ColorIndicatorLocator.js +40 -0
- package/es/ColorIndicator/index.js +91 -0
- package/es/ColorIndicator/props.js +31 -0
- package/es/ColorIndicator/styles.js +70 -0
- package/es/ColorIndicator/theme.js +53 -0
- package/es/ColorMixer/ColorMixerLocator.js +27 -0
- package/es/ColorMixer/ColorPalette/index.js +258 -0
- package/es/ColorMixer/ColorPalette/props.js +37 -0
- package/es/ColorMixer/ColorPalette/styles.js +81 -0
- package/es/ColorMixer/ColorPalette/theme.js +48 -0
- package/es/ColorMixer/RGBAInput/index.js +148 -0
- package/es/ColorMixer/RGBAInput/props.js +39 -0
- package/es/ColorMixer/RGBAInput/styles.js +63 -0
- package/es/ColorMixer/RGBAInput/theme.js +43 -0
- package/es/ColorMixer/Slider/index.js +218 -0
- package/es/ColorMixer/Slider/props.js +38 -0
- package/es/ColorMixer/Slider/styles.js +95 -0
- package/es/ColorMixer/Slider/theme.js +53 -0
- package/es/ColorMixer/index.js +232 -0
- package/es/ColorMixer/props.js +40 -0
- package/es/ColorMixer/styles.js +49 -0
- package/es/ColorMixer/utils/shallowCompare.js +32 -0
- package/es/ColorPicker/ColorPickerLocator.js +137 -0
- package/es/ColorPicker/index.js +487 -0
- package/es/ColorPicker/props.js +47 -0
- package/es/ColorPicker/styles.js +119 -0
- package/es/ColorPicker/theme.js +76 -0
- package/es/ColorPreset/ColorPresetLocator.js +27 -0
- package/es/ColorPreset/index.js +268 -0
- package/es/ColorPreset/props.js +36 -0
- package/es/ColorPreset/styles.js +102 -0
- package/es/ColorPreset/theme.js +53 -0
- package/es/index.js +28 -0
- package/lib/ColorContrast/ColorContrastLocator.js +66 -0
- package/lib/ColorContrast/index.js +169 -0
- package/lib/ColorContrast/props.js +51 -0
- package/lib/ColorContrast/styles.js +107 -0
- package/lib/ColorContrast/theme.js +63 -0
- package/lib/ColorIndicator/ColorIndicatorLocator.js +51 -0
- package/lib/ColorIndicator/index.js +82 -0
- package/lib/ColorIndicator/props.js +42 -0
- package/lib/ColorIndicator/styles.js +78 -0
- package/lib/ColorIndicator/theme.js +63 -0
- package/lib/ColorMixer/ColorMixerLocator.js +37 -0
- package/lib/ColorMixer/ColorPalette/index.js +252 -0
- package/lib/ColorMixer/ColorPalette/props.js +48 -0
- package/lib/ColorMixer/ColorPalette/styles.js +90 -0
- package/lib/ColorMixer/ColorPalette/theme.js +57 -0
- package/lib/ColorMixer/RGBAInput/index.js +142 -0
- package/lib/ColorMixer/RGBAInput/props.js +50 -0
- package/lib/ColorMixer/RGBAInput/styles.js +71 -0
- package/lib/ColorMixer/RGBAInput/theme.js +51 -0
- package/lib/ColorMixer/Slider/index.js +211 -0
- package/lib/ColorMixer/Slider/props.js +49 -0
- package/lib/ColorMixer/Slider/styles.js +103 -0
- package/lib/ColorMixer/Slider/theme.js +62 -0
- package/lib/ColorMixer/index.js +226 -0
- package/lib/ColorMixer/props.js +51 -0
- package/lib/ColorMixer/styles.js +57 -0
- package/lib/ColorMixer/utils/shallowCompare.js +40 -0
- package/lib/ColorPicker/ColorPickerLocator.js +151 -0
- package/lib/ColorPicker/index.js +500 -0
- package/lib/ColorPicker/props.js +58 -0
- package/lib/ColorPicker/styles.js +127 -0
- package/lib/ColorPicker/theme.js +85 -0
- package/lib/ColorPreset/ColorPresetLocator.js +37 -0
- package/lib/ColorPreset/index.js +274 -0
- package/lib/ColorPreset/props.js +47 -0
- package/lib/ColorPreset/styles.js +110 -0
- package/lib/ColorPreset/theme.js +61 -0
- package/lib/index.js +45 -0
- package/lib/package.json +1 -0
- package/package.json +62 -0
- package/src/ColorContrast/ColorContrastLocator.ts +51 -0
- package/src/ColorContrast/README.md +111 -0
- package/src/ColorContrast/index.tsx +189 -0
- package/src/ColorContrast/props.ts +140 -0
- package/src/ColorContrast/styles.ts +102 -0
- package/src/ColorContrast/theme.ts +62 -0
- package/src/ColorIndicator/ColorIndicatorLocator.ts +41 -0
- package/src/ColorIndicator/README.md +76 -0
- package/src/ColorIndicator/index.tsx +89 -0
- package/src/ColorIndicator/props.ts +68 -0
- package/src/ColorIndicator/styles.ts +88 -0
- package/src/ColorIndicator/theme.ts +58 -0
- package/src/ColorMixer/ColorMixerLocator.ts +29 -0
- package/src/ColorMixer/ColorPalette/index.tsx +250 -0
- package/src/ColorMixer/ColorPalette/props.ts +87 -0
- package/src/ColorMixer/ColorPalette/styles.ts +94 -0
- package/src/ColorMixer/ColorPalette/theme.ts +52 -0
- package/src/ColorMixer/README.md +98 -0
- package/src/ColorMixer/RGBAInput/index.tsx +172 -0
- package/src/ColorMixer/RGBAInput/props.ts +93 -0
- package/src/ColorMixer/RGBAInput/styles.ts +69 -0
- package/src/ColorMixer/RGBAInput/theme.ts +48 -0
- package/src/ColorMixer/Slider/index.tsx +242 -0
- package/src/ColorMixer/Slider/props.ts +94 -0
- package/src/ColorMixer/Slider/styles.ts +114 -0
- package/src/ColorMixer/Slider/theme.ts +59 -0
- package/src/ColorMixer/index.tsx +221 -0
- package/src/ColorMixer/props.ts +169 -0
- package/src/ColorMixer/styles.ts +51 -0
- package/src/ColorMixer/utils/shallowCompare.ts +35 -0
- package/src/ColorPicker/ColorPickerLocator.ts +124 -0
- package/src/ColorPicker/README.md +420 -0
- package/src/ColorPicker/index.tsx +609 -0
- package/src/ColorPicker/props.ts +293 -0
- package/src/ColorPicker/styles.ts +131 -0
- package/src/ColorPicker/theme.ts +80 -0
- package/src/ColorPreset/ColorPresetLocator.ts +29 -0
- package/src/ColorPreset/README.md +121 -0
- package/src/ColorPreset/index.tsx +328 -0
- package/src/ColorPreset/props.ts +162 -0
- package/src/ColorPreset/styles.ts +107 -0
- package/src/ColorPreset/theme.ts +58 -0
- package/src/index.ts +34 -0
- package/tsconfig.build.json +36 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/types/ColorContrast/ColorContrastLocator.d.ts +592 -0
- package/types/ColorContrast/ColorContrastLocator.d.ts.map +1 -0
- package/types/ColorContrast/index.d.ts +61 -0
- package/types/ColorContrast/index.d.ts.map +1 -0
- package/types/ColorContrast/props.d.ts +62 -0
- package/types/ColorContrast/props.d.ts.map +1 -0
- package/types/ColorContrast/styles.d.ts +76 -0
- package/types/ColorContrast/styles.d.ts.map +1 -0
- package/types/ColorContrast/theme.d.ts +10 -0
- package/types/ColorContrast/theme.d.ts.map +1 -0
- package/types/ColorIndicator/ColorIndicatorLocator.d.ts +577 -0
- package/types/ColorIndicator/ColorIndicatorLocator.d.ts.map +1 -0
- package/types/ColorIndicator/index.d.ts +35 -0
- package/types/ColorIndicator/index.d.ts.map +1 -0
- package/types/ColorIndicator/props.d.ts +25 -0
- package/types/ColorIndicator/props.d.ts.map +1 -0
- package/types/ColorIndicator/styles.d.ts +15 -0
- package/types/ColorIndicator/styles.d.ts.map +1 -0
- package/types/ColorIndicator/theme.d.ts +11 -0
- package/types/ColorIndicator/theme.d.ts.map +1 -0
- package/types/ColorMixer/ColorMixerLocator.d.ts +566 -0
- package/types/ColorMixer/ColorMixerLocator.d.ts.map +1 -0
- package/types/ColorMixer/ColorPalette/index.d.ts +70 -0
- package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -0
- package/types/ColorMixer/ColorPalette/props.d.ts +29 -0
- package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -0
- package/types/ColorMixer/ColorPalette/styles.d.ts +15 -0
- package/types/ColorMixer/ColorPalette/styles.d.ts.map +1 -0
- package/types/ColorMixer/ColorPalette/theme.d.ts +10 -0
- package/types/ColorMixer/ColorPalette/theme.d.ts.map +1 -0
- package/types/ColorMixer/RGBAInput/index.d.ts +51 -0
- package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -0
- package/types/ColorMixer/RGBAInput/props.d.ts +28 -0
- package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -0
- package/types/ColorMixer/RGBAInput/styles.d.ts +15 -0
- package/types/ColorMixer/RGBAInput/styles.d.ts.map +1 -0
- package/types/ColorMixer/RGBAInput/theme.d.ts +10 -0
- package/types/ColorMixer/RGBAInput/theme.d.ts.map +1 -0
- package/types/ColorMixer/Slider/index.d.ts +64 -0
- package/types/ColorMixer/Slider/index.d.ts.map +1 -0
- package/types/ColorMixer/Slider/props.d.ts +26 -0
- package/types/ColorMixer/Slider/props.d.ts.map +1 -0
- package/types/ColorMixer/Slider/styles.d.ts +15 -0
- package/types/ColorMixer/Slider/styles.d.ts.map +1 -0
- package/types/ColorMixer/Slider/theme.d.ts +10 -0
- package/types/ColorMixer/Slider/theme.d.ts.map +1 -0
- package/types/ColorMixer/index.d.ts +59 -0
- package/types/ColorMixer/index.d.ts.map +1 -0
- package/types/ColorMixer/props.d.ts +91 -0
- package/types/ColorMixer/props.d.ts.map +1 -0
- package/types/ColorMixer/styles.d.ts +14 -0
- package/types/ColorMixer/styles.d.ts.map +1 -0
- package/types/ColorMixer/utils/shallowCompare.d.ts +3 -0
- package/types/ColorMixer/utils/shallowCompare.d.ts.map +1 -0
- package/types/ColorPicker/ColorPickerLocator.d.ts +4113 -0
- package/types/ColorPicker/ColorPickerLocator.d.ts.map +1 -0
- package/types/ColorPicker/index.d.ts +158 -0
- package/types/ColorPicker/index.d.ts.map +1 -0
- package/types/ColorPicker/props.d.ts +166 -0
- package/types/ColorPicker/props.d.ts.map +1 -0
- package/types/ColorPicker/styles.d.ts +17 -0
- package/types/ColorPicker/styles.d.ts.map +1 -0
- package/types/ColorPicker/theme.d.ts +10 -0
- package/types/ColorPicker/theme.d.ts.map +1 -0
- package/types/ColorPreset/ColorPresetLocator.d.ts +566 -0
- package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -0
- package/types/ColorPreset/index.d.ts +100 -0
- package/types/ColorPreset/index.d.ts.map +1 -0
- package/types/ColorPreset/props.d.ts +87 -0
- package/types/ColorPreset/props.d.ts.map +1 -0
- package/types/ColorPreset/styles.d.ts +77 -0
- package/types/ColorPreset/styles.d.ts.map +1 -0
- package/types/ColorPreset/theme.d.ts +10 -0
- package/types/ColorPreset/theme.d.ts.map +1 -0
- package/types/index.d.ts +11 -0
- package/types/index.d.ts.map +1 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = exports.ColorContrast = void 0;
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
17
|
+
|
|
18
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
19
|
+
|
|
20
|
+
var _emotion = require("@instructure/emotion");
|
|
21
|
+
|
|
22
|
+
var _Text = require("@instructure/ui-text/lib/Text");
|
|
23
|
+
|
|
24
|
+
var _ColorIndicator = _interopRequireDefault(require("../ColorIndicator"));
|
|
25
|
+
|
|
26
|
+
var _props = require("./props");
|
|
27
|
+
|
|
28
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
29
|
+
|
|
30
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
|
31
|
+
|
|
32
|
+
var _contrast = require("@instructure/ui-color-utils/lib/contrast.js");
|
|
33
|
+
|
|
34
|
+
var _Pill = require("@instructure/ui-pill/lib/Pill");
|
|
35
|
+
|
|
36
|
+
const _excluded = ["styles", "elementRef", "failureLabel", "successLabel", "withoutColorPreview", "firstColor", "secondColor", "label", "firstColorLabel", "secondColorLabel", "normalTextLabel", "largeTextLabel", "graphicsTextLabel"];
|
|
37
|
+
|
|
38
|
+
var _dec, _dec2, _class, _class2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
---
|
|
42
|
+
category: components
|
|
43
|
+
---
|
|
44
|
+
@tsProps
|
|
45
|
+
**/
|
|
46
|
+
let ColorContrast = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class ColorContrast extends _react.Component {
|
|
47
|
+
constructor(props) {
|
|
48
|
+
super(props);
|
|
49
|
+
this.ref = null;
|
|
50
|
+
|
|
51
|
+
this.handleRef = el => {
|
|
52
|
+
const elementRef = this.props.elementRef;
|
|
53
|
+
this.ref = el;
|
|
54
|
+
|
|
55
|
+
if (typeof elementRef === 'function') {
|
|
56
|
+
elementRef(el);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
this.renderStatus = (pass, description) => {
|
|
61
|
+
const _this$props = this.props,
|
|
62
|
+
successLabel = _this$props.successLabel,
|
|
63
|
+
failureLabel = _this$props.failureLabel,
|
|
64
|
+
styles = _this$props.styles;
|
|
65
|
+
return (0, _emotion.jsx)("div", {
|
|
66
|
+
css: styles === null || styles === void 0 ? void 0 : styles.statusWrapper
|
|
67
|
+
}, (0, _emotion.jsx)("div", {
|
|
68
|
+
css: pass ? styles === null || styles === void 0 ? void 0 : styles.successDescription : styles === null || styles === void 0 ? void 0 : styles.failureDescription
|
|
69
|
+
}, description), (0, _emotion.jsx)("div", {
|
|
70
|
+
css: styles === null || styles === void 0 ? void 0 : styles.statusIndicatorWrapper
|
|
71
|
+
}, (0, _emotion.jsx)(_Pill.Pill, {
|
|
72
|
+
color: pass ? 'success' : 'danger'
|
|
73
|
+
}, pass ? successLabel : failureLabel)));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.renderColorIndicator = (color, label) => {
|
|
77
|
+
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
78
|
+
|
|
79
|
+
return (0, _emotion.jsx)(_react.default.Fragment, null, (0, _emotion.jsx)("div", null, (0, _emotion.jsx)("div", {
|
|
80
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
|
|
81
|
+
}, (0, _emotion.jsx)(_ColorIndicator.default, {
|
|
82
|
+
color: color
|
|
83
|
+
}))), (0, _emotion.jsx)("div", null, (0, _emotion.jsx)("div", {
|
|
84
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.colorIndicatorLabel
|
|
85
|
+
}, label), (0, _emotion.jsx)("div", {
|
|
86
|
+
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.pickedColorHex
|
|
87
|
+
}, color)));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
this.calcBlendedColor = (c1, c2) => {
|
|
91
|
+
const alpha = 1 - (1 - c1.a) * (1 - c2.a);
|
|
92
|
+
return {
|
|
93
|
+
r: c2.r * c2.a / alpha + c1.r * c1.a * (1 - c2.a) / alpha,
|
|
94
|
+
g: c2.g * c2.a / alpha + c1.g * c1.a * (1 - c2.a) / alpha,
|
|
95
|
+
b: c2.b * c2.a / alpha + c1.b * c1.a * (1 - c2.a) / alpha,
|
|
96
|
+
a: 1
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
componentDidMount() {
|
|
102
|
+
var _this$props$makeStyle, _this$props2;
|
|
103
|
+
|
|
104
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
componentDidUpdate() {
|
|
108
|
+
var _this$props$makeStyle2, _this$props3;
|
|
109
|
+
|
|
110
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//We project the firstColor onto an opaque white background, then we project the secondColor onto
|
|
114
|
+
//the projected first color. We calculate the contrast of these two, projected colors.
|
|
115
|
+
get calcContrast() {
|
|
116
|
+
const c1RGBA = colorToRGB(this.props.firstColor);
|
|
117
|
+
const c2RGBA = colorToRGB(this.props.secondColor);
|
|
118
|
+
const c1OnWhite = this.calcBlendedColor({
|
|
119
|
+
r: 255,
|
|
120
|
+
g: 255,
|
|
121
|
+
b: 255,
|
|
122
|
+
a: 1
|
|
123
|
+
}, c1RGBA);
|
|
124
|
+
const c2OnC1OnWhite = this.calcBlendedColor(c1OnWhite, c2RGBA);
|
|
125
|
+
return (0, _contrast.contrast)(colorToHex8(c1OnWhite), colorToHex8(c2OnC1OnWhite), 2);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
render() {
|
|
129
|
+
var _this$props$styles4, _this$props$styles5, _this$props$styles6, _this$props$styles7;
|
|
130
|
+
|
|
131
|
+
const _this$props4 = this.props,
|
|
132
|
+
styles = _this$props4.styles,
|
|
133
|
+
elementRef = _this$props4.elementRef,
|
|
134
|
+
failureLabel = _this$props4.failureLabel,
|
|
135
|
+
successLabel = _this$props4.successLabel,
|
|
136
|
+
withoutColorPreview = _this$props4.withoutColorPreview,
|
|
137
|
+
firstColor = _this$props4.firstColor,
|
|
138
|
+
secondColor = _this$props4.secondColor,
|
|
139
|
+
label = _this$props4.label,
|
|
140
|
+
firstColorLabel = _this$props4.firstColorLabel,
|
|
141
|
+
secondColorLabel = _this$props4.secondColorLabel,
|
|
142
|
+
normalTextLabel = _this$props4.normalTextLabel,
|
|
143
|
+
largeTextLabel = _this$props4.largeTextLabel,
|
|
144
|
+
graphicsTextLabel = _this$props4.graphicsTextLabel,
|
|
145
|
+
props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
|
|
146
|
+
const contrast = this.calcContrast;
|
|
147
|
+
return (0, _emotion.jsx)("div", Object.assign({}, (0, _passthroughProps.passthroughProps)(props), {
|
|
148
|
+
ref: this.handleRef,
|
|
149
|
+
css: styles === null || styles === void 0 ? void 0 : styles.colorContrast
|
|
150
|
+
}), (0, _emotion.jsx)("div", {
|
|
151
|
+
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.label
|
|
152
|
+
}, (0, _emotion.jsx)(_Text.Text, {
|
|
153
|
+
weight: "bold",
|
|
154
|
+
as: "div"
|
|
155
|
+
}, label)), (0, _emotion.jsx)(_Text.Text, {
|
|
156
|
+
size: "x-large"
|
|
157
|
+
}, contrast, ":1"), !withoutColorPreview && (0, _emotion.jsx)("div", {
|
|
158
|
+
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.colorPreview
|
|
159
|
+
}, (0, _emotion.jsx)("div", {
|
|
160
|
+
css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.firstColorPreview
|
|
161
|
+
}, this.renderColorIndicator(firstColor, firstColorLabel || '')), (0, _emotion.jsx)("div", {
|
|
162
|
+
css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.secondColorPreview
|
|
163
|
+
}, this.renderColorIndicator(secondColor, secondColorLabel || ''))), this.renderStatus(contrast >= 4.5, normalTextLabel), this.renderStatus(contrast >= 3, largeTextLabel), this.renderStatus(contrast >= 3, graphicsTextLabel));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}, _class2.displayName = "ColorContrast", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorContrast', _class2)) || _class) || _class);
|
|
167
|
+
exports.ColorContrast = ColorContrast;
|
|
168
|
+
var _default = ColorContrast;
|
|
169
|
+
exports.default = _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.propTypes = exports.allowedProps = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
const propTypes = {
|
|
36
|
+
elementRef: _propTypes.default.func,
|
|
37
|
+
failureLabel: _propTypes.default.string.isRequired,
|
|
38
|
+
firstColor: _propTypes.default.string.isRequired,
|
|
39
|
+
firstColorLabel: _propTypes.default.string,
|
|
40
|
+
graphicsTextLabel: _propTypes.default.string.isRequired,
|
|
41
|
+
withoutColorPreview: _propTypes.default.bool,
|
|
42
|
+
label: _propTypes.default.string.isRequired,
|
|
43
|
+
largeTextLabel: _propTypes.default.string.isRequired,
|
|
44
|
+
normalTextLabel: _propTypes.default.string.isRequired,
|
|
45
|
+
secondColor: _propTypes.default.string.isRequired,
|
|
46
|
+
secondColorLabel: _propTypes.default.string,
|
|
47
|
+
successLabel: _propTypes.default.string.isRequired
|
|
48
|
+
};
|
|
49
|
+
exports.propTypes = propTypes;
|
|
50
|
+
const allowedProps = ['elementRef', 'failureLabel', 'firstColor', 'firstColorLabel', 'graphicsTextLabel', 'withoutColorPreview', 'label', 'largeTextLabel', 'normalTextLabel', 'secondColor', 'secondColorLabel', 'successLabel'];
|
|
51
|
+
exports.allowedProps = allowedProps;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ---
|
|
34
|
+
* private: true
|
|
35
|
+
* ---
|
|
36
|
+
* Generates the style object from the theme and provided additional information
|
|
37
|
+
* @param {Object} componentTheme The theme variable object.
|
|
38
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
39
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
40
|
+
* @return {Object} The final style object, which will be used in the component
|
|
41
|
+
*/
|
|
42
|
+
const generateStyle = componentTheme => {
|
|
43
|
+
const statusDescriptionStyle = pass => ({
|
|
44
|
+
label: pass ? 'colorContrast__successDescription' : 'colorContrast__failureDescription',
|
|
45
|
+
flex: 1,
|
|
46
|
+
color: pass ? componentTheme.successColor : componentTheme.failureColor
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
colorContrast: {
|
|
51
|
+
label: 'colorContrast',
|
|
52
|
+
width: componentTheme.width,
|
|
53
|
+
fontFamily: componentTheme.fontFamily,
|
|
54
|
+
fontWeight: componentTheme.fontWeight,
|
|
55
|
+
lineHeight: componentTheme.lineHeight,
|
|
56
|
+
fontSize: componentTheme.fontSize
|
|
57
|
+
},
|
|
58
|
+
statusWrapper: {
|
|
59
|
+
label: 'colorContrast__statusWrapper',
|
|
60
|
+
width: '100%',
|
|
61
|
+
display: 'flex',
|
|
62
|
+
marginBottom: componentTheme.statusWrapperBottomMargin
|
|
63
|
+
},
|
|
64
|
+
successDescription: statusDescriptionStyle(true),
|
|
65
|
+
failureDescription: statusDescriptionStyle(false),
|
|
66
|
+
colorIndicator: {
|
|
67
|
+
marginInlineEnd: componentTheme.colorIndicatorRightMargin
|
|
68
|
+
},
|
|
69
|
+
statusIndicatorWrapper: {
|
|
70
|
+
label: 'colorContrast__statusIndicatorWrapper',
|
|
71
|
+
flex: 1,
|
|
72
|
+
display: 'flex',
|
|
73
|
+
flexDirection: 'row-reverse'
|
|
74
|
+
},
|
|
75
|
+
colorIndicatorLabel: {
|
|
76
|
+
label: 'colorContrast__colorIndicatorLabel',
|
|
77
|
+
wordBreak: 'break-all'
|
|
78
|
+
},
|
|
79
|
+
pickedColorHex: {
|
|
80
|
+
label: 'colorContrast__pickedColorHex',
|
|
81
|
+
color: componentTheme.pickedHexColor
|
|
82
|
+
},
|
|
83
|
+
colorPreview: {
|
|
84
|
+
label: 'colorContrast__colorPreview',
|
|
85
|
+
display: 'flex',
|
|
86
|
+
width: '100%',
|
|
87
|
+
marginBottom: componentTheme.colorPreviewBottomMargin,
|
|
88
|
+
marginTop: componentTheme.colorPreviewTopMargin
|
|
89
|
+
},
|
|
90
|
+
firstColorPreview: {
|
|
91
|
+
label: 'colorContrast__firstColorPreview',
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flex: 1
|
|
94
|
+
},
|
|
95
|
+
secondColorPreview: {
|
|
96
|
+
label: 'colorContrast__secondColorPreview',
|
|
97
|
+
display: 'flex'
|
|
98
|
+
},
|
|
99
|
+
label: {
|
|
100
|
+
label: 'colorContrast__label',
|
|
101
|
+
marginBottom: componentTheme.labelBottomMargin
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var _default = generateStyle;
|
|
107
|
+
exports.default = _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates the theme object for the component from the theme and provided additional information
|
|
34
|
+
* @param {Object} theme The actual theme object.
|
|
35
|
+
* @return {Object} The final theme object with the overrides and component variables
|
|
36
|
+
*/
|
|
37
|
+
const generateComponentTheme = theme => {
|
|
38
|
+
const colors = theme.colors,
|
|
39
|
+
typography = theme.typography,
|
|
40
|
+
spacing = theme.spacing,
|
|
41
|
+
borders = theme.borders;
|
|
42
|
+
const componentVariables = {
|
|
43
|
+
width: '17rem',
|
|
44
|
+
fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
|
|
45
|
+
fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
|
|
46
|
+
lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeight,
|
|
47
|
+
fontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
|
|
48
|
+
statusWrapperBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
|
|
49
|
+
colorIndicatorRightMargin: spacing === null || spacing === void 0 ? void 0 : spacing.small,
|
|
50
|
+
colorPreviewBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.small,
|
|
51
|
+
colorPreviewTopMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xSmall,
|
|
52
|
+
labelBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
|
|
53
|
+
smallBorder: borders.widthSmall,
|
|
54
|
+
successColor: colors.shamrock,
|
|
55
|
+
failureColor: colors.crimson,
|
|
56
|
+
pickedHexColor: colors.ash
|
|
57
|
+
};
|
|
58
|
+
return { ...componentVariables
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
var _default = generateComponentTheme;
|
|
63
|
+
exports.default = _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ColorIndicatorLocator = void 0;
|
|
7
|
+
|
|
8
|
+
var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
|
|
9
|
+
|
|
10
|
+
var _index = require("./index");
|
|
11
|
+
|
|
12
|
+
var _uiColorUtils = require("@instructure/ui-color-utils");
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The MIT License (MIT)
|
|
16
|
+
*
|
|
17
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
18
|
+
*
|
|
19
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
* in the Software without restriction, including without limitation the rights
|
|
22
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
* furnished to do so, subject to the following conditions:
|
|
25
|
+
*
|
|
26
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
* copies or substantial portions of the Software.
|
|
28
|
+
*
|
|
29
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
* SOFTWARE.
|
|
36
|
+
*/
|
|
37
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
38
|
+
const ColorIndicatorLocator = (0, _locator.locator)(_index.ColorIndicator.selector, {
|
|
39
|
+
getColorRGBA: element => {
|
|
40
|
+
const _getComputedStyle = getComputedStyle(element),
|
|
41
|
+
boxShadow = _getComputedStyle.boxShadow;
|
|
42
|
+
|
|
43
|
+
if (boxShadow === 'none') {
|
|
44
|
+
return boxShadow;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const shadowColor = /rgba?\(\d+,\s\d+,\s\d+(,\s.+)?\)/.exec(boxShadow)[0];
|
|
48
|
+
return (0, _uiColorUtils.colorToRGB)(shadowColor);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
exports.ColorIndicatorLocator = ColorIndicatorLocator;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = exports.ColorIndicator = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
var _react = require("react");
|
|
13
|
+
|
|
14
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
15
|
+
|
|
16
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
17
|
+
|
|
18
|
+
var _emotion = require("@instructure/emotion");
|
|
19
|
+
|
|
20
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
21
|
+
|
|
22
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
|
23
|
+
|
|
24
|
+
var _props = require("./props");
|
|
25
|
+
|
|
26
|
+
const _excluded = ["color", "elementRef"];
|
|
27
|
+
|
|
28
|
+
var _dec, _dec2, _class, _class2;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
---
|
|
32
|
+
category: components
|
|
33
|
+
---
|
|
34
|
+
@tsProps
|
|
35
|
+
**/
|
|
36
|
+
let ColorIndicator = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class ColorIndicator extends _react.Component {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(...arguments);
|
|
39
|
+
this.ref = null;
|
|
40
|
+
|
|
41
|
+
this.handleRef = el => {
|
|
42
|
+
const elementRef = this.props.elementRef;
|
|
43
|
+
this.ref = el;
|
|
44
|
+
|
|
45
|
+
if (typeof elementRef === 'function') {
|
|
46
|
+
elementRef(el);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
componentDidMount() {
|
|
52
|
+
var _this$props$makeStyle, _this$props;
|
|
53
|
+
|
|
54
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
componentDidUpdate() {
|
|
58
|
+
var _this$props$makeStyle2, _this$props2;
|
|
59
|
+
|
|
60
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
render() {
|
|
64
|
+
var _this$props$styles;
|
|
65
|
+
|
|
66
|
+
const _this$props3 = this.props,
|
|
67
|
+
color = _this$props3.color,
|
|
68
|
+
elementRef = _this$props3.elementRef,
|
|
69
|
+
props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
|
|
70
|
+
return (0, _emotion.jsx)("div", Object.assign({}, (0, _passthroughProps.passthroughProps)(props), {
|
|
71
|
+
ref: this.handleRef,
|
|
72
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}, _class2.displayName = "ColorIndicator", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorIndicator', _class2.defaultProps = {
|
|
77
|
+
color: '',
|
|
78
|
+
shape: 'circle'
|
|
79
|
+
}, _class2)) || _class) || _class);
|
|
80
|
+
exports.ColorIndicator = ColorIndicator;
|
|
81
|
+
var _default = ColorIndicator;
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.propTypes = exports.allowedProps = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
const propTypes = {
|
|
36
|
+
color: _propTypes.default.string,
|
|
37
|
+
elementRef: _propTypes.default.func,
|
|
38
|
+
shape: _propTypes.default.oneOf(['circle', 'rectangle'])
|
|
39
|
+
};
|
|
40
|
+
exports.propTypes = propTypes;
|
|
41
|
+
const allowedProps = ['color', 'elementRef', 'shape'];
|
|
42
|
+
exports.allowedProps = allowedProps;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _isValid = require("@instructure/ui-color-utils/lib/isValid.js");
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
const calcBlendedColor = (c1, c2) => {
|
|
34
|
+
// 0.4 as decided by design
|
|
35
|
+
const c2Alpha = c2.a * 0.4;
|
|
36
|
+
const c1Alpha = 1 - c2Alpha;
|
|
37
|
+
const alpha = 1 - c1Alpha * (1 - c1Alpha);
|
|
38
|
+
return `rgba(
|
|
39
|
+
${c2.r * c2Alpha / alpha + c1.r * c1Alpha * (1 - c2Alpha) / alpha},
|
|
40
|
+
${c2.g * c2Alpha / alpha + c1.g * c1Alpha * (1 - c2Alpha) / alpha},
|
|
41
|
+
${c2.b * c2Alpha / alpha + c1.b * c1Alpha * (1 - c2Alpha) / alpha},
|
|
42
|
+
${c2.a < 0.6 ? 0.6 : c2.a})`;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* ---
|
|
46
|
+
* private: true
|
|
47
|
+
* ---
|
|
48
|
+
* Generates the style object from the theme and provided additional information
|
|
49
|
+
* @param {Object} componentTheme The theme variable object.
|
|
50
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
51
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
52
|
+
* @return {Object} The final style object, which will be used in the component
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const generateStyle = (componentTheme, props) => {
|
|
57
|
+
const color = props.color,
|
|
58
|
+
shape = props.shape;
|
|
59
|
+
return {
|
|
60
|
+
colorIndicator: {
|
|
61
|
+
label: 'colorIndicator',
|
|
62
|
+
width: shape === 'rectangle' ? componentTheme.rectangleIndicatorSize : componentTheme.circleIndicatorSize,
|
|
63
|
+
height: shape === 'rectangle' ? componentTheme.rectangleIndicatorSize : componentTheme.circleIndicatorSize,
|
|
64
|
+
borderRadius: shape === 'rectangle' ? componentTheme.rectangularIndicatorBorderRadius : componentTheme.circleIndicatorSize,
|
|
65
|
+
boxSizing: 'border-box',
|
|
66
|
+
borderWidth: componentTheme.borderWidth,
|
|
67
|
+
boxShadow: color ? `inset 0 0 0 1.5rem ${color}` : 'none',
|
|
68
|
+
borderStyle: 'solid',
|
|
69
|
+
backgroundImage: componentTheme.backgroundImage,
|
|
70
|
+
backgroundSize: componentTheme.backgroundSize,
|
|
71
|
+
backgroundPosition: componentTheme.backgroundPosition,
|
|
72
|
+
borderColor: calcBlendedColor(colorToRGB(componentTheme.colorIndicatorBorderColor), colorToRGB((0, _isValid.isValid)(color) ? color : '#fff'))
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
var _default = generateStyle;
|
|
78
|
+
exports.default = _default;
|