Synertech Web/ui v0.57.5 Site Storybook

Documentation / Forms

Label

Server-compatible@synertech/uiOpen in Storybook

The form label: a <label> (or a <span> / <p> through as) with five sizes, eight semantic colours in three intensities, icons on either side and the “required” / “optional” marks. Linked to a field with htmlFor, it gives that field its accessible name.

required adds an asterisk hidden from screen readers, backed by invisible text, requiredLabel (“(required)” by default); optionalText defaults to "(optional)". tooltip renders as a native title attribute.

No hooks and no directive: it renders on the server, so UILabelsProvider does not reach it. Its two texts are props, English by default: pass frenchUILabels.labelRequired and frenchUILabels.labelOptional, or your own texts. The library’s fields (Input, Select…) already carry their own label through label; Label is for native fields and custom compositions.

Examples

Basic usage

htmlFor links the label to the field’s id: clicking it focuses the field.

Open in a tab
import { Label } from "@synertech/ui";

export function Basic() {
  return (
    <div className="flex flex-col gap-1.5">
      <Label htmlFor="company-name">Raison sociale</Label>
      <input id="company-name" className="rounded-lg border border-gray-300 p-2 text-sm" />
    </div>
  );
}

Required and optional

required adds the requiredIndicator mark (“*” by default); optional the optionalText text.

Open in a tab
import { Label } from "@synertech/ui";

export function RequiredOptional() {
  return (
    <div className="flex flex-col gap-2">
      <Label htmlFor="email" required>
        Adresse e-mail
      </Label>
      <Label htmlFor="phone" optional optionalText="(facultatif)">
        Téléphone
      </Label>
      <Label htmlFor="siret" required requiredIndicator=" (obligatoire)">
        SIRET
      </Label>
    </div>
  );
}

Sizes and weights

size goes from xs to xl, weight from normal to bold (medium by default).

Open in a tab
import { Label } from "@synertech/ui";

export function Sizes() {
  return (
    <div className="flex flex-col gap-2">
      <Label size="xs" weight="normal">
        Très petit, normal
      </Label>
      <Label size="sm">Petit, medium</Label>
      <Label size="lg" weight="semibold">
        Grand, semi-gras
      </Label>
      <Label size="xl" weight="bold">
        Très grand, gras
      </Label>
    </div>
  );
}

Colours and intensities

color picks the hue, variant its intensity: light, default or strong.

Open in a tab
import { Label } from "@synertech/ui";

export function Colors() {
  return (
    <div className="flex flex-wrap gap-4">
      <Label as="span" color="primary">
        Principal
      </Label>
      <Label as="span" color="success" variant="strong">
        Validé
      </Label>
      <Label as="span" color="warning">
        En attente
      </Label>
      <Label as="span" color="error" variant="strong">
        Refusé
      </Label>
      <Label as="span" color="muted" variant="light">
        Archivé
      </Label>
    </div>
  );
}

Icons, tooltip and disabled state

icon / endIcon frame the text, tooltip adds a title, truncate cuts long texts.

Open in a tab
import { Label } from "@synertech/ui";

const InfoIcon = () => (
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M12 16v-4m0-4h.01M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
    />
  </svg>
);

export function WithIcons() {
  return (
    <div className="flex w-56 flex-col gap-2">
      <Label
        htmlFor="vat"
        endIcon={<InfoIcon />}
        tooltip="Numéro de TVA intracommunautaire, ex. FR12345678901"
      >
        N° de TVA
      </Label>
      <Label htmlFor="ref" truncate className="w-full">
        Référence interne du dossier client chez le fournisseur
      </Label>
      <Label htmlFor="archived" disabled>
        Champ verrouillé
      </Label>
    </div>
  );
}

API reference

Components

Label

ComponentServer-compatible
import { Label } from "@synertech/ui";

Props — LabelProps

PropTypeDefaultDescription
as "label" | "span" | "p" "label"
children ReactNode —
color LabelColor "default"
disabled boolean false
endIcon ReactNode —
htmlFor string —
icon ReactNode —
optional boolean false
optionalText string serverUILabels.labelOptional

Hint shown after an optional label. English by default (labelOptional): Label renders on the server, so UILabelsProvider does not reach it — pass frenchUILabels.labelOptional, or your own text.

required boolean false
requiredIndicator ReactNode "*"
requiredLabel string serverUILabels.labelRequired

What a screen reader hears after a required label, in place of the indicator. English by default (labelRequired): Label renders on the server, so UILabelsProvider does not reach it — pass frenchUILabels.labelRequired, or your own text.

size LabelSize "md"
textColor string —
tooltip string —
truncate boolean false
variant LabelVariant "default"
weight LabelWeight "medium"

+ 276 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

type LabelColor = | "default"
  | "primary"
  | "secondary"
  | "success"
  | "warning"
  | "error"
  | "info"
  | "muted"
type LabelSize = "xs" | "sm" | "md" | "lg" | "xl"
type LabelVariant = "default" | "light" | "strong"
type LabelWeight = "normal" | "medium" | "semibold" | "bold"