diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 0ca498970729..c10c078eeb5a 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -8602,6 +8602,12 @@ Map { "value": Object { "type": "string", }, + "warning": Object { + "type": "bool", + }, + "warningText": Object { + "type": "node", + }, }, "render": [Function], }, diff --git a/packages/react/src/components/TimePicker/TimePicker.stories.js b/packages/react/src/components/TimePicker/TimePicker.stories.js index 988d5a371a95..9f062af247a2 100644 --- a/packages/react/src/components/TimePicker/TimePicker.stories.js +++ b/packages/react/src/components/TimePicker/TimePicker.stories.js @@ -112,6 +112,15 @@ Playground.argTypes = { invalidText: { control: { type: 'text' }, }, + warning: { + control: { + type: 'boolean', + }, + defaultValue: false, + }, + warningText: { + control: { type: 'text' }, + }, labelText: { control: { type: 'text' }, }, diff --git a/packages/react/src/components/TimePicker/TimePicker.tsx b/packages/react/src/components/TimePicker/TimePicker.tsx index 24f689d7b396..556777f97261 100644 --- a/packages/react/src/components/TimePicker/TimePicker.tsx +++ b/packages/react/src/components/TimePicker/TimePicker.tsx @@ -11,6 +11,7 @@ import React from 'react'; import { usePrefix } from '../../internal/usePrefix'; import deprecate from '../../prop-types/deprecate'; import { ForwardRefReturn, ReactAttr } from '../../types/common'; +import { WarningFilled, WarningAltFilled } from '@carbon/icons-react'; type ExcludedAttributes = 'id' | 'value'; @@ -51,6 +52,16 @@ export interface TimePickerProps */ invalidText?: React.ReactNode; + /** + * Specify a warning message + */ + warning?: boolean; + + /** + * Provide the text that is displayed when the control is in an warning state + */ + warningText?: React.ReactNode; + /** * Provide the text that will be read by a screen reader when visiting this * control @@ -135,6 +146,8 @@ const TimePicker: TimePickerComponent = React.forwardRef< id, invalidText = 'Invalid time format.', invalid = false, + warningText = 'Warning message.', + warning = false, labelText, light = false, maxLength = 5, @@ -192,6 +205,7 @@ const TimePicker: TimePickerComponent = React.forwardRef< [className], { [`${prefix}--text-input--light`]: light, + [`${prefix}--time-picker__input-field-error`]: invalid || warning, } ); @@ -199,6 +213,7 @@ const TimePicker: TimePickerComponent = React.forwardRef< [`${prefix}--time-picker`]: true, [`${prefix}--time-picker--light`]: light, [`${prefix}--time-picker--invalid`]: invalid, + [`${prefix}--time-picker--warning`]: warning, [`${prefix}--time-picker--readonly`]: readOnly, [`${prefix}--time-picker--${size}`]: size, ...(className && { [className]: true }), @@ -215,10 +230,6 @@ const TimePicker: TimePickerComponent = React.forwardRef< ) : null; - const error = invalid ? ( -