Synertech Web/ui v0.57.5 Site Storybook

Documentation / Navigation & actions

Button

Server-compatible@synertech/uiOpen in Storybook

The library’s action button: four sizes, icons on either side of the label, a loading state that disables the click, and colours passed as Tailwind classes rather than fixed variants.

It accepts every native <button> attribute (onClick, aria-*, form…). type defaults to "button": a button placed in a form only submits it when given type="submit".

Examples

Basic usage

The label goes in as children (or through label), the handler in onClick.

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

export function Basic() {
  return <Button onClick={() => console.log("Enregistré")}>Enregistrer</Button>;
}

Sizes and corners

size sets the padding, the type size and the icon size; rounded the corners.

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

export function Sizes() {
  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button size="sm">Petit</Button>
      <Button size="md">Moyen</Button>
      <Button size="lg" rounded="md">
        Grand
      </Button>
      <Button size="xl" rounded="full">
        Très grand
      </Button>
    </div>
  );
}

Icons

leftIcon / rightIcon frame the label. With icon alone and no label, the button becomes square: give it an aria-label then.

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

const PlusIcon = () => (
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
    <path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
  </svg>
);

export function WithIcons() {
  return (
    <div className="flex items-center gap-3">
      <Button leftIcon={<PlusIcon />}>Nouveau projet</Button>
      <Button icon={<PlusIcon />} aria-label="Ajouter" />
    </div>
  );
}

Custom colours

Colours are Tailwind classes: background, text and focus ring.

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

export function CustomColors() {
  return (
    <div className="flex gap-3">
      <Button bgColor="bg-red-600 hover:bg-red-700" focusColor="focus:ring-red-300">
        Supprimer
      </Button>
      <Button bgColor="bg-white hover:bg-gray-50 border border-gray-300" textColor="text-gray-700">
        Annuler
      </Button>
    </div>
  );
}

Loading state

loading swaps the content for a spinner and disables the button while the action runs.

Open in a tab
import { useState } from "react";
import { Button } from "@synertech/ui";

export function Loading() {
  const [saving, setSaving] = useState(false);

  const save = async () => {
    setSaving(true);
    await new Promise((resolve) => setTimeout(resolve, 1500));
    setSaving(false);
  };

  return (
    <Button loading={saving} onClick={save} fullWidth>
      Enregistrer les modifications
    </Button>
  );
}

In a form

Only type="submit" submits the form; the other buttons stay neutral.

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

export function InForm() {
  return (
    <form onSubmit={(event) => event.preventDefault()} className="flex gap-3">
      <Button type="submit">Envoyer</Button>
      <Button type="reset" bgColor="bg-gray-100 hover:bg-gray-200" textColor="text-gray-800">
        Réinitialiser
      </Button>
    </form>
  );
}

API reference

Components

Button

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

Props — ButtonProps

PropTypeDefaultDescription
bgColor string "bg-synertech-primary-600 hover:bg-synertech-primary-700"
children ReactNode —
focusColor string "focus:ring-synertech-primary-300"
fullWidth boolean false
icon ReactNode —
label string —
leftIcon ReactNode —
loading boolean false
rightIcon ReactNode —
rounded "none" | "sm" | "md" | "lg" | "full" "lg"
selected boolean false
showFocusOnClick boolean false
size "sm" | "md" | "lg" | "xl" "md"
textColor string —

Classes of the text. Left out, it is the colour the brand is written in (text-synertech-on-primary) on the default fill, and text-white on a fill passed as bgColor.

type "button" | "submit" | "reset" "button"
value string —

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