Unified UX relies on a host of popular technologies. Here we signpost you to some self-learning resources to get you up to speed quickly. As a starting point, it is assumed that developers are familiar with HTML and JavaScript.
Web Components Crash Course Building Web Components with lit-html An introduction to writing raw web components .
Get hands on experience by downloading the zip containing example code for creating web component- webcomponent-code.zip TypeScript Tutorial - TypeScript for React - Learn TypeScript -2020 In-Depth TypeScript Tutorials for 2021 TypeScript Cheatsheet Lit Tutorial Web Components Integration using LitElement and TypeScript LitElement app tutorial part 1: Getting started Lit playground/sandpit site Plugin for VS Code Lit TypeScript starter project
Download the ts starter kit lit-element-starter-ts-main.zip
.
Unzip, explore to the folder and use ‘cmd’…
Copy npm i
npm audit fix & :: tidy any deprecated packages
npm run build & :: to compile the ts from the /src folder into js
npm run serve & :: to run the web server
browse to http://localhost:8000/
(port may vary!!!)
put your ts in the src folder
Lit-VSCode-Extension
This VS Code extension is really helpfullit-vcode extension .
In a new folder…
Copy npm init @vitejs/app --template lit-element-ts & :: We want a lit ts install
cd lit-element-ts
npm install
npm run dev
That runs a web server on port 3000 using the files in the (current) folder C:\D\UUX\lit-element-ts
.
Simple Example
TS:
Copy import { html , css , LitElement } from 'lit' ;
import { customElement , property } from 'lit/decorators.js' ;
@ customElement ( 'simple-greeting' )
export class SimpleGreeting extends LitElement {
static styles = css ` p { color: blue } ` ;
@ property ( )
name = 'Somebody' ;
render ( ) {
return html ` <p>Hello, ${ this . name } !</p> ` ;
}
}
JS:
Copy import { html , css , LitElement } from 'lit' ;
export class SimpleGreeting extends LitElement {
static styles = css ` p { color: blue } ` ;
static properties = {
name : { type : String } ,
} ;
constructor ( ) {
super ( ) ;
this . name = 'Somebody' ;
}
render ( ) {
return html ` <p>Hello, ${ this . name } !</p> ` ;
}
}
customElements . define ( 'simple-greeting' , SimpleGreeting ) ;
HTML:
Copy < simple-greeting name = " World " > </ simple-greeting >
More detailed example with buttons
Copy import { LitElement , html , css } from 'lit' ;
import { customElement , property } from 'lit/decorators.js' ;
@ customElement ( "my-element" )
export class MyElement extends LitElement {
static styles = css `
:host {
display: inline-block;
padding: 10px;
background: lightgray;
}
.planet {
color: var(--planet-color, blue);
}
` ;
@ property ( ) greeting = "Hello" ;
@ property ( ) planet = "World" ;
render ( ) {
return html `
<span @click= ${ this . togglePlanet }
> ${ this . greeting }
<span class="planet"> ${ this . planet } </span>
</span>
` ;
}
togglePlanet ( ) {
this . planet = this . planet === "World" ? "Mars" : "World" ;
}
}
HTML
Copy <! DOCTYPE html >
< head >
< script type = " module " src = " ./my-element.js " > </ script >
< style >
.mars {
--planet-color : red ;
}
</ style >
</ head >
< body >
< my-element > </ my-element >
< hr />
< my-element class = " mars " planet = " Mars " > </ my-element >
</ body >
Vanilla Router supports simple navigation between so-called “pages” in a single page web application. The route/page name is seen after a # in the url shown by the browser. e.g. http://ip:port/mypage.html#main
When routing (“navigateTo”) occurs, a function is run that can re-render some, or all, of the page.
To install
Copy npm install vanilla-router
To include in your html page
Copy < script defer src = " ./node_modules/vanilla-router/index.js " > </ script >
Setup script
Copy function beforeRoute ( ) {
}
function afterRoute ( ) {
}
var router = new Router ( {
mode : 'hash' ,
root : '/CSA.html' ,
hooks : {
before : function ( newPage ) {
if ( logging ) { console . info ( 'Before page loads hook' , newPage ) ; }
beforeRoute ( ) ; } ,
after : function ( newPage ) {
if ( logging ) { console . info ( 'After page loads hook' , newPage ) ; }
afterRoute ( ) ;
}
} ,
page404 : function ( path ) {
console . log ( '"/' + path + '" Page not found' ) ;
}
} ) ;
router . add ( 'main' , function ( ) {
if ( logging ) { console . log ( 'router main' ) ; }
loadMain ( ) ;
} ) ;
router . add ( 'txndet' , function ( ) {
if ( logging ) { console . log ( 'router txndet' ) ; }
loadTxnDet ( ) ;
} ) ;
router . addUriListener ( ) ;
window . router = router ;
Function to navigate to main (the main page layout)…
Copy
function loadMain ( ) {
const emptyHtml = html ` ` ;
render ( emptyHtml , document . body . querySelector ( '.popuphost' ) ) ;
document . getElementsByClassName ( 'alternatecontent' ) [ 0 ] . classList . add ( 'hidden' ) ;
document . getElementsByClassName ( 'content' ) [ 0 ] . classList . remove ( 'hidden' ) ;
}
Function to navigate to txndet (a page layout that includes a popup showing transaction details)…
Copy
function loadTxnDet ( ) {
if ( logging ) { console . log ( 'loading TxnDet' ) ; }
const popupHtml = html `
<transaction-details class="ea transactiondetails popupESC" instance="0" transactiondata=" ${ sessionStorage . getItem ( 'txndet_transactiondata' ) } " accountid=" ${ sessionStorage . getItem ( 'txndet_accountid' ) } "></transaction-details>
` ;
render ( popupHtml , document . body . querySelector ( '.popuphost' ) ) ;
setTimeout ( function ( ) {
setupTransactionDetailsListener ( ) ;
var txnpopup = document . getElementsByClassName ( "transactiondetails" ) ;
trapFocus ( txnpopup [ 0 ] ) ;
autoFocus ( txnpopup [ 0 ] ) ;
} , 1 ) ;
}
Using vanilla-router to navigate…
Copy
window . router . navigateTo ( 'main' ) ;
sessionStorage . setItem ( 'txndet_accountid' , myAccountId ) ;
sessionStorage . setItem ( 'txndet_transactiondata' , myTransactionData ) ;
window . router . navigateTo ( 'txndet' ) ;
In order to access APIs in varying locations, it is necessary to run a cors proxy on your machine. If you do not, the browser will issue a cross-origin error.
Extract the cors-cache-proxy.zip from the resources folder and run the command below to run a proxy on port 8080.
Any API calls must use the prefix http://localhost:8080/
e.g. http://localhost:8080/http://52.169.75.162:8000/ms-party-api/api/v4.0.0/party/parties?lastName=Green
Whilst this looks strange, the proxy accepts the request and forwards it on to the specified URL.
More reading on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
UUX grid example Grid system explainer UUX grid component usage Dynamic Module Imports in JavaScript New user agents will use the Temenos Explorer . However, you can wrap a web component for use in Visualizer by following this video: