UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

93 lines (85 loc) 3.75 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var cx = require('classnames'); var PropTypes = require('prop-types'); var React = require('react'); var usePrefix = require('../../internal/usePrefix.js'); var deprecate = require('../../prop-types/deprecate.js'); var requiredIfGivenPropIsTruthy = require('../../prop-types/requiredIfGivenPropIsTruthy.js'); var MskIcon = require('../Icon/MskIcon.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); const TableExpandHeader = _ref => { let { ariaLabel, className: headerClassName, enableExpando, enableToggle, id = 'expand', isExpanded, onExpand, expandIconDescription, children, ...rest } = _ref; const prefix = usePrefix.usePrefix(); const className = cx__default["default"](`${prefix}--table-expand`, headerClassName); const previousValue = isExpanded ? 'collapsed' : undefined; return /*#__PURE__*/React__default["default"].createElement("th", _rollupPluginBabelHelpers["extends"]({ scope: "col", className: className, "data-previous-value": previousValue, id: id }, rest), enableExpando || enableToggle ? /*#__PURE__*/React__default["default"].createElement("button", { type: "button", className: `${prefix}--table-expand__button`, onClick: onExpand, title: expandIconDescription, "aria-label": ariaLabel }, /*#__PURE__*/React__default["default"].createElement(MskIcon.Icon, { icon: "chevron_right", className: `${prefix}--table-expand__svg`, "aria-label": expandIconDescription })) : null, children); }; TableExpandHeader.propTypes = { /** * Specify the string read by a voice reader when the expand trigger is * focused */ ariaLabel: PropTypes__default["default"].oneOfType([requiredIfGivenPropIsTruthy["default"]('enableExpando', PropTypes__default["default"].string), requiredIfGivenPropIsTruthy["default"]('enableToggle', PropTypes__default["default"].string)]), children: PropTypes__default["default"].node, className: PropTypes__default["default"].string, /** * The enableExpando prop is being replaced by enableToggle */ enableExpando: deprecate["default"](PropTypes__default["default"].bool, 'The `enableExpando` prop has been deprecated in favor of `enableToggle`. This prop will be removed in the next major release.'), /** * Specify whether an expand all button should be displayed */ enableToggle: PropTypes__default["default"].bool, /** * The description of the chevron right icon, to be put in its SVG `<title>` element. */ expandIconDescription: PropTypes__default["default"].string, /** * Supply an id to the th element. */ id: PropTypes__default["default"].string, /** * Specify whether this row is expanded or not. This helps coordinate data * attributes so that `TableExpandRow` and `TableExpandedRow` work together */ isExpanded: requiredIfGivenPropIsTruthy["default"]('enableToggle', PropTypes__default["default"].bool), /** * Hook for when a listener initiates a request to expand the given row */ onExpand: PropTypes__default["default"].oneOfType([requiredIfGivenPropIsTruthy["default"]('enableExpando', PropTypes__default["default"].func), requiredIfGivenPropIsTruthy["default"]('enableToggle', PropTypes__default["default"].func)]) }; exports["default"] = TableExpandHeader;