// Copyright (c) Meta Platforms, Inc. and affiliates. 'use client'; /** * @file FieldLabel.tsx * @input Uses React, Icon, IconType, useTranslator, FormLayoutContext * @output Exports FieldLabel component, FieldLabelProps * @position Core label implementation; used by Field, CheckboxInput, Switch * * SYNC: When modified, update these files to stay in sync: * - /packages/core/src/Field/Field.doc.mjs (props table, features, implementation notes) * - /packages/core/src/Field/index.ts (exports if types change) * - /packages/core/src/FormLayout/FormLayoutContext.ts (defaultOptionality drives the indicator) * - /packages/cli/assets/templates/blocks/components/Field/ (showcase blocks) * - /packages/core/locales/en.json (@astryx.field.required / @astryx.field.optional) */ import { use, useMemo, useRef, type ReactNode, type RefObject } from 'react'; import * as stylex from "../style-runtime.js"; import type { BaseProps } from "../BaseProps.js"; import { mergeProps } from "../utils/index.js"; import "../theme/tokens.stylex.js"; import { colorVars, fontWeightVars, spacingVars, typographyVars, typeScaleVars } from "../theme/tokens.stylex.js"; import { Icon, renderIconSlot, type IconType } from "../Icon/index.js"; import { Tooltip } from "../Tooltip/index.js"; import { useTranslator } from "../i18n/index.js"; import { themeProps } from "../utils/themeProps.js"; import { useInputContainer } from "../hooks/index.js"; import { FormLayoutContext } from "../FormLayout/FormLayoutContext.js"; const styles = { label: { k1xSpc: "x78zum5", kGNEyG: "x6s0dn4", kOIVth: "xzye2dw", kMv6JI: "x9ynric", kGuDYH: "xcr08ib", kLWn49: "x1kq96og", k63SB2: "x1e4wzip", kMwMTN: "xv1l7n4", kkrTdU: "x1ypdohk x16khyan", $$css: true as const }, labelDisabled: { kMwMTN: "xnbbluu", kkrTdU: "xt0e3qv", $$css: true as const }, srOnly: { ksu8eU: "xng3xce", kMcinP: "xzpqnlu", kZKoxP: "xjm9jq1", kLqNvP: "x1o0tod", kogj98: "xkdpibf", kVQacm: "xb3r6kr", kmVPX3: "x1717udv", kfzvcC: "x47corl", kVAEAm: "x10l6tqk", k87sOh: "x13vifvy", kfSwDN: "x87ps6o", khDVqt: "xuxw1ft", kzqmXN: "x1i1rx1s", $$css: true as const } }; export interface FieldLabelProps extends BaseProps { /** Ref forwarded to the root element */ ref?: React.Ref; /** * Label text (always rendered for accessibility). */ label: string; /** * ID of the input element this label points AT (rendered as `htmlFor` on the * label). This is *not* the id of the label element itself — see * `labelID` for that. */ inputID: string; /** * The `id` applied TO the label element itself (not the element it points * at — that's `inputID`). A grouping control (e.g. `role="radiogroup"`) can * reference this via `aria-labelledby` to take the label as its accessible * name. */ labelID?: string; /** * When true, the field wraps a *group* of controls (e.g. a radiogroup) * rather than a single input. In that case the label is rendered as a * `` instead of a `