UNPKG

@elastic/eui

Version:

Elastic UI Component Library

121 lines (120 loc) 5.27 kB
var _excluded = ["className", "step", "title", "onClick", "disabled", "status", "size"]; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } /* * 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 classNames from 'classnames'; import PropTypes from "prop-types"; import React from 'react'; import { EuiStepNumber } from './step_number'; import { useI18nCompleteStep, useI18nCurrentStep, useI18nDisabledStep, useI18nIncompleteStep, useI18nStep, useI18nWarningStep, useI18nErrorsStep, useI18nLoadingStep } from './step_strings'; import { useEuiTheme } from '../../services'; import { euiStepHorizontalStyles, euiStepHorizontalNumberStyles, euiStepHorizontalTitleStyles } from './step_horizontal.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiStepHorizontal = function EuiStepHorizontal(_ref) { var className = _ref.className, _ref$step = _ref.step, step = _ref$step === void 0 ? 1 : _ref$step, title = _ref.title, onClick = _ref.onClick, disabled = _ref.disabled, _ref$status = _ref.status, status = _ref$status === void 0 ? 'incomplete' : _ref$status, _ref$size = _ref.size, size = _ref$size === void 0 ? 'm' : _ref$size, rest = _objectWithoutProperties(_ref, _excluded); if (disabled) status = 'disabled'; var classes = classNames('euiStepHorizontal', className); var euiTheme = useEuiTheme(); var styles = euiStepHorizontalStyles(euiTheme); var cssStyles = [styles.euiStepHorizontal, styles[size], status === 'disabled' ? styles.disabled : styles.enabled]; var numberStyles = euiStepHorizontalNumberStyles(euiTheme); var cssNumberStyles = [numberStyles.euiStepHorizontal__number]; var titleStyles = euiStepHorizontalTitleStyles(euiTheme); var cssTitleStyles = [titleStyles.euiStepHorizontal__title, status === 'disabled' && titleStyles.disabled]; var titleAttrsMap = { step: useI18nStep({ number: step, title: title }), current: useI18nCurrentStep({ number: step, title: title }), disabled: useI18nDisabledStep({ number: step, title: title }), incomplete: useI18nIncompleteStep({ number: step, title: title }), complete: useI18nCompleteStep({ number: step, title: title }), warning: useI18nWarningStep({ number: step, title: title }), danger: useI18nErrorsStep({ number: step, title: title }), loading: useI18nLoadingStep({ number: step, title: title }) }; var titleAttr = titleAttrsMap[status || 'step']; var onStepClick = function onStepClick(event) { if (!disabled) onClick(event); }; return ___EmotionJSX("button", _extends({ className: classes, title: titleAttr, onClick: onStepClick, disabled: disabled, css: cssStyles, "data-step-status": status }, rest), ___EmotionJSX(EuiStepNumber, { className: "euiStepHorizontal__number", status: status, number: step, titleSize: size === 's' ? 'xs' : 'm' // The titleSize map is not 1 to 1; small == xs on the titleSize map , css: cssNumberStyles }), ___EmotionJSX("span", { className: "euiStepHorizontal__title", css: cssTitleStyles }, title)); }; EuiStepHorizontal.propTypes = { onClick: PropTypes.func.isRequired, /** * Makes the whole step button disabled. */ disabled: PropTypes.bool, /** * The number of the step in the list of steps */ step: PropTypes.number, title: PropTypes.string, /** * Visual representation of the step number indicator. * May replace the number provided in props.step with alternate styling. * The `disabled` prop will override this. */ status: PropTypes.any, size: PropTypes.any, className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any };