The BBUI Component Library
Relevant source files
The following files were used as context for generating this wiki page:
- packages/bbui/README.md
- packages/bbui/package.json
- AGENTS.md
- README.md
- packages/builder/src/settings/pages/version.svelte
- packages/builder/src/pages/builder/maintenance/index.svelte
- packages/builder/src/pages/builder/workspace/[application]/data/new.svelte
- packages/builder/src/settings/pages/translations/translations.svelte
The @budibase/bbui package is a shared Svelte component library that provides a consistent set of UI elements used across the entire Budibase organization. Its primary purpose is to ensure a cohesive user experience in all frontend applications, such as the Budibase builder (@budibase/builder) and the generated client apps (@budibase/client). The library contains beautifully designed, powerful components that serve as the building blocks for creating application UIs.
The bbui package is part of the Lerna monorepo structure of the main Budibase project, which facilitates modular development and dependency management between different parts of the platform. It is built using Svelte and Vite, and it heavily leverages Adobe's Spectrum CSS framework for styling.
Sources: packages/bbui/README.md, README.md:50-54, AGENTS.md:6-10
Architecture and Tooling
bbui in the Monorepo
The Budibase project is a monorepo managed by Lerna. The bbui package is one of the main frontend packages, alongside builder and frontend-core. This structure allows for easy sharing of code and consistent versioning. Other packages within the monorepo, like @budibase/builder, declare @budibase/bbui as a dependency to use its components.
Sources: AGENTS.md:4-10, README.md:150-151
The following diagram illustrates the position of bbui within the broader Budibase architecture.
Sources: AGENTS.md:6-10, README.md:150-160
Build Process
The bbui package uses vite for its build process. The main scripts available in its package.json are:
"build": "vite build": Compiles the Svelte components and TypeScript code into a distributable format."dev": "vite build --watch --mode=dev": Runs the build in watch mode for development, automatically recompiling on file changes.
The output is a single module file (dist/bbui.mjs) which is specified in the exports field of package.json.
Sources: packages/bbui/package.json:11-12
Key Dependencies
The bbui library is built upon several key technologies. The package.json file reveals its core dependencies.
| Dependency | Version | Description |
|---|---|---|
| Svelte | 1.4.0 (via @sveltejs/vite-plugin-svelte) | The component framework used to build the UI. |
@spectrum-css/* | various | A collection of packages from Adobe's Spectrum CSS framework, used for base styling of components like buttons, tables, and form inputs. |
vite | 1.4.0 (via @sveltejs/vite-plugin-svelte) | The build tool used to compile the Svelte components. |
@budibase/shared-core | * | A shared core library within the Budibase monorepo. |
date-fns / dayjs | ^4.1.0 / ^1.10.8 | Libraries for date and time manipulation. |
svelte-dnd-action | ^0.9.8 | A Svelte action for drag and drop functionality. |
Sources: packages/bbui/package.json:15-80
Component Development
Development Workflow
The bbui/README.md outlines a clear workflow for creating and testing new components. The process leverages Svench, a tool similar to Storybook, for component development and visualization in isolation.
The diagram below shows the typical workflow for adding a new component to bbui.
Sources: packages/bbui/README.md:11-17
Development Guidelines
To maintain code quality and reusability, the library follows a set of development guidelines.
| Guideline | Description |
|---|---|
| Reusability | Components should be designed to be as reusable as possible. |
| CSS Variables | Use CSS custom properties (variables) from the main stylesheet instead of hard-coded values to allow for easier theming and tweaking. |
| Event Handling | Prefer forwarding DOM events (e.g., <button on:click>) over using callback props. |
| No Outer Margins | Avoid adding margins to the outermost container of a component to give consumers control over layout and spacing. Spacing should be handled by parent containers using techniques like css grid with grid-gap. |
Sources: packages/bbui/README.md:20-35
Component Usage Examples
Components from @budibase/bbui are imported and used throughout the Budibase builder application.
Basic Component Import
The following snippet from the "Version" settings page shows how multiple bbui components are imported and used to construct a view.
// packages/builder/src/settings/pages/version.svelte:3-11
<script>
import { onMount } from "svelte"
import {
Layout,
Heading,
Body,
Divider,
notifications,
Label,
Link,
} from "@budibase/bbui"
// ...
</script>
// packages/builder/src/settings/pages/version.svelte:45-59
<Layout noPadding>
{#if loaded}
<Layout noPadding gap="S">
<Label size="L">Current version</Label>
<Heading size="XS">
{version || "-"}
</Heading>
<Divider noMargin />
<!-- ... -->
</Layout>
<Divider noMargin />
<Layout noPadding gap="XS">
<Heading size="XS">Updating Budibase</Heading>
<Body size="S"
>To update your self-host installation, follow the docs found <Link
size="L"
href="https://docs.budibase.com/docs/updating-budibase">here.</Link
></Body
>
</Layout>
{/if}
</Layout>
Sources: packages/builder/src/settings/pages/version.svelte:3-11, 45-59
Handling Events
Components like Button forward native DOM events. This allows parent components to listen for events like on:click directly.
// packages/builder/src/pages/builder/maintenance/index.svelte:30-34
<Button
on:click={() =>
(window.location = "https://docs.budibase.com/docs/migrations")}
>
Migration guide
</Button>
Sources: packages/builder/src/pages/builder/maintenance/index.svelte:30-34
This is consistent with the development guideline to forward events rather than use callbacks.
Sources: packages/bbui/README.md:24-25
Conclusion
The @budibase/bbui component library is a cornerstone of the Budibase frontend architecture. By providing a centralized, reusable, and consistent set of Svelte components, it enables rapid development of a polished and cohesive user interface across all Budibase products. Its foundation on Svelte, Vite, and Adobe Spectrum CSS, combined with clear development guidelines, makes it a robust and maintainable solution for the project's UI needs.
Sources: packages/bbui/README.md, AGENTS.md