import * as React from 'react'; import { TextField } from '@fluentui/react/lib/TextField'; import { Stack, IStackTokens, IStackStyles } from '@fluentui/react/lib/Stack'; import { Toggle } from '@fluentui/react/lib/Toggle'; import { useBoolean } from '@fluentui/react-hooks'; import { Icon, IIconStyles } from '@fluentui/react/lib/Icon'; import { Text } from '@fluentui/react/lib/Text'; const stackTokens: IStackTokens = { childrenGap: 20, maxWidth: 350, }; const richErrorIconStyles: Partial = { root: { color: 'red' } }; const richErrorStackStyles: Partial = { root: { height: 24 } }; const richErrorStackTokens: IStackTokens = { childrenGap: 8 }; const getErrorMessage = (value: string): string => { return value.length < 3 ? '' : `Input value length must be less than 3. Actual length is ${value.length}.`; }; const getErrorMessagePromise = (value: string): Promise => { return new Promise(resolve => { setTimeout(() => resolve(getErrorMessage(value)), 5000); }); }; const getRichErrorMessage = (value: string) => { return value.length < 3 ? ( '' ) : ( Input value length must be less than 3. Actual length is {value.length}. ); }; export const TextFieldErrorMessageExample: React.FunctionComponent = () => { const [showFields, { toggle: toggleShowFields }] = useBoolean(false); return ( {showFields && ( <> Hint: the input length must be less than 3. )} ); };