import type { ForwardedRef, PropsWithChildren } from 'react'; import React from 'react'; import classNames from 'classnames'; import type { FieldLabelProps as CoreFieldLabelProps } from '@shoptet/ui-core-web'; import { Field } from '@shoptet/ui-core-web'; import type { Exact } from '@shoptet/utils'; import type { OmitPrivate } from '../../types'; export interface FieldLabelOwnProps extends PropsWithChildren { /** * Controls the alignment of the label. */ justify?: boolean; /** * Whether the label is visually hidden. */ visuallyHidden?: boolean | 'keepSpace'; } export interface FieldLabelInheritedLabelProps extends OmitPrivate> {} /** @inheritdoc */ export interface FieldLabelProps extends FieldLabelOwnProps, FieldLabelInheritedLabelProps {} export const FieldLabel = React.forwardRef(function FormRowLabel( { visuallyHidden = false, justify, children, ...rest }: FieldLabelProps, forwardedRef: ForwardedRef ) { rest satisfies Exact; const className: CoreFieldLabelProps['className'] = ({ required }) => classNames('v2FormField__label', { 'v2FormField__label--justify': justify, 'v2FormField__label--required': required, }); if (visuallyHidden === true) { return null; } return ( {visuallyHidden === 'keepSpace' ? null : children} ); });