Docs
Introduction
PyBlade UI is a set of components for PyBlade templates, styled with Tailwind CSS. You do not install it as a dependency: the CLI copies the components you pick into your project, and from then on they are your templates.
Nothing in it needs a JavaScript framework. What the browser can do on its own, it does: a dialog is a <dialog>, a dropdown is a popover, an accordion is <details>, tabs are radio buttons. What needs state, a combobox, a calendar, a data table, is a PyBlade live component, answered by Python.
Each component documents its props and shows its examples next to their code. Start with Button, or browse all of them.
Installation
PyBlade UI comes with PyBlade: its components and its commands are part of it. It needs Tailwind CSS v4, which pyblade tailwind:config sets up. In the folder of your project, where pyblade.toml is, set it up:
$ pyblade ui:init --base zinc --color blue
It writes the theme, the colour variables the components are drawn with, and adds it to your Tailwind stylesheet. Then add the components you need; the ones they use come with them:
$ pyblade ui:add button card dialog
They land in components/ui, and are written <pb-ui.name> in any template:
<pb-ui.card title="Notifications" description="Choose what you hear about."> <pb-ui.switch name="emails" checked>Emails</pb-ui.switch> <pb-slot:footer> <pb-ui.button type="submit">Save</pb-ui.button> </pb-slot:footer> </pb-ui.card>
Every attribute a component does not declare as a prop goes on its root element. A class is added to its own classes:
<pb-ui.button variant="outline" class="w-full" id="save" disabled>Save</pb-ui.button>
CLI
The commands of PyBlade UI are commands of the pyblade CLI, under ui:.
| Command | What it does |
|---|---|
pyblade ui:init--base zinc --color blue --radius 0.625rem |
Sets the project up: writes static/css/theme.css, imports it into your Tailwind stylesheet, and keeps the theme under [ui] in pyblade.toml. |
pyblade ui:addbutton card | --all [--dry-run] [--overwrite] |
Copies components into components/ui, with the ones they use. A file you changed is kept, unless --overwrite. |
pyblade ui:list |
Lists the components there are, and the ones you have added. |
pyblade ui:diffbutton |
Shows how your copy of a component differs from the latest, before you update it. |
pyblade ui:themelist | show | set --base slate --color rose --radius 0.75rem |
Lists the bases and colours, shows the project's theme, or writes it again. What you wrote under its pyblade ui:custom line is kept. |
Theming
The components are drawn with a few colours, named after daisyUI's: three surfaces, base-100 for the page, base-200 for cards and menus and base-300 for borders; base-content for text; and primary, secondary, neutral, info, success, warning and error, each with a -content colour for the text written on it. They are Tailwind colours, so bg-primary or border-base-300 work in your own templates too.
pyblade ui:init writes them to static/css/theme.css for a base, the greys (neutral, zinc, slate, stone or gray), and a colour (neutral, blue, green, violet, rose, red, orange or yellow), in light and dark. The dark ones apply under <html class="dark"> or data-theme="dark". Change the theme at any time:
$ pyblade ui:theme set --base slate --color rose
To go further, write your own values under the last line of theme.css: they are kept when the theme is written again.
/* static/css/theme.css, below the line PyBlade writes up to */
/* pyblade ui:custom -- everything below this line is kept ... */
:root {
--ui-primary: oklch(0.6 0.2 160);
--ui-radius: 0.75rem;
}
.dark, [data-theme="dark"] {
--ui-primary: oklch(0.7 0.18 160);
}Live components
The Combobox, the Calendar, the Data table and the Chart are live components: a Python class and its template. Their state is kept on the server, and each click or keystroke is answered by the class, which renders them again. Write them like any other:
<pb-ui.combobox name="framework" :options="frameworks" prompt="Pick a framework" />
They need the script of PyBlade's live components, which @pbscripts puts in your layout, before </body>. Being yours, their class can be changed too: to read the options of a combobox from the database as you type, for instance.