diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c8485c1d2f..85fdcde03f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `side` prop to `EuiGlobalToastList` for choosing which window side to display toasts ([#3600](https://github.com/elastic/eui/pull/3600)) - Default `titleSize` get's implicitly set to 'm' for `EuiEmptyPrompt` ([#3598](https://github.com/elastic/eui/pull/3598)) - Updated `logoElastic` to meet brand guidelines ([#3613](https://github.com/elastic/eui/pull/3613)) +- Extended `CommonProps` in `EuiColorPalettePickerPaletteTextProps`, `EuiColorPalettePickerPaletteFixedProps` and `EuiColorPalettePickerPaletteGradientProps` types ([#3616](https://github.com/elastic/eui/pull/3616)) **Bug fixes** diff --git a/src/components/color_picker/color_palette_picker/__snapshots__/color_palette_picker.test.tsx.snap b/src/components/color_picker/color_palette_picker/__snapshots__/color_palette_picker.test.tsx.snap index 90d8ed2e996..b0d49cd535d 100644 --- a/src/components/color_picker/color_palette_picker/__snapshots__/color_palette_picker.test.tsx.snap +++ b/src/components/color_picker/color_palette_picker/__snapshots__/color_palette_picker.test.tsx.snap @@ -345,3 +345,1560 @@ exports[`EuiColorPalettePicker is rendered with the prop selectionDisplay set as `; + +exports[`EuiColorPalettePicker more props are propagated to each option 1`] = ` +
+
+ +
+
+ + Select an option: +
+ , is selected + + +
+ + +
+
+
+
+`; + +exports[`EuiColorPalettePicker more props are propagated to each option 2`] = ` + + +
+ Palette 1 +
+
+
, + "inputDisplay":
, + "value": "paletteFixed", + }, + Object { + "className": "paletteLinearClass", + "data-test-subj": "gradient-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient +
+
+
, + "inputDisplay":
, + "value": "paletteLinear", + }, + Object { + "data-test-subj": "gradient-with-stops-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient with stops +
+
+
, + "inputDisplay":
, + "value": "paletteLinearStops", + }, + Object { + "data-test-subj": "text-data-test-subj", + "dropdownDisplay":
+ Plain text as a custom option +
, + "inputDisplay": "Plain text as a custom option", + "value": "custom", + }, + ] + } + readOnly={false} + valueOfSelected="paletteFixed" + > + +
+ Palette 1 +
+
+
, + "inputDisplay":
, + "value": "paletteFixed", + }, + Object { + "className": "paletteLinearClass", + "data-test-subj": "gradient-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient +
+
+
, + "inputDisplay":
, + "value": "paletteLinear", + }, + Object { + "data-test-subj": "gradient-with-stops-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient with stops +
+
+
, + "inputDisplay":
, + "value": "paletteLinearStops", + }, + Object { + "data-test-subj": "text-data-test-subj", + "dropdownDisplay":
+ Plain text as a custom option +
, + "inputDisplay": "Plain text as a custom option", + "value": "custom", + }, + ] + } + readOnly={false} + value="paletteFixed" + /> + } + className="euiSuperSelect" + closePopover={[Function]} + display="block" + hasArrow={false} + isOpen={true} + ownFocus={false} + panelClassName="euiSuperSelect__popoverPanel" + panelPaddingSize="none" + popoverRef={[Function]} + > + +
+
+ +
+ Palette 1 +
+
+
, + "inputDisplay":
, + "value": "paletteFixed", + }, + Object { + "className": "paletteLinearClass", + "data-test-subj": "gradient-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient +
+
+
, + "inputDisplay":
, + "value": "paletteLinear", + }, + Object { + "data-test-subj": "gradient-with-stops-data-test-subj", + "dropdownDisplay":
+
+ Linear Gradient with stops +
+
+
, + "inputDisplay":
, + "value": "paletteLinearStops", + }, + Object { + "data-test-subj": "text-data-test-subj", + "dropdownDisplay":
+ Plain text as a custom option +
, + "inputDisplay": "Plain text as a custom option", + "value": "custom", + }, + ] + } + readOnly={false} + value="paletteFixed" + > + + +
+
+ + + , + } + } + > + + } + > + Select an option: +
+ , is selected + + + + + + +
+ + +
+
+ + +
+ + +
+
+
+
+ +
+
+
+ } + > + + + +
+ +
+
+
+ + + } + onActivation={[Function]} + onDeactivation={[Function]} + persistentFocus={false} + > + + + } + onActivation={[Function]} + onDeactivation={[Function]} + persistentFocus={false} + /> + + +
+
+ +
+ +

+ + You are in a form selector of 4 items and must select a single option. Use the up and down keys to navigate or escape to close. + +

+
+
+ + + + + + + + + + + + +
+
+
+
+ +
+
+ +
+ + + + + +
+ + + + +`; diff --git a/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx b/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx index d484a523a9f..1d0fcc2a189 100644 --- a/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx +++ b/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx @@ -18,13 +18,13 @@ */ import React from 'react'; -import { render } from 'enzyme'; +import { mount, render } from 'enzyme'; import { EuiColorPalettePicker, EuiColorPalettePickerPaletteProps, } from './color_palette_picker'; -import { requiredProps } from '../../../test'; +import { requiredProps, takeMountedSnapshot } from '../../../test'; jest.mock('./../../../services/accessibility', () => ({ htmlIdGenerator: () => () => 'generated-id', @@ -36,12 +36,17 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [ title: 'Palette 1', palette: ['#1fb0b2', '#ffdb6d', '#ee9191', '#ffffff', '#888094'], type: 'fixed', + 'data-test-subj': 'fixed-data-test-subj', + className: 'paletteFixedClass', + 'aria-label': 'my palette fixed', }, { value: 'paletteLinear', title: 'Linear Gradient', palette: ['#1fb0b2', '#ffdb6d', '#ee9191', '#ffffff', '#888094'], type: 'gradient', + 'data-test-subj': 'gradient-data-test-subj', + className: 'paletteLinearClass', }, { value: 'paletteLinearStops', @@ -65,11 +70,13 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [ }, ], type: 'gradient', + 'data-test-subj': 'gradient-with-stops-data-test-subj', }, { value: 'custom', title: 'Plain text as a custom option', type: 'text', + 'data-test-subj': 'text-data-test-subj', }, ]; @@ -151,4 +158,23 @@ describe('EuiColorPalettePicker', () => { expect(component).toMatchSnapshot(); }); + + test('more props are propagated to each option', () => { + const component = mount( + {}} + data-test-subj="colorPalettePicker" + /> + ); + + component + .find('button[data-test-subj="colorPalettePicker"]') + .simulate('click'); + + expect(takeMountedSnapshot(component)).toMatchSnapshot(); + + expect(component).toMatchSnapshot(); + }); }); diff --git a/src/components/color_picker/color_palette_picker/color_palette_picker.tsx b/src/components/color_picker/color_palette_picker/color_palette_picker.tsx index dd1bd843b00..2e9044a2790 100644 --- a/src/components/color_picker/color_palette_picker/color_palette_picker.tsx +++ b/src/components/color_picker/color_palette_picker/color_palette_picker.tsx @@ -28,7 +28,7 @@ import { ColorStop } from '../color_stops'; import { EuiSuperSelectProps } from '../../form/super_select'; -export interface EuiColorPalettePickerPaletteTextProps { +export interface EuiColorPalettePickerPaletteTextProps extends CommonProps { /** * For storing unique value of item */ @@ -48,7 +48,7 @@ export interface EuiColorPalettePickerPaletteTextProps { palette?: string[] | ColorStop[]; } -export interface EuiColorPalettePickerPaletteFixedProps { +export interface EuiColorPalettePickerPaletteFixedProps extends CommonProps { /** * For storing unique value of item */ @@ -67,7 +67,7 @@ export interface EuiColorPalettePickerPaletteFixedProps { palette: string[]; } -export interface EuiColorPalettePickerPaletteGradientProps { +export interface EuiColorPalettePickerPaletteGradientProps extends CommonProps { /** * For storing unique value of item */ @@ -145,23 +145,23 @@ export const EuiColorPalettePicker: FunctionComponent< const paletteOptions = palettes.map( (item: EuiColorPalettePickerPaletteProps) => { + const { type, value, title, palette, ...rest } = item; const paletteForDisplay = item.type !== 'text' ? getPalette(item) : null; return { - value: String(item.value), + value: String(value), inputDisplay: - selectionDisplay === 'title' || item.type === 'text' - ? item.title + selectionDisplay === 'title' || type === 'text' + ? title : paletteForDisplay, dropdownDisplay: (
- {item.title && item.type !== 'text' && ( -
- {item.title} -
+ {title && type !== 'text' && ( +
{title}
)} - {item.type === 'text' ? item.title : paletteForDisplay} + {type === 'text' ? title : paletteForDisplay}
), + ...rest, }; } );