Open Props UI Documentation

repository·main·Indexed 19 days ago

https://github.com/felix-bohlin/ui

A CSS UI library leveraging modern HTML and CSS features for component creation. It provides a framework-agnostic core (opui-css) and a collection of pre-built Astro components including layout elements, form controls, and feedback overlays. The library utilizes CSS Cascade Layers for specificity management and offers multiple entry points for CDN usage, bundler optimization, and framework integration.

Tokens
10.5K
Snippets
42
Records
60
Agent score
65%

What's inside Open Props UI

  1. Understand the Open Props UI project structure

    main

    The project is organized as a monorepo consisting of two primary parts:

    The Library (packages/opui)

    This is the framework-agnostic core, managed as the opui-css workspace package. It contains:

    • components/: Folders containing component logic, templates (e.g., Button.astro), and types.
    • css/: Component styles, themes, and entry-point imports.
    • astro/: The public entry point and barrel exports for Astro projects.

    The Documentation Site (src/)

    The Astro-based documentation site, containing layouts, pages, and site components.

  2. Understand Open Props UI Cascade Layers

    main

    Open Props UI uses CSS Cascade Layers (@layer) to manage specificity. The defined layer order is:

    @layer openprops, theme, normalize, components.root, components.extended, utils;

    To override library styles, wrap your custom CSS in a layer that appears after utils in the order above, or use unlayered styles.

    @layer openprops, theme, normalize, components.root, components.extended, utils;
  3. Install Open Props UI

    main

    To use Open Props UI, install the opui-css package along with open-props using pnpm:

    pnpm add opui-css open-props

    Peer Dependencies

    Depending on your chosen integration method, you may need the following peer dependencies:

    • astro ^6 (required only for Astro components)
    • vue ^3 (required only for Vue components)
    • open-props ^1
  4. Migrate from v3 to v4

    main

    Version 4 is a complete re-platform. Key changes include:

    1. Single Theme: The theme-one and theme-two options have been removed. The library now ships with a single theme located in css/theme.css. To customize the theme, override variables within a @layer theme block.
    2. Import Paths:
      • The default import "opui-css" now resolves to dist/opui.css instead of a specific theme file.
      • Component CSS files have moved from src/ to css/ (e.g., @import "opui-css/css/components/button.css";).
    3. Peer Dependency: open-props is now a peer dependency. You must install it manually in your project.
    4. Cascade Layers: The library uses CSS cascade layers. The defined order is: openprops, normalize, theme, components.root, components.extended, utils. To ensure overrides work correctly, place your custom styles in a later layer or an unlayered block.
    /* Customizing the single theme in v4+ */
    @layer theme {
      :root {
        --primary: oklch(60% 0.2 250);
      }
    }
    # Install open-props as a peer dependency
    pnpm add open-props
  5. Use Open Props UI Astro components

    main

    If you are using Astro, you can import pre-built components directly from opui-css/astro. You must also import the base CSS imports to ensure styles are applied.

    ---
    import "opui-css/css/imports.css"
    import { Button, Card } from "opui-css/astro"
    ---
    
    <Card>
      <Button variant="primary">Click me</Button>
    </Card>
  6. Migrate from v4 to v5

    main

    Version 5 introduces a ui- prefix to all OPUI-owned CSS classes.

    • Framework Components: If you use the provided framework components (e.g., <Button />), no action is required as they automatically emit the prefixed classes.
    • Raw HTML/CSS: If you use raw HTML or write custom CSS targeting library classes, you must update your references to include the ui- prefix.
    • CSS Variables: All CSS custom properties (e.g., --primary, --surface-default, --size-3) remain unchanged.

    Refer to the CHANGELOG.md for the full list of renamed tokens.

    <!-- Before v5 -->
    <button class="button outlined small">Save</button>
    
    <!-- After v5 -->
    <button class="ui-button ui-outlined ui-small">Save</button>
    /* Before v5 */
    .button.filled { /* override */ }
    
    /* After v5 */
    .ui-button.ui-filled { /* override */ }
  7. Add new components to the library

    main

    To add a new component to the opui-css package, follow these steps:

    1. Create a new directory for the component in packages/opui/components/[ComponentName].
    2. Create the component template file [ComponentName].astro within that folder.
    3. Export the new component from the barrel file located at packages/opui/astro/index.ts.
    4. (Optional) Add the component-specific styles in packages/opui/css/components/.
  8. Migrate from v5.0 to v5.1

    main

    In version 5.1.0, the critical prop has been renamed to error for all form components.

    Affected components:

    • TextField
    • Checkbox
    • Radio
    • Switch
    • Select
    • ClassicSelect
    • Textarea

    Note: Components used for severity styling (such as Button, Callout, and Badge) still use the critical prop and do not require changes.

    <!-- Before v5.1 -->
    <TextField critical label="Name" />
    
    <!-- After v5.1 -->
    <TextField error label="Name" />
  9. Use Open Props UI with Plain HTML and CSS

    main

    For projects without a build step, you can use a pre-bundled stylesheet via CDN. Use the documented class names (e.g., ui-button, ui-primary) to style elements.

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/opui-css/dist/opui.css"
    />
    
    <button class="ui-button ui-primary">Click me</button>

    Bundler Optimization

    If you use a bundler that resolves CSS @imports (like Vite, Astro, or webpack), import the source files instead of the pre-bundled dist file to enable tree-shaking and only ship the CSS you actually use.

    /* Import everything */
    @import "opui-css/css/imports.css";
    
    /* Or pick components à la carte */
    @import "opui-css/css/components/button.css";
  10. Get started with Open Props UI

    main

    Open Props UI is a CSS UI library designed to explore next-gen HTML and CSS features for component creation. For detailed installation and usage instructions, refer to the official getting started guide.

    https://open-props-ui.netlify.app/html/guide/getting-started/