@elastic/eui
Version:
Elastic UI Component Library
141 lines (138 loc) • 6.55 kB
JavaScript
var _excluded = ["className", "color", "size", "position", "max", "valueText", "label", "value", "labelProps"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { Fragment } from 'react';
import PropTypes from "prop-types";
import classNames from 'classnames';
import { EuiI18n } from '../i18n';
import { EuiInnerText } from '../inner_text';
import { isNil } from '../../services/predicate';
import { useEuiTheme, makeHighContrastColor } from '../../services';
import { euiProgressStyles, euiProgressDataStyles, euiProgressLabelStyles, euiProgressValueTextStyles } from './progress.styles';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var SIZES = ['xs', 's', 'm', 'l'];
export var COLORS = ['primary', 'success', 'warning', 'danger', 'subdued', 'accent', 'vis0', 'vis1', 'vis2', 'vis3', 'vis4', 'vis5', 'vis6', 'vis7', 'vis8', 'vis9'];
export var POSITIONS = ['fixed', 'absolute', 'static'];
export var EuiProgress = function EuiProgress(_ref) {
var className = _ref.className,
_ref$color = _ref.color,
color = _ref$color === void 0 ? 'success' : _ref$color,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'm' : _ref$size,
_ref$position = _ref.position,
position = _ref$position === void 0 ? 'static' : _ref$position,
max = _ref.max,
_ref$valueText = _ref.valueText,
valueText = _ref$valueText === void 0 ? false : _ref$valueText,
label = _ref.label,
value = _ref.value,
labelProps = _ref.labelProps,
rest = _objectWithoutProperties(_ref, _excluded);
var determinate = !isNil(max);
var isNamedColor = COLORS.includes(color);
var euiTheme = useEuiTheme();
var customColorStyles = !isNamedColor ? {
color: color
} : {};
var customTextColorStyles = !isNamedColor ? {
color: makeHighContrastColor(color)(euiTheme.euiTheme)
} : {};
var styles = euiProgressStyles(euiTheme, determinate);
var cssStyles = [styles.euiProgress, determinate && styles.native, !determinate && styles.indeterminate, styles[size], styles[position], isNamedColor ? styles[color] : styles.customColor];
var dataStyles = euiProgressDataStyles(euiTheme);
var dataCssStyles = [dataStyles.euiProgress__data, size === 'l' && dataStyles[size]];
var labelCssStyles = [euiProgressLabelStyles.euiProgress__label, labelProps === null || labelProps === void 0 ? void 0 : labelProps.css];
var valueTextStyles = euiProgressValueTextStyles(euiTheme);
var valueTextCssStyles = [valueTextStyles.euiProgress__valueText, isNamedColor ? valueTextStyles[color] : styles.customColor];
var classes = classNames('euiProgress', className);
var labelClasses = classNames('euiProgress__label', labelProps === null || labelProps === void 0 ? void 0 : labelProps.className);
var valueRender;
if (valueText === true) {
// valueText is true
valueRender = ___EmotionJSX(EuiI18n, {
token: "euiProgress.valueText",
default: "{value}%",
values: {
value: value
}
});
} else if (valueText) {
// valueText exists
valueRender = valueText;
}
// Because of a Firefox animation issue, indeterminate progress needs to not use <progress />.
// See https://css-tricks.com/html5-progress-element/
if (determinate) {
return ___EmotionJSX(Fragment, null, label || valueText ? ___EmotionJSX("div", {
css: dataCssStyles,
className: "euiProgress__data"
}, label && ___EmotionJSX(EuiInnerText, null, function (ref, innerText) {
return ___EmotionJSX("span", _extends({
title: innerText,
ref: ref
}, labelProps, {
className: labelClasses,
css: labelCssStyles
}), label);
}), valueRender && ___EmotionJSX(EuiInnerText, null, function (ref, innerText) {
return ___EmotionJSX("span", {
title: innerText,
ref: ref,
style: customTextColorStyles,
css: valueTextCssStyles,
className: "euiProgress__valueText"
}, valueRender);
})) : undefined, ___EmotionJSX("progress", _extends({
css: cssStyles,
className: classes,
style: customColorStyles,
max: max,
value: value,
"aria-hidden": label && valueText ? true : false
}, rest)));
} else {
return ___EmotionJSX("div", _extends({
css: cssStyles,
style: customColorStyles,
className: classes
}, rest));
}
};
EuiProgress.propTypes = {
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
size: PropTypes.any,
/**
* One of EUI's color palette, vis colors or a valid CSS color value https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
*/
/**
* One of EUI's color palette, vis colors or a valid CSS color value https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
*/
color: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.any.isRequired]),
position: PropTypes.any,
max: PropTypes.number,
/*
* If true, will render the percentage, otherwise pass a custom node
*/
valueText: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.node.isRequired]),
label: PropTypes.node,
/**
* Object of props passed to the <span/> wrapping the determinate progress's label
*/
labelProps: PropTypes.shape({
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any
})
};