UNPKG

@carbon/ibm-security

Version:

Carbon for Cloud & Cognitive IBM Security UI components

68 lines (67 loc) 2.16 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["children", "count", "countLabel", "className", "countClassName", "title"]; /** * @file Filter panel label component. * @copyright IBM Security 2020, 2021 */ import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { getComponentNamespace } from '../../../globals/namespace'; var namespace = getComponentNamespace('filter-panel-label'); var FilterPanelLabel = function FilterPanelLabel(_ref) { var children = _ref.children, count = _ref.count, countLabel = _ref.countLabel, className = _ref.className, countClassName = _ref.countClassName, title = _ref.title, other = _objectWithoutProperties(_ref, _excluded); return /*#__PURE__*/React.createElement("span", _extends({ className: classnames(namespace, className) }, other), /*#__PURE__*/React.createElement("span", { className: "".concat(namespace, "__text"), title: title }, children), !Number.isNaN(parseInt(count, 10)) && /*#__PURE__*/React.createElement("span", { className: classnames("".concat(namespace, "__count"), countClassName), "aria-label": "(".concat(countLabel(count), ")") }, count)); }; FilterPanelLabel.propTypes = { /** * Label text. */ children: PropTypes.node, /** * Optional class name. */ className: PropTypes.string, /** * Label count. */ count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), /** * Optional class name for the count. */ countClassName: PropTypes.string, /** * Function returning a translated text labeling the count for accessibility. */ countLabel: PropTypes.func, /** * The `title` attribute that is applied to the label node. */ title: PropTypes.string }; FilterPanelLabel.defaultProps = { children: undefined, count: undefined, countLabel: function countLabel(count) { return "".concat(count, " items"); }, className: undefined, countClassName: undefined, title: undefined }; export default FilterPanelLabel;