Vueless UI Component Library

repository·main·Indexed 41 days ago

https://github.com/vuelessjs/vueless

An open-architecture UI library for Vue.js 3 and Nuxt.js 3/4 powered by Tailwind CSS v4. It features 65+ customizable components, a runtime theme builder, and a flexible system using CSS variables and Class Variance Authority (CVA) for styling. Supports SSR, i18n, and accessibility, with dedicated integration for Storybook v10.

Tokens
52K
Snippets
172
Records
208
Agent score
51%

What's inside Vueless UI

  1. Overview of Vueless UI

    main
    Vueless UI is a UI library designed with an 'Open Architecture' for Vue.js 3 and Nuxt.js 3/4. It is built using Storybook v10 and Tailwind CSS v4. The library is designed to be highly flexible, allowing developers to customize, copy, extend, or build components from scratch. It supports unstyled mode, light/dark modes, and uses CSS variables for design tokens.
  2. Explore the Vueless UI Ecosystem

    main

    Vueless provides several specialized packages to extend its functionality:

    • @vueless/storybook: A Storybook preset for testing and documenting your component library.
    • @vueless/nuxt: A dedicated Nuxt.js module for seamless integration.
    • create-vueless: A CLI tool for scaffolding projects from templates, including vueless-quickstart (JavaScript) and vueless-quickstart-ts (TypeScript).
  3. Key features of Vueless UI

    main

    Vueless UI provides the following capabilities:

    • Component Library: 65+ crafted UI components (e.g., range date picker, multi-select, nested table).
    • Open Architecture: Full freedom to customize, copy, extend, or create components.
    • Storybook Integration: Built-in support for documentation and component exploration.
    • Theme Builder: Runtime theme customization available via the Vueless Theme Builder.
    • Styling & Theming: Beautiful default theme, unstyled mode, light/dark mode, and design tokens powered by CSS variables.
    • Developer Experience: Auto component imports, uncompiled source in npm, and full TypeScript support.
    • Core Capabilities: SSR support, Internationalization (i18n), Accessibility (a11y), and inline SVG icons.
    • Reliability: 1300+ unit tests for consistent logic.
  4. Configure component styling with CVA and Layers

    main

    Vueless uses a layered styling approach powered by Class Variance Authority (CVA) and Tailwind CSS. Customization can be applied at four levels:

    1. Base component styling: Defined in the component's config.ts.
    2. Global customization: Applied via the vueless.config.{js,ts} file.
    3. Per-instance customization: Applied via the :config prop on the component.
    4. Direct class application: Applied via the standard class attribute.

    In config.ts, you define base classes, variants (e.g., size, color), and compound variants (combinations of props).

    export default /*tw*/ {
      button: {
        base: "flex items-center justify-center font-medium rounded-medium transition cursor-pointer",
        variants: {
          size: {
            "2xs": "px-2 py-1 text-small gap-0.5",
            sm: "px-4 py-2 text-medium gap-1.5",
          },
          variant: {
            solid: "bg-{color} border-transparent text-inverted hover:bg-{color}-lifted",
            ghost: "text-{color} bg-transparent border-transparent",
          },
        },
      },
      defaults: {
        color: "primary",
        variant: "solid",
        size: "md",
      },
    };
  5. Use Vueless colors via CSS variables

    main

    Vueless exposes all primary and neutral shades as CSS variables, allowing for dynamic color changes at runtime.

    Available variables follow the pattern:

    • --vl-primary-{shade} (e.g., --vl-primary-500)
    • --vl-neutral-{shade} (e.g., --vl-neutral-500)

    You can use these directly in your HTML/Vue templates using Tailwind's custom property syntax.

    <UButton 
      class="
        text-(--vl-primary-600) dark:text-(--vl-primary-400) 
        bg-(--vl-neutral-200) dark:bg-(--vl-neutral-800)
      "
    />
  6. Extend keys with conditional styling (variants)

    main

    When you extend a key that contains conditional styling (such as variants or compoundVariants), Vueless resolves the conditional classes fully before applying the extension. The resulting resolved class string is then merged with the key where the extension is applied.

    export default {
      component: {
        UTable: {
          headerCellBase: {
            base: "p-4 text-sm ...",
            variants: {
              compact: {
                true: "px-4 py-3 ...",
              },
            },
          },
          headerCellCheckbox: "{>headerCellBase} w-10 ...",
          stickyHeaderCell: "{>headerCellBase} flex-none ...",
        }
      }
    };
  7. Understand the Vueless design system and color aliases

    main

    Vueless uses a design system that enhances Tailwind CSS theming through color aliases and CSS variables. Instead of using specific Tailwind colors (like blue-500) directly in components, Vueless uses semantic aliases (like primary or success). This allows you to change your entire brand aesthetic by simply remapping these aliases in your Vueless configuration without changing component code.

    Color Alias Reference

    Color AliasDefault Tailwind ColorDescription
    neutralgrayRegular neutral color.
    grayscalegrayContrasted neutral color.
    primarygrayscale (alias)The primary color, used as the default for components.
    secondarygrayA secondary color that complements the primary color.
    successgreenA color used for success states.
    errorredA color used for danger states or form error validation.
    warningorangeA color used for warning states.
    noticevioletA color used for highlighted informational states.
    infoblueA color used for informational states.
    Color Alias | Default
    ------------|----------
    neutral      | gray
    grayscale    | gray
    primary      | grayscale
    secondary    | gray
    success      | green
    error        | red
    warning      | orange
    notice       | violet
    info         | blue
  8. Implement conditional styling using the CVA pattern

    main

    Vueless components use a structured configuration object (often exported as default /*tw*/) to manage conditional styling. This pattern allows you to define styles that react to component props without manual class manipulation in the template.

    Key elements of the configuration:

    • base: Classes applied to every instance of the component.
    • variants: A mapping of prop names to their possible values and corresponding classes. You can use runtime placeholders like {color} to inject values from the defaults or current props.
    • compoundVariants: An array of objects defining classes that apply only when a specific combination of props is met (e.g., variant: 'solid' AND disabled: true).
    • defaults: The fallback values for props if they are not explicitly provided.
    export default /*tw*/ {
      button: {
        base: "flex items-center justify-center rounded-medium transition cursor-pointer",
        variants: {
          variant: {
            solid: "bg-{color} border-transparent text-inverted hover:bg-{color}-lifted",
            outlined: "text-{color} border-{color} hover:text-{color}-lifted",
          },
          size: {
            sm: "text-medium px-4 py-2",
            md: "text-medium px-5 py-2.5",
          },
          loading: {
            true: "gap-0 pointer-events-none",
          },
        },
        compoundVariants: [
          {
            variant: "solid",
            disabled: true,
            class: "bg-gray-300 hover:bg-gray-300",
          },
        ],
      },
      defaults: {
        color: "primary",
        variant: "solid",
        size: "md",
      },
    };
  9. How Vueless component styling works

    main

    Vueless uses Tailwind CSS for styling and CVA (Class Variance Authority) to handle conditional styles based on props.

    Each HTML tag within a component is mapped to a specific configuration key. When you provide new classes, Vueless uses tailwind-merge to intelligently merge them with the component's default styles, preventing class duplication and conflicts.

    Merging Priority

    When multiple styles are applied, they follow this priority order (from highest to lowest):

    1. Component class attribute: Applied to the top-level HTML tag.
    2. Component config prop: Used for fine-tuning specific internal parts.
    3. Global vueless.config.{js,ts}: Project-wide component overrides.
    4. Component default config: The library's built-in styles.
  10. Customize themes with the Vueless Theme Builder

    main
    The Vueless Theme Builder allows you to customize colors, rounding, and typography at runtime. You can generate full palettes and export a ready-to-use theme directly into your project.
  11. Understand Vueless design tokens and CSS variables

    main
    Vueless uses over 40 CSS variables as design tokens to provide consistent styling and seamless support for light and dark modes. These tokens are applied across all components and can be customized globally via the Vueless configuration or your main CSS file. These tokens serve as the foundation for the entire theming system.
  12. Understand the Vueless component file structure

    main

    All Vueless components follow a standardized internal file organization. While the folder name and location change based on the context (project-wide, local, or internal to the Vueless repo), the internal files remain consistent:

    • config.ts: Styling configuration, default prop values, and component settings.
    • constants.ts: Component constants and identifiers.
    • types.ts: TypeScript types and props interface.
    • U[component].vue: The main component file.
    • U[component][child].vue: Optional child components.
    • use[composable].ts: Optional component-specific composables.
    • util[service].ts: Optional component-specific utility functions.
    • storybook/: Contains docs.mdx and stories.ts for documentation and visualization.
    • tests/: Contains component, utility, and composable tests.