@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.
Files changed (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/es/ColorContrast/ColorContrastLocator.js +54 -0
  4. package/es/ColorContrast/index.js +174 -0
  5. package/es/ColorContrast/props.js +40 -0
  6. package/es/ColorContrast/styles.js +99 -0
  7. package/es/ColorContrast/theme.js +55 -0
  8. package/es/ColorIndicator/ColorIndicatorLocator.js +40 -0
  9. package/es/ColorIndicator/index.js +91 -0
  10. package/es/ColorIndicator/props.js +31 -0
  11. package/es/ColorIndicator/styles.js +70 -0
  12. package/es/ColorIndicator/theme.js +53 -0
  13. package/es/ColorMixer/ColorMixerLocator.js +27 -0
  14. package/es/ColorMixer/ColorPalette/index.js +258 -0
  15. package/es/ColorMixer/ColorPalette/props.js +37 -0
  16. package/es/ColorMixer/ColorPalette/styles.js +81 -0
  17. package/es/ColorMixer/ColorPalette/theme.js +48 -0
  18. package/es/ColorMixer/RGBAInput/index.js +148 -0
  19. package/es/ColorMixer/RGBAInput/props.js +39 -0
  20. package/es/ColorMixer/RGBAInput/styles.js +63 -0
  21. package/es/ColorMixer/RGBAInput/theme.js +43 -0
  22. package/es/ColorMixer/Slider/index.js +218 -0
  23. package/es/ColorMixer/Slider/props.js +38 -0
  24. package/es/ColorMixer/Slider/styles.js +95 -0
  25. package/es/ColorMixer/Slider/theme.js +53 -0
  26. package/es/ColorMixer/index.js +232 -0
  27. package/es/ColorMixer/props.js +40 -0
  28. package/es/ColorMixer/styles.js +49 -0
  29. package/es/ColorMixer/utils/shallowCompare.js +32 -0
  30. package/es/ColorPicker/ColorPickerLocator.js +137 -0
  31. package/es/ColorPicker/index.js +487 -0
  32. package/es/ColorPicker/props.js +47 -0
  33. package/es/ColorPicker/styles.js +119 -0
  34. package/es/ColorPicker/theme.js +76 -0
  35. package/es/ColorPreset/ColorPresetLocator.js +27 -0
  36. package/es/ColorPreset/index.js +268 -0
  37. package/es/ColorPreset/props.js +36 -0
  38. package/es/ColorPreset/styles.js +102 -0
  39. package/es/ColorPreset/theme.js +53 -0
  40. package/es/index.js +28 -0
  41. package/lib/ColorContrast/ColorContrastLocator.js +66 -0
  42. package/lib/ColorContrast/index.js +169 -0
  43. package/lib/ColorContrast/props.js +51 -0
  44. package/lib/ColorContrast/styles.js +107 -0
  45. package/lib/ColorContrast/theme.js +63 -0
  46. package/lib/ColorIndicator/ColorIndicatorLocator.js +51 -0
  47. package/lib/ColorIndicator/index.js +82 -0
  48. package/lib/ColorIndicator/props.js +42 -0
  49. package/lib/ColorIndicator/styles.js +78 -0
  50. package/lib/ColorIndicator/theme.js +63 -0
  51. package/lib/ColorMixer/ColorMixerLocator.js +37 -0
  52. package/lib/ColorMixer/ColorPalette/index.js +252 -0
  53. package/lib/ColorMixer/ColorPalette/props.js +48 -0
  54. package/lib/ColorMixer/ColorPalette/styles.js +90 -0
  55. package/lib/ColorMixer/ColorPalette/theme.js +57 -0
  56. package/lib/ColorMixer/RGBAInput/index.js +142 -0
  57. package/lib/ColorMixer/RGBAInput/props.js +50 -0
  58. package/lib/ColorMixer/RGBAInput/styles.js +71 -0
  59. package/lib/ColorMixer/RGBAInput/theme.js +51 -0
  60. package/lib/ColorMixer/Slider/index.js +211 -0
  61. package/lib/ColorMixer/Slider/props.js +49 -0
  62. package/lib/ColorMixer/Slider/styles.js +103 -0
  63. package/lib/ColorMixer/Slider/theme.js +62 -0
  64. package/lib/ColorMixer/index.js +226 -0
  65. package/lib/ColorMixer/props.js +51 -0
  66. package/lib/ColorMixer/styles.js +57 -0
  67. package/lib/ColorMixer/utils/shallowCompare.js +40 -0
  68. package/lib/ColorPicker/ColorPickerLocator.js +151 -0
  69. package/lib/ColorPicker/index.js +500 -0
  70. package/lib/ColorPicker/props.js +58 -0
  71. package/lib/ColorPicker/styles.js +127 -0
  72. package/lib/ColorPicker/theme.js +85 -0
  73. package/lib/ColorPreset/ColorPresetLocator.js +37 -0
  74. package/lib/ColorPreset/index.js +274 -0
  75. package/lib/ColorPreset/props.js +47 -0
  76. package/lib/ColorPreset/styles.js +110 -0
  77. package/lib/ColorPreset/theme.js +61 -0
  78. package/lib/index.js +45 -0
  79. package/lib/package.json +1 -0
  80. package/package.json +62 -0
  81. package/src/ColorContrast/ColorContrastLocator.ts +51 -0
  82. package/src/ColorContrast/README.md +111 -0
  83. package/src/ColorContrast/index.tsx +189 -0
  84. package/src/ColorContrast/props.ts +140 -0
  85. package/src/ColorContrast/styles.ts +102 -0
  86. package/src/ColorContrast/theme.ts +62 -0
  87. package/src/ColorIndicator/ColorIndicatorLocator.ts +41 -0
  88. package/src/ColorIndicator/README.md +76 -0
  89. package/src/ColorIndicator/index.tsx +89 -0
  90. package/src/ColorIndicator/props.ts +68 -0
  91. package/src/ColorIndicator/styles.ts +88 -0
  92. package/src/ColorIndicator/theme.ts +58 -0
  93. package/src/ColorMixer/ColorMixerLocator.ts +29 -0
  94. package/src/ColorMixer/ColorPalette/index.tsx +250 -0
  95. package/src/ColorMixer/ColorPalette/props.ts +87 -0
  96. package/src/ColorMixer/ColorPalette/styles.ts +94 -0
  97. package/src/ColorMixer/ColorPalette/theme.ts +52 -0
  98. package/src/ColorMixer/README.md +98 -0
  99. package/src/ColorMixer/RGBAInput/index.tsx +172 -0
  100. package/src/ColorMixer/RGBAInput/props.ts +93 -0
  101. package/src/ColorMixer/RGBAInput/styles.ts +69 -0
  102. package/src/ColorMixer/RGBAInput/theme.ts +48 -0
  103. package/src/ColorMixer/Slider/index.tsx +242 -0
  104. package/src/ColorMixer/Slider/props.ts +94 -0
  105. package/src/ColorMixer/Slider/styles.ts +114 -0
  106. package/src/ColorMixer/Slider/theme.ts +59 -0
  107. package/src/ColorMixer/index.tsx +221 -0
  108. package/src/ColorMixer/props.ts +169 -0
  109. package/src/ColorMixer/styles.ts +51 -0
  110. package/src/ColorMixer/utils/shallowCompare.ts +35 -0
  111. package/src/ColorPicker/ColorPickerLocator.ts +124 -0
  112. package/src/ColorPicker/README.md +420 -0
  113. package/src/ColorPicker/index.tsx +609 -0
  114. package/src/ColorPicker/props.ts +293 -0
  115. package/src/ColorPicker/styles.ts +131 -0
  116. package/src/ColorPicker/theme.ts +80 -0
  117. package/src/ColorPreset/ColorPresetLocator.ts +29 -0
  118. package/src/ColorPreset/README.md +121 -0
  119. package/src/ColorPreset/index.tsx +328 -0
  120. package/src/ColorPreset/props.ts +162 -0
  121. package/src/ColorPreset/styles.ts +107 -0
  122. package/src/ColorPreset/theme.ts +58 -0
  123. package/src/index.ts +34 -0
  124. package/tsconfig.build.json +36 -0
  125. package/tsconfig.build.tsbuildinfo +1 -0
  126. package/types/ColorContrast/ColorContrastLocator.d.ts +592 -0
  127. package/types/ColorContrast/ColorContrastLocator.d.ts.map +1 -0
  128. package/types/ColorContrast/index.d.ts +61 -0
  129. package/types/ColorContrast/index.d.ts.map +1 -0
  130. package/types/ColorContrast/props.d.ts +62 -0
  131. package/types/ColorContrast/props.d.ts.map +1 -0
  132. package/types/ColorContrast/styles.d.ts +76 -0
  133. package/types/ColorContrast/styles.d.ts.map +1 -0
  134. package/types/ColorContrast/theme.d.ts +10 -0
  135. package/types/ColorContrast/theme.d.ts.map +1 -0
  136. package/types/ColorIndicator/ColorIndicatorLocator.d.ts +577 -0
  137. package/types/ColorIndicator/ColorIndicatorLocator.d.ts.map +1 -0
  138. package/types/ColorIndicator/index.d.ts +35 -0
  139. package/types/ColorIndicator/index.d.ts.map +1 -0
  140. package/types/ColorIndicator/props.d.ts +25 -0
  141. package/types/ColorIndicator/props.d.ts.map +1 -0
  142. package/types/ColorIndicator/styles.d.ts +15 -0
  143. package/types/ColorIndicator/styles.d.ts.map +1 -0
  144. package/types/ColorIndicator/theme.d.ts +11 -0
  145. package/types/ColorIndicator/theme.d.ts.map +1 -0
  146. package/types/ColorMixer/ColorMixerLocator.d.ts +566 -0
  147. package/types/ColorMixer/ColorMixerLocator.d.ts.map +1 -0
  148. package/types/ColorMixer/ColorPalette/index.d.ts +70 -0
  149. package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -0
  150. package/types/ColorMixer/ColorPalette/props.d.ts +29 -0
  151. package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -0
  152. package/types/ColorMixer/ColorPalette/styles.d.ts +15 -0
  153. package/types/ColorMixer/ColorPalette/styles.d.ts.map +1 -0
  154. package/types/ColorMixer/ColorPalette/theme.d.ts +10 -0
  155. package/types/ColorMixer/ColorPalette/theme.d.ts.map +1 -0
  156. package/types/ColorMixer/RGBAInput/index.d.ts +51 -0
  157. package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -0
  158. package/types/ColorMixer/RGBAInput/props.d.ts +28 -0
  159. package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -0
  160. package/types/ColorMixer/RGBAInput/styles.d.ts +15 -0
  161. package/types/ColorMixer/RGBAInput/styles.d.ts.map +1 -0
  162. package/types/ColorMixer/RGBAInput/theme.d.ts +10 -0
  163. package/types/ColorMixer/RGBAInput/theme.d.ts.map +1 -0
  164. package/types/ColorMixer/Slider/index.d.ts +64 -0
  165. package/types/ColorMixer/Slider/index.d.ts.map +1 -0
  166. package/types/ColorMixer/Slider/props.d.ts +26 -0
  167. package/types/ColorMixer/Slider/props.d.ts.map +1 -0
  168. package/types/ColorMixer/Slider/styles.d.ts +15 -0
  169. package/types/ColorMixer/Slider/styles.d.ts.map +1 -0
  170. package/types/ColorMixer/Slider/theme.d.ts +10 -0
  171. package/types/ColorMixer/Slider/theme.d.ts.map +1 -0
  172. package/types/ColorMixer/index.d.ts +59 -0
  173. package/types/ColorMixer/index.d.ts.map +1 -0
  174. package/types/ColorMixer/props.d.ts +91 -0
  175. package/types/ColorMixer/props.d.ts.map +1 -0
  176. package/types/ColorMixer/styles.d.ts +14 -0
  177. package/types/ColorMixer/styles.d.ts.map +1 -0
  178. package/types/ColorMixer/utils/shallowCompare.d.ts +3 -0
  179. package/types/ColorMixer/utils/shallowCompare.d.ts.map +1 -0
  180. package/types/ColorPicker/ColorPickerLocator.d.ts +4113 -0
  181. package/types/ColorPicker/ColorPickerLocator.d.ts.map +1 -0
  182. package/types/ColorPicker/index.d.ts +158 -0
  183. package/types/ColorPicker/index.d.ts.map +1 -0
  184. package/types/ColorPicker/props.d.ts +166 -0
  185. package/types/ColorPicker/props.d.ts.map +1 -0
  186. package/types/ColorPicker/styles.d.ts +17 -0
  187. package/types/ColorPicker/styles.d.ts.map +1 -0
  188. package/types/ColorPicker/theme.d.ts +10 -0
  189. package/types/ColorPicker/theme.d.ts.map +1 -0
  190. package/types/ColorPreset/ColorPresetLocator.d.ts +566 -0
  191. package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -0
  192. package/types/ColorPreset/index.d.ts +100 -0
  193. package/types/ColorPreset/index.d.ts.map +1 -0
  194. package/types/ColorPreset/props.d.ts +87 -0
  195. package/types/ColorPreset/props.d.ts.map +1 -0
  196. package/types/ColorPreset/styles.d.ts +77 -0
  197. package/types/ColorPreset/styles.d.ts.map +1 -0
  198. package/types/ColorPreset/theme.d.ts +10 -0
  199. package/types/ColorPreset/theme.d.ts.map +1 -0
  200. package/types/index.d.ts +11 -0
  201. package/types/index.d.ts.map +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [8.25.1-snapshot-20](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-20) (2022-06-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * **ui-code-editor:** Add ColorPicker component ([1cbd877](https://github.com/instructure/instructure-ui/commit/1cbd87783da67144ffbd1f6ed535ccd370fd4eeb))
12
+
13
+
14
+
15
+
16
+
17
+ See the instructure-ui mono-repo [change log](#CHANGELOG) for past changes.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ---
2
+ category: packages
3
+ ---
4
+
5
+ ## ui-color-picker
6
+
7
+ [![npm][npm]][npm-url] 
8
+ [![MIT License][license-badge]][license] 
9
+ [![Code of Conduct][coc-badge]][coc]
10
+
11
+ A robust component for picking, mixing, validating colors
12
+
13
+ ### Installation
14
+
15
+ ```sh
16
+ yarn add @instructure/ui-color-picker
17
+ ```
18
+
19
+ ### Components
20
+
21
+ #### ColorPicker
22
+
23
+ The main component. It comes with an input field and can be customized to fit any input need
24
+
25
+ #### ColorIndicator
26
+
27
+ A component displaying a circle with checkerboard background capable of displaying colors
28
+
29
+ #### ColorMixer
30
+
31
+ Made for mixing colors setting `hue`, `saturation`, `luminance` and `alpha` or just typing in an `rgba` color
32
+
33
+ #### ColorPreset
34
+
35
+ Lets the user pick from a collection of preset colors. The list can be modified (added, removed) by the user if needed
36
+
37
+ #### ColorContrast
38
+
39
+ Calculates, visualizes and validates against WCAG 2.1 standards the contrast between two colors
40
+
41
+ [npm]: https://img.shields.io/npm/v/@instructure/ui-color-picker.svg
42
+ [npm-url]: https://npmjs.com/package/@instructure/ui-color-picker
43
+ [license-badge]: https://img.shields.io/npm/l/instructure-ui.svg?style=flat-square
44
+ [license]: https://github.com/instructure/instructure-ui/blob/master/LICENSE
45
+ [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
46
+ [coc]: https://github.com/instructure/instructure-ui/blob/master/CODE_OF_CONDUCT.md
@@ -0,0 +1,54 @@
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 { locator } from '@instructure/ui-test-locator';
25
+ import { find } from '@instructure/ui-test-queries';
26
+ /* eslint-disable no-restricted-imports */
27
+ // @ts-expect-error bypass no type definition found error
28
+
29
+ import { PillLocator } from '@instructure/ui-pill/es/Pill/PillLocator';
30
+ /* eslint-enable no-restricted-imports */
31
+
32
+ import { ColorContrast } from './index'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
33
+
34
+ export const ColorContrastLocator = locator(ColorContrast.selector, {
35
+ findPreview: function () {
36
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37
+ args[_key] = arguments[_key];
38
+ }
39
+
40
+ return find('[class$=-colorContrast__colorPreview]', ...args);
41
+ },
42
+ findNormalTextCheckPill: async () => {
43
+ const pills = await PillLocator.findAll();
44
+ return pills[0];
45
+ },
46
+ findLargeTextCheckPill: async () => {
47
+ const pills = await PillLocator.findAll();
48
+ return pills[1];
49
+ },
50
+ findGraphicsCheckPill: async () => {
51
+ const pills = await PillLocator.findAll();
52
+ return pills[2];
53
+ }
54
+ });
@@ -0,0 +1,174 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["styles", "elementRef", "failureLabel", "successLabel", "withoutColorPreview", "firstColor", "secondColor", "label", "firstColorLabel", "secondColorLabel", "normalTextLabel", "largeTextLabel", "graphicsTextLabel"];
3
+
4
+ var _dec, _dec2, _class, _class2;
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 { passthroughProps } from '@instructure/ui-react-utils';
35
+ import { testable } from '@instructure/ui-testable';
36
+ import { withStyle, jsx } from '@instructure/emotion';
37
+ import { Text } from '@instructure/ui-text';
38
+ import ColorIndicator from '../ColorIndicator';
39
+ import { propTypes, allowedProps } from './props';
40
+ import generateStyle from './styles';
41
+ import generateComponentTheme from './theme';
42
+ import { contrast as getContrast, colorToRGB, colorToHex8 } from '@instructure/ui-color-utils';
43
+ import { Pill } from '@instructure/ui-pill';
44
+
45
+ /**
46
+ ---
47
+ category: components
48
+ ---
49
+ @tsProps
50
+ **/
51
+ let ColorContrast = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class ColorContrast extends Component {
52
+ constructor(props) {
53
+ super(props);
54
+ this.ref = null;
55
+
56
+ this.handleRef = el => {
57
+ const elementRef = this.props.elementRef;
58
+ this.ref = el;
59
+
60
+ if (typeof elementRef === 'function') {
61
+ elementRef(el);
62
+ }
63
+ };
64
+
65
+ this.renderStatus = (pass, description) => {
66
+ const _this$props = this.props,
67
+ successLabel = _this$props.successLabel,
68
+ failureLabel = _this$props.failureLabel,
69
+ styles = _this$props.styles;
70
+ return jsx("div", {
71
+ css: styles === null || styles === void 0 ? void 0 : styles.statusWrapper
72
+ }, jsx("div", {
73
+ css: pass ? styles === null || styles === void 0 ? void 0 : styles.successDescription : styles === null || styles === void 0 ? void 0 : styles.failureDescription
74
+ }, description), jsx("div", {
75
+ css: styles === null || styles === void 0 ? void 0 : styles.statusIndicatorWrapper
76
+ }, jsx(Pill, {
77
+ color: pass ? 'success' : 'danger'
78
+ }, pass ? successLabel : failureLabel)));
79
+ };
80
+
81
+ this.renderColorIndicator = (color, label) => {
82
+ var _this$props$styles, _this$props$styles2, _this$props$styles3;
83
+
84
+ return jsx(React.Fragment, null, jsx("div", null, jsx("div", {
85
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
86
+ }, jsx(ColorIndicator, {
87
+ color: color
88
+ }))), jsx("div", null, jsx("div", {
89
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.colorIndicatorLabel
90
+ }, label), jsx("div", {
91
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.pickedColorHex
92
+ }, color)));
93
+ };
94
+
95
+ this.calcBlendedColor = (c1, c2) => {
96
+ const alpha = 1 - (1 - c1.a) * (1 - c2.a);
97
+ return {
98
+ r: c2.r * c2.a / alpha + c1.r * c1.a * (1 - c2.a) / alpha,
99
+ g: c2.g * c2.a / alpha + c1.g * c1.a * (1 - c2.a) / alpha,
100
+ b: c2.b * c2.a / alpha + c1.b * c1.a * (1 - c2.a) / alpha,
101
+ a: 1
102
+ };
103
+ };
104
+ }
105
+
106
+ componentDidMount() {
107
+ var _this$props$makeStyle, _this$props2;
108
+
109
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
110
+ }
111
+
112
+ componentDidUpdate() {
113
+ var _this$props$makeStyle2, _this$props3;
114
+
115
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
116
+ }
117
+
118
+ //We project the firstColor onto an opaque white background, then we project the secondColor onto
119
+ //the projected first color. We calculate the contrast of these two, projected colors.
120
+ get calcContrast() {
121
+ const c1RGBA = colorToRGB(this.props.firstColor);
122
+ const c2RGBA = colorToRGB(this.props.secondColor);
123
+ const c1OnWhite = this.calcBlendedColor({
124
+ r: 255,
125
+ g: 255,
126
+ b: 255,
127
+ a: 1
128
+ }, c1RGBA);
129
+ const c2OnC1OnWhite = this.calcBlendedColor(c1OnWhite, c2RGBA);
130
+ return getContrast(colorToHex8(c1OnWhite), colorToHex8(c2OnC1OnWhite), 2);
131
+ }
132
+
133
+ render() {
134
+ var _this$props$styles4, _this$props$styles5, _this$props$styles6, _this$props$styles7;
135
+
136
+ const _this$props4 = this.props,
137
+ styles = _this$props4.styles,
138
+ elementRef = _this$props4.elementRef,
139
+ failureLabel = _this$props4.failureLabel,
140
+ successLabel = _this$props4.successLabel,
141
+ withoutColorPreview = _this$props4.withoutColorPreview,
142
+ firstColor = _this$props4.firstColor,
143
+ secondColor = _this$props4.secondColor,
144
+ label = _this$props4.label,
145
+ firstColorLabel = _this$props4.firstColorLabel,
146
+ secondColorLabel = _this$props4.secondColorLabel,
147
+ normalTextLabel = _this$props4.normalTextLabel,
148
+ largeTextLabel = _this$props4.largeTextLabel,
149
+ graphicsTextLabel = _this$props4.graphicsTextLabel,
150
+ props = _objectWithoutProperties(_this$props4, _excluded);
151
+
152
+ const contrast = this.calcContrast;
153
+ return jsx("div", Object.assign({}, passthroughProps(props), {
154
+ ref: this.handleRef,
155
+ css: styles === null || styles === void 0 ? void 0 : styles.colorContrast
156
+ }), jsx("div", {
157
+ css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.label
158
+ }, jsx(Text, {
159
+ weight: "bold",
160
+ as: "div"
161
+ }, label)), jsx(Text, {
162
+ size: "x-large"
163
+ }, contrast, ":1"), !withoutColorPreview && jsx("div", {
164
+ css: (_this$props$styles5 = this.props.styles) === null || _this$props$styles5 === void 0 ? void 0 : _this$props$styles5.colorPreview
165
+ }, jsx("div", {
166
+ css: (_this$props$styles6 = this.props.styles) === null || _this$props$styles6 === void 0 ? void 0 : _this$props$styles6.firstColorPreview
167
+ }, this.renderColorIndicator(firstColor, firstColorLabel || '')), jsx("div", {
168
+ css: (_this$props$styles7 = this.props.styles) === null || _this$props$styles7 === void 0 ? void 0 : _this$props$styles7.secondColorPreview
169
+ }, this.renderColorIndicator(secondColor, secondColorLabel || ''))), this.renderStatus(contrast >= 4.5, normalTextLabel), this.renderStatus(contrast >= 3, largeTextLabel), this.renderStatus(contrast >= 3, graphicsTextLabel));
170
+ }
171
+
172
+ }, _class2.displayName = "ColorContrast", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorContrast', _class2)) || _class) || _class);
173
+ export { ColorContrast };
174
+ export default ColorContrast;
@@ -0,0 +1,40 @@
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
+ elementRef: PropTypes.func,
27
+ failureLabel: PropTypes.string.isRequired,
28
+ firstColor: PropTypes.string.isRequired,
29
+ firstColorLabel: PropTypes.string,
30
+ graphicsTextLabel: PropTypes.string.isRequired,
31
+ withoutColorPreview: PropTypes.bool,
32
+ label: PropTypes.string.isRequired,
33
+ largeTextLabel: PropTypes.string.isRequired,
34
+ normalTextLabel: PropTypes.string.isRequired,
35
+ secondColor: PropTypes.string.isRequired,
36
+ secondColorLabel: PropTypes.string,
37
+ successLabel: PropTypes.string.isRequired
38
+ };
39
+ const allowedProps = ['elementRef', 'failureLabel', 'firstColor', 'firstColorLabel', 'graphicsTextLabel', 'withoutColorPreview', 'label', 'largeTextLabel', 'normalTextLabel', 'secondColor', 'secondColorLabel', 'successLabel'];
40
+ export { propTypes, allowedProps };
@@ -0,0 +1,99 @@
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 => {
36
+ const statusDescriptionStyle = pass => ({
37
+ label: pass ? 'colorContrast__successDescription' : 'colorContrast__failureDescription',
38
+ flex: 1,
39
+ color: pass ? componentTheme.successColor : componentTheme.failureColor
40
+ });
41
+
42
+ return {
43
+ colorContrast: {
44
+ label: 'colorContrast',
45
+ width: componentTheme.width,
46
+ fontFamily: componentTheme.fontFamily,
47
+ fontWeight: componentTheme.fontWeight,
48
+ lineHeight: componentTheme.lineHeight,
49
+ fontSize: componentTheme.fontSize
50
+ },
51
+ statusWrapper: {
52
+ label: 'colorContrast__statusWrapper',
53
+ width: '100%',
54
+ display: 'flex',
55
+ marginBottom: componentTheme.statusWrapperBottomMargin
56
+ },
57
+ successDescription: statusDescriptionStyle(true),
58
+ failureDescription: statusDescriptionStyle(false),
59
+ colorIndicator: {
60
+ marginInlineEnd: componentTheme.colorIndicatorRightMargin
61
+ },
62
+ statusIndicatorWrapper: {
63
+ label: 'colorContrast__statusIndicatorWrapper',
64
+ flex: 1,
65
+ display: 'flex',
66
+ flexDirection: 'row-reverse'
67
+ },
68
+ colorIndicatorLabel: {
69
+ label: 'colorContrast__colorIndicatorLabel',
70
+ wordBreak: 'break-all'
71
+ },
72
+ pickedColorHex: {
73
+ label: 'colorContrast__pickedColorHex',
74
+ color: componentTheme.pickedHexColor
75
+ },
76
+ colorPreview: {
77
+ label: 'colorContrast__colorPreview',
78
+ display: 'flex',
79
+ width: '100%',
80
+ marginBottom: componentTheme.colorPreviewBottomMargin,
81
+ marginTop: componentTheme.colorPreviewTopMargin
82
+ },
83
+ firstColorPreview: {
84
+ label: 'colorContrast__firstColorPreview',
85
+ display: 'flex',
86
+ flex: 1
87
+ },
88
+ secondColorPreview: {
89
+ label: 'colorContrast__secondColorPreview',
90
+ display: 'flex'
91
+ },
92
+ label: {
93
+ label: 'colorContrast__label',
94
+ marginBottom: componentTheme.labelBottomMargin
95
+ }
96
+ };
97
+ };
98
+
99
+ export default generateStyle;
@@ -0,0 +1,55 @@
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
+ * Generates the theme object for the component from the theme and provided additional information
27
+ * @param {Object} theme The actual theme object.
28
+ * @return {Object} The final theme object with the overrides and component variables
29
+ */
30
+ const generateComponentTheme = theme => {
31
+ const colors = theme.colors,
32
+ typography = theme.typography,
33
+ spacing = theme.spacing,
34
+ borders = theme.borders;
35
+ const componentVariables = {
36
+ width: '17rem',
37
+ fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
38
+ fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightNormal,
39
+ lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeight,
40
+ fontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
41
+ statusWrapperBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
42
+ colorIndicatorRightMargin: spacing === null || spacing === void 0 ? void 0 : spacing.small,
43
+ colorPreviewBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.small,
44
+ colorPreviewTopMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xSmall,
45
+ labelBottomMargin: spacing === null || spacing === void 0 ? void 0 : spacing.xxSmall,
46
+ smallBorder: borders.widthSmall,
47
+ successColor: colors.shamrock,
48
+ failureColor: colors.crimson,
49
+ pickedHexColor: colors.ash
50
+ };
51
+ return { ...componentVariables
52
+ };
53
+ };
54
+
55
+ export default generateComponentTheme;
@@ -0,0 +1,40 @@
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 { locator } from '@instructure/ui-test-locator';
25
+ import { ColorIndicator } from './index';
26
+ import { colorToRGB } from '@instructure/ui-color-utils'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
27
+
28
+ export const ColorIndicatorLocator = locator(ColorIndicator.selector, {
29
+ getColorRGBA: element => {
30
+ const _getComputedStyle = getComputedStyle(element),
31
+ boxShadow = _getComputedStyle.boxShadow;
32
+
33
+ if (boxShadow === 'none') {
34
+ return boxShadow;
35
+ }
36
+
37
+ const shadowColor = /rgba?\(\d+,\s\d+,\s\d+(,\s.+)?\)/.exec(boxShadow)[0];
38
+ return colorToRGB(shadowColor);
39
+ }
40
+ });
@@ -0,0 +1,91 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["color", "elementRef"];
3
+
4
+ var _dec, _dec2, _class, _class2;
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
+ import { Component } from 'react';
32
+ import { testable } from '@instructure/ui-testable';
33
+ import { passthroughProps } from '@instructure/ui-react-utils';
34
+ import { withStyle, jsx } from '@instructure/emotion';
35
+ import generateStyle from './styles';
36
+ import generateComponentTheme from './theme';
37
+ import { propTypes, allowedProps } from './props';
38
+ /**
39
+ ---
40
+ category: components
41
+ ---
42
+ @tsProps
43
+ **/
44
+
45
+ let ColorIndicator = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class ColorIndicator extends Component {
46
+ constructor() {
47
+ super(...arguments);
48
+ this.ref = null;
49
+
50
+ this.handleRef = el => {
51
+ const elementRef = this.props.elementRef;
52
+ this.ref = el;
53
+
54
+ if (typeof elementRef === 'function') {
55
+ elementRef(el);
56
+ }
57
+ };
58
+ }
59
+
60
+ componentDidMount() {
61
+ var _this$props$makeStyle, _this$props;
62
+
63
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
64
+ }
65
+
66
+ componentDidUpdate() {
67
+ var _this$props$makeStyle2, _this$props2;
68
+
69
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
70
+ }
71
+
72
+ render() {
73
+ var _this$props$styles;
74
+
75
+ const _this$props3 = this.props,
76
+ color = _this$props3.color,
77
+ elementRef = _this$props3.elementRef,
78
+ props = _objectWithoutProperties(_this$props3, _excluded);
79
+
80
+ return jsx("div", Object.assign({}, passthroughProps(props), {
81
+ ref: this.handleRef,
82
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.colorIndicator
83
+ }));
84
+ }
85
+
86
+ }, _class2.displayName = "ColorIndicator", _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.componentId = 'ColorIndicator', _class2.defaultProps = {
87
+ color: '',
88
+ shape: 'circle'
89
+ }, _class2)) || _class) || _class);
90
+ export default ColorIndicator;
91
+ export { ColorIndicator };
@@ -0,0 +1,31 @@
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
+ color: PropTypes.string,
27
+ elementRef: PropTypes.func,
28
+ shape: PropTypes.oneOf(['circle', 'rectangle'])
29
+ };
30
+ const allowedProps = ['color', 'elementRef', 'shape'];
31
+ export { propTypes, allowedProps };