UNPKG

@elastic/eui

Version:

Elastic UI Component Library

168 lines (167 loc) 5.82 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiCardSelect = void 0; exports.euiCardSelectableColor = euiCardSelectableColor; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _i18n = require("../../i18n"); var _button = require("../../button/button"); var _card_select = require("./card_select.styles"); var _react2 = require("@emotion/react"); var _excluded = ["isSelected", "isDisabled", "disabled", "color", "children"]; /* * 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. */ var EuiCardSelect = exports.EuiCardSelect = function EuiCardSelect(_ref) { var _ref$isSelected = _ref.isSelected, isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected, isDisabled = _ref.isDisabled, disabled = _ref.disabled, color = _ref.color, children = _ref.children, rest = (0, _objectWithoutProperties2.default)(_ref, _excluded); var styles = (0, _card_select.euiCardSelectStyles)(); var baseCSS = [styles.euiCardSelect]; var child = euiCardSelectableText(isSelected, isDisabled || disabled, children); return (0, _react2.jsx)(_button.EuiButton, (0, _extends2.default)({ css: baseCSS, color: euiCardSelectableColor(color, isSelected), size: "m", isDisabled: isDisabled || disabled, iconType: isSelected ? 'check' : undefined, role: "switch", "aria-checked": isSelected, fullWidth: true }, rest), child); }; EuiCardSelect.propTypes = { href: _propTypes.default.string, onClick: _propTypes.default.func, children: _propTypes.default.node, /** * Make button a solid color for prominence */ /** * Make button a solid color for prominence */ fill: _propTypes.default.bool, /** * Any of the named color palette options. * * Do not use the following colors for standalone buttons directly, * they exist to serve other components: * - accent * - warning * - neutral * - risk */ color: _propTypes.default.any, /** * Use size `s` in confined spaces */ /** * Use size `s` in confined spaces */ size: _propTypes.default.any, /** * Controls the disabled behavior via the native `disabled` attribute. */ /** * Controls the disabled behavior via the native `disabled` attribute. */ isDisabled: _propTypes.default.bool, /** * NOTE: Beta feature, may be changed or removed in the future * * Changes the native `disabled` attribute to `aria-disabled` to preserve focusability. * This results in a semantically disabled button without the default browser handling of the disabled state. * * Use e.g. when a disabled button should have a tooltip. */ /** * NOTE: Beta feature, may be changed or removed in the future * * Changes the native `disabled` attribute to `aria-disabled` to preserve focusability. * This results in a semantically disabled button without the default browser handling of the disabled state. * * Use e.g. when a disabled button should have a tooltip. */ hasAriaDisabled: _propTypes.default.bool, className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any, buttonRef: _propTypes.default.any, element: _propTypes.default.oneOf(["a", "button", "span"]), /** * Applies the boolean state as the `aria-pressed` property to create a toggle button. * *Only use when the readable text does not change between states.* */ isSelected: _propTypes.default.bool, /** * Extends the button to 100% width */ fullWidth: _propTypes.default.bool, /** * Override the default minimum width */ minWidth: _propTypes.default.oneOfType([_propTypes.default.any.isRequired, _propTypes.default.oneOf([false])]), /** * Force disables the button and changes the icon to a loading spinner */ isLoading: _propTypes.default.bool, /** * Object of props passed to the <span/> wrapping the button's content */ contentProps: _propTypes.default.shape({ className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any }), style: _propTypes.default.any, type: _propTypes.default.any }; function euiCardSelectableText(isSelected, isDisabled, children) { if (children) { return children; } var text; if (isSelected) { text = (0, _react2.jsx)(_i18n.EuiI18n, { token: "euiCardSelect.selected", default: "Selected" }); } else if (isDisabled) { text = (0, _react2.jsx)(_i18n.EuiI18n, { token: "euiCardSelect.unavailable", default: "Unavailable" }); } else { text = (0, _react2.jsx)(_i18n.EuiI18n, { token: "euiCardSelect.select", default: "Select" }); } return text; } function euiCardSelectableColor(color, isSelected) { var calculatedColor; if (color) { calculatedColor = color; } else if (isSelected) { calculatedColor = 'success'; } else { calculatedColor = 'text'; } return calculatedColor; }