@instructure/ui-color-picker 8.26.1 → 8.26.2

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 (75) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/ColorContrast/index.js +43 -35
  3. package/es/ColorIndicator/index.js +4 -14
  4. package/es/ColorMixer/ColorPalette/index.js +6 -6
  5. package/es/ColorMixer/RGBAInput/index.js +5 -5
  6. package/es/ColorMixer/Slider/index.js +5 -5
  7. package/es/ColorMixer/index.js +6 -16
  8. package/es/ColorMixer/props.js +2 -2
  9. package/es/ColorPicker/index.js +65 -77
  10. package/es/ColorPicker/props.js +37 -3
  11. package/es/ColorPreset/ColorPresetLocator.js +53 -1
  12. package/es/ColorPreset/index.js +34 -24
  13. package/es/ColorPreset/props.js +32 -3
  14. package/lib/ColorContrast/index.js +47 -38
  15. package/lib/ColorIndicator/index.js +4 -14
  16. package/lib/ColorMixer/ColorPalette/index.js +7 -7
  17. package/lib/ColorMixer/RGBAInput/index.js +5 -5
  18. package/lib/ColorMixer/Slider/index.js +5 -5
  19. package/lib/ColorMixer/index.js +6 -16
  20. package/lib/ColorMixer/props.js +2 -2
  21. package/lib/ColorPicker/index.js +66 -78
  22. package/lib/ColorPicker/props.js +37 -3
  23. package/lib/ColorPreset/ColorPresetLocator.js +58 -1
  24. package/lib/ColorPreset/index.js +35 -25
  25. package/lib/ColorPreset/props.js +32 -3
  26. package/package.json +25 -25
  27. package/src/ColorContrast/index.tsx +60 -32
  28. package/src/ColorContrast/props.ts +4 -2
  29. package/src/ColorIndicator/index.tsx +5 -5
  30. package/src/ColorMixer/ColorPalette/index.tsx +8 -7
  31. package/src/ColorMixer/ColorPalette/props.ts +2 -1
  32. package/src/ColorMixer/RGBAInput/index.tsx +10 -9
  33. package/src/ColorMixer/RGBAInput/props.ts +2 -1
  34. package/src/ColorMixer/Slider/index.tsx +5 -5
  35. package/src/ColorMixer/index.tsx +12 -14
  36. package/src/ColorMixer/props.ts +5 -34
  37. package/src/ColorPicker/README.md +30 -34
  38. package/src/ColorPicker/index.tsx +71 -68
  39. package/src/ColorPicker/props.ts +79 -37
  40. package/src/ColorPreset/ColorPresetLocator.ts +47 -1
  41. package/src/ColorPreset/README.md +4 -2
  42. package/src/ColorPreset/index.tsx +34 -24
  43. package/src/ColorPreset/props.ts +44 -13
  44. package/tsconfig.build.tsbuildinfo +1 -1
  45. package/types/ColorContrast/index.d.ts +5 -1
  46. package/types/ColorContrast/index.d.ts.map +1 -1
  47. package/types/ColorContrast/props.d.ts +4 -2
  48. package/types/ColorContrast/props.d.ts.map +1 -1
  49. package/types/ColorIndicator/index.d.ts +0 -1
  50. package/types/ColorIndicator/index.d.ts.map +1 -1
  51. package/types/ColorMixer/ColorPalette/index.d.ts +6 -6
  52. package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -1
  53. package/types/ColorMixer/ColorPalette/props.d.ts +1 -1
  54. package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -1
  55. package/types/ColorMixer/RGBAInput/index.d.ts +22 -12
  56. package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -1
  57. package/types/ColorMixer/RGBAInput/props.d.ts +1 -1
  58. package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -1
  59. package/types/ColorMixer/Slider/index.d.ts +5 -5
  60. package/types/ColorMixer/Slider/index.d.ts.map +1 -1
  61. package/types/ColorMixer/index.d.ts +5 -4
  62. package/types/ColorMixer/index.d.ts.map +1 -1
  63. package/types/ColorMixer/props.d.ts +3 -24
  64. package/types/ColorMixer/props.d.ts.map +1 -1
  65. package/types/ColorPicker/ColorPickerLocator.d.ts +5 -5
  66. package/types/ColorPicker/index.d.ts +24 -25
  67. package/types/ColorPicker/index.d.ts.map +1 -1
  68. package/types/ColorPicker/props.d.ts +32 -33
  69. package/types/ColorPicker/props.d.ts.map +1 -1
  70. package/types/ColorPreset/ColorPresetLocator.d.ts +1452 -10
  71. package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -1
  72. package/types/ColorPreset/index.d.ts +17 -7
  73. package/types/ColorPreset/index.d.ts.map +1 -1
  74. package/types/ColorPreset/props.d.ts +9 -9
  75. package/types/ColorPreset/props.d.ts.map +1 -1
@@ -22,8 +22,54 @@
22
22
  * SOFTWARE.
23
23
  */
24
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 { DrilldownLocator } from '@instructure/ui-drilldown/es/Drilldown/DrilldownLocator'
30
+ // @ts-expect-error bypass no type definition found error
31
+ import { TooltipLocator } from '@instructure/ui-tooltip/es/Tooltip/TooltipLocator'
32
+ // @ts-expect-error bypass no type definition found error
33
+ import { PopoverLocator } from '@instructure/ui-popover/es/Popover/PopoverLocator'
34
+ /* eslint-enable no-restricted-imports */
35
+
36
+ import { ColorIndicatorLocator } from '../ColorIndicator/ColorIndicatorLocator'
25
37
 
26
38
  import { ColorPreset } from './index'
27
39
 
28
40
  // @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)
41
+ export const ColorPresetLocator = locator(ColorPreset.selector, {
42
+ findAllColorIndicators: (...args: any[]) => {
43
+ return ColorIndicatorLocator.findAll(...args)
44
+ },
45
+ findAllColorTooltips: (...args: any[]) => {
46
+ return TooltipLocator.findAll(...args)
47
+ },
48
+ findAllColorMenus: (...args: any[]) => {
49
+ return DrilldownLocator.findAll(...args)
50
+ },
51
+ findSelectedIndicator: async (...args: any[]) => {
52
+ const selected = await find('[aria-label="selected"]', ...args)
53
+
54
+ if (!selected) {
55
+ return selected
56
+ }
57
+
58
+ return await ColorIndicatorLocator.find(selected.getDOMNode())
59
+ },
60
+ findSelectedIcon: (...args: any[]) => {
61
+ return find('[class$=-colorPreset__selectedIndicator]', ...args)
62
+ },
63
+ findAddColorPopoverContent: (...args: any[]) => {
64
+ return PopoverLocator.findContent(...args)
65
+ },
66
+ getMenuForIndex: async (_element: any, index: number) => {
67
+ const component = await ColorPresetLocator.find()
68
+ const indicators = await component.findAllColorIndicators()
69
+ const menus = await component.findAllColorMenus()
70
+
71
+ await indicators[index].click()
72
+
73
+ return await menus[index].findPopoverContent()
74
+ }
75
+ })
@@ -83,10 +83,13 @@ class Example extends React.Component {
83
83
  colors={this.state.colors}
84
84
  selected={this.state.selected}
85
85
  onSelect={(selected) => this.setState({ selected })}
86
- addNewPresetButtonScreenReaderLabel='Add new color'
87
86
  colorMixerSettings={{
88
87
  addNewPresetButtonScreenReaderLabel:'Add new preset button label',
88
+ selectColorLabel: 'Select',
89
+ removeColorLabel: 'Remove',
89
90
  onPresetChange:(colors) => this.setState({ colors }),
91
+ popoverAddButtonLabel: "Add",
92
+ popoverCloseButtonLabel: "Cancel",
90
93
  colorMixer:{
91
94
  rgbRedInputScreenReaderLabel:'Input field for red',
92
95
  rgbGreenInputScreenReaderLabel:'Input field for green',
@@ -98,7 +101,6 @@ class Example extends React.Component {
98
101
  },
99
102
  colorContrast:{
100
103
  firstColor:"#FF0000",
101
- secondColor:"#FFFF00",
102
104
  label:"Color Contrast Ratio",
103
105
  successLabel:"PASS",
104
106
  failureLabel:"FAIL",
@@ -26,7 +26,7 @@
26
26
  import { Component } from 'react'
27
27
 
28
28
  import { withStyle, jsx } from '@instructure/emotion'
29
- import { passthroughProps } from '@instructure/ui-react-utils'
29
+ import { omitProps } from '@instructure/ui-react-utils'
30
30
  import { testable } from '@instructure/ui-testable'
31
31
  import { colorToHex8, colorToRGB } from '@instructure/ui-color-utils'
32
32
 
@@ -68,6 +68,7 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
68
68
 
69
69
  constructor(props: ColorPresetProps) {
70
70
  super(props)
71
+
71
72
  this.state = {
72
73
  openEditor: false,
73
74
  openAddNew: false,
@@ -95,6 +96,15 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
95
96
  this.props.makeStyles?.()
96
97
  }
97
98
 
99
+ get isModifiable() {
100
+ return typeof this.props.colorMixerSettings?.onPresetChange === 'function'
101
+ }
102
+
103
+ isSelectedColor(color: string) {
104
+ const { selected } = this.props
105
+ return !!selected && colorToHex8(selected) === colorToHex8(color)
106
+ }
107
+
98
108
  onMenuItemSelected =
99
109
  (color: string): DrilldownProps['onSelect'] =>
100
110
  (_e, args) => {
@@ -219,18 +229,19 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
219
229
  color="primary"
220
230
  margin="0 xx-small 0 xx-small"
221
231
  >
222
- Add
232
+ {this.props.colorMixerSettings?.popoverAddButtonLabel}
223
233
  </Button>
224
234
  <Button
225
235
  onClick={() => this.setState({ openAddNew: false })}
226
236
  color="secondary"
227
237
  margin="0 xx-small 0 xx-small"
228
238
  >
229
- Close
239
+ {this.props.colorMixerSettings?.popoverCloseButtonLabel}
230
240
  </Button>
231
241
  </div>
232
242
  </Popover>
233
243
  )
244
+
234
245
  renderColorIndicator = (color: string, selectOnClick?: boolean) => (
235
246
  <Tooltip renderTip={<div>{color}</div>}>
236
247
  <View
@@ -248,12 +259,12 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
248
259
  {...(selectOnClick
249
260
  ? { onClick: () => this.props.onSelect(color) }
250
261
  : {})}
251
- {...(this.props.selected === color ? { 'aria-label': 'selected' } : {})}
262
+ {...(this.isSelectedColor(color) ? { 'aria-label': 'selected' } : {})}
252
263
  role="presentation"
253
264
  >
254
265
  <div>
255
266
  <ColorIndicator color={color} shape="rectangle" />
256
- {this.props.selected === color && (
267
+ {this.isSelectedColor(color) && (
257
268
  <div css={this.props?.styles?.selectedIndicator}>
258
269
  <IconCheckDarkSolid
259
270
  themeOverride={{ sizeXSmall: '0.8rem' }}
@@ -265,6 +276,7 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
265
276
  </View>
266
277
  </Tooltip>
267
278
  )
279
+
268
280
  renderSettingsMenu = (color: string, index: number) => (
269
281
  <Drilldown
270
282
  onSelect={this.onMenuItemSelected(color)}
@@ -276,30 +288,27 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
276
288
  >
277
289
  <Drilldown.Page withoutHeaderSeparator id="root" renderTitle={color}>
278
290
  <Drilldown.Option value="select" id="select">
279
- Select
291
+ {this.props.colorMixerSettings!.selectColorLabel}
280
292
  </Drilldown.Option>
281
293
  <Drilldown.Option value="remove" id="remove">
282
- Remove
294
+ {this.props.colorMixerSettings!.removeColorLabel}
283
295
  </Drilldown.Option>
284
296
  </Drilldown.Page>
285
297
  </Drilldown>
286
298
  )
287
299
 
288
300
  render() {
289
- const {
290
- disabled,
291
- onSelect,
292
- selected,
293
- styles,
294
- label,
295
- colorMixerSettings,
296
- colors,
297
- elementRef,
298
- ...props
299
- } = this.props
301
+ const { styles, label, colors } = this.props
302
+
303
+ if (!this.isModifiable && colors.length === 0) {
304
+ // if there is no preset and no ability to add new,
305
+ // there is no point of rendering the component
306
+ return null
307
+ }
308
+
300
309
  return (
301
310
  <div
302
- {...passthroughProps(props)}
311
+ {...omitProps(this.props, ColorPreset.allowedProps)}
303
312
  ref={this.handleRef}
304
313
  css={styles?.colorPreset}
305
314
  >
@@ -308,17 +317,18 @@ class ColorPreset extends Component<ColorPresetProps, ColorPresetState> {
308
317
  <Text weight="bold">{label}</Text>
309
318
  </div>
310
319
  )}
311
- {typeof colorMixerSettings?.onPresetChange === 'function' &&
312
- this.renderAddNewPresetButton()}
313
- {colors.map((color, index) =>
314
- typeof colorMixerSettings?.onPresetChange === 'function' ? (
320
+
321
+ {this.isModifiable && this.renderAddNewPresetButton()}
322
+
323
+ {colors.map((color, index) => {
324
+ return this.isModifiable ? (
315
325
  this.renderSettingsMenu(color, index)
316
326
  ) : (
317
327
  <div key={`color-preset-color-${index}`}>
318
328
  {this.renderColorIndicator(color, true)}
319
329
  </div>
320
330
  )
321
- )}
331
+ })}
322
332
  </div>
323
333
  )
324
334
  }
@@ -30,13 +30,9 @@ import type {
30
30
  PropValidators,
31
31
  ColorPresetTheme
32
32
  } from '@instructure/shared-types'
33
- import type { RGBAType } from '../ColorMixer/props'
33
+ import type { RGBAType } from '@instructure/ui-color-utils'
34
34
 
35
35
  type ContrastStrength = 'min' | 'mid' | 'max'
36
- type MessageType = Array<{
37
- type: 'success' | 'hint' | 'error' | 'screenreader-only'
38
- text: string
39
- }>
40
36
 
41
37
  type ColorPresetOwnProps = {
42
38
  /**
@@ -67,10 +63,14 @@ type ColorPresetOwnProps = {
67
63
  * screenReaderLabel for the add new preset button
68
64
  */
69
65
  addNewPresetButtonScreenReaderLabel: string
70
- maxHeight: string
66
+ selectColorLabel: string
67
+ removeColorLabel: string
71
68
  onPresetChange: (colors: ColorPresetOwnProps['colors']) => void
69
+ popoverAddButtonLabel: string
70
+ popoverCloseButtonLabel: string
71
+ maxHeight?: string
72
72
  colorMixer: {
73
- withAlpha: boolean
73
+ withAlpha?: boolean
74
74
  rgbRedInputScreenReaderLabel: string
75
75
  rgbGreenInputScreenReaderLabel: string
76
76
  rgbBlueInputScreenReaderLabel: string
@@ -102,7 +102,7 @@ type ColorPresetOwnProps = {
102
102
  /**
103
103
  * The currently selected HEX string
104
104
  */
105
- selected: string | null
105
+ selected?: string
106
106
  }
107
107
 
108
108
  type ColorPresetState = {
@@ -132,13 +132,45 @@ type ColorPresetStyle = ComponentStyle<
132
132
 
133
133
  const propTypes: PropValidators<PropKeys> = {
134
134
  colors: PropTypes.array.isRequired,
135
+ onSelect: PropTypes.func.isRequired,
136
+ selected: PropTypes.string,
135
137
  disabled: PropTypes.bool,
136
138
  elementRef: PropTypes.func,
137
139
  label: PropTypes.string,
138
- colorMixerSettings: PropTypes.object,
139
- onSelect: PropTypes.func.isRequired,
140
140
  popoverScreenReaderLabel: PropTypes.string,
141
- selected: PropTypes.string.isRequired
141
+ colorMixerSettings: PropTypes.shape({
142
+ addNewPresetButtonScreenReaderLabel: PropTypes.string.isRequired,
143
+ selectColorLabel: PropTypes.string.isRequired,
144
+ removeColorLabel: PropTypes.string.isRequired,
145
+ onPresetChange: PropTypes.func,
146
+ popoverAddButtonLabel: PropTypes.string.isRequired,
147
+ popoverCloseButtonLabel: PropTypes.string.isRequired,
148
+ maxHeight: PropTypes.string,
149
+ colorMixer: PropTypes.shape({
150
+ withAlpha: PropTypes.bool,
151
+ rgbRedInputScreenReaderLabel: PropTypes.string.isRequired,
152
+ rgbGreenInputScreenReaderLabel: PropTypes.string.isRequired,
153
+ rgbBlueInputScreenReaderLabel: PropTypes.string.isRequired,
154
+ rgbAlphaInputScreenReaderLabel: PropTypes.string.isRequired,
155
+ colorSliderNavigationExplanationScreenReaderLabel:
156
+ PropTypes.string.isRequired,
157
+ alphaSliderNavigationExplanationScreenReaderLabel:
158
+ PropTypes.string.isRequired,
159
+ colorPaletteNavigationExplanationScreenReaderLabel:
160
+ PropTypes.string.isRequired
161
+ }).isRequired,
162
+ colorContrast: PropTypes.shape({
163
+ firstColor: PropTypes.string.isRequired,
164
+ label: PropTypes.string.isRequired,
165
+ successLabel: PropTypes.string.isRequired,
166
+ failureLabel: PropTypes.string.isRequired,
167
+ normalTextLabel: PropTypes.string.isRequired,
168
+ largeTextLabel: PropTypes.string.isRequired,
169
+ graphicsTextLabel: PropTypes.string.isRequired,
170
+ firstColorLabel: PropTypes.string.isRequired,
171
+ secondColorLabel: PropTypes.string.isRequired
172
+ })
173
+ })
142
174
  }
143
175
 
144
176
  const allowedProps: AllowedPropKeys = [
@@ -156,7 +188,6 @@ export type {
156
188
  ColorPresetProps,
157
189
  ColorPresetStyle,
158
190
  ColorPresetState,
159
- ContrastStrength,
160
- MessageType
191
+ ContrastStrength
161
192
  }
162
193
  export { propTypes, allowedProps }