@elastic/eui
Version:
Elastic UI Component Library
162 lines (161 loc) • 5.81 kB
JavaScript
var _excluded = ["isSelected", "isDisabled", "disabled", "color", "children"];
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 from 'react';
import PropTypes from "prop-types";
import { EuiI18n } from '../../i18n';
import { EuiButton } from '../../button/button';
import { euiCardSelectStyles } from './card_select.styles';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var 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 = _objectWithoutProperties(_ref, _excluded);
var styles = euiCardSelectStyles();
var baseCSS = [styles.euiCardSelect];
var child = euiCardSelectableText(isSelected, isDisabled || disabled, children);
return ___EmotionJSX(EuiButton, _extends({
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.string,
onClick: PropTypes.func,
children: PropTypes.node,
/**
* Make button a solid color for prominence
*/
/**
* Make button a solid color for prominence
*/
fill: PropTypes.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.any,
/**
* Use size `s` in confined spaces
*/
/**
* Use size `s` in confined spaces
*/
size: PropTypes.any,
/**
* Controls the disabled behavior via the native `disabled` attribute.
*/
/**
* Controls the disabled behavior via the native `disabled` attribute.
*/
isDisabled: PropTypes.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.bool,
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any,
buttonRef: PropTypes.any,
element: PropTypes.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.bool,
/**
* Extends the button to 100% width
*/
fullWidth: PropTypes.bool,
/**
* Override the default minimum width
*/
minWidth: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.oneOf([false])]),
/**
* Force disables the button and changes the icon to a loading spinner
*/
isLoading: PropTypes.bool,
/**
* Object of props passed to the <span/> wrapping the button's content
*/
contentProps: PropTypes.shape({
className: PropTypes.string,
"aria-label": PropTypes.string,
"data-test-subj": PropTypes.string,
css: PropTypes.any
}),
style: PropTypes.any,
type: PropTypes.any
};
function euiCardSelectableText(isSelected, isDisabled, children) {
if (children) {
return children;
}
var text;
if (isSelected) {
text = ___EmotionJSX(EuiI18n, {
token: "euiCardSelect.selected",
default: "Selected"
});
} else if (isDisabled) {
text = ___EmotionJSX(EuiI18n, {
token: "euiCardSelect.unavailable",
default: "Unavailable"
});
} else {
text = ___EmotionJSX(EuiI18n, {
token: "euiCardSelect.select",
default: "Select"
});
}
return text;
}
export function euiCardSelectableColor(color, isSelected) {
var calculatedColor;
if (color) {
calculatedColor = color;
} else if (isSelected) {
calculatedColor = 'success';
} else {
calculatedColor = 'text';
}
return calculatedColor;
}