import * as React from 'react'; import { TextField, ITextFieldProps } from '@fluentui/react/lib/TextField'; import { DefaultButton, IconButton, IButtonStyles } from '@fluentui/react/lib/Button'; import { Icon, IIconStyles } from '@fluentui/react/lib/Icon'; import { Callout } from '@fluentui/react/lib/Callout'; import { IStackTokens, Stack, IStackStyles } from '@fluentui/react/lib/Stack'; import { Text } from '@fluentui/react/lib/Text'; import { IRenderFunction, memoizeFunction } from '@fluentui/react/lib/Utilities'; import { getTheme, FontWeights, ITheme } from '@fluentui/react/lib/Styling'; import { useBoolean, useId } from '@fluentui/react-hooks'; export interface ITextFieldCustomRenderExampleState { isCalloutVisible: boolean; } const stackTokens: IStackTokens = { childrenGap: 4, maxWidth: 300, }; const labelCalloutStackStyles: Partial = { root: { padding: 20 } }; const iconButtonStyles: Partial = { root: { marginBottom: -3 } }; const iconStyles: Partial = { root: { marginBottom: -3 } }; const iconProps = { iconName: 'Info' }; const getDescriptionStyles = memoizeFunction((theme: ITheme) => ({ root: { color: theme.palette.green, fontWeight: FontWeights.bold }, })); const onRenderDescription = (props: ITextFieldProps): JSX.Element => { const theme = getTheme(); return ( {props.description} ); }; const onWrapDefaultLabelRenderer = ( props: ITextFieldProps, defaultRender: IRenderFunction, ): JSX.Element => { return ( <> {defaultRender(props)} ); }; const CustomLabel = (props: ITextFieldProps): JSX.Element => { const [isCalloutVisible, { toggle: toggleIsCalloutVisible }] = useBoolean(false); const descriptionId: string = useId('description'); const iconButtonId: string = useId('iconButton'); return ( <> {props.label} {isCalloutVisible && ( The custom label includes an IconButton that displays this Callout on click. Close )} ); }; export const TextFieldCustomRenderExample: React.FunctionComponent = () => { const labelId: string = useId('label'); const onRenderLabel = (props: ITextFieldProps) => ; return ( ); };