UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

102 lines (98 loc) 3.28 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 FluidTextInput from '../FluidTextInput/FluidTextInput.js'; import { usePrefix } from '../../internal/usePrefix.js'; import { WarningFilled, WarningAltFilled } from '@carbon/icons-react'; const FluidTimePicker = /*#__PURE__*/React__default.forwardRef(function FluidTimePicker(_ref, ref) { let { className, children, disabled, invalid, invalidText, warn, warnText, ...other } = _ref; const prefix = usePrefix(); const classNames = cx(className, { [`${prefix}--time-picker--fluid`]: true, [`${prefix}--time-picker--equal-width`]: children?.length !== 2, [`${prefix}--time-picker--fluid--disabled`]: disabled, [`${prefix}--time-picker--fluid--invalid`]: invalid, [`${prefix}--time-picker--fluid--warning`]: warn }); const errorText = () => { if (invalid) { return invalidText; } if (warn) { return warnText; } }; const error = invalid || warn; return /*#__PURE__*/React__default.createElement("div", { className: classNames }, /*#__PURE__*/React__default.createElement("div", { className: `${prefix}--time-picker--fluid__wrapper` }, /*#__PURE__*/React__default.createElement("div", { className: `${prefix}--time-picker__input` }, /*#__PURE__*/React__default.createElement(FluidTextInput, _extends({ disabled: disabled, ref: ref }, other))), disabled ? React__default.Children.toArray(children).map(child => { return /*#__PURE__*/React__default.cloneElement(child, { disabled }); }) : children), error && /*#__PURE__*/React__default.createElement("hr", { className: `${prefix}--time-picker__divider` }), error && /*#__PURE__*/React__default.createElement("div", { className: `${prefix}--form-requirement` }, errorText()), error && invalid ? /*#__PURE__*/React__default.createElement(WarningFilled, { className: `${prefix}--time-picker__icon ${prefix}--time-picker__icon--invalid` }) : /*#__PURE__*/React__default.createElement(WarningAltFilled, { className: `${prefix}--time-picker__icon ${prefix}--time-picker__icon--warn` })); }); FluidTimePicker.propTypes = { /** * The child node(s) */ children: PropTypes.node, /** * Specify an optional className to be applied to the outer FluidTimePicker wrapper */ className: PropTypes.string, /** * Specify whether the `<input>` should be disabled */ disabled: PropTypes.bool, /** * Specify whether or not the control is invalid */ invalid: PropTypes.bool, /** * Provide the text that is displayed when the control is in error state */ invalidText: PropTypes.node, /** * Provide the text that will be read by a screen reader when visiting this * control */ labelText: PropTypes.node.isRequired, /** * Specify whether the control is currently in warning state */ warn: PropTypes.bool, /** * Provide the text that is displayed when the control is in warning state */ warnText: PropTypes.node }; var FluidTimePicker$1 = FluidTimePicker; export { FluidTimePicker$1 as default };