@carbon/react
Version:
React components for the Carbon Design System
73 lines (71 loc) • 2.47 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { usePrefix } from "../../internal/usePrefix.js";
import { useId } from "../../internal/useId.js";
import { deprecate } from "../../prop-types/deprecate.js";
import InlineCheckbox_default from "../InlineCheckbox/index.js";
import RadioButton_default from "../RadioButton/index.js";
import classNames from "classnames";
import "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/DataTable/TableSelectRow.tsx
/**
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const TableSelectRow = ({ ariaLabel: deprecatedAriaLabel, ["aria-label"]: ariaLabel, checked, id, name, onSelect, onChange, disabled, radio, className }) => {
const prefix = usePrefix();
const uniqueNameId = useId();
const handleRadioChange = onChange ? (value, name, event) => {
onChange(!!value, name || "", event);
} : void 0;
const handleCheckboxChange = onChange ? (checked, name, event) => {
onChange(checked, name, event);
} : void 0;
const selectionInputProps = {
id,
name: name ? name : uniqueNameId,
onClick: onSelect,
checked,
disabled
};
const labelValue = ariaLabel || deprecatedAriaLabel || "";
return /* @__PURE__ */ jsx("td", {
className: classNames(`${prefix}--table-column-checkbox`, {
...className && { [className]: true },
[`${prefix}--table-column-radio`]: radio
}),
"aria-live": "off",
children: radio ? /* @__PURE__ */ jsx(RadioButton_default, {
...selectionInputProps,
labelText: labelValue,
onChange: handleRadioChange,
hideLabel: true
}) : /* @__PURE__ */ jsx(InlineCheckbox_default, {
...selectionInputProps,
"aria-label": labelValue,
onChange: handleCheckboxChange
})
});
};
TableSelectRow.propTypes = {
["aria-label"]: PropTypes.string,
ariaLabel: deprecate(PropTypes.string, "This prop syntax has been deprecated. Please use the new `aria-label`."),
checked: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
onChange: PropTypes.func,
onSelect: PropTypes.func.isRequired,
radio: PropTypes.bool
};
//#endregion
export { TableSelectRow as default };