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