UNPKG

@carbon/react

Version:

React components for the Carbon Design System

120 lines (116 loc) 3.75 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import FluidTextInput from '../FluidTextInput/FluidTextInput.js'; import '../FluidTextInput/FluidPasswordInput.js'; import '../FluidTextInput/FluidTextInput.Skeleton.js'; import { usePrefix } from '../../internal/usePrefix.js'; import { WarningFilled, WarningAltFilled } from '@carbon/icons-react'; const FluidTimePicker = /*#__PURE__*/React.forwardRef(function FluidTimePicker({ className, children, disabled, invalid, invalidText, warn, warnText, readOnly, ...other }, ref) { const prefix = 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__*/React.cloneElement(child, { disabled: true })); } if (readOnly) { return React.Children.toArray(children).map(child => /*#__PURE__*/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, _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(WarningFilled, { className: `${prefix}--time-picker__icon ${prefix}--time-picker__icon--invalid` }) : /*#__PURE__*/React.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, /** * Whether or not the component is readonly */ readOnly: PropTypes.bool }; export { FluidTimePicker as default };