UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

119 lines (115 loc) 3.6 kB
/** * MSKCC 2021, 2024 */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import { CheckmarkFilled } from '@carbon/icons-react'; import cx from 'classnames'; import PropTypes from 'prop-types'; import React__default from 'react'; import { useFallbackId } from '../../internal/useId.js'; import { usePrefix } from '../../internal/usePrefix.js'; import deprecate from '../../prop-types/deprecate.js'; import { matches } from '../../internal/keyboard/match.js'; import { Enter, Space } from '../../internal/keyboard/keys.js'; var _CheckmarkFilled; const RadioTile = /*#__PURE__*/React__default.forwardRef(function RadioTile(_ref, ref) { let { children, className: customClassName, disabled, // eslint-disable-next-line no-unused-vars light, checked, name, value, id, onChange, tabIndex, ...rest } = _ref; const prefix = usePrefix(); const inputId = useFallbackId(id); const className = cx(customClassName, `${prefix}--tile`, `${prefix}--tile--selectable`, { [`${prefix}--tile--is-selected`]: checked, [`${prefix}--tile--light`]: light, [`${prefix}--tile--disabled`]: disabled }); function handleOnChange(evt) { onChange(value, name, evt); } function handleOnKeyDown(evt) { if (matches(evt, [Enter, Space])) { evt.preventDefault(); onChange(value, name, evt); } } return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("input", { checked: checked, className: `${prefix}--tile-input`, disabled: disabled, id: inputId, name: name, onChange: !disabled ? handleOnChange : null, onKeyDown: !disabled ? handleOnKeyDown : null, tabIndex: !disabled ? tabIndex : null, type: "radio", value: value, ref: ref }), /*#__PURE__*/React__default.createElement("label", _extends({}, rest, { htmlFor: inputId, className: className }), /*#__PURE__*/React__default.createElement("span", { className: `${prefix}--tile__checkmark` }, _CheckmarkFilled || (_CheckmarkFilled = /*#__PURE__*/React__default.createElement(CheckmarkFilled, null))), /*#__PURE__*/React__default.createElement("span", { className: `${prefix}--tile-content` }, children))); }); RadioTile.propTypes = { /** * `true` if this tile should be selected. */ checked: PropTypes.bool, /** * The tile content. */ children: PropTypes.node, /** * The CSS class names. */ className: PropTypes.string, /** * Specify whether the RadioTile should be disabled */ disabled: PropTypes.bool, /** * The ID of the `<input>`. */ id: PropTypes.string, /** * `true` to use the light version. For use on $ui-01 backgrounds only. * Don't use this to make tile background color same as container background color. */ light: deprecate(PropTypes.bool, 'The `light` prop for `RadioTile` is no longer needed and has ' + 'been deprecated in v11 in favor of the new `Layer` component. It will be moved in the next major release.'), /** * The `name` of the `<input>`. */ name: PropTypes.string, /** * The handler of the massaged `change` event on the `<input>`. */ onChange: PropTypes.func, /** * Specify the tab index of the wrapper element */ tabIndex: PropTypes.number, /** * The `value` of the `<input>`. */ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired }; RadioTile.defaultProps = { onChange: () => {}, tabIndex: 0 }; var RadioTile$1 = RadioTile; export { RadioTile$1 as default };