@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,500 @@
|
|
|
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.ColorPicker = void 0;
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _emotion = require("@instructure/emotion");
|
|
17
|
+
|
|
18
|
+
var _console = require("@instructure/console");
|
|
19
|
+
|
|
20
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
21
|
+
|
|
22
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
23
|
+
|
|
24
|
+
var _isValid = require("@instructure/ui-color-utils/lib/isValid.js");
|
|
25
|
+
|
|
26
|
+
var _contrast = require("@instructure/ui-color-utils/lib/contrast.js");
|
|
27
|
+
|
|
28
|
+
var _TextInput = require("@instructure/ui-text-input/lib/TextInput");
|
|
29
|
+
|
|
30
|
+
var _Tooltip = require("@instructure/ui-tooltip/lib/Tooltip");
|
|
31
|
+
|
|
32
|
+
var _Button = require("@instructure/ui-buttons/lib/Button");
|
|
33
|
+
|
|
34
|
+
var _IconButton = require("@instructure/ui-buttons/lib/IconButton");
|
|
35
|
+
|
|
36
|
+
var _Popover = require("@instructure/ui-popover/lib/Popover");
|
|
37
|
+
|
|
38
|
+
var _IconCheckDarkLine2 = require("@instructure/ui-icons/lib/IconCheckDarkLine.js");
|
|
39
|
+
|
|
40
|
+
var _IconWarningLine2 = require("@instructure/ui-icons/lib/IconWarningLine.js");
|
|
41
|
+
|
|
42
|
+
var _IconTroubleLine2 = require("@instructure/ui-icons/lib/IconTroubleLine.js");
|
|
43
|
+
|
|
44
|
+
var _IconInfoLine2 = require("@instructure/ui-icons/lib/IconInfoLine.js");
|
|
45
|
+
|
|
46
|
+
var _ColorIndicator = _interopRequireDefault(require("../ColorIndicator"));
|
|
47
|
+
|
|
48
|
+
var _ColorMixer = _interopRequireDefault(require("../ColorMixer"));
|
|
49
|
+
|
|
50
|
+
var _ColorContrast = _interopRequireDefault(require("../ColorContrast"));
|
|
51
|
+
|
|
52
|
+
var _ColorPreset = _interopRequireDefault(require("../ColorPreset"));
|
|
53
|
+
|
|
54
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
55
|
+
|
|
56
|
+
var _theme = _interopRequireDefault(require("./theme"));
|
|
57
|
+
|
|
58
|
+
var _props = require("./props");
|
|
59
|
+
|
|
60
|
+
const _excluded = ["checkContrast", "colorMixerSettings", "disabled", "elementRef", "isRequired", "label", "onChange", "placeholderText", "popoverButtonScreenReaderLabel", "renderInvalidColorMessage", "renderIsRequiredMessage", "renderMessages", "tooltip", "value", "width", "withAlpha"];
|
|
61
|
+
|
|
62
|
+
var _dec, _dec2, _class, _class2, _IconTroubleLine, _IconWarningLine, _IconCheckDarkLine, _IconInfoLine;
|
|
63
|
+
|
|
64
|
+
const acceptedCharactersForHEX = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', null];
|
|
65
|
+
/**
|
|
66
|
+
---
|
|
67
|
+
category: components
|
|
68
|
+
---
|
|
69
|
+
@tsProps
|
|
70
|
+
**/
|
|
71
|
+
|
|
72
|
+
let ColorPicker = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class ColorPicker extends _react.Component {
|
|
73
|
+
constructor(props) {
|
|
74
|
+
super(props);
|
|
75
|
+
this.ref = null;
|
|
76
|
+
|
|
77
|
+
this.handleRef = el => {
|
|
78
|
+
const elementRef = this.props.elementRef;
|
|
79
|
+
this.ref = el;
|
|
80
|
+
|
|
81
|
+
if (typeof elementRef === 'function') {
|
|
82
|
+
elementRef(el);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
this.checkSettings = () => {
|
|
87
|
+
if (this.props.children && this.props.colorMixerSettings) {
|
|
88
|
+
(0, _console.warn)(false, 'You should either use children, colorMixerSettings or neither, not both. In this case, the colorMixerSettings will be ignored', '');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
this.stripAlphaIfNeeded = hex => hex.length === 8 && hex.slice(-2) === 'FF' ? hex.slice(0, -2) : hex;
|
|
93
|
+
|
|
94
|
+
this.renderPopover = () => {
|
|
95
|
+
var _this$props$styles;
|
|
96
|
+
|
|
97
|
+
return (0, _emotion.jsx)(_Popover.Popover, {
|
|
98
|
+
renderTrigger: (0, _emotion.jsx)(_IconButton.IconButton, {
|
|
99
|
+
disabled: this.props.disabled,
|
|
100
|
+
screenReaderLabel: this.props.popoverButtonScreenReaderLabel || ''
|
|
101
|
+
}, (0, _emotion.jsx)(_ColorIndicator.default, {
|
|
102
|
+
color: `#${this.state.hexCode}`
|
|
103
|
+
})),
|
|
104
|
+
isShowingContent: this.state.openColorPicker,
|
|
105
|
+
onShowContent: () => {
|
|
106
|
+
this.setState({
|
|
107
|
+
openColorPicker: true,
|
|
108
|
+
mixedColor: this.state.hexCode
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
onHideContent: () => {
|
|
112
|
+
this.setState({
|
|
113
|
+
openColorPicker: false
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
on: "click",
|
|
117
|
+
screenReaderLabel: this.props.popoverScreenReaderLabel || '',
|
|
118
|
+
shouldContainFocus: true,
|
|
119
|
+
shouldReturnFocus: true,
|
|
120
|
+
shouldCloseOnDocumentClick: true,
|
|
121
|
+
offsetY: "10rem"
|
|
122
|
+
}, (0, _emotion.jsx)("div", {
|
|
123
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.popoverContentContainer
|
|
124
|
+
}, this.isDefaultPopover ? this.renderDefaultPopoverContent() : this.renderCustomPopoverContent()));
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
this.renderCustomPopoverContent = () => {
|
|
128
|
+
var _this$props$styles2, _this$props, _this$props2;
|
|
129
|
+
|
|
130
|
+
return (0, _emotion.jsx)("div", {
|
|
131
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.popoverContent
|
|
132
|
+
}, typeof ((_this$props = this.props) === null || _this$props === void 0 ? void 0 : _this$props.children) === 'function' && ((_this$props2 = this.props) === null || _this$props2 === void 0 ? void 0 : _this$props2.children(this.stripAlphaIfNeeded(this.state.mixedColor), color => {
|
|
133
|
+
this.setState({
|
|
134
|
+
mixedColor: color
|
|
135
|
+
});
|
|
136
|
+
}, () => {
|
|
137
|
+
var _this$props3, _this$props3$onChange;
|
|
138
|
+
|
|
139
|
+
this.setState({
|
|
140
|
+
openColorPicker: false,
|
|
141
|
+
hexCode: `${this.stripAlphaIfNeeded(this.state.mixedColor)}`
|
|
142
|
+
});
|
|
143
|
+
(_this$props3 = this.props) === null || _this$props3 === void 0 ? void 0 : (_this$props3$onChange = _this$props3.onChange) === null || _this$props3$onChange === void 0 ? void 0 : _this$props3$onChange.call(_this$props3, `#${this.stripAlphaIfNeeded(this.state.mixedColor.slice(1))}`);
|
|
144
|
+
}, () => this.setState({
|
|
145
|
+
openColorPicker: false,
|
|
146
|
+
mixedColor: this.state.hexCode
|
|
147
|
+
}))));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
this.renderDefaultPopoverContent = () => {
|
|
151
|
+
var _this$props$styles3, _this$props4, _this$props4$colorMix, _this$props5, _this$props5$colorMix, _this$props$styles4, _this$props6, _this$props6$colorMix, _this$props$styles5, _this$props$styles6, _this$props$colorMixe, _this$props$colorMixe2;
|
|
152
|
+
|
|
153
|
+
return (0, _emotion.jsx)(_react.default.Fragment, null, (0, _emotion.jsx)("div", {
|
|
154
|
+
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.popoverContent
|
|
155
|
+
}, ((_this$props4 = this.props) === null || _this$props4 === void 0 ? void 0 : (_this$props4$colorMix = _this$props4.colorMixerSettings) === null || _this$props4$colorMix === void 0 ? void 0 : _this$props4$colorMix.colorMixer) && (0, _emotion.jsx)(_ColorMixer.default, {
|
|
156
|
+
value: `#${this.state.mixedColor}`,
|
|
157
|
+
onChange: newColor => this.setState({
|
|
158
|
+
mixedColor: colorToHex8(newColor).slice(1)
|
|
159
|
+
}),
|
|
160
|
+
withAlpha: this.props.colorMixerSettings.colorMixer.withAlpha,
|
|
161
|
+
rgbRedInputScreenReaderLabel: this.props.colorMixerSettings.colorMixer.rgbRedInputScreenReaderLabel,
|
|
162
|
+
rgbGreenInputScreenReaderLabel: this.props.colorMixerSettings.colorMixer.rgbGreenInputScreenReaderLabel,
|
|
163
|
+
rgbBlueInputScreenReaderLabel: this.props.colorMixerSettings.colorMixer.rgbBlueInputScreenReaderLabel,
|
|
164
|
+
rgbAlphaInputScreenReaderLabel: this.props.colorMixerSettings.colorMixer.rgbAlphaInputScreenReaderLabel,
|
|
165
|
+
colorSliderNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.colorSliderNavigationExplanationScreenReaderLabel,
|
|
166
|
+
alphaSliderNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.alphaSliderNavigationExplanationScreenReaderLabel,
|
|
167
|
+
colorPaletteNavigationExplanationScreenReaderLabel: this.props.colorMixerSettings.colorMixer.colorPaletteNavigationExplanationScreenReaderLabel
|
|
168
|
+
}), ((_this$props5 = this.props) === null || _this$props5 === void 0 ? void 0 : (_this$props5$colorMix = _this$props5.colorMixerSettings) === null || _this$props5$colorMix === void 0 ? void 0 : _this$props5$colorMix.colorPreset) && (0, _emotion.jsx)("div", {
|
|
169
|
+
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.popoverContentBlock
|
|
170
|
+
}, (0, _emotion.jsx)(_ColorPreset.default, {
|
|
171
|
+
label: this.props.colorMixerSettings.colorPreset.label,
|
|
172
|
+
colors: this.props.colorMixerSettings.colorPreset.colors,
|
|
173
|
+
selected: this.state.mixedColor,
|
|
174
|
+
onSelect: color => this.setState({
|
|
175
|
+
mixedColor: color.slice(1)
|
|
176
|
+
})
|
|
177
|
+
})), ((_this$props6 = this.props) === null || _this$props6 === void 0 ? void 0 : (_this$props6$colorMix = _this$props6.colorMixerSettings) === null || _this$props6$colorMix === void 0 ? void 0 : _this$props6$colorMix.colorContrast) && (0, _emotion.jsx)("div", {
|
|
178
|
+
css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.popoverContentBlock
|
|
179
|
+
}, (0, _emotion.jsx)(_ColorContrast.default, {
|
|
180
|
+
firstColor: this.props.colorMixerSettings.colorContrast.firstColor,
|
|
181
|
+
secondColor: `#${this.stripAlphaIfNeeded(this.state.mixedColor)}`,
|
|
182
|
+
label: this.props.colorMixerSettings.colorContrast.label,
|
|
183
|
+
successLabel: this.props.colorMixerSettings.colorContrast.successLabel,
|
|
184
|
+
failureLabel: this.props.colorMixerSettings.colorContrast.failureLabel,
|
|
185
|
+
normalTextLabel: this.props.colorMixerSettings.colorContrast.normalTextLabel,
|
|
186
|
+
largeTextLabel: this.props.colorMixerSettings.colorContrast.largeTextLabel,
|
|
187
|
+
graphicsTextLabel: this.props.colorMixerSettings.colorContrast.graphicsTextLabel,
|
|
188
|
+
firstColorLabel: this.props.colorMixerSettings.colorContrast.firstColorLabel,
|
|
189
|
+
secondColorLabel: this.props.colorMixerSettings.colorContrast.secondColorLabel
|
|
190
|
+
}))), (0, _emotion.jsx)("div", {
|
|
191
|
+
css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.popoverFooter
|
|
192
|
+
}, (0, _emotion.jsx)(_Button.Button, {
|
|
193
|
+
onClick: () => this.setState({
|
|
194
|
+
openColorPicker: false,
|
|
195
|
+
mixedColor: this.state.hexCode
|
|
196
|
+
}),
|
|
197
|
+
color: "secondary",
|
|
198
|
+
margin: "xx-small"
|
|
199
|
+
}, (_this$props$colorMixe = this.props.colorMixerSettings) === null || _this$props$colorMixe === void 0 ? void 0 : _this$props$colorMixe.popoverCloseButtonLabel), (0, _emotion.jsx)(_Button.Button, {
|
|
200
|
+
onClick: () => {
|
|
201
|
+
if (typeof this.props.onChange === 'function') {
|
|
202
|
+
this.props.onChange(`#${this.stripAlphaIfNeeded(this.state.mixedColor)}`);
|
|
203
|
+
this.setState({
|
|
204
|
+
openColorPicker: false
|
|
205
|
+
});
|
|
206
|
+
} else {
|
|
207
|
+
this.setState({
|
|
208
|
+
openColorPicker: false,
|
|
209
|
+
hexCode: `${this.stripAlphaIfNeeded(this.state.mixedColor)}`
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
color: "primary",
|
|
214
|
+
margin: "xx-small"
|
|
215
|
+
}, (_this$props$colorMixe2 = this.props.colorMixerSettings) === null || _this$props$colorMixe2 === void 0 ? void 0 : _this$props$colorMixe2.popoverAddButtonLabel)));
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
this.state = {
|
|
219
|
+
hexCode: '',
|
|
220
|
+
showHelperErrorMessages: false,
|
|
221
|
+
openColorPicker: false,
|
|
222
|
+
mixedColor: ''
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
componentDidMount() {
|
|
227
|
+
var _this$props$makeStyle, _this$props7, _this$props$value;
|
|
228
|
+
|
|
229
|
+
(_this$props$makeStyle = (_this$props7 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props7, { ...this.state,
|
|
230
|
+
isSimple: this.isSimple
|
|
231
|
+
});
|
|
232
|
+
this.checkSettings();
|
|
233
|
+
this.props.value && this.setState({
|
|
234
|
+
hexCode: (_this$props$value = this.props.value) === null || _this$props$value === void 0 ? void 0 : _this$props$value.slice(1)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
componentDidUpdate(prevProps) {
|
|
239
|
+
var _this$props$makeStyle2, _this$props8;
|
|
240
|
+
|
|
241
|
+
(_this$props$makeStyle2 = (_this$props8 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props8, { ...this.state,
|
|
242
|
+
isSimple: this.isSimple
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (prevProps.value !== this.props.value) {
|
|
246
|
+
var _this$props$value2;
|
|
247
|
+
|
|
248
|
+
this.setState({
|
|
249
|
+
showHelperErrorMessages: false,
|
|
250
|
+
hexCode: ((_this$props$value2 = this.props.value) === null || _this$props$value2 === void 0 ? void 0 : _this$props$value2.slice(1)) || ''
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
this.checkSettings();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
get renderMode() {
|
|
258
|
+
if (this.props.children) {
|
|
259
|
+
return 'customPopover';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (this.props.colorMixerSettings) {
|
|
263
|
+
return 'defaultPopover';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return 'simple';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
get isSimple() {
|
|
270
|
+
return this.renderMode === 'simple';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
get isDefaultPopover() {
|
|
274
|
+
return this.renderMode === 'defaultPopover';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
get isCustomPopover() {
|
|
278
|
+
return this.renderMode === 'customPopover';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
getMinContrast(strength) {
|
|
282
|
+
return {
|
|
283
|
+
min: 3,
|
|
284
|
+
mid: 4.5,
|
|
285
|
+
max: 7
|
|
286
|
+
}[strength];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
renderMessages() {
|
|
290
|
+
var _this$props$checkCont;
|
|
291
|
+
|
|
292
|
+
const _this$state = this.state,
|
|
293
|
+
hexCode = _this$state.hexCode,
|
|
294
|
+
showHelperErrorMessages = _this$state.showHelperErrorMessages;
|
|
295
|
+
const isValidHex = (0, _isValid.isValid)(hexCode);
|
|
296
|
+
const _this$props9 = this.props,
|
|
297
|
+
checkContrast = _this$props9.checkContrast,
|
|
298
|
+
renderMessages = _this$props9.renderMessages,
|
|
299
|
+
renderInvalidColorMessage = _this$props9.renderInvalidColorMessage,
|
|
300
|
+
renderIsRequiredMessage = _this$props9.renderIsRequiredMessage,
|
|
301
|
+
isRequired = _this$props9.isRequired;
|
|
302
|
+
const contrast = isValidHex ? (0, _contrast.contrast)(((_this$props$checkCont = this.props.checkContrast) === null || _this$props$checkCont === void 0 ? void 0 : _this$props$checkCont.contrastAgainst) || '#fff', hexCode, 2) : void 0;
|
|
303
|
+
const contrastStrength = checkContrast !== null && checkContrast !== void 0 && checkContrast.contrastStrength ? checkContrast.contrastStrength : 'mid';
|
|
304
|
+
const minContrast = this.getMinContrast(contrastStrength);
|
|
305
|
+
let invalidColorMessages = [];
|
|
306
|
+
let isRequiredMessages = [];
|
|
307
|
+
let generalMessages = [];
|
|
308
|
+
let contrastMessages = [];
|
|
309
|
+
|
|
310
|
+
if (checkContrast && contrast) {
|
|
311
|
+
const renderContrastSuccessMessage = checkContrast.renderContrastSuccessMessage,
|
|
312
|
+
renderContrastErrorMessage = checkContrast.renderContrastErrorMessage;
|
|
313
|
+
|
|
314
|
+
if (contrast < minContrast) {
|
|
315
|
+
contrastMessages = typeof renderContrastErrorMessage === 'function' ? renderContrastErrorMessage(contrast, minContrast) : checkContrast.isStrict ? [{
|
|
316
|
+
type: 'error',
|
|
317
|
+
text: ''
|
|
318
|
+
}] : [];
|
|
319
|
+
} else if (typeof renderContrastSuccessMessage === 'function') {
|
|
320
|
+
contrastMessages = renderContrastSuccessMessage(contrast, minContrast);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (showHelperErrorMessages && hexCode !== '' && !isValidHex && typeof renderInvalidColorMessage === 'function') {
|
|
325
|
+
invalidColorMessages = renderInvalidColorMessage(hexCode);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (isRequired && showHelperErrorMessages && hexCode === '') {
|
|
329
|
+
isRequiredMessages = typeof renderIsRequiredMessage === 'function' ? renderIsRequiredMessage() : [{
|
|
330
|
+
type: 'error',
|
|
331
|
+
text: '*'
|
|
332
|
+
}];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (typeof renderMessages === 'function') {
|
|
336
|
+
generalMessages = renderMessages(hexCode, isValidHex, minContrast, contrast);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return [...invalidColorMessages, ...isRequiredMessages, ...generalMessages, ...contrastMessages];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
renderBeforeInput() {
|
|
343
|
+
const styles = this.props.styles;
|
|
344
|
+
return (0, _emotion.jsx)("div", {
|
|
345
|
+
css: styles === null || styles === void 0 ? void 0 : styles.simpleColorContainer
|
|
346
|
+
}, this.isSimple && (0, _emotion.jsx)(_ColorIndicator.default, {
|
|
347
|
+
color: `#${this.state.hexCode}`
|
|
348
|
+
}), (0, _emotion.jsx)("div", {
|
|
349
|
+
css: styles === null || styles === void 0 ? void 0 : styles.hashMarkContainer
|
|
350
|
+
}, "#"));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
renderAfterInput() {
|
|
354
|
+
const _this$props10 = this.props,
|
|
355
|
+
checkContrast = _this$props10.checkContrast,
|
|
356
|
+
styles = _this$props10.styles;
|
|
357
|
+
const hexCode = this.state.hexCode;
|
|
358
|
+
|
|
359
|
+
if (checkContrast && (0, _isValid.isValid)(hexCode)) {
|
|
360
|
+
const contrast = (0, _contrast.contrast)(checkContrast.contrastAgainst || '#fff', hexCode, 2);
|
|
361
|
+
const minContrast = this.getMinContrast(checkContrast.contrastStrength ? checkContrast.contrastStrength : 'mid');
|
|
362
|
+
|
|
363
|
+
if (minContrast >= contrast) {
|
|
364
|
+
return (0, _emotion.jsx)("div", {
|
|
365
|
+
css: styles === null || styles === void 0 ? void 0 : styles.errorIcons
|
|
366
|
+
}, checkContrast.isStrict ? _IconTroubleLine || (_IconTroubleLine = (0, _emotion.jsx)(_IconTroubleLine2.IconTroubleLine, null)) : _IconWarningLine || (_IconWarningLine = (0, _emotion.jsx)(_IconWarningLine2.IconWarningLine, null)));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (0, _emotion.jsx)("div", {
|
|
370
|
+
css: styles === null || styles === void 0 ? void 0 : styles.successIcon
|
|
371
|
+
}, _IconCheckDarkLine || (_IconCheckDarkLine = (0, _emotion.jsx)(_IconCheckDarkLine2.IconCheckDarkLine, null)));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
handleOnChange(_event, value) {
|
|
378
|
+
const onChange = this.props.onChange;
|
|
379
|
+
|
|
380
|
+
if (value.length > (this.props.withAlpha ? 8 : 6) || value.split('').find(char => !acceptedCharactersForHEX.includes(char)) !== void 0) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (typeof onChange === 'function') {
|
|
385
|
+
onChange(`#${value}`);
|
|
386
|
+
} else {
|
|
387
|
+
this.setState({
|
|
388
|
+
showHelperErrorMessages: false,
|
|
389
|
+
hexCode: value
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
handleOnPaste(event) {
|
|
395
|
+
const pasted = event.clipboardData.getData('Text');
|
|
396
|
+
let toPaste = pasted;
|
|
397
|
+
|
|
398
|
+
if (pasted[0] && pasted[0] === '#') {
|
|
399
|
+
toPaste = pasted.slice(1);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (this.props.withAlpha && toPaste.length > 8 || !this.props.withAlpha && toPaste.length > 6) {
|
|
403
|
+
return event.preventDefault();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const newHex = `${this.state.hexCode}${toPaste}`;
|
|
407
|
+
|
|
408
|
+
if ((0, _isValid.isValid)(newHex)) {
|
|
409
|
+
if (typeof this.props.onChange === 'function') {
|
|
410
|
+
this.props.onChange(`#${newHex}`);
|
|
411
|
+
} else {
|
|
412
|
+
this.setState({
|
|
413
|
+
showHelperErrorMessages: false,
|
|
414
|
+
hexCode: newHex
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
handleOnBlur() {
|
|
423
|
+
this.setState({
|
|
424
|
+
showHelperErrorMessages: true
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
renderLabel() {
|
|
429
|
+
const _this$props11 = this.props,
|
|
430
|
+
label = _this$props11.label,
|
|
431
|
+
tooltip = _this$props11.tooltip,
|
|
432
|
+
styles = _this$props11.styles;
|
|
433
|
+
return tooltip ? (0, _emotion.jsx)("div", null, (0, _emotion.jsx)("span", {
|
|
434
|
+
css: styles === null || styles === void 0 ? void 0 : styles.label
|
|
435
|
+
}, label), (0, _emotion.jsx)("span", null, (0, _emotion.jsx)(_Tooltip.Tooltip, {
|
|
436
|
+
renderTip: tooltip
|
|
437
|
+
}, _IconInfoLine || (_IconInfoLine = (0, _emotion.jsx)(_IconInfoLine2.IconInfoLine, {
|
|
438
|
+
tabIndex: -1
|
|
439
|
+
}))))) : label;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
render() {
|
|
443
|
+
var _this$props$styles7, _this$props$styles8, _this$props$styles9;
|
|
444
|
+
|
|
445
|
+
const _this$props12 = this.props,
|
|
446
|
+
checkContrast = _this$props12.checkContrast,
|
|
447
|
+
colorMixerSettings = _this$props12.colorMixerSettings,
|
|
448
|
+
disabled = _this$props12.disabled,
|
|
449
|
+
elementRef = _this$props12.elementRef,
|
|
450
|
+
isRequired = _this$props12.isRequired,
|
|
451
|
+
label = _this$props12.label,
|
|
452
|
+
onChange = _this$props12.onChange,
|
|
453
|
+
placeholderText = _this$props12.placeholderText,
|
|
454
|
+
popoverButtonScreenReaderLabel = _this$props12.popoverButtonScreenReaderLabel,
|
|
455
|
+
renderInvalidColorMessage = _this$props12.renderInvalidColorMessage,
|
|
456
|
+
renderIsRequiredMessage = _this$props12.renderIsRequiredMessage,
|
|
457
|
+
renderMessages = _this$props12.renderMessages,
|
|
458
|
+
tooltip = _this$props12.tooltip,
|
|
459
|
+
value = _this$props12.value,
|
|
460
|
+
width = _this$props12.width,
|
|
461
|
+
withAlpha = _this$props12.withAlpha,
|
|
462
|
+
props = (0, _objectWithoutProperties2.default)(_this$props12, _excluded);
|
|
463
|
+
return (0, _emotion.jsx)("div", Object.assign({}, (0, _passthroughProps.passthroughProps)(props), {
|
|
464
|
+
css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.colorPicker,
|
|
465
|
+
ref: this.handleRef
|
|
466
|
+
}), (0, _emotion.jsx)(_TextInput.TextInput, {
|
|
467
|
+
isRequired: isRequired,
|
|
468
|
+
disabled: disabled,
|
|
469
|
+
renderLabel: () => this.renderLabel(),
|
|
470
|
+
display: "inline-block",
|
|
471
|
+
width: width,
|
|
472
|
+
placeholder: placeholderText,
|
|
473
|
+
themeOverride: {
|
|
474
|
+
padding: ''
|
|
475
|
+
},
|
|
476
|
+
renderAfterInput: this.renderAfterInput(),
|
|
477
|
+
renderBeforeInput: this.renderBeforeInput(),
|
|
478
|
+
value: this.state.hexCode,
|
|
479
|
+
onChange: (event, value) => this.handleOnChange(event, value),
|
|
480
|
+
onPaste: event => this.handleOnPaste(event),
|
|
481
|
+
onBlur: () => this.handleOnBlur(),
|
|
482
|
+
messages: this.renderMessages()
|
|
483
|
+
}), !this.isSimple && (0, _emotion.jsx)("div", {
|
|
484
|
+
css: (_this$props$styles8 = this.props.styles) === null || _this$props$styles8 === void 0 ? void 0 : _this$props$styles8.colorMixerButtonContainer
|
|
485
|
+
}, (0, _emotion.jsx)("div", {
|
|
486
|
+
css: (_this$props$styles9 = this.props.styles) === null || _this$props$styles9 === void 0 ? void 0 : _this$props$styles9.colorMixerButtonWrapper
|
|
487
|
+
}, this.renderPopover())));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
}, _class2.displayName = "ColorPicker", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorPicker', _class2.defaultProps = {
|
|
491
|
+
elementRef: () => null,
|
|
492
|
+
disabled: false,
|
|
493
|
+
label: 'Color',
|
|
494
|
+
checkContrast: false,
|
|
495
|
+
width: '22.5rem',
|
|
496
|
+
withAlpha: false
|
|
497
|
+
}, _class2)) || _class) || _class);
|
|
498
|
+
exports.ColorPicker = ColorPicker;
|
|
499
|
+
var _default = ColorPicker;
|
|
500
|
+
exports.default = _default;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
checkContrast: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.object]),
|
|
37
|
+
colorMixerSettings: _propTypes.default.object,
|
|
38
|
+
children: _propTypes.default.func,
|
|
39
|
+
disabled: _propTypes.default.bool,
|
|
40
|
+
elementRef: _propTypes.default.func,
|
|
41
|
+
isRequired: _propTypes.default.bool,
|
|
42
|
+
label: _propTypes.default.node,
|
|
43
|
+
onChange: _propTypes.default.func,
|
|
44
|
+
placeholderText: _propTypes.default.string,
|
|
45
|
+
popoverScreenReaderLabel: _propTypes.default.string,
|
|
46
|
+
popoverButtonScreenReaderLabel: _propTypes.default.string,
|
|
47
|
+
popoverMaxHeight: _propTypes.default.string,
|
|
48
|
+
renderInvalidColorMessage: _propTypes.default.func,
|
|
49
|
+
renderIsRequiredMessage: _propTypes.default.func,
|
|
50
|
+
renderMessages: _propTypes.default.func,
|
|
51
|
+
tooltip: _propTypes.default.node,
|
|
52
|
+
value: _propTypes.default.string,
|
|
53
|
+
width: _propTypes.default.string,
|
|
54
|
+
withAlpha: _propTypes.default.bool
|
|
55
|
+
};
|
|
56
|
+
exports.propTypes = propTypes;
|
|
57
|
+
const allowedProps = ['checkContrast', 'colorMixerSettings', 'children', 'disabled', 'elementRef', 'isRequired', 'label', 'onChange', 'placeholderText', 'popoverScreenReaderLabel', 'popoverButtonScreenReaderLabel', 'popoverMaxHeight', 'renderInvalidColorMessage', 'renderIsRequiredMessage', 'renderMessages', 'tooltip', 'value', 'width', 'withAlpha'];
|
|
58
|
+
exports.allowedProps = allowedProps;
|
|
@@ -0,0 +1,127 @@
|
|
|
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, props, state) => {
|
|
43
|
+
const hashMarkColor = componentTheme.hashMarkColor,
|
|
44
|
+
errorIconColor = componentTheme.errorIconColor,
|
|
45
|
+
warningIconColor = componentTheme.warningIconColor,
|
|
46
|
+
successIconColor = componentTheme.successIconColor;
|
|
47
|
+
const checkContrast = props.checkContrast,
|
|
48
|
+
popoverMaxHeight = props.popoverMaxHeight;
|
|
49
|
+
const isSimple = state.isSimple;
|
|
50
|
+
return {
|
|
51
|
+
colorPicker: {
|
|
52
|
+
label: 'colorPicker',
|
|
53
|
+
display: 'flex'
|
|
54
|
+
},
|
|
55
|
+
simpleColorContainer: {
|
|
56
|
+
label: 'colorPicker__simpleColorContainer',
|
|
57
|
+
display: 'flex',
|
|
58
|
+
paddingLeft: componentTheme.simpleColorContainerLeftPadding,
|
|
59
|
+
alignItems: 'center'
|
|
60
|
+
},
|
|
61
|
+
hashMarkContainer: {
|
|
62
|
+
label: 'colorPicker__hashMarkContainer',
|
|
63
|
+
color: hashMarkColor,
|
|
64
|
+
display: 'inline-block',
|
|
65
|
+
fontSize: '1rem',
|
|
66
|
+
lineHeight: componentTheme.hashMarkContainerLineHeight,
|
|
67
|
+
...(isSimple ? {
|
|
68
|
+
paddingInlineStart: componentTheme.hashMarkContainerLeftPadding,
|
|
69
|
+
paddingInlineEnd: componentTheme.hashMarkContainerRightPadding
|
|
70
|
+
} : {})
|
|
71
|
+
},
|
|
72
|
+
errorIcons: {
|
|
73
|
+
label: 'colorPicker__errorIcons',
|
|
74
|
+
display: 'flex',
|
|
75
|
+
paddingInlineEnd: componentTheme.errorIconsRightPadding,
|
|
76
|
+
color: checkContrast !== null && checkContrast !== void 0 && checkContrast.isStrict ? errorIconColor : warningIconColor
|
|
77
|
+
},
|
|
78
|
+
successIcon: {
|
|
79
|
+
label: 'colorPicker__successIcon',
|
|
80
|
+
display: 'flex',
|
|
81
|
+
paddingInlineEnd: componentTheme.successIconRightPadding,
|
|
82
|
+
color: successIconColor
|
|
83
|
+
},
|
|
84
|
+
label: {
|
|
85
|
+
label: 'colorPicker__label',
|
|
86
|
+
marginInlineEnd: componentTheme.labelRightMargin
|
|
87
|
+
},
|
|
88
|
+
popoverContent: {
|
|
89
|
+
label: 'colorPicker__popoverContent',
|
|
90
|
+
padding: componentTheme.popoverContentPadding
|
|
91
|
+
},
|
|
92
|
+
popoverContentBlock: {
|
|
93
|
+
label: 'colorPicker__popoverContentBlock',
|
|
94
|
+
borderTop: 'solid',
|
|
95
|
+
borderWidth: componentTheme.popoverContentBlockBorderWidth,
|
|
96
|
+
borderColor: componentTheme.popoverSeparatorColor,
|
|
97
|
+
marginTop: componentTheme.popoverContentBlockTopMargin,
|
|
98
|
+
marginBottom: componentTheme.popoverContentBlockBottomMargin
|
|
99
|
+
},
|
|
100
|
+
popoverFooter: {
|
|
101
|
+
label: 'colorPicker__popoverFooter',
|
|
102
|
+
backgroundColor: componentTheme.popoverFooterColor,
|
|
103
|
+
display: 'flex',
|
|
104
|
+
justifyContent: 'flex-end',
|
|
105
|
+
padding: componentTheme.popoverFooterPadding,
|
|
106
|
+
borderTop: `solid ${componentTheme.popoverFooterTopBorderWidth}`,
|
|
107
|
+
borderColor: componentTheme.popoverSeparatorColor
|
|
108
|
+
},
|
|
109
|
+
colorMixerButtonContainer: {
|
|
110
|
+
label: 'colorPicker__colorMixerButtonContainer',
|
|
111
|
+
alignSelf: 'flex-end',
|
|
112
|
+
marginInlineStart: componentTheme.colorMixerButtonContainerLeftMargin
|
|
113
|
+
},
|
|
114
|
+
popoverContentContainer: {
|
|
115
|
+
label: 'colorPicker__popoverContentContainer',
|
|
116
|
+
maxHeight: popoverMaxHeight || '100vh',
|
|
117
|
+
overflow: 'scroll'
|
|
118
|
+
},
|
|
119
|
+
colorMixerButtonWrapper: {
|
|
120
|
+
position: 'absolute',
|
|
121
|
+
top: '2.69rem'
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var _default = generateStyle;
|
|
127
|
+
exports.default = _default;
|