UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

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