Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

or-header, npm webcomponent package

robindekkers8480bbd252a8
diff --git a/ui/component/README.md b/ui/component/README.md
new file mode 100644
index 000000000..08efe8e65
--- /dev/null
+++ b/ui/component/README.md
@@ -0,0 +1,16 @@
+# OpenRemote Webcomponents
+
+Library of Webcomponents for OpenRemote.
+
+[Source](https://github.com/openremote/openremote) **·** [Documentation](https://github.com/openremote/openremote/wiki) **·** [Community](https://groups.google.com/forum/#!forum/openremotecommunity) **·** [Issues](https://github.com/openremote/openremote/issues) **·** [Docker Images](https://hub.docker.com/u/openremote/) **·** [OpenRemote Inc.](http://openremote.com)
+
+
+## Getting started with OpenRemote
+
+We are currently working on v3 of the OpenRemote platform. This is **alpha** software that should be used only for development.
+
+If you want to try OpenRemote v2, [read the OpenRemote v2 documentation](https://github.com/openremote/Documentation/wiki).
+
+## Discuss OpenRemote
+
+Join us on the [community group](https://groups.google.com/forum/#!forum/openremotecommunity).
diff --git a/ui/component/or-header/.npmignore b/ui/component/or-header/.npmignore
new file mode 100644
index 000000000..ca658009d
--- /dev/null
+++ b/ui/component/or-header/.npmignore
@@ -0,0 +1,3 @@
+build/
+build.gradle
+test/
\ No newline at end of file
diff --git a/ui/component/or-header/README.md b/ui/component/or-header/README.md
new file mode 100644
index 000000000..6bf87e6a9
--- /dev/null
+++ b/ui/component/or-header/README.md
@@ -0,0 +1,21 @@
+# \<or-header\>
+
+Displays header with menu based on slots.
+
+## Install the Polymer-CLI
+
+First, make sure you have the [Polymer CLI](https://www.npmjs.com/package/polymer-cli) and npm (packaged with [Node.js](https://nodejs.org)) installed. Run `npm install` to install your element's dependencies, then run `polymer serve` to serve your element locally.
+
+## Viewing Your Element
+
+```
+$ polymer serve
+```
+
+## Running Tests
+
+```
+$ polymer test
+```
+
+Your application is already set up to be tested via [web-component-tester](https://github.com/Polymer/web-component-tester). Run `polymer test` to run your application's test suite locally.
diff --git a/ui/component/or-header/build.gradle b/ui/component/or-header/build.gradle
new file mode 100644
index 000000000..56d41d45d
--- /dev/null
+++ b/ui/component/or-header/build.gradle
@@ -0,0 +1,9 @@
+task clean() {
+ doLast {
+ delete "dist"
+ }
+}
+
+task build() {
+ dependsOn npmBuild
+}
diff --git a/ui/component/or-header/package.json b/ui/component/or-header/package.json
new file mode 100644
index 000000000..09907e2a6
--- /dev/null
+++ b/ui/component/or-header/package.json
@@ -0,0 +1,27 @@
+{
+ "name": "@openremote/or-header",
+ "version": "1.0.0",
+ "description": "Displays header with menu for mobile and desktop",
+ "main": "dist/index.js",
+ "types": "src/index.ts",
+ "scripts": {
+ "build": "npx tsc",
+ "test": "echo \"No tests\" && exit 0"
+ },
+ "author": "OpenRemote",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "lit-element": "^2.0.0-rc.2",
+ "lit-html": "1.0.0-rc.2"
+ },
+ "devDependencies": {
+ "@polymer/decorators": "^3.0.0",
+ "@polymer/iron-demo-helpers": "^3.0.0-pre.19",
+ "@webcomponents/webcomponentsjs": "^2.0.0",
+ "css-loader": "^2.0.0",
+ "style-loader": "^0.23.1",
+ "tslint": "^5.11.0",
+ "typescript": "^3.1.6",
+ "wct-browser-legacy": "^1.0.0"
+ }
+}
diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.ts
new file mode 100644
index 000000000..27143ac98
--- /dev/null
+++ b/ui/component/or-header/src/index.ts
@@ -0,0 +1,163 @@
+import {LitElement, html, property} from 'lit-element';
+
+const menu = html`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 24 24">
+ <g>
+ <path d="M24,3c0-0.6-0.4-1-1-1H1C0.4,2,0,2.4,0,3v2c0,0.6,0.4,1,1,1h22c0.6,0,1-0.4,1-1V3z"/>
+ <path d="M24,11c0-0.6-0.4-1-1-1H1c-0.6,0-1,0.4-1,1v2c0,0.6,0.4,1,1,1h22c0.6,0,1-0.4,1-1V11z"/>
+ <path d="M24,19c0-0.6-0.4-1-1-1H1c-0.6,0-1,0.4-1,1v2c0,0.6,0.4,1,1,1h22c0.6,0,1-0.4,1-1V19z"/>
+ </g>
+</svg>
+`;
+
+const close = html`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21.9 21.9" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 21.9 21.9">
+ <path d="M14.1,11.3c-0.2-0.2-0.2-0.5,0-0.7l7.5-7.5c0.2-0.2,0.3-0.5,0.3-0.7s-0.1-0.5-0.3-0.7l-1.4-1.4C20,0.1,19.7,0,19.5,0 c-0.3,0-0.5,0.1-0.7,0.3l-7.5,7.5c-0.2,0.2-0.5,0.2-0.7,0L3.1,0.3C2.9,0.1,2.6,0,2.4,0S1.9,0.1,1.7,0.3L0.3,1.7C0.1,1.9,0,2.2,0,2.4 s0.1,0.5,0.3,0.7l7.5,7.5c0.2,0.2,0.2,0.5,0,0.7l-7.5,7.5C0.1,19,0,19.3,0,19.5s0.1,0.5,0.3,0.7l1.4,1.4c0.2,0.2,0.5,0.3,0.7,0.3 s0.5-0.1,0.7-0.3l7.5-7.5c0.2-0.2,0.5-0.2,0.7,0l7.5,7.5c0.2,0.2,0.5,0.3,0.7,0.3s0.5-0.1,0.7-0.3l1.4-1.4c0.2-0.2,0.3-0.5,0.3-0.7 s-0.1-0.5-0.3-0.7L14.1,11.3z"/>
+</svg>`;
+
+class OrHeader extends LitElement {
+
+ @property({type: Boolean})
+ private _drawerOpened = false;
+
+ @property({type: String})
+ private logo = '';
+
+ protected render() {
+ return html`
+ <style>
+ app-header {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 60px;
+ text-align: center;
+ background-color: var(--app-header-background-color);
+ color: var(--app-header-text-color);
+ z-index: 9999999;
+ box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.57);
+ }
+
+ .toolbar-top {
+ display: flex;
+ background-color: var(--app-header-background-color);
+ padding: 0;
+ }
+
+ #logo {
+ height: 60px;
+ display: block;
+ }
+
+ slot[name="desktop-right"] {
+ display: none;
+ }
+
+ slot[name="desktop-right"]{
+ margin-left: auto;
+ margin-right: 20px;
+ }
+
+
+ app-drawer {
+ z-index: 999999;
+ position: absolute;
+ top: 60px;
+ width: 100%;
+ height: calc(100% - 60px);
+ transition: all 300ms ease-in;
+ transition-property: -webkit-transform;
+ transition-property: transform;
+ -webkit-transform: translate3d(0, -100%, 0);
+ transform: translate3d(0, -100%, 0);
+ }
+
+ app-drawer[opened] {
+ -webkit-transform: translate3d(0, 0, 0);
+ transform: translate3d(0, 0, 0);
+ }
+
+ .menu-btn {
+ background: none;
+ border: none;
+ fill: var(--app-header-text-color);
+ cursor: pointer;
+ height: 40px;
+ width: 40px;
+ margin: 10px 0 10px auto;
+ }
+
+ .menu-btn svg {
+ width: 24px;
+ height: 24px;
+ }
+ .menu-btn svg,
+ .menu-btn svg path {
+ fill: #FFF;
+ }
+
+ .drawer-list {
+ box-sizing: border-box;
+ width: 100%;
+ height: 100%;
+ padding: 24px;
+ background: var(--app-drawer-background-color);
+ position: relative;
+ }
+
+ /* Wide layout: when the viewport width is bigger than 460px, layout
+ changes to a wide layout. */
+ @media (min-width: 460px) {
+ .menu-btn {
+ display: none;
+ }
+ slot[name="desktop-left"],
+ slot[name="desktop-right"] {
+ display: block;
+ }
+ }
+ </style>
+ <!-- Header -->
+ <app-header condenses reveals effects="waterfall">
+ <div class="toolbar-top">
+ <div><img id="logo" src="${this.logo}" /></div>
+ <!-- This gets hidden on a small screen-->
+
+ <nav class="toolbar-list">
+ <slot name="desktop-left"></slot>
+ </nav>
+
+ <slot name="desktop-right"></slot>
+
+ <button class="menu-btn" title="Menu" @click="${this._menuButtonClicked}">${this._drawerOpened ? close : menu}</button>
+ </div>
+ </app-header>
+
+ <app-drawer ?opened="${this._drawerOpened}" @click="${this._close}">
+ <nav class="drawer-list">
+ <slot name="mobile-top"></slot>
+
+ <slot name="mobile-bottom"></slot>
+ </nav>
+ </app-drawer>
+
+ `;
+ }
+
+
+ constructor() {
+ super();
+ }
+
+ private _close () {
+ this._drawerOpened = false;
+ }
+
+ private _menuButtonClicked() {
+ this._drawerOpened = !this._drawerOpened;
+ }
+
+}
+
+window.customElements.define('or-header', OrHeader);
+
+
diff --git a/ui/component/or-header/src/or-header-style.ts b/ui/component/or-header/src/or-header-style.ts
new file mode 100644
index 000000000..423d533a3
--- /dev/null
+++ b/ui/component/or-header/src/or-header-style.ts
@@ -0,0 +1,75 @@
+import {html} from 'lit-html';
+export const OrHeaderStyle = html`
+<style>
+ or-header a, a:link, a:visited {
+ text-decoration: none !important;
+ }
+
+ or-header a, a:link, a:visited {
+ display: inline-block;
+ color: rgba(255,255,255, 0.8);
+ line-height: 60px;
+ padding: 0 5px;
+ text-transform: uppercase;
+ font-size: 14px;
+ text-decoration: none !important;
+ cursor: pointer;
+ }
+ or-header a[selected]{
+ color: var(--app-light-text-color);
+ font-weight: 400;
+ }
+
+ or-header a[selected] svg path{
+ fill: var(--app-light-text-color);
+ }
+
+ [slot="mobile-top"] > a,
+ [slot="mobile-bottom"] > a {
+ color: var(--app-drawer-text-color);
+ display: block;
+ }
+ [slot="mobile-top"] > a[selected] svg path,
+ [slot="mobile-bottom"] > a[selected] svg path {
+ fill: var(--app-drawer-text-color);
+ }
+
+ [slot="mobile-top"] > a[selected],
+ [slot="mobile-bottom"] > a[selected] {
+ color: var(--app-drawer-text-color);
+ /*border-bottom: 4px solid #A3BDD0;*/
+ }
+
+
+ or-header .svg-inline--fa {
+ height: 14px;
+ width: 14px;
+ margin: -2px 4px;
+ }
+
+ [slot="desktop-left"] svg path {
+ fill: rgba(255,255,255, 0.8);
+ }
+
+ [slot="desktop-left"] > a {
+ display: none;
+ line-height: 60px;
+ padding: 0 24px;
+ }
+
+
+ [slot="desktop-left"] > a[selected] {
+ display:inline-block;
+ }
+
+ @media (min-width: 460px) {
+ [slot="desktop-left"] > a {
+ display:inline-block;
+ line-height: 56px;
+ }
+
+ [slot="desktop-left"] > a[selected] {
+ border-bottom: 4px solid #A3BDD0;
+ }
+</style>
+`;
diff --git a/ui/component/or-header/tsconfig.json b/ui/component/or-header/tsconfig.json
new file mode 100644
index 000000000..aa12a532d
--- /dev/null
+++ b/ui/component/or-header/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "./dist/",
+ "rootDir": "src"
+ },
+ "include": [
+ "./src"
+ ],
+ "references": [
+ { "path": "../core" },
+ { "path": "../rest" }
+ ]
+}
\ No newline at end of file
diff --git a/ui/demo/demo-or-header/.gitignore b/ui/demo/demo-or-header/.gitignore
new file mode 100644
index 000000000..9fde23e0a
--- /dev/null
+++ b/ui/demo/demo-or-header/.gitignore
@@ -0,0 +1,3 @@
+src/**/*.d.ts
+src/**/*.js.map
+src/**/*.js
\ No newline at end of file
diff --git a/ui/demo/demo-or-header/build.gradle b/ui/demo/demo-or-header/build.gradle
new file mode 100644
index 000000000..71cf5c0f7
--- /dev/null
+++ b/ui/demo/demo-or-header/build.gradle
@@ -0,0 +1,9 @@
+buildDir = "dist"
+
+task build {
+ dependsOn npmBuild
+}
+
+task clean() {
+ dependsOn npmClean
+}
\ No newline at end of file
diff --git a/ui/demo/demo-or-header/index.html b/ui/demo/demo-or-header/index.html
new file mode 100644
index 000000000..657202f75
--- /dev/null
+++ b/ui/demo/demo-or-header/index.html
@@ -0,0 +1,68 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
+
+ <title>Demo</title>
+
+ <!--
+ Feature detect Custom Elements support. If the browser DOES support Custom
+ Elements then we need to load the custom-elements-es5-adapter because
+ our project code has been transpiled from ES2015 to ES5 and native Custom
+ Elements expect elements will be registered as classes.
+ -->
+ <script>if (!window.customElements) { document.write('<!--'); }</script>
+ <script src="./modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
+ <!--! DO NOT REMOVE THIS COMMENT, WE NEED ITS CLOSING MARKER -->
+
+ <custom-style>
+ <style is="custom-style" include="demo-pages-shared-styles">
+ </style>
+ </custom-style>
+</head>
+<body>
+<div class="vertical-section-container centered">
+ <h3>Demo</h3>
+ <demo-snippet>
+ <template>
+ <or-header logo="">
+ <div slot="desktop-left">
+ <a href="/map">Map</a>
+ <a href="/overview">Overview</a>
+ </div>
+ <div slot="desktop-right">
+ <a>Logout</a>
+ </div>
+ <div slot="mobile-top">
+ <a href="/map">Map</a>
+ <a>Logout</a>
+ </div>
+ <div slot="mobile-bottom">
+ </div>
+ </or-header>
+ </template>
+ </demo-snippet>
+</div>
+
+<!--
+Use the webcomponents-loader script which will feature detect which Web
+Components features are missing and lazy load the appropriate polyfills.
+When we hear the 'WebComponentsReady' event from the polyfill bundle we can
+insert our 'bundle.js'.
+-->
+<script>
+ (function () {
+ document.addEventListener('WebComponentsReady', function componentsReady() {
+ document.removeEventListener('WebComponentsReady', componentsReady, false);
+ var script = document.createElement('script');
+ script.src = '<%= htmlWebpackPlugin.files.js[0] %>';
+ var refScript = document.getElementsByTagName('script')[0];
+ refScript.parentNode.insertBefore(script, refScript);
+ }, false);
+ })();
+</script>
+<script src="modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
+
+</body>
+</html>
diff --git a/ui/demo/demo-or-header/package.json b/ui/demo/demo-or-header/package.json
new file mode 100644
index 000000000..c8dff8538
--- /dev/null
+++ b/ui/demo/demo-or-header/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "@openremote/demo-or-header",
+ "version": "1.0.0",
+ "description": "Component Demo",
+ "scripts": {
+ "clean": "npx shx rm -rf dist",
+ "build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
+ "serve": "npx webpack-dev-server",
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "OpenRemote",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "@openremote/or-header": "^1.0.0",
+ "source-map-loader": "^0.2.4"
+ },
+ "devDependencies": {
+ "@babel/core": "^7.2.2",
+ "@babel/plugin-syntax-dynamic-import": "^7.2.0",
+ "@babel/plugin-syntax-object-rest-spread": "^7.2.0",
+ "@babel/plugin-transform-regenerator": "^7.0.0",
+ "@babel/plugin-transform-runtime": "^7.2.0",
+ "@babel/preset-env": "^7.2.0",
+ "@babel/runtime": "^7.2.0",
+ "babel-loader": "^8.0.4",
+ "@polymer/iron-demo-helpers": "^3.0.0-pre.19",
+ "copy-webpack-plugin": "^4.6.0",
+ "cross-env": "^5.2.0",
+ "css-loader": "^2.0.0",
+ "file-loader": "^2.0.0",
+ "html-webpack-plugin": "^3.2.0",
+ "raw-loader": "^0.5.1",
+ "shx": "^0.3.2",
+ "style-loader": "^0.23.1",
+ "tslint": "^5.11.0",
+ "typescript": "^3.1.6",
+ "url-loader": "^1.1.2",
+ "webpack": "^4.24.0",
+ "webpack-cli": "^3.1.2",
+ "webpack-dev-server": "^3.1.10"
+ }
+}
diff --git a/ui/demo/demo-or-header/src/index.ts b/ui/demo/demo-or-header/src/index.ts
new file mode 100644
index 000000000..c50b82956
--- /dev/null
+++ b/ui/demo/demo-or-header/src/index.ts
@@ -0,0 +1,3 @@
+import '@polymer/iron-demo-helpers/demo-pages-shared-styles';
+import '@polymer/iron-demo-helpers/demo-snippet';
+import "@openremote/or-header";
\ No newline at end of file
diff --git a/ui/demo/demo-or-header/tsconfig.json b/ui/demo/demo-or-header/tsconfig.json
new file mode 100644
index 000000000..dc1be1b78
--- /dev/null
+++ b/ui/demo/demo-or-header/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "../../tsconfig",
+ "include": [
+ "./src"
+ ],
+ "references": [
+ { "path": "../../component/or-header" }
+ ]
+}
\ No newline at end of file
diff --git a/ui/demo/demo-or-header/webpack.config.js b/ui/demo/demo-or-header/webpack.config.js
new file mode 100644
index 000000000..57b6a2e91
--- /dev/null
+++ b/ui/demo/demo-or-header/webpack.config.js
@@ -0,0 +1,80 @@
+
+var HtmlWebpackPlugin = require("html-webpack-plugin");
+// The below was an attempt to get native ES6 module support alongside bundled JS modules but due to lack
+// of understanding about webpack internals and poor docs given up for now and will just rely on bundles.
+// class ES6Plugin {
+// apply(compiler) {
+// compiler.hooks.normalModuleFactory.tap(
+// "NormalModuleReplacementPlugin",
+// nmf => {
+// nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => {
+// if (!result) return;
+// if (/node_modules/.test(result.request)) {
+// let relPath = path.relative(__dirname, result.request);
+// let dest = relPath.split(path.sep);
+// while(dest.length > 0 && dest[0] !== 'node_modules') {
+// dest.shift();
+// }
+// dest.shift();
+// dest = path.join(compiler.options.output.path, 'modules', dest.join(path.sep));
+// fs.mkdirsSync(path.dirname(dest));
+// fs.copySync(result.request, dest, {overwrite: true});
+// result.resource = dest;
+// } else {
+// console.log(result.request);
+// }
+// return result;
+// });
+// }
+// );
+// }
+// }
+
+module.exports = {
+ mode: 'development',
+ entry: {
+ 'bundle': './src/index.ts'
+ },
+ output: {
+ path: __dirname + "/dist",
+ filename: "[name].[hash].js",
+ publicPath: ""
+ },
+ resolve: {
+ extensions: [ '.tsx', '.ts', '.js' ],
+ mainFields: ['types', 'browser', 'module', 'main']
+ },
+ devtool: 'inline-source-map',
+ devServer: {
+ port: 9000,
+ contentBase: './dist'
+ },
+ plugins: [
+ new HtmlWebpackPlugin({
+ chunksSortMode: 'none',
+ inject: false,
+ template: 'index.html'
+ })
+ ],
+ module: {
+ rules: [
+ {
+ test: /\.tsx?$/,
+ use: 'awesome-typescript-loader',
+ exclude: /node_modules/
+ },
+ {
+ test: /\.js$/,
+ exclude: /webcomponentsjs/,
+ use: [
+ {
+ loader: 'babel-loader',
+ options: {
+ presets: ['@babel/preset-env']
+ }
+ }
+ ]
+ }
+ ]
+ }
+};
\ No newline at end of file