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

[Maps] replace ColorStops component with EuiColorStops #49512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@import './components/color_gradient';
@import './components/static_dynamic_style_row';
@import './vector/components/color/color_stops';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';

import { EuiSuperSelect, EuiSpacer } from '@elastic/eui';
import { EuiSuperSelect, EuiSpacer, EuiColorStops } from '@elastic/eui';
import { COLOR_GRADIENTS } from '../../../color_utils';
import { FormattedMessage } from '@kbn/i18n/react';
import { ColorStops } from './color_stops';
import { isInvalid } from './color_stops_utils';
import { i18n } from '@kbn/i18n';

const CUSTOM_COLOR_RAMP = 'CUSTOM_COLOR_RAMP';

Expand All @@ -36,15 +38,14 @@ export class ColorRampSelect extends Component {
});
};

_onCustomColorRampChange = ({ colorStops, isInvalid }) => {
// Manage invalid custom color ramp in local state
if (isInvalid) {
_onCustomColorRampChange = (colorStops) => {
if (isInvalid(colorStops)) {
this.setState({ customColorRamp: colorStops });
return;
}

this.props.onChange({
customColorRamp: colorStops,
customColorRamp: _.sortBy(colorStops, 'stop')
});
};

Expand All @@ -62,9 +63,13 @@ export class ColorRampSelect extends Component {
colorStopsInput = (
<Fragment>
<EuiSpacer size="s" />
<ColorStops
<EuiColorStops
label={i18n.translate('xpack.maps.style.colorRampStopsLabel', {
defaultMessage: 'Color ramp stops'
})}
colorStops={this.state.customColorRamp}
onChange={this._onCustomColorRampChange}
stopType="fixed"
/>
</Fragment>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,6 @@

import { isValidHex } from '@elastic/eui';

export function removeRow(colorStops, index) {
if (colorStops.length === 1) {
return colorStops;
}

return [...colorStops.slice(0, index), ...colorStops.slice(index + 1)];
}

export function addRow(colorStops, index) {
const currentStop = colorStops[index].stop;
let delta = 1;
if (index === colorStops.length - 1) {
// Adding row to end of list.
if (index !== 0) {
const prevStop = colorStops[index - 1].stop;
delta = currentStop - prevStop;
}
} else {
// Adding row in middle of list.
const nextStop = colorStops[index + 1].stop;
delta = (nextStop - currentStop) / 2;
}

const newRow = {
stop: currentStop + delta,
color: '#FF0000',
};
return [
...colorStops.slice(0, index + 1),
newRow,
...colorStops.slice(index + 1),
];
}

export function isColorInvalid(color) {
return !isValidHex(color) || color === '';
}
Expand All @@ -49,18 +15,7 @@ export function isStopInvalid(stop) {
}

export function isInvalid(colorStops) {
return colorStops.some((colorStop, index) => {
// expect stops to be in ascending order
let isDescending = false;
if (index !== 0) {
const prevStop = colorStops[index - 1].stop;
isDescending = prevStop >= colorStop.stop;
}

return (
isColorInvalid(colorStop.color) ||
isStopInvalid(colorStop.stop) ||
isDescending
);
return colorStops.some((colorStop) => {
return isColorInvalid(colorStop.color) || isStopInvalid(colorStop.stop);
});
}