Use the palettes prop to pass your palettes as
- an array of objects. For each object, you should pass a palette
- (array of hex values) and specify the type. Use{' '}
- fixed palettes for categorical data and{' '}
- gradient palettes for continuous data.
+ an array strings or an array of{' '}
+ ColorStops in the form of{' '}
+ {'{ stop: number, color: string }'}. For each
+ object, you should pass a palette (array of hex values) and
+ specify the type. Use fixed{' '}
+ palettes for categorical data and gradient{' '}
+ palettes for continuous data.
+ Use EuiColorPaletteDisplay to show the palette in
+ use for a data visualization.
+
+
+ Use the palette prop to pass your palette as an array of color{' '}
+ strings or an array of{' '}
+ ColorStops in the form of{' '}
+ {'{ stop: number, color: string }'}. Use{' '}
+ fixed palettes for categorical data and{' '}
+ gradient palettes for continuous data.
+
+
+ In cases you need to apply a palette, it's recommended to use
+ the{' '}
+
+ EuiColorPalettePicker
+
+ .
+
+
+
+ ),
+ source: [
+ {
+ type: GuideSectionTypes.JS,
+ code: colorPaletteDisplaySource,
+ },
+ {
+ type: GuideSectionTypes.HTML,
+ code: colorPaletteDisplayHtml,
+ },
+ ],
+ props: {
+ EuiColorPaletteDisplay,
+ ColorStop,
+ },
+ snippet: colorPaletteDisplaySnippet,
+ demo: ,
+ },
{
title: 'Color stops',
text: (
@@ -391,7 +471,10 @@ export const ColorPickerExample = {
code: colorStopsHtml,
},
],
- props: { EuiColorStops },
+ props: {
+ EuiColorStops,
+ ColorStop,
+ },
snippet: [
colorStopsSnippetStandard,
colorStopsSnippetAdd,
@@ -409,9 +492,9 @@ export const ColorPickerExample = {
defined min and max range
values. It is also possible to leave the range open-ended for
cases where the target data set is unknown or maleable. In this
- case, a user{"'"}s added values will define min{' '}
- and max and users will have more freedom over
- resetting the values on the fly.
+ case, a user's added values will define{' '}
+ min and max and users will
+ have more freedom over resetting the values on the fly.
diff --git a/src/components/color_picker/_index.scss b/src/components/color_picker/_index.scss
index cd7341001db..895912e9bc9 100644
--- a/src/components/color_picker/_index.scss
+++ b/src/components/color_picker/_index.scss
@@ -4,4 +4,5 @@
@import 'hue';
@import 'saturation';
@import 'color_stops/index';
-@import 'color_palette_picker/index';
\ No newline at end of file
+@import 'color_palette_picker/index';
+@import 'color_palette_display/index';
\ No newline at end of file
diff --git a/src/components/color_picker/color_palette_display/__snapshots__/color_palette_display.test.tsx.snap b/src/components/color_picker/color_palette_display/__snapshots__/color_palette_display.test.tsx.snap
new file mode 100644
index 00000000000..9874be69b8c
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/__snapshots__/color_palette_display.test.tsx.snap
@@ -0,0 +1,214 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`EuiColorPaletteDisplay is rendered 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props HTML attributes accepts span attributes 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props size m is rendered 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props size s is rendered 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props size xs is rendered 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props type and palette are rendered with type fixed and palette with stops 1`] = `
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props type and palette are rendered with type fixed and palette without stops 1`] = `
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`EuiColorPaletteDisplay props type and palette are rendered with type gradient and palette with stops 1`] = `
+
+`;
+
+exports[`EuiColorPaletteDisplay props type and palette are rendered with type gradient and palette without stops 1`] = `
+
+`;
diff --git a/src/components/color_picker/color_palette_display/_color_palette_display.scss b/src/components/color_picker/color_palette_display/_color_palette_display.scss
new file mode 100644
index 00000000000..bfc2a1e8a48
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/_color_palette_display.scss
@@ -0,0 +1,18 @@
+.euiColorPaletteDisplay {
+ display: flex;
+ flex-direction: row;
+ overflow: hidden;
+ height: $euiSizeS;
+}
+
+@each $name, $size in $euiColorPaletteDisplaySizes {
+ .euiColorPaletteDisplay--#{$name} {
+ @include innerBorder('dark', $size, .2);
+ height: $size;
+ border-radius: $size;
+ }
+
+ .euiColorPaletteDisplay--#{$name} .euiColorPaletteDisplayFixed__bleedArea {
+ height: $size;
+ }
+}
diff --git a/src/components/color_picker/color_palette_display/_color_palette_display_fixed.scss b/src/components/color_picker/color_palette_display/_color_palette_display_fixed.scss
new file mode 100644
index 00000000000..f39a743f052
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/_color_palette_display_fixed.scss
@@ -0,0 +1,12 @@
+.euiColorPaletteDisplayFixed {
+ // In a few screen sizes the palette display doesn't get a fully 100% width
+ // it gets 1px less on width and for this reason we're adding an horizontal 1px bleed area
+ &__bleedArea {
+ position: absolute;
+ top: 0;
+ left: 0;
+ display: flex;
+ height: $euiSizeS;
+ width: calc(100% + 1px);
+ }
+}
diff --git a/src/components/color_picker/color_palette_display/_index.scss b/src/components/color_picker/color_palette_display/_index.scss
new file mode 100644
index 00000000000..fd1e1d6846d
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/_index.scss
@@ -0,0 +1,3 @@
+@import 'variables';
+@import 'color_palette_display';
+@import 'color_palette_display_fixed';
diff --git a/src/components/color_picker/color_palette_display/_variables.scss b/src/components/color_picker/color_palette_display/_variables.scss
new file mode 100644
index 00000000000..96c9024c891
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/_variables.scss
@@ -0,0 +1,6 @@
+// Color Palette Display come in different sizes.
+$euiColorPaletteDisplaySizes: (
+ sizeExtraSmall: $euiSizeXS,
+ sizeSmall: $euiSizeS,
+ sizeMedium: $euiSize,
+);
diff --git a/src/components/color_picker/color_palette_display/color_palette_display.test.tsx b/src/components/color_picker/color_palette_display/color_palette_display.test.tsx
new file mode 100644
index 00000000000..74ea700aa5b
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/color_palette_display.test.tsx
@@ -0,0 +1,139 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import React from 'react';
+import { render } from 'enzyme';
+
+import { EuiColorPaletteDisplay, SIZES } from './color_palette_display';
+import { requiredProps } from '../../../test';
+
+const palette = ['#1fb0b2', '#ffdb6d', '#ee9191', '#ffffff', '#888094'];
+
+const paletteWithStops = [
+ {
+ stop: 100,
+ color: '#54B399',
+ },
+ {
+ stop: 250,
+ color: '#D36086',
+ },
+ {
+ stop: 350,
+ color: '#9170B8',
+ },
+ {
+ stop: 470,
+ color: '#F5A700',
+ },
+];
+
+describe('EuiColorPaletteDisplay', () => {
+ test('is rendered', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+
+ describe('props', () => {
+ describe('type and palette', () => {
+ it('are rendered with type fixed and palette without stops', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+
+ it('are rendered with type gradient and palette without stops', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+
+ it('are rendered with type fixed and palette with stops', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+
+ it('are rendered with type gradient and palette with stops', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+
+ describe('size', () => {
+ SIZES.forEach((size) => {
+ it(`${size} is rendered`, () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+ });
+
+ describe('HTML attributes', () => {
+ it('accepts span attributes', () => {
+ const component = render(
+
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+ });
+ });
+});
diff --git a/src/components/color_picker/color_palette_display/color_palette_display.tsx b/src/components/color_picker/color_palette_display/color_palette_display.tsx
new file mode 100644
index 00000000000..6dae05d5795
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/color_palette_display.tsx
@@ -0,0 +1,102 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import React, { FunctionComponent } from 'react';
+import classnames from 'classnames';
+import { ExclusiveUnion, keysOf } from '../../common';
+import { ColorStop } from '../color_stops';
+import {
+ EuiColorPaletteDisplayFixed,
+ EuiColorPaletteDisplayFixedProps,
+} from './color_palette_display_fixed';
+import {
+ EuiColorPaletteDisplayGradient,
+ EuiColorPaletteDisplayGradientProps,
+} from './color_palette_display_gradient';
+
+const sizeToClassNameMap = {
+ xs: 'euiColorPaletteDisplay--sizeExtraSmall',
+ s: 'euiColorPaletteDisplay--sizeSmall',
+ m: 'euiColorPaletteDisplay--sizeMedium',
+};
+
+export const SIZES = keysOf(sizeToClassNameMap);
+
+export type EuiColorPaletteDisplaySize = keyof typeof sizeToClassNameMap;
+
+export interface EuiColorPaletteDisplayShared {
+ /**
+ * Array of color `strings` or an array of #ColorStop. The stops must be numbers in an ordered range.
+ */
+ palette: string[] | ColorStop[];
+}
+
+interface DisplayGradient extends EuiColorPaletteDisplayGradientProps {
+ /**
+ * Specify the type of palette.
+ * `gradient`: each color fades into the next.
+ */
+ type: 'gradient';
+}
+
+interface DisplayFixed extends EuiColorPaletteDisplayFixedProps {
+ /**
+ * `fixed`: individual color blocks.
+ */
+ type?: 'fixed';
+}
+
+export type EuiColorPaletteDisplayProps = {
+ /**
+ * Height of the palette display
+ */
+ size?: EuiColorPaletteDisplaySize;
+} & ExclusiveUnion;
+
+export const EuiColorPaletteDisplay: FunctionComponent = ({
+ type = 'fixed',
+ palette,
+ className,
+ size = 's',
+ ...rest
+}) => {
+ const classes = classnames(
+ 'euiColorPaletteDisplay',
+ className,
+ sizeToClassNameMap[size]
+ );
+
+ return (
+ <>
+ {type === 'fixed' ? (
+
+ ) : (
+
+ )}
+ >
+ );
+};
diff --git a/src/components/color_picker/color_palette_display/color_palette_display_fixed.tsx b/src/components/color_picker/color_palette_display/color_palette_display_fixed.tsx
new file mode 100644
index 00000000000..a9e8930abaa
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/color_palette_display_fixed.tsx
@@ -0,0 +1,55 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import React, { FunctionComponent, HTMLAttributes } from 'react';
+import { CommonProps } from '../../common';
+import { getFixedLinearGradient } from '../utils';
+import { EuiColorPaletteDisplayShared } from './color_palette_display';
+
+export interface EuiColorPaletteDisplayFixedProps
+ extends HTMLAttributes,
+ CommonProps,
+ EuiColorPaletteDisplayShared {}
+
+interface paletteItem {
+ color: string;
+ width: string;
+}
+
+export const EuiColorPaletteDisplayFixed: FunctionComponent = ({
+ palette,
+ ...rest
+}) => {
+ const fixedGradient = getFixedLinearGradient(palette);
+
+ const paletteStops = fixedGradient.map((item: paletteItem, index: number) => (
+
+ ));
+
+ return (
+
+
+ {paletteStops}
+
+
+ );
+};
diff --git a/src/components/color_picker/color_palette_display/color_palette_display_gradient.tsx b/src/components/color_picker/color_palette_display/color_palette_display_gradient.tsx
new file mode 100644
index 00000000000..7c148b1d162
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/color_palette_display_gradient.tsx
@@ -0,0 +1,38 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import React, { FunctionComponent, HTMLAttributes } from 'react';
+import { CommonProps } from '../../common';
+import { getLinearGradient } from '../utils';
+import { EuiColorPaletteDisplayShared } from './color_palette_display';
+
+export interface EuiColorPaletteDisplayGradientProps
+ extends HTMLAttributes,
+ CommonProps,
+ EuiColorPaletteDisplayShared {}
+
+export const EuiColorPaletteDisplayGradient: FunctionComponent = ({
+ palette,
+ style = {},
+ ...rest
+}) => {
+ const gradient = getLinearGradient(palette);
+
+ return ;
+};
diff --git a/src/components/color_picker/color_palette_display/index.ts b/src/components/color_picker/color_palette_display/index.ts
new file mode 100644
index 00000000000..8c3f953d8c2
--- /dev/null
+++ b/src/components/color_picker/color_palette_display/index.ts
@@ -0,0 +1,33 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export {
+ EuiColorPaletteDisplay,
+ EuiColorPaletteDisplayProps,
+} from './color_palette_display';
+
+export {
+ EuiColorPaletteDisplayFixed,
+ EuiColorPaletteDisplayFixedProps,
+} from './color_palette_display_fixed';
+
+export {
+ EuiColorPaletteDisplayGradient,
+ EuiColorPaletteDisplayGradientProps,
+} from './color_palette_display_gradient';
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 bbddf2aec64..28804ea3f8a 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
@@ -124,10 +124,29 @@ exports[`EuiColorPalettePicker is rendered with a selected fixed palette 1`] = `
id="generated-id"
>
Select an option:
-
+
+
+
+
+
+
+
+
+
, is selected
Select an option:
-
, is selected
@@ -198,8 +236,8 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette 1`]
data-test-subj="test subject string"
type="button"
>
-
@@ -244,8 +282,8 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette with
id="generated-id"
>
Select an option:
-
, is selected
@@ -258,8 +296,8 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette with
data-test-subj="test subject string"
type="button"
>
-
@@ -356,9 +394,29 @@ exports[`EuiColorPalettePicker more props are propagated to each option 1`] = `
id="generated-id"
>
Select an option:
-
+
+
+
+
+
+
+
+
+
, is selected