@@ -11,6 +11,7 @@ import { feedbackHeight, feedbackStyles } from '../../utils/feedback.styles';
1111import { reset } from '../../utils/reset.styles' ;
1212import { sizes as typographySizes , styles as typographyStyles } from '../../utils/typography.styles' ;
1313import { visuallyHidden } from '../../utils/visually-hidden.styles' ;
14+ import type { FieldFeedback as FormFieldFeedback } from '../form' ;
1415import type { FieldOrientation } from './field.context' ;
1516import {
1617 FieldMessageProvider ,
@@ -202,18 +203,19 @@ const Message = React.forwardRef<HTMLDivElement, FieldMessageProps>(function Mos
202203 return < FieldMessageProvider register = { register } > { rendered } </ FieldMessageProvider > ;
203204} ) ;
204205
205- type FieldFeedbackKind = 'error' | 'success' ;
206+ type FieldFeedbackKind = 'error' | 'success' | 'info' ;
206207
207- const FEEDBACK : Record < FieldFeedbackKind , { slot : string ; icon : IconName ; color : stylex . StyleXStyles } > = {
208+ const FEEDBACK : Record < FieldFeedbackKind , { slot : string ; icon ? : IconName ; color : stylex . StyleXStyles } > = {
208209 error : { slot : 'field-error' , icon : 'exclamation-circle' , color : feedbackStyles . error } ,
209210 success : { slot : 'field-success' , icon : 'checkmark' , color : feedbackStyles . success } ,
211+ info : { slot : 'field-info' , color : feedbackStyles . info } ,
210212} ;
211213
212- interface FieldFeedbackProps extends MosaicComponentProps < 'p' > {
214+ interface FieldFeedbackPartProps extends MosaicComponentProps < 'p' > {
213215 kind : FieldFeedbackKind ;
214216}
215217
216- const FieldFeedback = React . forwardRef < HTMLParagraphElement , FieldFeedbackProps > ( function MosaicFieldFeedback (
218+ const FieldFeedback = React . forwardRef < HTMLParagraphElement , FieldFeedbackPartProps > ( function MosaicFieldFeedback (
217219 { render, xstyle, id : idProp , children, kind, ...rest } ,
218220 ref ,
219221) {
@@ -240,7 +242,7 @@ const FieldFeedback = React.forwardRef<HTMLParagraphElement, FieldFeedbackProps>
240242 rest ,
241243 ) ,
242244 id,
243- children : < FeedbackBody icon = { icon } > { message } </ FeedbackBody > ,
245+ children : icon ? < FeedbackBody icon = { icon } > { message } </ FeedbackBody > : message ,
244246 } ,
245247 } ) ;
246248} ) ;
@@ -271,5 +273,47 @@ const FieldSuccess = React.forwardRef<HTMLParagraphElement, FieldSuccessProps>(f
271273 ) ;
272274} ) ;
273275
276+ export type FieldHintProps = MosaicComponentProps < 'p' > ;
277+
278+ const FieldHint = React . forwardRef < HTMLParagraphElement , FieldHintProps > ( function MosaicFieldHint ( props , ref ) {
279+ return (
280+ < FieldFeedback
281+ ref = { ref }
282+ kind = 'info'
283+ { ...props }
284+ />
285+ ) ;
286+ } ) ;
287+
288+ export interface FieldFeedbackProps extends Omit < FieldMessageProps , 'children' > {
289+ feedback ?: FormFieldFeedback ;
290+ }
291+
292+ const Feedback = React . forwardRef < HTMLDivElement , FieldFeedbackProps > ( function MosaicFieldFeedbackValue (
293+ { feedback, ...props } ,
294+ ref ,
295+ ) {
296+ return (
297+ < Message
298+ ref = { ref }
299+ { ...props }
300+ >
301+ < FieldError > { feedback ?. type === 'error' ? feedback . message : null } </ FieldError >
302+ < FieldHint > { feedback ?. type === 'info' || feedback ?. type === 'warning' ? feedback . message : null } </ FieldHint >
303+ < FieldSuccess > { feedback ?. type === 'success' ? feedback . message : null } </ FieldSuccess >
304+ </ Message >
305+ ) ;
306+ } ) ;
307+
274308/** Styled parts for composing an automatically associated single-control field. */
275- export const Field = { Root, Label, Content, Description, Message, Error : FieldError , Success : FieldSuccess } ;
309+ export const Field = {
310+ Root,
311+ Label,
312+ Content,
313+ Description,
314+ Message,
315+ Feedback,
316+ Error : FieldError ,
317+ Success : FieldSuccess ,
318+ Hint : FieldHint ,
319+ } ;
0 commit comments