mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fixes loading element icon color (#24551)
* Fixed loading element icon color
* Fixed package.json
* Fixed loading component test
* Revert "Fixed package.json"
This reverts commit 033fc8477d
.
This commit is contained in:
parent
f74f633920
commit
567576a724
4 changed files with 33 additions and 6 deletions
18
x-pack/plugins/canvas/common/lib/hex_to_rgb.js
Normal file
18
x-pack/plugins/canvas/common/lib/hex_to_rgb.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const hexToRgb = hex => {
|
||||
const shorthandHexColor = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i;
|
||||
const hexColor = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
||||
|
||||
const shorthandMatches = shorthandHexColor.exec(hex);
|
||||
if (shorthandMatches) return shorthandMatches.slice(1, 4).map(hex => parseInt(hex + hex, 16));
|
||||
|
||||
const hexMatches = hexColor.exec(hex);
|
||||
if (hexMatches) return hexMatches.slice(1, 4).map(hex => parseInt(hex, 16));
|
||||
|
||||
return null;
|
||||
};
|
|
@ -8,7 +8,7 @@ import React from 'react';
|
|||
import expect from 'expect.js';
|
||||
import { shallow } from 'enzyme';
|
||||
import { EuiLoadingSpinner, EuiIcon } from '@elastic/eui';
|
||||
import { Loading } from '../';
|
||||
import { Loading } from '../loading';
|
||||
|
||||
describe('<Loading />', () => {
|
||||
it('uses EuiIcon by default', () => {
|
||||
|
|
|
@ -4,7 +4,12 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { pure } from 'recompose';
|
||||
import { connect } from 'react-redux';
|
||||
import { getSelectedPage, getPageById } from '../../state/selectors/workpad';
|
||||
import { Loading as Component } from './loading';
|
||||
|
||||
export const Loading = pure(Component);
|
||||
const mapStateToProps = state => ({
|
||||
backgroundColor: getPageById(state, getSelectedPage(state)).style.background,
|
||||
});
|
||||
|
||||
export const Loading = connect(mapStateToProps)(Component);
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { EuiLoadingSpinner, EuiIcon } from '@elastic/eui';
|
||||
import { EuiLoadingSpinner, EuiIcon, isColorDark } from '@elastic/eui';
|
||||
import { hexToRgb } from '../../../common/lib/hex_to_rgb';
|
||||
|
||||
export const Loading = ({ animated, text }) => {
|
||||
export const Loading = ({ animated, text, backgroundColor }) => {
|
||||
if (animated) {
|
||||
return (
|
||||
<div className="canvasLoading">
|
||||
|
@ -23,6 +24,8 @@ export const Loading = ({ animated, text }) => {
|
|||
);
|
||||
}
|
||||
|
||||
const rgb = hexToRgb(backgroundColor);
|
||||
|
||||
return (
|
||||
<div className="canvasLoading">
|
||||
{text && (
|
||||
|
@ -31,7 +34,7 @@ export const Loading = ({ animated, text }) => {
|
|||
|
||||
</span>
|
||||
)}
|
||||
<EuiIcon type="clock" />
|
||||
<EuiIcon color={rgb && isColorDark(...rgb) ? 'ghost' : 'text'} type="clock" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -39,6 +42,7 @@ export const Loading = ({ animated, text }) => {
|
|||
Loading.propTypes = {
|
||||
animated: PropTypes.bool,
|
||||
text: PropTypes.string,
|
||||
backgroundColor: PropTypes.string,
|
||||
};
|
||||
|
||||
Loading.defaultProps = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue