Light Dark System

Vue

Vue plays nice with custom elements, so you can use Pure UI in your Vue apps with ease.

Installation

To add Pure UI to your Vue app, install the package from npm.

npm install pure-uikit

Next, include a theme and set the base path for icons and other assets. In this example, we’ll import the light theme and use the CDN as a base path.

// main.js or main.ts
import "pure-uikit/dist/themes/light.css";
import { setBasePath } from "pure-uikit/dist/utilities/base-path";

setBasePath("https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/");

Configuration

If you haven’t configured your Vue.js project to work with custom elements/web components, follow the instructions here based on your project type to ensure your project will not throw an error when it encounters a custom element.

Now you can start using Pure UI components in your app!

Types

Once you have configured your application for custom elements, you should be able to use Pure UI in your application without it causing any errors. Unfortunately, this doesn’t register the custom elements to behave like components built using Vue. To provide autocomplete information and type safety for your components, you can import the Pure UI Vue types into your tsconfig.json to get better integration in your standard Vue and JSX templates.

{
  "compilerOptions": {
    "types": ["pure-uikit/dist/types/vue"]
  }
}

Usage

QR code generator example

<template>
  <div class="container">
    <h1>QR code generator</h1>

    <p-input maxlength="255" clearable label="Value" v-model="qrCode"></p-input>

    <p-qr-code :value="qrCode"></p-qr-code>
  </div>
</template>

<script setup>
  import { ref } from "vue";
  import "pure-uikit/dist/components/qr-code/qr-code.js";
  import "pure-uikit/dist/components/input/input.js";

  const qrCode = ref();
</script>

<style>
  .container {
    max-width: 400px;
    margin: 0 auto;
  }

  p-input {
    margin: var(--p-spacing-large) 0;
  }
</style>

Binding Complex Data

When binding complex data such as objects and arrays, use the .prop modifier to make Vue bind them as a property instead of an attribute.

<p-color-picker :swatches.prop="mySwatches" />

Two-way Binding

One caveat is there’s currently no support for v-model on custom elements, but you can still achieve two-way binding manually.

<!-- This doesn't work -->
<p-input v-model="name"></p-input>
<!-- This works, but it's a bit longer -->
<p-input :value="name" @input="name = $event.target.value"></p-input>

If that’s too verbose for your liking, you can use a custom directive instead. This utility adds a custom directive that will work just like v-model but for Pure UI components.

Slots

Slots in Pure UI/web components are functionally the same as basic slots in Vue. Slots can be assigned to elements using the slot attribute followed by the name of the slot it is being assigned to.

Here is an example:

<p-drawer label="Drawer" placement="start" class="drawer-placement-start" :open="drawerIsOpen">
  This drawer slides in from the start.
  <div slot="footer">
    <p-button variant="primary" @click=" drawerIsOpen = false">Close</p-button>
  </div>
</p-drawer>

Boilerplate

To add Pure UI to your Vue 3 app quickly, you can use the Pure UI Vue Boilerplate, which has already been configured to work with Pure UI.