Skip to content

Commit

Permalink
EuiColorStops with user-defined ranges (#2396)
Browse files Browse the repository at this point in the history
* allow for range to be partially defined or undefined

* dont set initial terminals

* better range reset

* fix tests

* docs

* add snapshot tests

* CL

* better handling of undefined ranges

* fix single-stop, fixed-segment background

* use != null instead of gs

* fix empty array keyboard add bug

* open popover on new stop creation

* class name
  • Loading branch information
thompsongl committed Oct 16, 2019
1 parent fab513d commit dbb9e08
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 75 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `14.6.0`.
- Added ability for `EuiColorStops` to accept user-defined range bounds ([#2396](https://github.com/elastic/eui/pull/2396))

## [`14.6.0`](https://github.com/elastic/eui/tree/v14.6.0)

- Added new updated `infraApp` and `logsApp` icons. ([#2430](https://github.com/elastic/eui/pull/2430))

**Bug fixes**

- Fixed missing misc. button and link type definition exports ([#2434](https://github.com/elastic/eui/pull/2434))
Expand Down
39 changes: 39 additions & 0 deletions src-docs/src/views/color_picker/color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const colorStopsSnippetFixed = `<EuiColorStops
/>
`;

import { ColorStopsRange } from './color_stops_range';
const colorStopsRangeSource = require('!!raw-loader!./color_stops');
const colorStopsRangeHtml = renderToHtml(ColorStopsRange);
const colorPickerRangeSnippet = `<EuiColorStops
label="Free-range color stops"
onChange={handleChange}
colorStops={colorStops}
/>
`;

import { CustomSwatches } from './custom_swatches';
const customSwatchesSource = require('!!raw-loader!./custom_swatches');
const customSwatchesHtml = renderToHtml(CustomSwatches);
Expand Down Expand Up @@ -290,6 +300,35 @@ export const ColorPickerExample = {
],
demo: <ColorStops />,
},
{
title: 'Free-range color stops',
text: (
<React.Fragment>
<EuiText>
<p>
Typical use of <EuiCode>EuiColorStops</EuiCode> (as above) will
have 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.
</p>
</EuiText>
</React.Fragment>
),
source: [
{
type: GuideSectionTypes.JS,
code: colorStopsRangeSource,
},
{
type: GuideSectionTypes.HTML,
code: colorStopsRangeHtml,
},
],
snippet: colorPickerRangeSnippet,
demo: <ColorStopsRange />,
},
{
title: 'Custom color swatches',
source: [
Expand Down
104 changes: 104 additions & 0 deletions src-docs/src/views/color_picker/color_stops_range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useState } from 'react';

import { EuiColorStops, EuiFormRow } from '../../../../src/components';

export const ColorStopsRange = () => {
const [emptyColorStops, setEmptyColorStops] = useState([]);

const handleEmptyChange = colorStops => {
setEmptyColorStops(colorStops);
};

const [emptyColorStops2, setEmptyColorStops2] = useState([]);

const handleEmptyChange2 = colorStops => {
setEmptyColorStops2(colorStops);
};

const [emptyColorStops3, setEmptyColorStops3] = useState([]);

const handleEmptyChange3 = colorStops => {
setEmptyColorStops3(colorStops);
};

const [singleColorStops, setSingleColorStops] = useState([
{ stop: 10, color: '#DB1374' },
]);

const handleSingleChange = colorStops => {
setSingleColorStops(colorStops);
};

const [singleColorStops2, setSingleColorStops2] = useState([
{ stop: 10, color: '#DB1374' },
]);

const handleSingleChange2 = colorStops => {
setSingleColorStops2(colorStops);
};

const [singleColorStops3, setSingleColorStops3] = useState([
{ stop: 10, color: '#DB1374' },
]);

const handleSingleChange3 = colorStops => {
setSingleColorStops3(colorStops);
};

return (
<React.Fragment>
<EuiFormRow label="Empty array without `min` or `max`">
<EuiColorStops
label="Empty start"
onChange={handleEmptyChange2}
colorStops={emptyColorStops2}
stopType="fixed"
/>
</EuiFormRow>
<EuiFormRow label="Empty array with `min` defined">
<EuiColorStops
label="Empty start"
onChange={handleEmptyChange}
colorStops={emptyColorStops}
min={0}
stopType="fixed"
/>
</EuiFormRow>
<EuiFormRow label="Empty array with `max` defined">
<EuiColorStops
label="Empty start"
onChange={handleEmptyChange3}
colorStops={emptyColorStops3}
max={100}
stopType="fixed"
/>
</EuiFormRow>
<EuiFormRow label="Single stop without `min` or `max`">
<EuiColorStops
label="Single start"
onChange={handleSingleChange}
colorStops={singleColorStops}
stopType="fixed"
/>
</EuiFormRow>
<EuiFormRow label="Single stop with `min` defined">
<EuiColorStops
label="Single start"
onChange={handleSingleChange2}
colorStops={singleColorStops2}
min={0}
stopType="fixed"
/>
</EuiFormRow>
<EuiFormRow label="Single stop with `max` defined">
<EuiColorStops
label="Single start"
onChange={handleSingleChange3}
colorStops={singleColorStops3}
max={100}
stopType="fixed"
/>
</EuiFormRow>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ exports[`renders EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -127,11 +127,11 @@ exports[`renders compressed EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight euiRangeHighlight--compressed"
class="euiRangeHighlight euiRangeHighlight--compressed euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -238,11 +238,11 @@ exports[`renders disabled EuiColorStops 1`] = `
class="euiRangeTrack euiRangeTrack--disabled"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -352,11 +352,11 @@ exports[`renders empty EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="margin-left:0%;width:100%"
style="background:linear-gradient(to right,);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -388,11 +388,11 @@ exports[`renders fixed stop EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000, #FF0000 undefined%,#00FF00 undefined%, #00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%, #FF0000 undefined%,#00FF00 undefined%, #00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -483,6 +483,42 @@ exports[`renders fixed stop EuiColorStops 1`] = `
</div>
`;

exports[`renders free-range EuiColorStops 1`] = `
<div
class="euiRangeWrapper euiColorStops testClass1 testClass2"
data-test-subj="euiColorStops"
tabindex="0"
>
<p
aria-live="polite"
class="euiScreenReaderOnly"
>
Test: Color stop picker. Each stop consists of a number and corresponding color value. Use the Down and Up arrow keys to select individual stops. Press the Enter key to create a new stop.
</p>
<div
class="euiRangeTrack"
>
<div
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,);margin-left:0%;width:100%"
/>
</div>
<div
class="euiColorStops__addContainer"
data-test-subj="euiColorStopsAdd"
>
<div
class="euiColorStops__addTarget"
style="left:0%"
/>
</div>
</div>
</div>
`;

exports[`renders fullWidth EuiColorStops 1`] = `
<div
class="euiRangeWrapper euiRangeWrapper--fullWidth euiColorStops testClass1 testClass2"
Expand All @@ -499,11 +535,11 @@ exports[`renders fullWidth EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down Expand Up @@ -594,6 +630,78 @@ exports[`renders fullWidth EuiColorStops 1`] = `
</div>
`;

exports[`renders max-only EuiColorStops 1`] = `
<div
class="euiRangeWrapper euiColorStops testClass1 testClass2"
data-test-subj="euiColorStops"
tabindex="0"
>
<p
aria-live="polite"
class="euiScreenReaderOnly"
>
Test: Color stop picker. Each stop consists of a number and corresponding color value. Use the Down and Up arrow keys to select individual stops. Press the Enter key to create a new stop.
</p>
<div
class="euiRangeTrack"
>
<div
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,);margin-left:0%;width:100%"
/>
</div>
<div
class="euiColorStops__addContainer"
data-test-subj="euiColorStopsAdd"
>
<div
class="euiColorStops__addTarget"
style="left:0%"
/>
</div>
</div>
</div>
`;

exports[`renders min-only EuiColorStops 1`] = `
<div
class="euiRangeWrapper euiColorStops testClass1 testClass2"
data-test-subj="euiColorStops"
tabindex="0"
>
<p
aria-live="polite"
class="euiScreenReaderOnly"
>
Test: Color stop picker. Each stop consists of a number and corresponding color value. Use the Down and Up arrow keys to select individual stops. Press the Enter key to create a new stop.
</p>
<div
class="euiRangeTrack"
>
<div
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,);margin-left:0%;width:100%"
/>
</div>
<div
class="euiColorStops__addContainer"
data-test-subj="euiColorStopsAdd"
>
<div
class="euiColorStops__addTarget"
style="left:0%"
/>
</div>
</div>
</div>
`;

exports[`renders readOnly EuiColorStops 1`] = `
<div
class="euiRangeWrapper euiColorStops euiColorStops-isReadOnly testClass1 testClass2"
Expand All @@ -610,11 +718,11 @@ exports[`renders readOnly EuiColorStops 1`] = `
class="euiRangeTrack"
>
<div
class="euiRangeHighlight"
class="euiRangeHighlight euiColorStops__highlight"
>
<div
class="euiRangeHighlight__progress"
style="background:linear-gradient(to right,#FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
style="background:linear-gradient(to right,currentColor, currentColor undefined%, #FF0000 undefined%,#00FF00 undefined%,#0000FF undefined%);margin-left:0%;width:100%"
/>
</div>
<div
Expand Down
Loading

0 comments on commit dbb9e08

Please sign in to comment.