UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

100 lines (92 loc) 3 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = require('prop-types'); var React = require('react'); var cx = require('classnames'); var InlineCheckbox = require('../InlineCheckbox/InlineCheckbox.js'); var RadioButton = require('../RadioButton/RadioButton.js'); var usePrefix = require('../../internal/usePrefix.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); const TableSelectRow = _ref => { let { ariaLabel, checked, id, name, onSelect, onChange, disabled, radio, className } = _ref; const prefix = usePrefix.usePrefix(); const selectionInputProps = { id, name, onClick: onSelect, onChange, checked, disabled }; const InlineInputComponent = radio ? RadioButton["default"] : InlineCheckbox["default"]; const tableSelectRowClasses = cx__default["default"](`${prefix}--table-column-checkbox`, { ...(className && { [className]: true }), [`${prefix}--table-column-radio`]: radio }); return /*#__PURE__*/React__default["default"].createElement("td", { className: tableSelectRowClasses }, /*#__PURE__*/React__default["default"].createElement(InlineInputComponent, _rollupPluginBabelHelpers["extends"]({}, selectionInputProps, radio && { labelText: ariaLabel, hideLabel: true }, !radio && { ['aria-label']: ariaLabel }))); }; TableSelectRow.propTypes = { /** * Specify the aria label for the underlying input control */ ariaLabel: PropTypes__default["default"].string.isRequired, /** * Specify whether this row is selected, or not */ checked: PropTypes__default["default"].bool.isRequired, /** * The CSS class names of the cell that wraps the underlying input control */ className: PropTypes__default["default"].string, /** * Specify whether the control is disabled */ disabled: PropTypes__default["default"].bool, /** * Provide an `id` for the underlying input control */ id: PropTypes__default["default"].string.isRequired, /** * Provide a `name` for the underlying input control */ name: PropTypes__default["default"].string.isRequired, /** * Provide an optional hook that is called each time the input is updated */ onChange: PropTypes__default["default"].func, /** * Provide a handler to listen to when a user initiates a selection request */ onSelect: PropTypes__default["default"].func.isRequired, /** * Specify whether the control should be a radio button or inline checkbox */ radio: PropTypes__default["default"].bool }; exports["default"] = TableSelectRow;