@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
@@ -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
+
25
+ import type { ColorMixerStyle } from './props'
26
+
27
+ /**
28
+ * ---
29
+ * private: true
30
+ * ---
31
+ * Generates the style object from the theme and provided additional information
32
+ * @param {Object} componentTheme The theme variable object.
33
+ * @param {Object} props the props of the component, the style is applied to
34
+ * @param {Object} state the state of the component, the style is applied to
35
+ * @return {Object} The final style object, which will be used in the component
36
+ */
37
+ const generateStyle = (): ColorMixerStyle => {
38
+ return {
39
+ colorMixer: {
40
+ label: 'colorMixer',
41
+ width: '17rem'
42
+ },
43
+ sliderAndPaletteContainer: {
44
+ label: 'colorMixer__sliderAndPaletteContainer',
45
+ display: 'flex',
46
+ flexDirection: 'column'
47
+ }
48
+ }
49
+ }
50
+
51
+ export default generateStyle
@@ -0,0 +1,35 @@
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
+ const shallowCompare = (
26
+ newObj: Record<string, unknown>,
27
+ prevObj: Record<string, unknown>
28
+ ) => {
29
+ for (const key in newObj) {
30
+ if (newObj[key] !== prevObj[key]) return true
31
+ }
32
+ return false
33
+ }
34
+
35
+ export default shallowCompare
@@ -0,0 +1,124 @@
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 {
26
+ find,
27
+ findAll,
28
+ parseQueryArguments,
29
+ findWithText,
30
+ within
31
+ } from '@instructure/ui-test-utils'
32
+
33
+ import { ColorPicker } from '.'
34
+
35
+ /* eslint-disable no-restricted-imports */
36
+ // @ts-expect-error bypass no type definition found error
37
+ import { PopoverLocator } from '@instructure/ui-popover/es/Popover/PopoverLocator'
38
+ /* eslint-enable no-restricted-imports */
39
+
40
+ import { ColorIndicatorLocator } from '../ColorIndicator/ColorIndicatorLocator'
41
+ import { ColorMixerLocator } from '../ColorMixer/ColorMixerLocator'
42
+ import { ColorPresetLocator } from '../ColorPreset/ColorPresetLocator'
43
+
44
+ async function _findColorPreset(...args: any[]) {
45
+ const popoverContent = await PopoverLocator.findContent(...args)
46
+ const colorPreset = await ColorPresetLocator.find(popoverContent.getDOMNode())
47
+
48
+ return ColorIndicatorLocator.findAll(colorPreset.getDOMNode())
49
+ }
50
+
51
+ const customMethods = {
52
+ findTextInput: (...args: any[]) => {
53
+ return find('[id^=TextInput_]', ...args)
54
+ },
55
+ findColorIndicator: (...args: any[]) => {
56
+ return ColorIndicatorLocator.find(...args)
57
+ },
58
+ findInputAfterIcon: (...args: any[]) => {
59
+ return find('[class$=-textInput__afterElement]', ...args)
60
+ },
61
+ findFormMessages: (...args: any[]) => {
62
+ return findAll('[class$=-formFieldMessage]', ...args)
63
+ },
64
+ findPopoverRoot: (...args: any[]) => {
65
+ return PopoverLocator.find(...args)
66
+ },
67
+ findPopoverTrigger: (...args: any[]) => {
68
+ return PopoverLocator.findTrigger(...args)
69
+ },
70
+ findColorMixer: (...args: any[]) => {
71
+ return ColorMixerLocator.find(...args)
72
+ },
73
+ findPopoverContent: (...args: any[]) => {
74
+ const { element, selector, options } = parseQueryArguments(...args)
75
+ return PopoverLocator.findContent(element, selector, {
76
+ ...options,
77
+ customMethods: {
78
+ ...options.customMethods,
79
+ ...customMethods
80
+ }
81
+ })
82
+ },
83
+ findRGBAInputs: async (...args: any[]) => {
84
+ const rgbaInputs = await findAll('[class$=-RGBAInput__rgbInput]', ...args)
85
+
86
+ return Promise.all(rgbaInputs.map((span) => span.find('input')))
87
+ },
88
+ findPopoverButtonWithText: async (...args: any[]) => {
89
+ let el = await findWithText(...args)
90
+
91
+ while (el.getTagName() !== 'button') {
92
+ const parentNode = el.getParentNode()
93
+ if (!parentNode) {
94
+ break
95
+ }
96
+ el = within(parentNode as Element)
97
+ }
98
+
99
+ return el
100
+ },
101
+ findColorPreset: async (...args: []) => {
102
+ return _findColorPreset(...args)
103
+ },
104
+ findColorPresetButtons: async (...args: []) => {
105
+ const colorPresets = await _findColorPreset(...args)
106
+
107
+ const colorPresetButtons = []
108
+
109
+ for (let el of colorPresets) {
110
+ while (el.getTagName() !== 'button') {
111
+ const parentNode = el.getParentNode()
112
+ if (!parentNode) {
113
+ break
114
+ }
115
+ el = within(parentNode as Element) as any
116
+ }
117
+ colorPresetButtons.push(el)
118
+ }
119
+ return colorPresetButtons
120
+ }
121
+ }
122
+
123
+ //@ts-expect-error no selector on class
124
+ export const ColorPickerLocator = locator(ColorPicker.selector, customMethods)
@@ -0,0 +1,420 @@
1
+ ---
2
+ describes: ColorPicker
3
+ ---
4
+
5
+ The `ColorPicker` is a versatile component that can be used to select colors and check their contrast ratios. It has 2 modes of operation:
6
+
7
+ - In the simple, color input mode, it lets the user enter hex codes. It will display the color, validate the hex and check the contrast.
8
+ - In the more complex, color picker mode, the same functionality is available as for the simpler mode, but there is the option to pick a color from a visual color mixer component or from any other method added in a popover.
9
+
10
+ The component can be either `uncontrolled` or `controlled`. If the `onChange` and `value` props are used, it will behave in a `controlled` manner, otherwise `uncontrolled`.
11
+
12
+ ### ColorPicker with default popover content
13
+
14
+ ```js
15
+ ---
16
+ render: false
17
+ example: true
18
+ ---
19
+ class Example extends React.Component {
20
+ constructor(props) {
21
+ super(props);
22
+ this.state = {
23
+ value: ""
24
+ };
25
+ }
26
+
27
+ render() {
28
+ const { value } = this.state;
29
+
30
+ return (
31
+ <ColorPicker
32
+ // value={value}
33
+ // onChange={(value) =>{ this.setState({ value })}}
34
+ label="Color Input"
35
+ tooltip="This is an example"
36
+ placeholderText="Enter HEX"
37
+ popoverButtonScreenReaderLabel="Open color mixer popover"
38
+ withAlpha
39
+ colorMixerSettings={{
40
+ popoverAddButtonLabel: "Add",
41
+ popoverCloseButtonLabel: "Cancel",
42
+ colorMixer: {
43
+ withAlpha: false,
44
+ rgbRedInputScreenReaderLabel:'Input field for red',
45
+ rgbGreenInputScreenReaderLabel:'Input field for green',
46
+ rgbBlueInputScreenReaderLabel:'Input field for blue',
47
+ rgbAlphaInputScreenReaderLabel:'Input field for alpha',
48
+ colorSliderNavigationExplanationScreenReaderLabel:`You are on a color slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`,
49
+ alphaSliderNavigationExplanationScreenReaderLabel:`You are on an alpha slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`,
50
+ colorPaletteNavigationExplanationScreenReaderLabel:`You are on a color palette. To navigate on the palette up, left, down or right, use the 'W', 'A', 'S' and 'D' buttons respectively`
51
+ },
52
+ colorPreset: {
53
+ label: "Choose a nice color",
54
+ colors: [
55
+ "#ffffff",
56
+ "#0CBF94",
57
+ "#0C89BF00",
58
+ "#BF0C6D",
59
+ "#BF8D0C",
60
+ "#ff0000",
61
+ "#576A66",
62
+ "#35423A",
63
+ "#35423F",
64
+ ],
65
+ },
66
+ colorContrast: {
67
+ firstColor: "#FFFF00",
68
+ label: "Color Contrast Ratio",
69
+ successLabel: "PASS",
70
+ failureLabel: "FAIL",
71
+ normalTextLabel: "Normal text",
72
+ largeTextLabel: "Large text",
73
+ graphicsTextLabel: "Graphics text",
74
+ firstColorLabel: "Background",
75
+ secondColorLabel: "Foreground",
76
+ },
77
+ }}
78
+ />
79
+ );
80
+ }
81
+ }
82
+
83
+ render(<Example />);
84
+
85
+
86
+ ```
87
+
88
+ ### ColorPicker with custom popover content
89
+
90
+ ```js
91
+ ---
92
+ render: false
93
+ example: true
94
+ ---
95
+ class Example extends React.Component {
96
+ constructor(props) {
97
+ super(props);
98
+ this.state = {
99
+ value: "",
100
+ };
101
+ }
102
+ renderPopoverContent = (value, onChange, handleAdd, handleClose) => (
103
+ <div>
104
+ <div style={{ padding: "20px" }}>
105
+ <ColorMixer
106
+ withAlpha
107
+ value={value}
108
+ onChange={onChange}
109
+ rgbRedInputScreenReaderLabel='Input field for red'
110
+ rgbGreenInputScreenReaderLabel='Input field for green'
111
+ rgbBlueInputScreenReaderLabel='Input field for blue'
112
+ rgbAlphaInputScreenReaderLabel='Input field for alpha'
113
+ colorSliderNavigationExplanationScreenReaderLabel={`You are on a color slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`}
114
+ alphaSliderNavigationExplanationScreenReaderLabel={`You are on an alpha slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`}
115
+ colorPaletteNavigationExplanationScreenReaderLabel={`You are on a color palette. To navigate on the palette up, left, down or right, use the 'W', 'A', 'S' and 'D' buttons respectively`}
116
+
117
+ />
118
+ <div
119
+ style={{
120
+ borderTop: "solid",
121
+ borderWidth: "1px",
122
+ borderColor: "#C7CDD1",
123
+ margin: "20px 0 20px 0",
124
+ }}
125
+ />
126
+ <ColorPreset
127
+ label="Choose a color"
128
+ colors={[
129
+ "#ffffff",
130
+ "#0CBF94",
131
+ "#0C89BF00",
132
+ "#BF0C6D",
133
+ "#BF8D0C",
134
+ "#ff0000",
135
+ "#576A66",
136
+ "#35423A",
137
+ "#35423F",
138
+ ]}
139
+ selected={value}
140
+ onSelect={onChange}
141
+ />
142
+ <div
143
+ style={{
144
+ borderTop: "solid",
145
+ borderWidth: "1px",
146
+ borderColor: "#C7CDD1",
147
+ margin: "20px 0 20px 0",
148
+ }}
149
+ />
150
+ <ColorContrast
151
+ firstColor="#FFFFFF"
152
+ secondColor={value}
153
+ label="Color Contrast Ratio"
154
+ successLabel="PASS"
155
+ failureLabel="FAIL"
156
+ normalTextLabel="Normal text"
157
+ largeTextLabel="Large text"
158
+ graphicsTextLabel="Graphics text"
159
+ firstColorLabel="Background"
160
+ secondColorLabel="Foreground"
161
+ />
162
+ </div>
163
+ <div
164
+ style={{
165
+ backgroundColor: "#F5F5F5",
166
+ display: "flex",
167
+ flexDirection: "row-reverse",
168
+ padding: "7px",
169
+ borderTop: "solid 1px #C7CDD1",
170
+ }}
171
+ >
172
+ <Button onClick={handleAdd} color="primary" margin="xx-small">
173
+ Add
174
+ </Button>
175
+ <Button onClick={handleClose} color="secondary" margin="xx-small">
176
+ Close
177
+ </Button>
178
+ </div>
179
+ </div>
180
+ );
181
+
182
+ render() {
183
+ return (
184
+ <div>
185
+ <ColorPicker
186
+ value={this.state.value}
187
+ onChange={(value) => {
188
+ this.setState({ value });
189
+ }}
190
+ label="Color Input"
191
+ tooltip="This is an example"
192
+ placeholderText="Enter HEX"
193
+ popoverButtonScreenReaderLabel="Open color mixer popover"
194
+ >
195
+ {this.renderPopoverContent}
196
+ </ColorPicker>
197
+ </div>
198
+ );
199
+ }
200
+ }
201
+
202
+
203
+ render(<Example />);
204
+ ```
205
+
206
+ ### Complex Color input example
207
+
208
+ ```js
209
+ ---
210
+ render: false
211
+ example: true
212
+ ---
213
+ class Example extends React.Component {
214
+ constructor(props) {
215
+ super(props);
216
+
217
+ this.state = {
218
+ value: "",
219
+ withCheckContrast: false,
220
+ contrastStrength: "mid",
221
+ isStrict: false,
222
+ disabled: false,
223
+ isRequired: false,
224
+ contrastAgainst: "#ffffff",
225
+ colors: [
226
+ "#ffffff",
227
+ "#0CBF94",
228
+ "#0C89BF00",
229
+ "#BF0C6D",
230
+ "#BF8D0C",
231
+ "#ff0000",
232
+ "#576A66",
233
+ "#35423A",
234
+ "#35423F",
235
+ ],
236
+ withAlpha: false,
237
+ };
238
+ }
239
+
240
+ render() {
241
+ const {
242
+ withCheckContrast,
243
+ contrastStrength,
244
+ isStrict,
245
+ contrastAgainst,
246
+ disabled,
247
+ isRequired,
248
+ withAlpha,
249
+ value,
250
+ } = this.state;
251
+
252
+ return (
253
+ <View as="div">
254
+ <ColorPicker
255
+ onChange={(value) => this.setState({ value })}
256
+ value={value}
257
+ placeholderText="Enter HEX"
258
+ label="Color Input"
259
+ tooltip="This is an example"
260
+ disabled={disabled}
261
+ isRequired={isRequired}
262
+ withAlpha={withAlpha}
263
+ popoverButtonScreenReaderLabel="Open color mixer popover"
264
+ checkContrast={
265
+ withCheckContrast
266
+ ? {
267
+ isStrict,
268
+ contrastStrength,
269
+ contrastAgainst,
270
+ renderContrastErrorMessage: (contrast, minContrast) => [
271
+ {
272
+ type: "error",
273
+ text: `Not high enough contrast. Minimum required is ${minContrast}:1, current is ${contrast}:1`,
274
+ },
275
+ ],
276
+ }
277
+ : false
278
+ }
279
+ renderInvalidColorMessage={(hexCode) => [
280
+ {
281
+ type: "error",
282
+ text: `Not valid hex color. It should be either 3, 6 or 8 character long.`,
283
+ },
284
+ ]}
285
+ renderIsRequiredMessage={() => [
286
+ {
287
+ type: "error",
288
+ text: `This field is required, please enter a valid hex code`,
289
+ },
290
+ ]}
291
+ />
292
+ <hr />
293
+ <FormFieldGroup description="Settings">
294
+ <Checkbox
295
+ label="isRequired"
296
+ value="small"
297
+ variant="toggle"
298
+ size="small"
299
+ inline
300
+ checked={isRequired}
301
+ onChange={() =>
302
+ this.setState({
303
+ isRequired: !isRequired,
304
+ })
305
+ }
306
+ />
307
+ <Checkbox
308
+ label="withAlpha"
309
+ value="small"
310
+ variant="toggle"
311
+ size="small"
312
+ inline
313
+ checked={withAlpha}
314
+ onChange={() =>
315
+ this.setState({
316
+ withAlpha: !withAlpha,
317
+ value: value.slice(0, 6),
318
+ })
319
+ }
320
+ />
321
+
322
+ <Checkbox
323
+ label="Disabled"
324
+ value="small"
325
+ variant="toggle"
326
+ size="small"
327
+ inline
328
+ checked={disabled}
329
+ onChange={() => this.setState({ disabled: !disabled })}
330
+ />
331
+
332
+ <Checkbox
333
+ label="With contrast checking (checkContrast)"
334
+ value="small"
335
+ variant="toggle"
336
+ size="small"
337
+ inline
338
+ checked={withCheckContrast}
339
+ onChange={() =>
340
+ this.setState({ withCheckContrast: !withCheckContrast })
341
+ }
342
+ />
343
+
344
+ {withCheckContrast && (
345
+ <FormFieldGroup description="Check contrast options">
346
+ <Checkbox
347
+ label="isStrict"
348
+ value="small"
349
+ variant="toggle"
350
+ size="small"
351
+ checked={isStrict}
352
+ onChange={() => this.setState({ isStrict: !isStrict })}
353
+ />
354
+ <RadioInputGroup
355
+ name="contrastStrength"
356
+ description="contrastStrength"
357
+ layout="columns"
358
+ value={contrastStrength}
359
+ onChange={(event, value) =>
360
+ this.setState({ contrastStrength: value })
361
+ }
362
+ >
363
+ <RadioInput label="min (3:1)" value="min" />
364
+ <RadioInput label="mid (4.5:1)" value="mid" />
365
+ <RadioInput label="max (7:1)" value="max" />
366
+ </RadioInputGroup>
367
+
368
+ <ColorPreset
369
+ label="contrastAgainst"
370
+ colors={this.state.colors}
371
+ selected={this.state.contrastAgainst}
372
+ onSelect={(contrastAgainst) =>
373
+ this.setState({ contrastAgainst })
374
+ }
375
+ onPresetChange={(colors) => this.setState({ colors })}
376
+ />
377
+ </FormFieldGroup>
378
+ )}
379
+ </FormFieldGroup>
380
+ </View>
381
+ );
382
+ }
383
+ }
384
+
385
+ render(<Example />);
386
+
387
+
388
+ ```
389
+
390
+ ### Uncontrolled Color Input
391
+
392
+ ```js
393
+ ---
394
+ example: true
395
+ ---
396
+ <div>
397
+ <ColorPicker
398
+ checkContrast={{
399
+ isStrict: false,
400
+ renderContrastSuccessMessage: () => [
401
+ { type: "success", text: "I am a contrast success message" },
402
+ ],
403
+ renderContrastErrorMessage: () => [
404
+ { type: "error", text: "I am a contrast warning message" },
405
+ ],
406
+ }}
407
+ renderMessages={() => [
408
+ { type: "hint", text: "I can display anything, at any time" },
409
+ ]}
410
+ renderInvalidColorMessage={() => [
411
+ { type: "error", text: "I am an invalid color message" },
412
+ ]}
413
+ renderIsRequiredMessage={() => [
414
+ { type: "error", text: "I am a required message" },
415
+ ]}
416
+ placeholderText="Enter HEX"
417
+ />
418
+ </div>;
419
+
420
+ ```