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

EuiColorStops #2360

Merged
merged 33 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1e06162
WIP
thompsongl Sep 20, 2019
317c77d
WIP: scaling clean up
thompsongl Sep 23, 2019
68c21ef
reverse up/down keys
thompsongl Sep 23, 2019
efce438
add left/right movement
thompsongl Sep 23, 2019
7dbf922
update test
thompsongl Sep 23, 2019
6a10f68
doubleClick addStop; clean up; tests removal
thompsongl Sep 23, 2019
44e74ee
use more range components directly
thompsongl Sep 23, 2019
90c338c
Firefox cleanup
thompsongl Sep 23, 2019
9719b81
i18n; refactor
thompsongl Sep 23, 2019
2ce45d0
Merge branch 'master' into eui-color-stops
thompsongl Sep 24, 2019
83fc325
WIP: add new stop via click
thompsongl Sep 24, 2019
3b77831
clean up
thompsongl Sep 24, 2019
006ba4e
better keyboard interaction
thompsongl Sep 25, 2019
d188f7d
add stop styles
ryankeairns Sep 25, 2019
6907a02
Merge pull request #8 from ryankeairns/eui-color-stops
thompsongl Sep 25, 2019
a1ce7cf
empty set; backspace fix; drag handle fix
thompsongl Sep 25, 2019
f51cf46
readOnly and disabled
thompsongl Sep 25, 2019
b61bed9
screen reader
thompsongl Sep 26, 2019
3f0b89d
more i18n
thompsongl Sep 26, 2019
4f8efd5
cleanup of thumbs
snide Sep 27, 2019
a57ceff
Merge pull request #9 from snide/design/stop
thompsongl Sep 30, 2019
dd8b9c9
Update src/components/color_picker/color_stops/color_stop_thumb.tsx
thompsongl Sep 30, 2019
cd35b46
thumb title
thompsongl Sep 30, 2019
783574c
required label
thompsongl Sep 30, 2019
d078fc8
misc feeback
thompsongl Sep 30, 2019
32c7209
update zIndex for active thumb
thompsongl Sep 30, 2019
f6c0411
Merge branch 'master' into eui-color-stops
thompsongl Oct 1, 2019
020a44b
docs refactor
thompsongl Oct 1, 2019
90f6cf4
util; basic snapshot tests
thompsongl Oct 1, 2019
7259d1a
color stops tests
thompsongl Oct 1, 2019
5285b90
thumb snapshot tests
thompsongl Oct 1, 2019
42ce462
CL
thompsongl Oct 1, 2019
6b94aa5
use sorted array for add via keyboard location
thompsongl Oct 2, 2019
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
40 changes: 39 additions & 1 deletion src-docs/src/views/color_picker/color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';

import { EuiCode, EuiColorPicker, EuiText } from '../../../../src/components';
import {
EuiCode,
EuiColorPicker,
EuiColorStops,
EuiText,
} from '../../../../src/components';

import { ColorPicker } from './color_picker';
const colorPickerSource = require('!!raw-loader!./color_picker');
Expand Down Expand Up @@ -121,6 +126,15 @@ const kitchenSinkSnippet = `<EuiColorPicker
/>
`;

import { ColorStops } from './color_stops';
const colorStopsSource = require('!!raw-loader!./color_stops');
const colorStopsHtml = renderToHtml(ColorStops);
const colorStopsSnippet = `<EuiColorStops
onChange={handleChange}
colorStops={colorStops}
/>
`;

export const ColorPickerExample = {
title: 'Color Picker',
intro: (
Expand Down Expand Up @@ -284,5 +298,29 @@ export const ColorPickerExample = {
snippet: kitchenSinkSnippet,
demo: <KitchenSink />,
},
{
title: 'Color stops',
source: [
{
type: GuideSectionTypes.JS,
code: colorStopsSource,
},
{
type: GuideSectionTypes.HTML,
code: colorStopsHtml,
},
],
props: { EuiColorStops },
text: (
<p>
Use <EuiCode>EuiColorStops</EuiCode> to define color stops for data
driven styling. Stops are numbers within the provided range. The color
segment spans from the given stop number (inclusive) to the next stop
number (exclusive).
</p>
),
snippet: colorStopsSnippet,
demo: <ColorStops />,
},
],
};
173 changes: 173 additions & 0 deletions src-docs/src/views/color_picker/color_stops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import React, { useState } from 'react';

import { DisplayToggles } from '../form_controls/display_toggles';
import {
EuiColorStops,
EuiFormRow,
EuiSpacer,
} from '../../../../src/components';

export const ColorStops = () => {
const generateRandomColor = () =>
// https://www.paulirish.com/2009/random-hex-color-code-snippets/
`#${Math.floor(Math.random() * 16777215).toString(16)}`;

const [addColor, setAddColor] = useState(generateRandomColor());
const [colorStops, setColorStops] = useState([
{
stop: 20,
color: '#00B3A4',
},
{
stop: 50,
color: '#DB1374',
},
{
stop: 65,
color: '#490092',
},
]);

const handleChange = colorStops => {
setColorStops(colorStops);
setAddColor(generateRandomColor());
};

const [extendedColorStops, setExtendedColorStops] = useState([
{
stop: 100,
color: '#00B3A4',
},
{
stop: 250,
color: '#DB1374',
},
{
stop: 350,
color: '#490092',
},
]);

const handleExtendedChange = colorStops => {
setExtendedColorStops(colorStops);
};

const [emptyColorStops, setEmptyColorStops] = useState([]);

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

const changeProps = () => {
setColorStops([
{
stop: 0,
color: '#ff0000',
},
{
stop: 25,
color: '#FFFF00',
},
{
stop: 45,
color: '#008000',
},
]);
};

return (
<React.Fragment>
<button onClick={changeProps}>Prop Change</button>
<EuiFormRow label="Empty start">
<EuiColorStops
label="Empty start"
onChange={handleEmptyChange}
colorStops={emptyColorStops}
min={0}
max={100}
/>
</EuiFormRow>
<EuiFormRow label="Standard">
<EuiColorStops
label="Standard"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
fullWidth={true}
/>
</EuiFormRow>
<EuiFormRow label="Random new color">
<EuiColorStops
label="Random new color"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
addColor={addColor}
/>
</EuiFormRow>
<EuiFormRow label="Extended range">
<EuiColorStops
label="Extended range"
onChange={handleExtendedChange}
colorStops={extendedColorStops}
min={100}
max={400}
/>
</EuiFormRow>
<EuiFormRow label="Swatch-only mode">
<EuiColorStops
label="Swatch-only mode"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
mode="swatch"
/>
</EuiFormRow>
<EuiFormRow label="Picker-only mode">
<EuiColorStops
label="Picker-only mode"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
mode="picker"
/>
</EuiFormRow>
<EuiFormRow label="Custom swatches">
<EuiColorStops
label="Custom swatches"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
swatches={['#333', '#666', '#999', '#CCC']}
/>
</EuiFormRow>
<EuiFormRow label="Fixed color segments">
<EuiColorStops
label="Fixed color segments"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
stopType="fixed"
/>
</EuiFormRow>

<EuiSpacer size="xxl" />

<DisplayToggles canLoading={false}>
<EuiColorStops
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the EuiFormRow this components just floats on the page with no label and feels off

floating on the page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the props weren't passed down correctly when I originally tried with a form row. I'll look again when I get to formal docs

label="State options"
onChange={handleChange}
colorStops={colorStops}
min={0}
max={100}
/>
</DisplayToggles>
</React.Fragment>
);
};
3 changes: 1 addition & 2 deletions src/components/color_picker/_color_picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

.euiColorPicker {
position: relative;
// 5 columns of swatches + margins + border
width: ($euiSizeL * 5) + ($euiSizeS * 4);
width: $euiColorPickerWidth;

}

Expand Down
1 change: 1 addition & 0 deletions src/components/color_picker/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@import 'color_picker_swatch';
@import 'hue';
@import 'saturation';
@import 'color_stops/index';
1 change: 1 addition & 0 deletions src/components/color_picker/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ $euiColorPickerValueRange1: rgba(255, 255, 255, 0);
$euiColorPickerSaturationRange0: rgba(0, 0, 0, 1);
$euiColorPickerSaturationRange1: rgba(0, 0, 0, 0);
$euiColorPickerIndicatorSize: $euiSizeM;
$euiColorPickerWidth: ($euiSizeL * 5) + ($euiSizeS * 4); // 5 columns of swatches + margins + border
4 changes: 0 additions & 4 deletions src/components/color_picker/color_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export interface EuiColorPickerProps
* Custom validation flag
*/
isInvalid?: boolean;
/**
* Renders inline, without an input element or popover
*/
inline?: boolean;
/**
* Choose between swatches with gradient picker (default), swatches only, or gradient picker only.
*/
Expand Down
81 changes: 81 additions & 0 deletions src/components/color_picker/color_stops/_color_stops.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@import '../../form/range/_variables';

.euiColorStops:not(.euiColorStops-isDisabled) {
&:focus {
outline: 2px solid $euiFocusRingColor;
}
}

.euiColorStops__addContainer {
display: block;
position: absolute;
left: 0;
right: 0;
top: 50%;
height: $euiRangeThumbHeight;
margin-top: $euiRangeThumbHeight * -.5;

&:hover:not(.euiColorStops__addContainer-isDisabled) {
cursor: pointer;

.euiColorStops__addTarget {
opacity: .7;
}
}
}

.euiColorStops__addTarget {
@include euiCustomControl($type: 'round');
@include euiRangeThumbStyle;
position: absolute;
top: 0;
height: $euiRangeThumbHeight;
width: $euiRangeThumbHeight;
background-color: $euiColorLightestShade;
pointer-events: none;
opacity: 0;
transition: opacity $euiAnimSpeedFast;
}

.euiColorStop {
width: $euiColorPickerWidth;
}

.euiColorStopPopover.euiPopover {
position: absolute;
top: 50%;
width: $euiRangeThumbWidth;
height: $euiRangeThumbHeight;
margin-top: $euiRangeThumbHeight * -.5;
}

.euiColorStopPopover-hasFocus {
z-index: 1;
}

.euiColorStopPopover__anchor {
position: absolute;
width: 100%;
height: 100%;
}

.euiColorStopThumb.euiRangeThumb:not(:disabled) {
// sass-lint:disable-block no-color-literals, indentation
top: 0;
margin-top: 0;
pointer-events: auto;
cursor: grab;
border: solid ($euiSizeXS - 1px) $euiColorEmptyShade;
box-shadow:
0 0 0 1px $euiColorMediumShade,
0 2px 2px -1px rgba($euiShadowColor, .2),
0 1px 5px -2px rgba($euiShadowColor, .2);

&:active {
cursor: grabbing;
}
}

.euiColorStops.euiColorStops-isDragging:not(.euiColorStops-isDisabled):not(.euiColorStops-isReadOnly) {
cursor: grabbing;
}
1 change: 1 addition & 0 deletions src/components/color_picker/color_stops/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'color_stops';
Loading