@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,293 @@
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 { FormMessage } from '@instructure/ui-form-field'
28
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
29
+ import type {
30
+ ColorPickerTheme,
31
+ OtherHTMLAttributes,
32
+ PropValidators
33
+ } from '@instructure/shared-types'
34
+
35
+ type ContrastStrength = 'min' | 'mid' | 'max'
36
+ type MessageType = Array<FormMessage>
37
+
38
+ type ColorPickerOwnProps = {
39
+ /**
40
+ * Configures the contrast checker. If false, there will be no checking.
41
+ *
42
+ *
43
+ * isStrict: if it's true, it will display an error if false, a warning
44
+ *
45
+ * contrastStrength: can be one of ('min','mid','max'), which translates to 3:1, 4.5:1, 7:1 contrast, defalts to 'mid'
46
+ *
47
+ * contrastAgainst: is the color which the component checks the contrast against. Accepts hex, defaults to #ffffff
48
+ *
49
+ * renderContrastSuccessMessage: if set and the contrast is high enough, it will display the message
50
+ *
51
+ * renderContrastErrorMessage: if set and the contrast is not high enough, it will display the message
52
+ *
53
+ *
54
+ * MessageType: Array<{
55
+ * type: 'success' | 'hint' | 'error' | 'screenreader-only'
56
+ * text: string
57
+ * }>
58
+ */
59
+ checkContrast?: {
60
+ isStrict: boolean
61
+ contrastStrength?: ContrastStrength
62
+ contrastAgainst?: string
63
+ renderContrastSuccessMessage?: (
64
+ contrast: number,
65
+ minContrast: number
66
+ ) => MessageType
67
+
68
+ renderContrastErrorMessage?: (
69
+ contrast: number,
70
+ minContrast: number
71
+ ) => MessageType
72
+ }
73
+
74
+ /**
75
+ * If set, the default popover will appear for the picker. Those components whose corresponding keys aren't provided (e.g. `colorMixer`, `colorPreset` or `colorContrast`)
76
+ * will not be rendered.
77
+ */
78
+ colorMixerSettings?: {
79
+ popoverAddButtonLabel: string
80
+ popoverCloseButtonLabel: string
81
+ colorMixer?: {
82
+ withAlpha: boolean
83
+ rgbRedInputScreenReaderLabel: string
84
+ rgbGreenInputScreenReaderLabel: string
85
+ rgbBlueInputScreenReaderLabel: string
86
+ rgbAlphaInputScreenReaderLabel: string
87
+ colorSliderNavigationExplanationScreenReaderLabel: string
88
+ alphaSliderNavigationExplanationScreenReaderLabel: string
89
+ colorPaletteNavigationExplanationScreenReaderLabel: string
90
+ }
91
+ colorPreset?: {
92
+ colors: Array<string>
93
+ label: string
94
+ }
95
+ colorContrast?: {
96
+ firstColor: string
97
+ label: string
98
+ successLabel: string
99
+ failureLabel: string
100
+ normalTextLabel: string
101
+ largeTextLabel: string
102
+ graphicsTextLabel: string
103
+ firstColorLabel: string
104
+ secondColorLabel: string
105
+ }
106
+ }
107
+ /**
108
+ * If a child function is provided, the component will render it to the popover.
109
+ */
110
+ children?: (
111
+ value: string,
112
+ onChange: (hex: string) => void,
113
+ handleAdd: () => void,
114
+ handleClose: () => void
115
+ ) => Node
116
+ /**
117
+ * Sets the input to disabled state
118
+ */
119
+ disabled?: boolean
120
+
121
+ /**
122
+ * provides a reference to the underlying html root element
123
+ */
124
+ elementRef: (element: Element | null) => void
125
+
126
+ /**
127
+ * If true, it will display a red error ring or a message after a blur event and remove it after a change event
128
+ */
129
+ isRequired?: boolean
130
+
131
+ /**
132
+ * The label of the component
133
+ */
134
+ label: string
135
+
136
+ /**
137
+ * If 'value' is set, this must be set. It'll be called on every change
138
+ */
139
+ onChange?: (value: string) => void
140
+
141
+ /**
142
+ * Placeholder for the inputfield
143
+ */
144
+ placeholderText: string
145
+ /**
146
+ * If set, it will set the popover's max height. Useful when the popover is too big
147
+ */
148
+ popoverMaxHeight?: string
149
+ /**
150
+ * Sets the ScreenReaderLabel for the popover
151
+ */
152
+ popoverScreenReaderLabel?: string
153
+ /**
154
+ * Sets the ScreenReaderLabel for the popover Button
155
+ */
156
+ popoverButtonScreenReaderLabel?: string
157
+ /**
158
+ * If set and the hex is invalid, it will display the message after a blur event and remove it after a change event
159
+ *
160
+ * MessageType: Array<{
161
+ * type: 'success' | 'hint' | 'error' | 'screenreader-only'
162
+ * text: string
163
+ * }>
164
+ */
165
+ renderInvalidColorMessage?: (hexCode: string) => MessageType
166
+
167
+ /**
168
+ * If set, isRequired is true and the input is empty, it will display the message after a blur event and remove it after a change event
169
+ *
170
+ * MessageType: Array<{
171
+ * type: 'success' | 'hint' | 'error' | 'screenreader-only'
172
+ * text: string
173
+ * }>
174
+ */
175
+ renderIsRequiredMessage?: () => MessageType
176
+
177
+ /**
178
+ * If set, it will display the message it returns
179
+ *
180
+ * MessageType: Array<{
181
+ * type: 'success' | 'hint' | 'error' | 'screenreader-only'
182
+ * text: string
183
+ * }>
184
+ */
185
+ renderMessages?: (
186
+ hexCode: string,
187
+ isValidHex: boolean,
188
+ minContrast: number,
189
+ contrast?: number
190
+ ) => MessageType
191
+
192
+ /**
193
+ * If set, an info icon with a tooltip will be displayed
194
+ */
195
+ tooltip?: React.ReactNode
196
+
197
+ /**
198
+ * If set, the component will behave as controlled
199
+ */
200
+ value?: string
201
+
202
+ /**
203
+ * The width of the input.
204
+ */
205
+ width?: string
206
+ /**
207
+ * If true, alpha slider will be rendered. Deafults to false
208
+ */
209
+ withAlpha?: boolean
210
+ }
211
+
212
+ type ColorPickerState = {
213
+ hexCode: string
214
+ showHelperErrorMessages: boolean
215
+ openColorPicker: boolean
216
+ mixedColor: string
217
+ }
218
+
219
+ type PropKeys = keyof ColorPickerOwnProps
220
+
221
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
222
+
223
+ type ColorPickerProps = ColorPickerOwnProps &
224
+ WithStyleProps<ColorPickerTheme, ColorPickerStyle> &
225
+ OtherHTMLAttributes<ColorPickerOwnProps>
226
+
227
+ type ColorPickerStyle = ComponentStyle<
228
+ | 'colorPicker'
229
+ | 'simpleColorContainer'
230
+ | 'hashMarkContainer'
231
+ | 'errorIcons'
232
+ | 'successIcon'
233
+ | 'label'
234
+ | 'popoverContent'
235
+ | 'popoverContentBlock'
236
+ | 'popoverFooter'
237
+ | 'colorMixerButtonContainer'
238
+ | 'popoverContentContainer'
239
+ | 'colorMixerButtonWrapper'
240
+ >
241
+
242
+ const propTypes: PropValidators<PropKeys> = {
243
+ checkContrast: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
244
+ colorMixerSettings: PropTypes.object,
245
+ children: PropTypes.func,
246
+ disabled: PropTypes.bool,
247
+ elementRef: PropTypes.func,
248
+ isRequired: PropTypes.bool,
249
+ label: PropTypes.node,
250
+ onChange: PropTypes.func,
251
+ placeholderText: PropTypes.string,
252
+ popoverScreenReaderLabel: PropTypes.string,
253
+ popoverButtonScreenReaderLabel: PropTypes.string,
254
+ popoverMaxHeight: PropTypes.string,
255
+ renderInvalidColorMessage: PropTypes.func,
256
+ renderIsRequiredMessage: PropTypes.func,
257
+ renderMessages: PropTypes.func,
258
+ tooltip: PropTypes.node,
259
+ value: PropTypes.string,
260
+ width: PropTypes.string,
261
+ withAlpha: PropTypes.bool
262
+ }
263
+
264
+ const allowedProps: AllowedPropKeys = [
265
+ 'checkContrast',
266
+ 'colorMixerSettings',
267
+ 'children',
268
+ 'disabled',
269
+ 'elementRef',
270
+ 'isRequired',
271
+ 'label',
272
+ 'onChange',
273
+ 'placeholderText',
274
+ 'popoverScreenReaderLabel',
275
+ 'popoverButtonScreenReaderLabel',
276
+ 'popoverMaxHeight',
277
+ 'renderInvalidColorMessage',
278
+ 'renderIsRequiredMessage',
279
+ 'renderMessages',
280
+ 'tooltip',
281
+ 'value',
282
+ 'width',
283
+ 'withAlpha'
284
+ ]
285
+
286
+ export type {
287
+ ColorPickerProps,
288
+ ColorPickerStyle,
289
+ ColorPickerState,
290
+ ContrastStrength,
291
+ MessageType
292
+ }
293
+ export { propTypes, allowedProps }
@@ -0,0 +1,131 @@
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 { ColorPickerTheme } from '@instructure/shared-types'
26
+
27
+ import type {
28
+ ColorPickerProps,
29
+ ColorPickerState,
30
+ ColorPickerStyle
31
+ } from './props'
32
+
33
+ /**
34
+ * ---
35
+ * private: true
36
+ * ---
37
+ * Generates the style object from the theme and provided additional information
38
+ * @param {Object} componentTheme The theme variable object.
39
+ * @param {Object} props the props of the component, the style is applied to
40
+ * @param {Object} state the state of the component, the style is applied to
41
+ * @return {Object} The final style object, which will be used in the component
42
+ */
43
+ const generateStyle = (
44
+ componentTheme: ColorPickerTheme,
45
+ props: ColorPickerProps,
46
+ state: ColorPickerState & { isSimple: boolean }
47
+ ): ColorPickerStyle => {
48
+ const { hashMarkColor, errorIconColor, warningIconColor, successIconColor } =
49
+ componentTheme
50
+ const { checkContrast, popoverMaxHeight } = props
51
+ const { isSimple } = state
52
+
53
+ return {
54
+ colorPicker: {
55
+ label: 'colorPicker',
56
+ display: 'flex'
57
+ },
58
+ simpleColorContainer: {
59
+ label: 'colorPicker__simpleColorContainer',
60
+ display: 'flex',
61
+ paddingLeft: componentTheme.simpleColorContainerLeftPadding,
62
+ alignItems: 'center'
63
+ },
64
+ hashMarkContainer: {
65
+ label: 'colorPicker__hashMarkContainer',
66
+ color: hashMarkColor,
67
+ display: 'inline-block',
68
+ fontSize: '1rem',
69
+ lineHeight: componentTheme.hashMarkContainerLineHeight,
70
+ ...(isSimple
71
+ ? {
72
+ paddingInlineStart: componentTheme.hashMarkContainerLeftPadding,
73
+ paddingInlineEnd: componentTheme.hashMarkContainerRightPadding
74
+ }
75
+ : {})
76
+ },
77
+ errorIcons: {
78
+ label: 'colorPicker__errorIcons',
79
+ display: 'flex',
80
+ paddingInlineEnd: componentTheme.errorIconsRightPadding,
81
+ color: checkContrast?.isStrict ? errorIconColor : warningIconColor
82
+ },
83
+ successIcon: {
84
+ label: 'colorPicker__successIcon',
85
+ display: 'flex',
86
+ paddingInlineEnd: componentTheme.successIconRightPadding,
87
+ color: successIconColor
88
+ },
89
+ label: {
90
+ label: 'colorPicker__label',
91
+ marginInlineEnd: componentTheme.labelRightMargin
92
+ },
93
+ popoverContent: {
94
+ label: 'colorPicker__popoverContent',
95
+ padding: componentTheme.popoverContentPadding
96
+ },
97
+ popoverContentBlock: {
98
+ label: 'colorPicker__popoverContentBlock',
99
+ borderTop: 'solid',
100
+ borderWidth: componentTheme.popoverContentBlockBorderWidth,
101
+ borderColor: componentTheme.popoverSeparatorColor,
102
+ marginTop: componentTheme.popoverContentBlockTopMargin,
103
+ marginBottom: componentTheme.popoverContentBlockBottomMargin
104
+ },
105
+ popoverFooter: {
106
+ label: 'colorPicker__popoverFooter',
107
+ backgroundColor: componentTheme.popoverFooterColor,
108
+ display: 'flex',
109
+ justifyContent: 'flex-end',
110
+ padding: componentTheme.popoverFooterPadding,
111
+ borderTop: `solid ${componentTheme.popoverFooterTopBorderWidth}`,
112
+ borderColor: componentTheme.popoverSeparatorColor
113
+ },
114
+ colorMixerButtonContainer: {
115
+ label: 'colorPicker__colorMixerButtonContainer',
116
+ alignSelf: 'flex-end',
117
+ marginInlineStart: componentTheme.colorMixerButtonContainerLeftMargin
118
+ },
119
+ popoverContentContainer: {
120
+ label: 'colorPicker__popoverContentContainer',
121
+ maxHeight: popoverMaxHeight || '100vh',
122
+ overflow: 'scroll'
123
+ },
124
+ colorMixerButtonWrapper: {
125
+ position: 'absolute',
126
+ top: '2.69rem'
127
+ }
128
+ }
129
+ }
130
+
131
+ export default generateStyle
@@ -0,0 +1,80 @@
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 { Theme } from '@instructure/ui-themes'
26
+ import type { ColorPickerTheme } from '@instructure/shared-types'
27
+ import { colorIndicatorBorderColor } from '../ColorIndicator/theme'
28
+
29
+ /**
30
+ * Generates the theme object for the component from the theme and provided additional information
31
+ * @param {Object} theme The actual theme object.
32
+ * @return {Object} The final theme object with the overrides and component variables
33
+ */
34
+ const generateComponentTheme = (theme: Theme): ColorPickerTheme => {
35
+ const { colors, borders, spacing, typography } = theme
36
+
37
+ const componentVariables = {
38
+ hashMarkColor: colors?.ash,
39
+ warningIconColor: colors?.textWarning,
40
+ errorIconColor: colors?.textDanger,
41
+ successIconColor: colors?.textSuccess,
42
+ popoverSeparatorColor: colors?.tiara,
43
+ popoverFooterColor: colors?.porcelain,
44
+ smallBorder: borders?.widthSmall,
45
+ smallSpacing: spacing?.small,
46
+ xSmallSpacing: spacing?.xSmall,
47
+ xxSmallSpacing: spacing?.xxSmall,
48
+ xxxSmallSpacing: spacing?.xxxSmall,
49
+ xLargeFontSize: typography?.fontSizeXLarge,
50
+ checkerboardBackgroundColor: colors.white,
51
+ checkerboardBackgroundImage: `linear-gradient(45deg, ${colors.tiara} 25%, transparent 25%),
52
+ linear-gradient(-45deg, ${colors.tiara} 25%, transparent 25%),
53
+ linear-gradient(45deg, transparent 75%, ${colors.tiara} 75%),
54
+ linear-gradient(-45deg, transparent 75%, ${colors.tiara} 75%)`,
55
+ checkerboardBackgroundSize: '.5rem .5rem',
56
+ checkerboardBackgroundPosition:
57
+ '0 0, 0 .25rem, .25rem -0.25rem, -0.25rem 0px',
58
+ colorIndicatorBorderColor,
59
+ simpleColorContainerLeftPadding: spacing?.xSmall,
60
+ hashMarkContainerLineHeight: typography?.fontSizeXLarge,
61
+ hashMarkContainerLeftPadding: spacing?.xSmall,
62
+ hashMarkContainerRightPadding: spacing?.xxxSmall,
63
+ errorIconsRightPadding: spacing?.small,
64
+ successIconRightPadding: spacing?.small,
65
+ labelRightMargin: spacing?.xxSmall,
66
+ popoverContentPadding: spacing?.small,
67
+ popoverContentBlockBorderWidth: borders?.widthSmall,
68
+ popoverContentBlockTopMargin: spacing?.small,
69
+ popoverContentBlockBottomMargin: spacing?.small,
70
+ popoverFooterPadding: spacing?.xSmall,
71
+ popoverFooterTopBorderWidth: borders?.widthSmall,
72
+ colorMixerButtonContainerLeftMargin: spacing?.xSmall
73
+ }
74
+
75
+ return {
76
+ ...componentVariables
77
+ }
78
+ }
79
+
80
+ export default generateComponentTheme
@@ -0,0 +1,29 @@
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
+
26
+ import { ColorPreset } from './index'
27
+
28
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
29
+ export const ColorPresetLocator = locator(ColorPreset.selector)
@@ -0,0 +1,121 @@
1
+ ---
2
+ describes: ColorPreset
3
+ ---
4
+
5
+ A component for picking a color from a list of colors. Supports adding new colors either programatically through the `colors` prop, or manually with the built in color picker.
6
+
7
+ ### Color Preset
8
+
9
+ ```js
10
+ ---
11
+ render: false
12
+ example: true
13
+ ---
14
+ class Example extends React.Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ selected: "",
19
+ colors: [
20
+ "#ffffff",
21
+ "#0CBF94",
22
+ "#0C89BF00",
23
+ "#BF0C6D",
24
+ "#BF8D0C",
25
+ "#ff0000",
26
+ "#576A66",
27
+ "#35423A",
28
+ "#35423F",
29
+ ],
30
+ };
31
+ }
32
+
33
+ render() {
34
+ return (
35
+ <div>
36
+ <ColorPreset
37
+ label="Choose a color"
38
+ colors={this.state.colors}
39
+ selected={this.state.selected}
40
+ onSelect={(selected) => this.setState({ selected })}
41
+ />
42
+ </div>
43
+ );
44
+ }
45
+ }
46
+
47
+
48
+ render(<Example />);
49
+
50
+
51
+ ```
52
+
53
+ ### Color Preset (with addition, deletion)
54
+
55
+ ```js
56
+ ---
57
+ render: false
58
+ example: true
59
+ ---
60
+ class Example extends React.Component {
61
+ constructor(props) {
62
+ super(props);
63
+ this.state = {
64
+ selected: "",
65
+ colors: [
66
+ "#ffffff",
67
+ "#0CBF94",
68
+ "#0C89BF00",
69
+ "#BF0C6D",
70
+ "#BF8D0C",
71
+ "#ff0000",
72
+ "#576A66",
73
+ "#35423A",
74
+ "#35423F",
75
+ ],
76
+ };
77
+ }
78
+
79
+ render() {
80
+ return (
81
+ <div>
82
+ <ColorPreset
83
+ colors={this.state.colors}
84
+ selected={this.state.selected}
85
+ onSelect={(selected) => this.setState({ selected })}
86
+ addNewPresetButtonScreenReaderLabel='Add new color'
87
+ colorMixerSettings={{
88
+ addNewPresetButtonScreenReaderLabel:'Add new preset button label',
89
+ onPresetChange:(colors) => this.setState({ colors }),
90
+ colorMixer:{
91
+ rgbRedInputScreenReaderLabel:'Input field for red',
92
+ rgbGreenInputScreenReaderLabel:'Input field for green',
93
+ rgbBlueInputScreenReaderLabel:'Input field for blue',
94
+ rgbAlphaInputScreenReaderLabel:'Input field for alpha',
95
+ colorSliderNavigationExplanationScreenReaderLabel:`You are on a color slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`,
96
+ alphaSliderNavigationExplanationScreenReaderLabel:`You are on an alpha slider. To navigate the slider left or right, use the 'A' and 'D' buttons respectively`,
97
+ 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`
98
+ },
99
+ colorContrast:{
100
+ firstColor:"#FF0000",
101
+ secondColor:"#FFFF00",
102
+ label:"Color Contrast Ratio",
103
+ successLabel:"PASS",
104
+ failureLabel:"FAIL",
105
+ normalTextLabel:"Normal text",
106
+ largeTextLabel:"Large text",
107
+ graphicsTextLabel:"Graphics text",
108
+ firstColorLabel:"Background",
109
+ secondColorLabel:"Foreground",
110
+ }
111
+ }}
112
+ />
113
+ </div>
114
+ );
115
+ }
116
+ }
117
+
118
+ render(<Example />);
119
+
120
+
121
+ ```