Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EuiColorPaletteDisplay #3865

Merged
merged 46 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bb7e29b
Initial color palette display code
elizabetdev Aug 5, 2020
8d03929
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Sep 2, 2020
ea9597d
Palette display section and testing one color
elizabetdev Sep 2, 2020
f4a6e1e
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Oct 21, 2020
b229cd8
Type gradient as default
elizabetdev Oct 21, 2020
8b5167e
Using spans for linear fixed gradient with stops
elizabetdev Oct 27, 2020
40d49a1
Adding examples and improving code
elizabetdev Oct 27, 2020
c87f62d
Adding tests
elizabetdev Oct 27, 2020
6da9452
Adding rest to spread required props. Adding classNames.
elizabetdev Oct 27, 2020
9814b1d
Better examples
elizabetdev Oct 27, 2020
7d585cc
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Oct 27, 2020
c0941ab
CL
elizabetdev Oct 27, 2020
8854dfe
Is new
elizabetdev Oct 27, 2020
ec8cdfe
Adding line break
elizabetdev Oct 27, 2020
72efd8f
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Oct 27, 2020
db94882
Adding a bleed area for fixed palettes
elizabetdev Oct 29, 2020
c365c22
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Oct 29, 2020
7cd1b93
Placing CL into master
elizabetdev Oct 29, 2020
c534d87
Replacing divs with spans
elizabetdev Oct 29, 2020
24287f2
Removing classname
elizabetdev Oct 29, 2020
6a449a1
Code improvements
elizabetdev Oct 31, 2020
de5ac12
Update src/components/color_picker/color_palette_display/_color_palet…
elizabetdev Nov 2, 2020
ceb9ce3
Update src-docs/src/views/color_picker/color_palette_picker.js
elizabetdev Nov 2, 2020
25e6727
Fixing ESLint warning
elizabetdev Nov 2, 2020
251bd63
Merge branch 'add-color-palette-display' of https://github.com/miukim…
elizabetdev Nov 2, 2020
e7994fe
Improving complex example
elizabetdev Nov 2, 2020
b0005f7
ESLint
elizabetdev Nov 2, 2020
cd33095
Complex example title size
elizabetdev Nov 2, 2020
77ddaf6
Complex example with column compressed
elizabetdev Nov 2, 2020
37fc940
Importing color prop with prop loader
elizabetdev Nov 2, 2020
e0072cf
ESLint
elizabetdev Nov 2, 2020
374652f
New structure
elizabetdev Nov 2, 2020
f6efbc8
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Nov 2, 2020
6ad15b0
Adding sizes
elizabetdev Nov 2, 2020
5a70935
ESLint
elizabetdev Nov 2, 2020
6bcd7a5
Update src/components/color_picker/color_palette_display/color_palett…
elizabetdev Nov 3, 2020
d1ff28e
Update src/components/color_picker/color_palette_display/color_palett…
elizabetdev Nov 3, 2020
ecda5ea
Adding getFixedLinearGradient
elizabetdev Nov 3, 2020
d4a4a91
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Nov 3, 2020
bd17a5f
Small fix in palette picker example
elizabetdev Nov 3, 2020
c5f23e1
typescript help
thompsongl Nov 3, 2020
63cdbab
Merge pull request #6 from thompsongl/add-color-palette-display
elizabetdev Nov 4, 2020
5b29003
Addressing PR review
elizabetdev Nov 4, 2020
8f8cf1e
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Nov 4, 2020
396a201
CL
elizabetdev Nov 4, 2020
96487d6
Merge remote-tracking branch 'upstream/master' into add-color-palette…
elizabetdev Nov 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `30.2.0`.
- Added `EuiColorPaletteDisplay` component ([#3865](https://github.com/elastic/eui/pull/3865))

## [`30.2.0`](https://github.com/elastic/eui/tree/v30.2.0)

Expand Down
202 changes: 202 additions & 0 deletions src-docs/src/views/color_picker/color_palette_display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import React, { useState } from 'react';
import {
euiPaletteColorBlind,
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplimentary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
} from '../../../../src/services/color';

import {
EuiColorPaletteDisplay,
EuiColorPalettePicker,
EuiFormRow,
EuiSpacer,
EuiTitle,
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
EuiRange,
EuiSwitch,
EuiCode,
EuiButtonEmpty,
EuiSelect,
} from '../../../../src/components/';

const paletteWithStops = [
{
stop: 100,
color: 'white',
},
{
stop: 250,
color: 'lightgray',
},
{
stop: 320,
color: 'gray',
},
{
stop: 470,
color: 'black',
},
];

const paletteData = {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplimentary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
};

const paletteNames = Object.keys(paletteData);

const sizes = [
{ value: 'xs', text: 'Extra small' },
{ value: 's', text: 'Small' },
{ value: 'm', text: 'Medium' },
];

export default () => {
const [palette, setPalette] = useState('1');
const [categories, setCategories] = useState(5);
const [selectionType, setSelectionType] = useState(true);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [size, setSize] = useState(sizes[1].value);

const onChangeSize = (e) => {
setSize(e.target.value);
};

const onChange = (e) => {
setCategories(parseInt(e.target.value));
};

const palettes = paletteNames.map((paletteName, index) => {
return {
value: String(index + 1),
title: paletteName,
palette: paletteData[paletteNames[index]](categories),
type: selectionType ? 'fixed' : 'gradient',
};
});

const selectedPalette = paletteData[paletteNames[palette - 1]](categories);

const onButtonClick = () =>
setIsPopoverOpen((isPopoverOpen) => !isPopoverOpen);
const closePopover = () => setIsPopoverOpen(false);

const button = (
<EuiButtonEmpty
onClick={onButtonClick}
iconType="controlsVertical"
aria-label="Open settings"
color="text"
size="xs">
Customize
</EuiButtonEmpty>
);

return (
<>
<EuiTitle size="xxxs">
<h3>Fixed</h3>
</EuiTitle>
<EuiSpacer size="s" />
<EuiColorPaletteDisplay type="fixed" palette={euiPaletteColorBlind()} />
<EuiSpacer />
<EuiTitle size="xxxs">
<h3>Gradient</h3>
</EuiTitle>
<EuiSpacer size="s" />
<EuiColorPaletteDisplay
type="gradient"
palette={euiPaletteColorBlind()}
/>
<EuiSpacer />
<EuiTitle size="xxxs">
<h3>Fixed with stops</h3>
</EuiTitle>
<EuiSpacer size="s" />
<EuiColorPaletteDisplay type="fixed" palette={paletteWithStops} />
<EuiSpacer />
<EuiTitle size="xxxs">
<h3>Gradient with stops</h3>
</EuiTitle>
<EuiSpacer size="s" />
<EuiColorPaletteDisplay type="gradient" palette={paletteWithStops} />
<EuiSpacer />
<EuiTitle size="xxxs">
<h3>Complex example</h3>
</EuiTitle>
<EuiSpacer size="xs" />
<EuiFlexGroup alignItems="center" gutterSize="xs">
<EuiFlexItem>
<EuiColorPaletteDisplay
type={selectionType ? 'fixed' : 'gradient'}
palette={selectedPalette}
size={size}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiPopover
panelStyle={{ minWidth: 380 }}
ownFocus
button={button}
isOpen={isPopoverOpen}
closePopover={closePopover}>
<EuiFormRow label="Color palette" display="columnCompressed">
<EuiColorPalettePicker
palettes={palettes}
onChange={setPalette}
valueOfSelected={palette}
selectionDisplay="title"
compressed
/>
</EuiFormRow>
<EuiFormRow label="Number of stops" display="columnCompressed">
<EuiRange
value={categories}
onChange={onChange}
min={1}
max={10}
compressed
showValue
/>
</EuiFormRow>
<EuiFormRow label="Size" display="columnCompressed">
<EuiSelect
options={sizes}
value={size}
onChange={(e) => onChangeSize(e)}
compressed
/>
</EuiFormRow>
<EuiFormRow
label={
<span>
Display <EuiCode>fixed</EuiCode>
</span>
}
display="columnCompressedSwitch">
<EuiSwitch
checked={selectionType}
onChange={() => setSelectionType(!selectionType)}
compressed
/>
</EuiFormRow>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {
euiPaletteForStatus,
euiPaletteForTemperature,
} from '../../../../src/services';
import { EuiSwitch } from '../../../../src/components/form';
import { EuiSpacer } from '../../../../src/components/spacer';
import { EuiCode } from '../../../../src/components/code';

import {
EuiSwitch,
EuiSpacer,
EuiCode,
EuiColorPalettePicker,
EuiColorPalettePickerPaletteProps,
} from '../../../../src/components/color_picker/color_palette_picker';
// @ts-ignore importing from a JS file
} from '../../../../src/components/';

import { DisplayToggles } from '../form_controls/display_toggles';

const palettes: EuiColorPalettePickerPaletteProps[] = [
const palettes = [
{
value: 'pallette_1',
title: 'EUI color blind (fixed)',
Expand All @@ -23,12 +23,18 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [
},
{
value: 'pallette_2',
title: 'EUI palette for status (gradient)',
palette: euiPaletteForStatus(5),
type: 'gradient',
},
{
value: 'pallette_3',
title: 'EUI palette for temperature (fixed)',
palette: euiPaletteForTemperature(5),
type: 'fixed',
},
{
value: 'pallette_3',
value: 'pallette_4',
title: 'Grayscale (gradient with stops)',
palette: [
{
Expand All @@ -37,11 +43,11 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [
},
{
stop: 250,
color: 'gray',
color: 'lightgray',
},
{
stop: 350,
color: 'dimgray',
stop: 320,
color: 'gray',
},
{
stop: 470,
Expand All @@ -51,10 +57,27 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [
type: 'gradient',
},
{
value: 'pallette_4',
title: 'EUI palette for status (gradient)',
palette: euiPaletteForStatus(5),
type: 'gradient',
value: 'pallette_5',
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
title: 'Grayscale (fixed with stops)',
palette: [
{
stop: 100,
color: 'white',
},
{
stop: 250,
color: 'lightgray',
},
{
stop: 320,
color: 'gray',
},
{
stop: 470,
color: 'black',
},
],
type: 'fixed',
},
{
value: 'custom',
Expand All @@ -63,7 +86,7 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [
},
];

export const ColorPalettePicker = () => {
export default () => {
const [selectionDisplay, setSelectionDisplay] = useState(false);
const [pallette, setPallette] = useState('pallette_1');

Expand Down
Loading