• Stars
    star
    613
  • Rank 71,545 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UI component library for the web

PCUI - User Interface Component Library for the Web

GitHub license NPM Version NPM Downloads

PCUI Banner

This library enables the creation of reliable and visually pleasing user interfaces by providing fully styled components that you can use directly on your site. The components are useful in a wide range of use cases, from creating simple forms to building graphical user interfaces for complex web tools.

A full guide to using the PCUI library can be found here.

Getting Started

To install the PCUI NPM module, run the following command:

npm install @playcanvas/pcui

If you are using ESM, you can then import each individual element from PCUI. In the example below you can see how the PCUI Label component is imported from the PCUI library. The styles for PCUI are then imported into the example. Styles only need to be imported once per project.

import { Label } from '@playcanvas/pcui';
import '@playcanvas/pcui/styles';

const label = new Label({
    text: 'Hello World'
});
document.body.appendChild(label.dom);

If you'd like to include PCUI in your React project, you can import the individual components as follows:

import * as React from 'react';
import ReactDOM from 'react-dom';
import { TextInput } from '@playcanvas/pcui/react';
import '@playcanvas/pcui/styles';

ReactDOM.render(
    <TextInput text='Hello World'/>,
    document.body
);

Building a UMD bundle

If you need a UMD version of the library so that you for example, it can useed with a PlayCanvas Editor project, please refer to our build guide.

Including your own font

PCUI uses four CSS classes to add styled fonts to the various components. These are .font-regular, .font-bold, .font-thin and .font-light. You can use your own font with PCUI by adding font-family CSS rules to these classes on your webpage. For example:

.font-regular, .font-bold, .font-thin, .font-light {
    font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;
}

Data Binding

The PCUI library offers a data binding layer that can be used to synchronize data across multiple components. It offers two way binding to a given observer object, so updates made in a component are reflected in the observer's data and distributed out to all other subscribed components. A simple use case is shown below:

import { Observer } from '@playcanvas/observer';
import { Label, TextInput, BindingObserversToElement, BindingElementToObservers } from '@playcanvs/pcui';
import '@playcanvas/pcui/styles';

// create a new observer for a simple object which contains a text string
const observer = new Observer({
    text: 'Hello World'
});

// create a label which will listen to updates from the observer
const label = new Label({
    binding: new BindingObserversToElement()
});

// link the observer to the label, telling it to use the text variable as its value
label.link(observer, 'text');

// create a text input which will send updates to the observer
const textInput = new TextInput({
    binding: new BindingElementToObservers()
});

// link the observer to the label, telling it to set the text variable on change
textInput.link(observer, 'text');

In the above example, the created label will start with Hello World as its text value. When a user enters a value into the text input, the label will be updated with the new value.

Observers can also be bound bi-directionally, in which case an element can both send and receive updates through its observer. The following example shows a two way binding between two text inputs, where either input can update the value of the other. It's been written in React to showcase binding with React components:

import { Observer } from '@playcanvas/observer';
import { BindingTwoWay, TextInput } from '@playcanvas/pcui/react';
import '@playcanvas/pcui/styles';

// create a new observer for a simple object which contains a text string
const observer = new Observer({
    text: 'Hello World'
});

// create two text inputs, which can both send and receive updates through the linked observer
const TextInput1 = () => <TextInput binding={new BindingTwoWay()} link={{ observer, path: 'text'} />;
const TextInput2 = () => <TextInput binding={new BindingTwoWay()} link={{ observer, path: 'text'} />;

Development

Each component exists in its own folder within the ./src/components directory. They each contain:

  • index.ts: The PCUI element itself.
  • style.scss: The SASS styles for the component.
  • component.tsx: A React wrapper for the element, currently used to display the element in Storybook.
  • index.stories.tsx: The Storybook entry for this component.

Locally developed components can be viewed & tested by running the Storybook app, as mentioned in the following section.

If you'd like to build your own custom version of the library you can run the npm run build command which will create a dist directory with your custom build.

Storybook

If you wish to view all components available to you in the library, you can run a local version Storybook. It allows you to browse the entire collection of components and test any changes you make to them. Each component page also includes component documentation and allows you to test each component in all of its configuration states.

Run Storybook as follows:

npm install
npm run storybook

Documentation

Information on building the documentation can be found in the docs directory.

More Repositories

1

engine

Fast and lightweight JavaScript game engine built on WebGL and glTF
JavaScript
9,091
star
2

model-viewer

glTF 2.0 model viewer
TypeScript
250
star
3

awesome-playcanvas

A curated list of awesome PlayCanvas assets, resources, and more.
245
star
4

playcanvas-ar

Fast and Easy Augmented Reality for the Web 🚀
JavaScript
209
star
5

pcui-graph

A PCUI extension for creating node-based graphs
JavaScript
110
star
6

editor

Issue tracker for the PlayCanvas Editor
106
star
7

playcanvas-gltf

glTF 2.0 support for the PlayCanvas Engine
JavaScript
98
star
8

playcanvas.github.io

Live examples of the PlayCanvas Engine
JavaScript
78
star
9

playcanvas-sync

Real-time synchronization of files between PlayCanvas and your local machine
JavaScript
73
star
10

developer.playcanvas.com

Developer resources website for PlayCanvas
JavaScript
65
star
11

playcanvas-tween

A tween library for PlayCanvas
JavaScript
55
star
12

webvr

**Deprecated**: WebVR support for PlayCanvas WebGL Game Engine. WebVR is now supported in the PlayCanvas engine directly, this project is now considered legacy and should not be used in new projects.
JavaScript
45
star
13

playcanvas-spine

Plugin component for PlayCanvas which enables support for Spine animations.
JavaScript
43
star
14

fonts

Scripts that allow you to render Bitmap fonts in PlayCanvas.
JavaScript
24
star
15

playcanvas-editor-ts-template

A simple TypeScript template for PlayCanvas that can also sync with your playcanvas.com project
TypeScript
21
star
16

playcanvas-rest-api-tools

A set of tools to use with the PlayCanvas REST API for common jobs such as downloading a build and archiving a project
JavaScript
21
star
17

playcanvas-p2.js

An integration of PlayCanvas with the 2D physics engine p2.js
JavaScript
20
star
18

walkthrough.js

walkthough.js allows you to create interactive walkthroughs on your website
JavaScript
20
star
19

sprites

Scripts that allow you to render Sprites in PlayCanvas
JavaScript
20
star
20

editor-api

The PlayCanvas Editor API
JavaScript
16
star
21

playcanvas-webpack

Demonstration of building a PlayCanvas app with Webpack
JavaScript
16
star
22

google-play-game-services

A PlayCanvas integration for Google Play Game Services
JavaScript
11
star
23

playcanvas-inspector

Chrome extension for inspecting published PlayCanvas apps
JavaScript
11
star
24

playcanvas-observer

Contains the Observer class and related functionality used across the PlayCanvas Editor, pcui etc.
JavaScript
7
star
25

canvas-mock

Mock for HTMLCanvasElement and related classes
JavaScript
6
star
26

playcanvas-texturepacker

Custom PlayCanvas exporter for TexturePacker
6
star
27

playcanvas-eslint-config

ESLint configuration used by PlayCanvas
JavaScript
5
star
28

sublime-completions

Sublime Text completions file for PlayCanvas
JavaScript
5
star
29

playcanvas-facebook

Plugin component for PlayCanvas which enables integration of the Facebook API.
JavaScript
5
star
30

api-reference

PlayCanvas API reference manual
JavaScript
5
star
31

texture-tool

Texture tool for graphics programmers
JavaScript
4
star
32

playcanvas-jsdoc-template

JSDoc 3 template for PlayCanvas
JavaScript
3
star
33

visual-tests

Generate screenshots and compare them across versions of the engine
JavaScript
3
star
34

playcanvas-csp

Node.js tool to download a build via REST API and add CSP rules
JavaScript
2
star
35

blog

The PlayCanvas blog site
HTML
1
star