Light Dark System

Angular

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

Installation

Download the npm package

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

npm install pure-uikit

Update the Angular Configuration

Next, include a theme. In this example, we’ll import the light theme.

Its also important to load the components by using a <script> tag into the index.html file. However, the Angular way to do it is by adding a script configurations into your angular.json file as follows:

"architect": {
  "build": {
    ...
    "options": {
      ...
      "styles": [
        "src/styles.scss",
        "pure-uikit/dist/themes/light.css"
       ],
      "scripts": [
        "pure-uikit/dist/pure-ui.js"
      ]
      ...

Setting up the base path

Next, set the base path for icons and other assets in the main.ts. In this example, we’ll use the CDN as a base path.

import { setBasePath } from "pure-uikit/dist/utilities/base-path";

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

Configuration

Then make sure to apply the custom elements schema as shown below.

import { BrowserModule } from "@angular/platform-browser";
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";

import { AppComponent } from "./app.component";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

Reference Pure UI components in your Angular component code

import { PDrawer } from 'pure-uikit';

@Component({
  selector: 'app-drawer-example',
  template: '<div id="page"><button (click)="showDrawer()">Show drawer</button><p-drawer #drawer label="Drawer" class="drawer-focus" style="--size: 50vw"><p>Drawer content</p></p-drawer></div>'
})
export class DrawerExampleComponent implements OnInit {

  // use @ViewChild to get a reference to the #drawer element within component template
  @ViewChild('drawer')
  drawer?: ElementRef<PDrawer>;

  ...

  constructor(...) {
  }

  ngOnInit() {
  }

  ...

  showDrawer() {
    // use nativeElement to access Pure UI components
    this.drawer?.nativeElement.show();
  }
}

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