UNPKG

@carbon/react

Version:

React components for the Carbon Design System

131 lines (125 loc) 4.26 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var React = require('react'); var PropTypes = require('prop-types'); var cx = require('classnames'); var FluidTextInput = require('../FluidTextInput/FluidTextInput.js'); require('../FluidTextInput/FluidPasswordInput.js'); require('../FluidTextInput/FluidTextInput.Skeleton.js'); var usePrefix = require('../../internal/usePrefix.js'); var iconsReact = require('@carbon/icons-react'); // eslint-disable-next-line react/display-name -- https://github.com/carbon-design-system/carbon/issues/20452 const FluidTimePicker = /*#__PURE__*/React.forwardRef(({ className, children, disabled, invalid, invalidText, warn, warnText, readOnly, ...other }, ref) => { const prefix = usePrefix.usePrefix(); const classNames = cx(className, { [`${prefix}--time-picker--fluid`]: true, [`${prefix}--time-picker--equal-width`]: React.Children.toArray(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; const childrenWithProps = () => { if (disabled) { return React.Children.toArray(children).map(child => /*#__PURE__*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452 React.cloneElement(child, { disabled: true })); } if (readOnly) { return React.Children.toArray(children).map(child => /*#__PURE__*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452 React.cloneElement(child, { readOnly: true })); } return children; }; return /*#__PURE__*/React.createElement("div", { className: classNames }, /*#__PURE__*/React.createElement("div", { className: `${prefix}--time-picker--fluid__wrapper` }, /*#__PURE__*/React.createElement("div", { className: `${prefix}--time-picker__input` }, /*#__PURE__*/React.createElement(FluidTextInput.default, _rollupPluginBabelHelpers.extends({ ref: ref, readOnly: readOnly, disabled: disabled }, other))), childrenWithProps()), error && /*#__PURE__*/React.createElement("hr", { className: `${prefix}--time-picker__divider` }), error && /*#__PURE__*/React.createElement("div", { className: `${prefix}--form-requirement` }, errorText()), error && invalid ? /*#__PURE__*/React.createElement(iconsReact.WarningFilled, { className: `${prefix}--time-picker__icon ${prefix}--time-picker__icon--invalid` }) : /*#__PURE__*/React.createElement(iconsReact.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, /** * Whether or not the component is readonly */ readOnly: PropTypes.bool }; exports.default = FluidTimePicker;