Synertech Web/ui v0.57.5 Site Storybook

Documentation / Formulaires

Label

Compatible serveur@synertech/uiVoir dans Storybook

Le libellé de formulaire : un <label> (ou un <span> / <p> via as) avec cinq tailles, huit couleurs sémantiques en trois intensités, des icônes de part et d’autre et les marques « obligatoire » / « facultatif ». Relié à un champ par htmlFor, il lui donne son nom accessible.

required ajoute un astérisque masqué aux lecteurs d’écran, doublé d’un texte invisible, requiredLabel (« (required) » par défaut) ; optionalText vaut "(optional)" par défaut. tooltip se rend en attribut title natif.

Sans hook ni directive : il se rend côté serveur, et UILabelsProvider ne l’atteint donc pas. Ses deux textes sont des props, anglaises par défaut : passez frenchUILabels.labelRequired et frenchUILabels.labelOptional, ou vos propres textes. Les champs de la librairie (Input, Select…) portent déjà leur propre libellé via label ; Label sert aux champs natifs et aux compositions sur mesure.

Exemples

Utilisation de base

htmlFor relie le libellé à l’id du champ : cliquer dessus donne le focus au champ.

Ouvrir dans un onglet
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>
  );
}

Obligatoire et facultatif

required ajoute la marque requiredIndicator (« * » par défaut) ; optional le texte optionalText.

Ouvrir dans un onglet
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>
  );
}

Tailles et graisses

size va de xs à xl, weight de normal à bold (medium par défaut).

Ouvrir dans un onglet
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>
  );
}

Couleurs et intensités

color choisit la teinte, variant son intensité : light, default ou strong.

Ouvrir dans un onglet
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>
  );
}

Icônes, info-bulle et état désactivé

icon / endIcon encadrent le texte, tooltip ajoute un title, truncate coupe les textes longs.

Ouvrir dans un onglet
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>
  );
}

Référence d’API

Composants

Label

ComposantCompatible serveur
import { Label } from "@synertech/ui";

Props — LabelProps

PropTypeDéfautDescription
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

Mention affichée après un libellé facultatif. En anglais par défaut (labelOptional) : Label est rendu côté serveur, donc UILabelsProvider ne l’atteint pas — passez frenchUILabels.labelOptional, ou votre propre texte.

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

Ce qu’un lecteur d’écran entend après un libellé obligatoire, à la place de l’indicateur. En anglais par défaut (labelRequired) : Label est rendu côté serveur, donc UILabelsProvider ne l’atteint pas — passez frenchUILabels.labelRequired, ou votre propre texte.

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

+ 276 attributs natifs hérités de HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, gestionnaires d’événements…).

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"