Fragiola

Getting started

Your first component

Build a styled "Edit profile" dialog in React, Vue or Angular, part by part, with focus, Escape and the backdrop handled by the primitive.

A dialog is a Root that holds its state, a Trigger, a Portal, and the Backdrop and Popup it moves to the end of body, with a Title, a Description and Close buttons inside.

Edit profile
Gallery

The parts

edit-profile.tsx
import { Dialog } from "@fragiola/primitives-react/dialog";
import { styles } from "./styles.ts";

export function EditProfile() {
    return (
        <Dialog.Root>
            <Dialog.Trigger className={styles.trigger}>Edit profile</Dialog.Trigger>
            <Dialog.Portal>
                <Dialog.Backdrop className={styles.backdrop} />
                <Dialog.Popup className={styles.popup}>
                    <Dialog.Title className={styles.title}>Edit profile</Dialog.Title>
                    <Dialog.Description className={styles.description}>
                        Change how others see you.
                    </Dialog.Description>
                    <label>
                        Name
                        <input defaultValue="Ada Lovelace" />
                    </label>
                    <Dialog.Close className={styles.close}>Save</Dialog.Close>
                </Dialog.Popup>
            </Dialog.Portal>
        </Dialog.Root>
    );
}

What the primitive does

  • The trigger is a button with aria-haspopup="dialog" and aria-expanded, and data-popup-open while the dialog is open.
  • On open, focus moves to the first field; Tab and Shift+Tab stay inside the popup, and the rest of the page is inert and does not scroll.
  • Escape, a press outside the popup and the Close buttons close it; focus goes back to the trigger.
  • The popup is named by its Title and described by its Description.

The styles

The class strings live in a styles.ts beside the component, one per part, so the markup holds none. The examples read them from the recipes of examples/shared, keyed on the part and state attributes (data-starting-style for the opening transition, data-ending-style for the closing one):

styles.ts
export const styles = {
    trigger: "h-9 px-3 rounded-md border",
    backdrop: "fixed inset-0 bg-black/40 transition-opacity data-starting-style:opacity-0 data-ending-style:opacity-0",
    popup: "fixed top-1/2 start-1/2 -translate-1/2 w-96 p-6 rounded-xl bg-white",
    title: "text-lg font-semibold",
    description: "opacity-85",
    close: "h-9 px-3 rounded-md border",
};

Next: the Dialog API, or the Tabs.