@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/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@instructure/ui-color-picker",
3
+ "version": "8.25.1-snapshot-20",
4
+ "description": "A UI component library made by Instructure Inc.",
5
+ "author": "Instructure, Inc. Engineering and Product Design",
6
+ "module": "./es/index.js",
7
+ "main": "./lib/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/instructure/instructure-ui.git"
12
+ },
13
+ "homepage": "https://instructure.github.io/instructure-ui/",
14
+ "bugs": "https://github.com/instructure/instructure-ui/issues",
15
+ "scripts": {
16
+ "lint": "run -T ui-test --lint",
17
+ "lint:fix": "run -T ui-test --lint --fix",
18
+ "clean": "run -T ui-build --clean",
19
+ "build": "run -T ui-build --modules es,cjs",
20
+ "build:watch": "run -T ui-build --watch",
21
+ "build:types": "run -T tsc -p tsconfig.build.json",
22
+ "ts:check": "run -T tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
23
+ },
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@babel/runtime": "^7.13.10",
27
+ "@instructure/console": "8.25.1-snapshot-20",
28
+ "@instructure/emotion": "8.25.1-snapshot-20",
29
+ "@instructure/shared-types": "8.25.1-snapshot-20",
30
+ "@instructure/ui-a11y-content": "8.25.1-snapshot-20",
31
+ "@instructure/ui-buttons": "8.25.1-snapshot-20",
32
+ "@instructure/ui-color-utils": "8.25.1-snapshot-20",
33
+ "@instructure/ui-dom-utils": "8.25.1-snapshot-20",
34
+ "@instructure/ui-drilldown": "8.25.1-snapshot-20",
35
+ "@instructure/ui-form-field": "8.25.1-snapshot-20",
36
+ "@instructure/ui-icons": "8.25.1-snapshot-20",
37
+ "@instructure/ui-pill": "8.25.1-snapshot-20",
38
+ "@instructure/ui-popover": "8.25.1-snapshot-20",
39
+ "@instructure/ui-react-utils": "8.25.1-snapshot-20",
40
+ "@instructure/ui-testable": "8.25.1-snapshot-20",
41
+ "@instructure/ui-text": "8.25.1-snapshot-20",
42
+ "@instructure/ui-text-input": "8.25.1-snapshot-20",
43
+ "@instructure/ui-themes": "8.25.1-snapshot-20",
44
+ "@instructure/ui-tooltip": "8.25.1-snapshot-20",
45
+ "@instructure/ui-utils": "8.25.1-snapshot-20",
46
+ "@instructure/ui-view": "8.25.1-snapshot-20",
47
+ "prop-types": "^15"
48
+ },
49
+ "devDependencies": {
50
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-20",
51
+ "@instructure/ui-test-locator": "8.25.1-snapshot-20",
52
+ "@instructure/ui-test-queries": "8.25.1-snapshot-20",
53
+ "@instructure/ui-test-utils": "8.25.1-snapshot-20"
54
+ },
55
+ "peerDependencies": {
56
+ "react": ">=16.8 <=17"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "sideEffects": false
62
+ }
@@ -0,0 +1,51 @@
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
+
27
+ /* eslint-disable no-restricted-imports */
28
+ // @ts-expect-error bypass no type definition found error
29
+ import { PillLocator } from '@instructure/ui-pill/es/Pill/PillLocator'
30
+ /* eslint-enable no-restricted-imports */
31
+
32
+ import { ColorContrast } from './index'
33
+
34
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
35
+ export const ColorContrastLocator = locator(ColorContrast.selector, {
36
+ findPreview: (...args: any[]) => {
37
+ return find('[class$=-colorContrast__colorPreview]', ...args)
38
+ },
39
+ findNormalTextCheckPill: async () => {
40
+ const pills = await PillLocator.findAll()
41
+ return pills[0]
42
+ },
43
+ findLargeTextCheckPill: async () => {
44
+ const pills = await PillLocator.findAll()
45
+ return pills[1]
46
+ },
47
+ findGraphicsCheckPill: async () => {
48
+ const pills = await PillLocator.findAll()
49
+ return pills[2]
50
+ }
51
+ })
@@ -0,0 +1,111 @@
1
+ ---
2
+ describes: ColorContrast
3
+ ---
4
+
5
+ A component for displaying color contrast between two colors. It will perform checks according to the [WCAG 2.1 standard](https://webaim.org/articles/contrast/#ratio), determinig if a given contrast ratio is acceptable for `normal`, `large` or `graphics` texts. `normal` needs to be `4.5`, the other two `3`.
6
+
7
+ ### Color Contrast
8
+
9
+ ```js
10
+ ---
11
+ render: false
12
+ example: true
13
+ ---
14
+ class Example extends React.Component {
15
+ render() {
16
+ return (
17
+ <ColorContrast
18
+ firstColor="#FF0000"
19
+ secondColor="#FFFF00"
20
+ label="Color Contrast Ratio"
21
+ successLabel="PASS"
22
+ failureLabel="FAIL"
23
+ normalTextLabel="Normal text"
24
+ largeTextLabel="Large text"
25
+ graphicsTextLabel="Graphics text"
26
+ firstColorLabel="Background"
27
+ secondColorLabel="Foreground"
28
+ />
29
+ );
30
+ }
31
+ }
32
+
33
+ render(<Example />);
34
+ ```
35
+
36
+ ### In-line Color setting
37
+
38
+ ```js
39
+ ---
40
+ render: false
41
+ example: true
42
+ ---
43
+ class Example extends React.Component {
44
+ constructor(props) {
45
+ super(props);
46
+ this.state = {
47
+ selectedForeGround: "#0CBF94",
48
+ selectedBackGround: "#35423A",
49
+ };
50
+ }
51
+
52
+ render() {
53
+ return (
54
+ <div>
55
+ <ColorPreset
56
+ label="Background"
57
+ colors={[
58
+ "#ffffff",
59
+ "#0CBF94",
60
+ "#0C89BF",
61
+ "#BF0C6D",
62
+ "#BF8D0C",
63
+ "#ff0000",
64
+ "#576A66",
65
+ "#35423A",
66
+ "#35423F",
67
+ ]}
68
+ selected={this.state.selectedBackGround}
69
+ onSelect={(selectedBackGround) =>
70
+ this.setState({ selectedBackGround })
71
+ }
72
+ />
73
+ <ColorPreset
74
+ label="Foreground"
75
+ colors={[
76
+ "#ffffff",
77
+ "#0CBF94",
78
+ "#0C89BF",
79
+ "#BF0C6D",
80
+ "#BF8D0C",
81
+ "#ff0000",
82
+ "#576A66",
83
+ "#35423A",
84
+ "#35423F",
85
+ ]}
86
+ selected={this.state.selectedForeGround}
87
+ onSelect={(selectedForeGround) =>
88
+ this.setState({ selectedForeGround })
89
+ }
90
+ />
91
+ <hr style={{ width: "272px", marginLeft: 0 }} />
92
+ <ColorContrast
93
+ withoutColorPreview
94
+ firstColor={this.state.selectedBackGround}
95
+ secondColor={this.state.selectedForeGround}
96
+ label="Contrast Ratio"
97
+ successLabel="PASS"
98
+ failureLabel="FAIL"
99
+ normalTextLabel="Normal text"
100
+ largeTextLabel="Large text"
101
+ graphicsTextLabel="Graphics text"
102
+ />
103
+ </div>
104
+ );
105
+ }
106
+ }
107
+
108
+ render(<Example />);
109
+
110
+
111
+ ```
@@ -0,0 +1,189 @@
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
+ /** @jsx jsx */
26
+ /** @jsxFrag React.Fragment */
27
+ import React, { Component } from 'react'
28
+
29
+ import { passthroughProps } from '@instructure/ui-react-utils'
30
+ import { testable } from '@instructure/ui-testable'
31
+ import { withStyle, jsx } from '@instructure/emotion'
32
+ import { Text } from '@instructure/ui-text'
33
+ import ColorIndicator from '../ColorIndicator'
34
+
35
+ import type { ColorContrastProps } from './props'
36
+ import { propTypes, allowedProps } from './props'
37
+ import generateStyle from './styles'
38
+ import generateComponentTheme from './theme'
39
+ import {
40
+ contrast as getContrast,
41
+ colorToRGB,
42
+ colorToHex8
43
+ } from '@instructure/ui-color-utils'
44
+ import { Pill } from '@instructure/ui-pill'
45
+
46
+ import type { RGBAType } from '../ColorMixer/props'
47
+
48
+ /**
49
+ ---
50
+ category: components
51
+ ---
52
+ @tsProps
53
+ **/
54
+ @withStyle(generateStyle, generateComponentTheme)
55
+ @testable()
56
+ class ColorContrast extends Component<ColorContrastProps> {
57
+ static propTypes = propTypes
58
+ static allowedProps = allowedProps
59
+ static readonly componentId = 'ColorContrast'
60
+
61
+ constructor(props: ColorContrastProps) {
62
+ super(props)
63
+ }
64
+
65
+ ref: HTMLDivElement | null = null
66
+
67
+ handleRef = (el: HTMLDivElement | null) => {
68
+ const { elementRef } = this.props
69
+
70
+ this.ref = el
71
+
72
+ if (typeof elementRef === 'function') {
73
+ elementRef(el)
74
+ }
75
+ }
76
+
77
+ componentDidMount() {
78
+ this.props.makeStyles?.()
79
+ }
80
+
81
+ componentDidUpdate() {
82
+ this.props.makeStyles?.()
83
+ }
84
+
85
+ renderStatus = (pass: boolean, description: string) => {
86
+ const { successLabel, failureLabel, styles } = this.props
87
+ return (
88
+ <div css={styles?.statusWrapper}>
89
+ <div
90
+ css={pass ? styles?.successDescription : styles?.failureDescription}
91
+ >
92
+ {description}
93
+ </div>
94
+ <div css={styles?.statusIndicatorWrapper}>
95
+ <Pill color={pass ? 'success' : 'danger'}>
96
+ {pass ? successLabel : failureLabel}
97
+ </Pill>
98
+ </div>
99
+ </div>
100
+ )
101
+ }
102
+
103
+ renderColorIndicator = (color: string, label: string) => (
104
+ <>
105
+ <div>
106
+ <div css={this.props.styles?.colorIndicator}>
107
+ <ColorIndicator color={color} />
108
+ </div>
109
+ </div>
110
+
111
+ <div>
112
+ <div css={this.props.styles?.colorIndicatorLabel}>{label}</div>
113
+ <div css={this.props.styles?.pickedColorHex}>{color}</div>
114
+ </div>
115
+ </>
116
+ )
117
+ calcBlendedColor = (c1: RGBAType, c2: RGBAType) => {
118
+ const alpha = 1 - (1 - c1.a) * (1 - c2.a)
119
+ return {
120
+ r: (c2.r * c2.a) / alpha + (c1.r * c1.a * (1 - c2.a)) / alpha,
121
+ g: (c2.g * c2.a) / alpha + (c1.g * c1.a * (1 - c2.a)) / alpha,
122
+ b: (c2.b * c2.a) / alpha + (c1.b * c1.a * (1 - c2.a)) / alpha,
123
+ a: 1
124
+ }
125
+ }
126
+
127
+ //We project the firstColor onto an opaque white background, then we project the secondColor onto
128
+ //the projected first color. We calculate the contrast of these two, projected colors.
129
+ get calcContrast() {
130
+ const c1RGBA = colorToRGB(this.props.firstColor)
131
+ const c2RGBA = colorToRGB(this.props.secondColor)
132
+ const c1OnWhite = this.calcBlendedColor(
133
+ { r: 255, g: 255, b: 255, a: 1 },
134
+ c1RGBA
135
+ )
136
+ const c2OnC1OnWhite = this.calcBlendedColor(c1OnWhite, c2RGBA)
137
+
138
+ return getContrast(colorToHex8(c1OnWhite), colorToHex8(c2OnC1OnWhite), 2)
139
+ }
140
+ render() {
141
+ const {
142
+ styles,
143
+ elementRef,
144
+ failureLabel,
145
+ successLabel,
146
+ withoutColorPreview,
147
+ firstColor,
148
+ secondColor,
149
+ label,
150
+ firstColorLabel,
151
+ secondColorLabel,
152
+ normalTextLabel,
153
+ largeTextLabel,
154
+ graphicsTextLabel,
155
+ ...props
156
+ } = this.props
157
+ const contrast = this.calcContrast
158
+ return (
159
+ <div
160
+ {...passthroughProps(props)}
161
+ ref={this.handleRef}
162
+ css={styles?.colorContrast}
163
+ >
164
+ <div css={this.props.styles?.label}>
165
+ <Text weight="bold" as="div">
166
+ {label}
167
+ </Text>
168
+ </div>
169
+ <Text size="x-large">{contrast}:1</Text>
170
+ {!withoutColorPreview && (
171
+ <div css={this.props.styles?.colorPreview}>
172
+ <div css={this.props.styles?.firstColorPreview}>
173
+ {this.renderColorIndicator(firstColor, firstColorLabel || '')}
174
+ </div>
175
+ <div css={this.props.styles?.secondColorPreview}>
176
+ {this.renderColorIndicator(secondColor, secondColorLabel || '')}
177
+ </div>
178
+ </div>
179
+ )}
180
+ {this.renderStatus(contrast >= 4.5, normalTextLabel)}
181
+ {this.renderStatus(contrast >= 3, largeTextLabel)}
182
+ {this.renderStatus(contrast >= 3, graphicsTextLabel)}
183
+ </div>
184
+ )
185
+ }
186
+ }
187
+
188
+ export { ColorContrast }
189
+ export default ColorContrast
@@ -0,0 +1,140 @@
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
+ import PropTypes from 'prop-types'
26
+
27
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
28
+ import type {
29
+ OtherHTMLAttributes,
30
+ PropValidators,
31
+ ColorContrastTheme
32
+ } from '@instructure/shared-types'
33
+
34
+ type ColorContrastOwnProps = {
35
+ /**
36
+ * Provides a reference to the component's underlying html element.
37
+ */
38
+ elementRef?: (element: Element | null) => void
39
+ /**
40
+ * Text of the failure indicator (Suggested english text: FAIL)
41
+ */
42
+ failureLabel: string
43
+ /**
44
+ * The first color to compare (HEX code)
45
+ */
46
+ firstColor: string
47
+ /**
48
+ * The name of the first color which will be compared
49
+ */
50
+ firstColorLabel?: string
51
+ /**
52
+ * Text of the third check (Suggested english text: Graphics text)
53
+ */
54
+ graphicsTextLabel: string
55
+ /**
56
+ * Label of the component
57
+ */
58
+ label: string
59
+ /**
60
+ * Text of the second check (Suggested english text: Large text)
61
+ */
62
+ largeTextLabel: string
63
+ /**
64
+ * Text of the first check (Suggested english text: Normal text)
65
+ */
66
+ normalTextLabel: string
67
+ /**
68
+ * The second color to compare (HEX code)
69
+ */
70
+ secondColor: string
71
+ /**
72
+ * The name of the second color which will be compared
73
+ */
74
+ secondColorLabel?: string
75
+ /**
76
+ * Text of the success indicator (Suggested english text: PASS)
77
+ */
78
+ successLabel: string
79
+ /**
80
+ * toggles the color preview part of the component
81
+ * if true, firstColorLabel and secondColorLabel is not necessary. Otherwise required
82
+ */
83
+ withoutColorPreview?: boolean
84
+ }
85
+
86
+ type PropKeys = keyof ColorContrastOwnProps
87
+
88
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
89
+
90
+ type ColorContrastProps = ColorContrastOwnProps &
91
+ WithStyleProps<ColorContrastTheme, ColorContrastStyle> &
92
+ OtherHTMLAttributes<ColorContrastOwnProps>
93
+
94
+ type ColorContrastStyle = ComponentStyle<
95
+ | 'colorContrast'
96
+ | 'successDescription'
97
+ | 'failureDescription'
98
+ | 'statusWrapper'
99
+ | 'colorIndicator'
100
+ | 'statusIndicatorWrapper'
101
+ | 'colorIndicatorLabel'
102
+ | 'pickedColorHex'
103
+ | 'colorPreview'
104
+ | 'firstColorPreview'
105
+ | 'secondColorPreview'
106
+ | 'label'
107
+ >
108
+
109
+ const propTypes: PropValidators<PropKeys> = {
110
+ elementRef: PropTypes.func,
111
+ failureLabel: PropTypes.string.isRequired,
112
+ firstColor: PropTypes.string.isRequired,
113
+ firstColorLabel: PropTypes.string,
114
+ graphicsTextLabel: PropTypes.string.isRequired,
115
+ withoutColorPreview: PropTypes.bool,
116
+ label: PropTypes.string.isRequired,
117
+ largeTextLabel: PropTypes.string.isRequired,
118
+ normalTextLabel: PropTypes.string.isRequired,
119
+ secondColor: PropTypes.string.isRequired,
120
+ secondColorLabel: PropTypes.string,
121
+ successLabel: PropTypes.string.isRequired
122
+ }
123
+
124
+ const allowedProps: AllowedPropKeys = [
125
+ 'elementRef',
126
+ 'failureLabel',
127
+ 'firstColor',
128
+ 'firstColorLabel',
129
+ 'graphicsTextLabel',
130
+ 'withoutColorPreview',
131
+ 'label',
132
+ 'largeTextLabel',
133
+ 'normalTextLabel',
134
+ 'secondColor',
135
+ 'secondColorLabel',
136
+ 'successLabel'
137
+ ]
138
+
139
+ export type { ColorContrastProps, ColorContrastStyle }
140
+ export { propTypes, allowedProps }
@@ -0,0 +1,102 @@
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
+ import type { ColorContrastTheme } from '@instructure/shared-types'
26
+ /**
27
+ * ---
28
+ * private: true
29
+ * ---
30
+ * Generates the style object from the theme and provided additional information
31
+ * @param {Object} componentTheme The theme variable object.
32
+ * @param {Object} props the props of the component, the style is applied to
33
+ * @param {Object} state the state of the component, the style is applied to
34
+ * @return {Object} The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = (componentTheme: ColorContrastTheme) => {
37
+ const statusDescriptionStyle = (pass: boolean) => ({
38
+ label: pass
39
+ ? 'colorContrast__successDescription'
40
+ : 'colorContrast__failureDescription',
41
+ flex: 1,
42
+ color: pass ? componentTheme.successColor : componentTheme.failureColor
43
+ })
44
+
45
+ return {
46
+ colorContrast: {
47
+ label: 'colorContrast',
48
+ width: componentTheme.width,
49
+ fontFamily: componentTheme.fontFamily,
50
+ fontWeight: componentTheme.fontWeight,
51
+ lineHeight: componentTheme.lineHeight,
52
+ fontSize: componentTheme.fontSize
53
+ },
54
+ statusWrapper: {
55
+ label: 'colorContrast__statusWrapper',
56
+ width: '100%',
57
+ display: 'flex',
58
+ marginBottom: componentTheme.statusWrapperBottomMargin
59
+ },
60
+ successDescription: statusDescriptionStyle(true),
61
+ failureDescription: statusDescriptionStyle(false),
62
+ colorIndicator: {
63
+ marginInlineEnd: componentTheme.colorIndicatorRightMargin
64
+ },
65
+ statusIndicatorWrapper: {
66
+ label: 'colorContrast__statusIndicatorWrapper',
67
+ flex: 1,
68
+ display: 'flex',
69
+ flexDirection: 'row-reverse'
70
+ },
71
+ colorIndicatorLabel: {
72
+ label: 'colorContrast__colorIndicatorLabel',
73
+ wordBreak: 'break-all'
74
+ },
75
+ pickedColorHex: {
76
+ label: 'colorContrast__pickedColorHex',
77
+ color: componentTheme.pickedHexColor
78
+ },
79
+ colorPreview: {
80
+ label: 'colorContrast__colorPreview',
81
+ display: 'flex',
82
+ width: '100%',
83
+ marginBottom: componentTheme.colorPreviewBottomMargin,
84
+ marginTop: componentTheme.colorPreviewTopMargin
85
+ },
86
+ firstColorPreview: {
87
+ label: 'colorContrast__firstColorPreview',
88
+ display: 'flex',
89
+ flex: 1
90
+ },
91
+ secondColorPreview: {
92
+ label: 'colorContrast__secondColorPreview',
93
+ display: 'flex'
94
+ },
95
+ label: {
96
+ label: 'colorContrast__label',
97
+ marginBottom: componentTheme.labelBottomMargin
98
+ }
99
+ }
100
+ }
101
+
102
+ export default generateStyle