diff --git a/components/TextField/TextField.stories.tsx b/components/TextField/TextField.stories.tsx index f1bb4078..8bacfbdb 100644 --- a/components/TextField/TextField.stories.tsx +++ b/components/TextField/TextField.stories.tsx @@ -2,8 +2,12 @@ import React from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; import { Flex } from '../Flex'; +import { Label } from '../Label'; +import { Text } from '../Text'; +import { Popover, PopoverTrigger, PopoverContent } from '../Popover'; import { TextField, TextFieldProps, TextFieldVariants } from './TextField'; -import { MagnifyingGlassIcon } from '@radix-ui/react-icons'; +import { MagnifyingGlassIcon, InfoCircledIcon } from '@radix-ui/react-icons'; +import { styled } from '../../stitches.config'; import { modifyVariantsForStory } from '../../utils/modifyVariantsForStory'; import ignoreArgType from '../../utils/ignoreArgType'; @@ -97,4 +101,58 @@ DisplayClearable.args = { id: 'displayclearable', clearable: true, }; -ignoreArgType('id', DisplayClearable); \ No newline at end of file +ignoreArgType('id', DisplayClearable); + +export const LabelComponent: ComponentStory = ({ id, ...args }) => ( + + + + + + +) + +const StyledInfoCircledIcon = styled(InfoCircledIcon, { + ml: '$2', + '@hover': { + '&:hover': { + cursor: 'pointer' + } + } +}); + +const label = (props) => ( + +) + +LabelComponent.args = { + id: 'labelcomponent', + label: label, +} +ignoreArgType('id', LabelComponent); \ No newline at end of file diff --git a/components/TextField/TextField.tsx b/components/TextField/TextField.tsx index de936494..45f030e4 100644 --- a/components/TextField/TextField.tsx +++ b/components/TextField/TextField.tsx @@ -13,10 +13,16 @@ import { } from '@radix-ui/react-icons'; // TYPES +export interface TextFieldLabelProps { + variant: 'red' | 'subtle' | 'contrast' | 'default' + disabled?: boolean + invalid?: boolean + htmlFor?: string +} export type TextFieldProps = InputProps & { type?: string; clearable?: boolean; - label?: string; + label?: string | ((props: TextFieldLabelProps) => JSX.Element); }; export type TextFieldVariants = InputVariants; @@ -60,7 +66,7 @@ const StyledCrossCircledIcon = styled(CrossCircledIcon, { export const TextField = React.forwardRef, TextFieldProps>( ( - { state, clearable, label, id, type, disabled, readOnly, onBlur, onFocus, css, ...props }, + { state, clearable, label: LabelOrComponent, id, type, disabled, readOnly, onBlur, onFocus, css, ...props }, forwardedRef ) => { const inputRef = React.useRef(null); @@ -85,6 +91,25 @@ export const TextField = React.forwardRef, TextFi return 'default'; }, [invalid, disabled, inputHasFocus]); + const LabelNode = React.useMemo( + () => { + if (LabelOrComponent === undefined || LabelOrComponent === null) { + return null; + } + if (typeof LabelOrComponent === 'string') { + return ( + + ); + } + return ( + + ); + }, + [LabelOrComponent, labelVariant, disabled, invalid, id], + ); + const isPasswordType = React.useMemo(() => type === 'password', [type]); const typeOrInnerType = React.useMemo(() => (isPasswordType ? innerType : type), [ @@ -154,11 +179,7 @@ export const TextField = React.forwardRef, TextFi return ( - {label && ( - - )} + {LabelNode}