- );
- }
-}
-
-ColorPicker.propTypes = {
- name: PropTypes.string.isRequired,
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
- disableTrash: PropTypes.bool,
- onChange: PropTypes.func,
-};
diff --git a/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.js b/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.js
deleted file mode 100644
index 8d3c65833bdda..0000000000000
--- a/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.js
+++ /dev/null
@@ -1,69 +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.
- */
-
-import React from 'react';
-import { ColorPicker } from './color_picker';
-import { mount } from 'enzyme';
-import { CustomColorPicker } from './custom_color_picker';
-
-const defaultProps = {
- name: 'color',
- value: null,
- onChange: jest.fn(),
- disableTrash: true,
-};
-
-describe('ColorPicker', () => {
- it('should change state after click', () => {
- const wrapper = mount();
-
- const stateBefore = wrapper.state();
- wrapper.find('button').at(0).simulate('click');
- const stateAfter = wrapper.state();
-
- expect(stateBefore.displayPicker).toBe(!stateAfter.displayPicker);
- });
-
- it('should close popup after click', () => {
- const wrapper = mount();
- wrapper.setState({ displayPicker: true });
-
- wrapper.find('.tvbColorPicker__cover').simulate('click');
-
- expect(wrapper.state().displayPicker).toBeFalsy();
- });
-
- it('should exist CustomColorPickerUI component', () => {
- const wrapper = mount();
- wrapper.setState({ displayPicker: true });
-
- const w2 = wrapper.find(CustomColorPicker).exists();
-
- expect(w2).toBeTruthy();
- });
-
- it('should call clear function', () => {
- const props = { ...defaultProps, disableTrash: false, value: 'rgba(85,66,177,1)' };
- const wrapper = mount();
-
- wrapper.find('.tvbColorPicker__clear').simulate('click');
-
- expect(defaultProps.onChange).toHaveBeenCalled();
- });
-});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.tsx b/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.tsx
new file mode 100644
index 0000000000000..ca8750a991d83
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/application/components/color_picker.test.tsx
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+import React from 'react';
+import { ColorPicker, ColorPickerProps } from './color_picker';
+import { mount } from 'enzyme';
+import { ReactWrapper } from 'enzyme';
+import { EuiColorPicker, EuiIconTip } from '@elastic/eui';
+
+describe('ColorPicker', () => {
+ const defaultProps: ColorPickerProps = {
+ name: 'color',
+ value: null,
+ onChange: jest.fn(),
+ disableTrash: true,
+ };
+ let component: ReactWrapper;
+
+ it('should render the EuiColorPicker', () => {
+ component = mount();
+ expect(component.find(EuiColorPicker).length).toBe(1);
+ });
+
+ it('should not render the clear button', () => {
+ component = mount();
+ expect(component.find('.tvbColorPicker__clear').length).toBe(0);
+ });
+
+ it('should render the correct aria label to the color swatch button', () => {
+ const props = { ...defaultProps, value: 'rgba(85,66,177,0.59)' };
+ component = mount();
+ const button = component.find('.tvbColorPicker button');
+ expect(button.prop('aria-label')).toBe('Color picker (rgba(85,66,177,0.59)), not accessible');
+ });
+
+ it('should call clear function if the disableTrash prop is false', () => {
+ const props = { ...defaultProps, disableTrash: false, value: 'rgba(85,66,177,1)' };
+ component = mount();
+
+ component.find('.tvbColorPicker__clear').simulate('click');
+
+ expect(component.find(EuiIconTip).length).toBe(1);
+ expect(defaultProps.onChange).toHaveBeenCalled();
+ });
+});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/color_picker.tsx b/src/plugins/vis_type_timeseries/public/application/components/color_picker.tsx
new file mode 100644
index 0000000000000..be580c80d5941
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/application/components/color_picker.tsx
@@ -0,0 +1,95 @@
+/*
+ * 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 React, { useState } from 'react';
+import {
+ EuiIconTip,
+ EuiColorPicker,
+ EuiColorPickerProps,
+ EuiColorPickerSwatch,
+} from '@elastic/eui';
+import { i18n } from '@kbn/i18n';
+
+const COMMAS_NUMS_ONLY_RE = /[^0-9,]/g;
+
+interface ColorProps {
+ [key: string]: string | null;
+}
+
+export interface ColorPickerProps {
+ name: string;
+ value: string | null;
+ disableTrash?: boolean;
+ onChange: (props: ColorProps) => void;
+}
+
+export function ColorPicker({ name, value, disableTrash = false, onChange }: ColorPickerProps) {
+ const initialColorValue = value ? value.replace(COMMAS_NUMS_ONLY_RE, '') : '';
+ const [color, setColor] = useState(initialColorValue);
+
+ const handleColorChange: EuiColorPickerProps['onChange'] = (text: string, { rgba, hex }) => {
+ setColor(text);
+ const part: ColorProps = {};
+ part[name] = hex ? `rgba(${rgba.join(',')})` : '';
+ onChange(part);
+ };
+
+ const handleClear = () => {
+ setColor('');
+ const part: ColorProps = {};
+ part[name] = null;
+ onChange(part);
+ };
+
+ const label = value
+ ? i18n.translate('visTypeTimeseries.colorPicker.notAccessibleWithValueAriaLabel', {
+ defaultMessage: 'Color picker ({value}), not accessible',
+ values: { value },
+ })
+ : i18n.translate('visTypeTimeseries.colorPicker.notAccessibleAriaLabel', {
+ defaultMessage: 'Color picker, not accessible',
+ });
+
+ return (
+
+ }
+ />
+ {!disableTrash && (
+
+
+
+ )}
+
+ );
+}
diff --git a/src/plugins/vis_type_timeseries/public/application/components/custom_color_picker.js b/src/plugins/vis_type_timeseries/public/application/components/custom_color_picker.js
deleted file mode 100644
index bb10c9f495f56..0000000000000
--- a/src/plugins/vis_type_timeseries/public/application/components/custom_color_picker.js
+++ /dev/null
@@ -1,200 +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.
- */
-
-import PropTypes from 'prop-types';
-import React, { PureComponent } from 'react';
-
-import {
- ColorWrap as colorWrap,
- Saturation,
- Hue,
- Alpha,
- Checkboard,
-} from 'react-color/lib/components/common';
-import ChromeFields from 'react-color/lib/components/chrome/ChromeFields';
-import ChromePointer from 'react-color/lib/components/chrome/ChromePointer';
-import ChromePointerCircle from 'react-color/lib/components/chrome/ChromePointerCircle';
-import CompactColor from 'react-color/lib/components/compact/CompactColor';
-import color from 'react-color/lib/helpers/color';
-
-class CustomColorPickerUI extends PureComponent {
- constructor(props) {
- super(props);
- this.handleChange = this.handleChange.bind(this);
- }
-
- handleChange(data) {
- this.props.onChange(data);
- }
-
- render() {
- const rgb = this.props.rgb;
-
- const styles = {
- active: {
- background: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`,
- },
- Saturation: {
- radius: '2px 2px 0 0 ',
- },
- Hue: {
- radius: '2px',
- },
- Alpha: {
- radius: '2px',
- },
- };
-
- const handleSwatchChange = (data) => {
- if (data.hex) {
- color.isValidHex(data.hex) &&
- this.props.onChange({
- hex: data.hex,
- source: 'hex',
- });
- } else {
- this.props.onChange(data);
- }
- };
-
- const swatches = this.props.colors.map((c) => {
- return ;
- });
-
- return (
-