From ab1270e566f878dfc5e9ae226fe42cccb1ff92d6 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 17 Jun 2020 14:27:05 +0300 Subject: [PATCH] Replaces the Custom Color Picker on TSVB with the EuiColorPicker (#68888) * Replace the Custom Color Picker on TSVB with the EuiColorPicker * Remove the custom picker sass * Remove private modules of eui and the custom color swatches * Clear the color * changes in test implementation Co-authored-by: Elastic Machine --- .../application/components/_color_picker.scss | 33 --- .../components/_custom_color_picker.scss | 97 --------- .../public/application/components/_index.scss | 1 - .../application/components/color_picker.js | 125 ----------- .../components/color_picker.test.js | 69 ------ .../components/color_picker.test.tsx | 61 ++++++ .../application/components/color_picker.tsx | 95 +++++++++ .../components/custom_color_picker.js | 200 ------------------ .../page_objects/visual_builder_page.ts | 4 +- 9 files changed, 158 insertions(+), 527 deletions(-) delete mode 100644 src/plugins/vis_type_timeseries/public/application/components/_custom_color_picker.scss delete mode 100644 src/plugins/vis_type_timeseries/public/application/components/color_picker.js delete mode 100644 src/plugins/vis_type_timeseries/public/application/components/color_picker.test.js create mode 100644 src/plugins/vis_type_timeseries/public/application/components/color_picker.test.tsx create mode 100644 src/plugins/vis_type_timeseries/public/application/components/color_picker.tsx delete mode 100644 src/plugins/vis_type_timeseries/public/application/components/custom_color_picker.js diff --git a/src/plugins/vis_type_timeseries/public/application/components/_color_picker.scss b/src/plugins/vis_type_timeseries/public/application/components/_color_picker.scss index e486f56fe0fe8a..9d50b0875dd0dd 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/_color_picker.scss +++ b/src/plugins/vis_type_timeseries/public/application/components/_color_picker.scss @@ -8,39 +8,6 @@ position: relative; } -.tvbColorPicker__swatch-empty, -.tvbColorPicker__swatch { - // SASSTODO: Replace with EUI component - // sass-lint:disable-block placeholder-in-extend - @extend .euiColorPickerSwatch; -} - -.tvbColorPicker__swatch-empty { - background-color: transparent; - background-size: 22px 22px; - background-image: repeating-linear-gradient( - -45deg, - $euiColorDanger, - $euiColorDanger 2px, - transparent 2px, - transparent $euiSize - ); -} - .tvbColorPicker__clear { margin-left: $euiSizeXS; } - -.tvbColorPicker__popover { - position: absolute; - top: $euiSizeL; - z-index: 2; -} - -.tvbColorPicker__cover { - position: fixed; - top: 0; - right: 0; - left: 0; - bottom: 0; -} diff --git a/src/plugins/vis_type_timeseries/public/application/components/_custom_color_picker.scss b/src/plugins/vis_type_timeseries/public/application/components/_custom_color_picker.scss deleted file mode 100644 index f2f5eff35fc5d6..00000000000000 --- a/src/plugins/vis_type_timeseries/public/application/components/_custom_color_picker.scss +++ /dev/null @@ -1,97 +0,0 @@ -// EUITODO: Convert to EuiColorPicker -// with additional support for alpha, saturation, swatches - -// SASSTODO: This custom picker moved all styles from react-color inline styles -// to SASS, but it should be in EUI. -// Also, some pixel values were kept as is to match inline styles from react-color -.tvbColorPickerPopUp { - @include euiBottomShadowMedium; - background-color: $euiColorEmptyShade; - border-radius: $euiBorderRadius; - box-sizing: initial; - width: 275px; - font-family: 'Menlo'; -} - -.tvbColorPickerPopUp__saturation { - width: 100%; - padding-bottom: 55%; - position: relative; - border-radius: $euiBorderRadius $euiBorderRadius 0 0; - overflow: hidden; -} - -.tvbColorPickerPopUp__body { - padding: $euiSize; -} - -.tvbColorPickerPopUp__controls { - display: flex; -} - -.tvbColorPickerPopUp__color { - width: $euiSizeXL; - - // The color indicator doesn't work, hiding it until it does - display: none; -} - -.tvbColorPickerPopUp__color-disableAlpha { - width: $euiSizeL; -} - -.tvbColorPickerPopUp__swatch { - margin-top: 6px; - width: $euiSize; - height: $euiSize; - border-radius: $euiSizeS; - position: relative; - overflow: hidden; -} - -.tvbColorPickerPopUp__swatch-disableAlpha { - width: 10px; - height: 10px; - margin: 0; -} - -.tvbColorPickerPopUp__active { - @include euiBottomShadowMedium; - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - border-radius: $euiSizeS; - z-index: 2; -} - -.tvbColorPickerPopUp__toggles { - flex: 1; -} - -.tvbColorPickerPopUp__hue { - height: 10px; - position: relative; - margin-bottom: $euiSizeS; -} - -.tvbColorPickerPopUp__hue-disableAlpha { - margin-bottom: 0; -} - -.tvbColorPickerPopUp__alpha { - height: 10px; - position: relative; -} - -.tvbColorPickerPopUp__alpha-disableAlpha { - display: none; -} - -.tvbColorPickerPopUp__swatches { - display: flex; - flex-wrap: wrap; - justify-content: center; - margin-top: $euiSize; -} diff --git a/src/plugins/vis_type_timeseries/public/application/components/_index.scss b/src/plugins/vis_type_timeseries/public/application/components/_index.scss index 3a10b07c23e2b7..4ee5c1863946b5 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/_index.scss +++ b/src/plugins/vis_type_timeseries/public/application/components/_index.scss @@ -1,7 +1,6 @@ @import './annotations_editor'; @import './color_rules'; @import './color_picker'; -@import './custom_color_picker'; @import './error'; @import './no_data'; @import './markdown_editor'; diff --git a/src/plugins/vis_type_timeseries/public/application/components/color_picker.js b/src/plugins/vis_type_timeseries/public/application/components/color_picker.js deleted file mode 100644 index f12797518cd28f..00000000000000 --- a/src/plugins/vis_type_timeseries/public/application/components/color_picker.js +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ -// The color picker is not yet accessible. - -import PropTypes from 'prop-types'; -import React, { Component } from 'react'; -import { EuiIconTip } from '@elastic/eui'; -import { CustomColorPicker } from './custom_color_picker'; -import { i18n } from '@kbn/i18n'; - -export class ColorPicker extends Component { - constructor(props) { - super(props); - this.state = { - displayPicker: false, - color: {}, - }; - } - - handleChange = (color) => { - const { rgb } = color; - const part = {}; - part[this.props.name] = `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`; - if (this.props.onChange) this.props.onChange(part); - }; - - handleClick = () => { - this.setState({ displayPicker: !this.state.displayColorPicker }); - }; - - handleClose = () => { - this.setState({ displayPicker: false }); - }; - - handleClear = () => { - const part = {}; - part[this.props.name] = null; - this.props.onChange(part); - }; - - renderSwatch() { - if (!this.props.value) { - return ( -