@record-evolution/widget-navbar 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 widget-linechart
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # \<widget-navbar>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i widget-navbar
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'widget-navbar/widget-navbar.js'
16
+ </script>
17
+
18
+ <widget-navbar></widget-navbar>
19
+ ```
20
+
21
+ ## Expected data format
22
+
23
+ ## Tooling configs
24
+
25
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
26
+
27
+ If you customize the configuration a lot, you can consider moving them to individual files.
28
+
29
+ ## Local Demo with `web-dev-server`
30
+
31
+ ```bash
32
+ npm start
33
+ ```
34
+
35
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,19 @@
1
+ {
2
+ "title": "",
3
+ "style": {
4
+ "fontSize": 16,
5
+ "fontWeight": 400
6
+ },
7
+ "navItems": [
8
+ {
9
+ "label": "Assets",
10
+ "iconName": "image",
11
+ "route": "/assets/"
12
+ },
13
+ {
14
+ "label": "Settings",
15
+ "iconName": "settings",
16
+ "route": "/settings/"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,50 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * This file was automatically generated by json-schema-to-typescript.
4
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
+ * and run json-schema-to-typescript to regenerate this file.
6
+ */
7
+
8
+ export type TitleSettings = string;
9
+ /**
10
+ * Navigation to perform on title click. Example: If you are at route /my/route/asset then 'settings/profile' routes to '/my/route/settings/profile'.
11
+ */
12
+ export type TitleNavigation = string;
13
+ export type FontSize = number;
14
+ export type FontWeight = number;
15
+ export type Label = string;
16
+ /**
17
+ * Name of the icon from https://fonts.google.com/icons
18
+ */
19
+ export type IconName = string;
20
+ /**
21
+ * Navigation to perform on click. Example: If you are at route /my/route/asset then 'settings/profile' routes to '/my/route/settings/profile'.
22
+ */
23
+ export type NavigationRoute = string;
24
+ export type NavigationItems = {
25
+ label?: Label;
26
+ iconName?: IconName;
27
+ route?: NavigationRoute;
28
+ [k: string]: unknown;
29
+ }[];
30
+
31
+ export interface InputData {
32
+ title?: TitleSettings;
33
+ route?: TitleNavigation;
34
+ style?: ItemStyle;
35
+ navItems?: NavigationItems;
36
+ [k: string]: unknown;
37
+ }
38
+ export interface ItemStyle {
39
+ fontSize?: FontSize;
40
+ fontWeight?: FontWeight;
41
+ color?: FontColor;
42
+ backgroundColor?: BackgroundColor;
43
+ [k: string]: unknown;
44
+ }
45
+ export interface FontColor {
46
+ [k: string]: unknown;
47
+ }
48
+ export interface BackgroundColor {
49
+ [k: string]: unknown;
50
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "title": "Input Data",
3
+ "type": "object",
4
+ "properties": {
5
+ "title": {
6
+ "title": "Title Settings",
7
+ "order": 1,
8
+ "type": "string"
9
+ },
10
+ "route": {
11
+ "title": "Title Navigation",
12
+ "order": 3,
13
+ "description": "Navigation to perform on title click. Example: If you are at route /my/route/asset then 'settings/profile' routes to '/my/route/settings/profile'.",
14
+ "type": "string"
15
+ },
16
+ "style": {
17
+ "title": "Item Style",
18
+ "order": 3,
19
+ "type": "object",
20
+ "properties": {
21
+ "fontSize": {
22
+ "title": "Font Size",
23
+ "order": 1,
24
+ "dataDrivenDisabled": true,
25
+ "type": "number"
26
+ },
27
+ "fontWeight": {
28
+ "title": "Font Weight",
29
+ "order": 3,
30
+ "dataDrivenDisabled": true,
31
+ "type": "number"
32
+ },
33
+ "color": {
34
+ "title": "Font Color",
35
+ "order": 4,
36
+ "type": "color",
37
+ "dataDrivenDisabled": true
38
+ },
39
+ "backgroundColor": {
40
+ "title": "Background Color",
41
+ "order": 4,
42
+ "type": "color",
43
+ "dataDrivenDisabled": true
44
+ }
45
+ }
46
+ },
47
+ "navItems": {
48
+ "title": "Navigation Items",
49
+ "order": 3,
50
+ "type": "array",
51
+ "items": {
52
+ "type": "object",
53
+ "properties": {
54
+ "label": {
55
+ "title": "Label",
56
+ "order": 1,
57
+ "type": "string"
58
+ },
59
+ "iconName": {
60
+ "title": "Icon Name",
61
+ "order": 2,
62
+ "description": "Name of the icon from https://fonts.google.com/icons",
63
+ "dataDrivenDisabled": true,
64
+ "type": "string"
65
+ },
66
+ "route": {
67
+ "title": "Navigation Route",
68
+ "order": 3,
69
+ "description": "Navigation to perform on click. Example: If you are at route /my/route/asset then 'settings/profile' routes to '/my/route/settings/profile'.",
70
+ "type": "string"
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,162 @@
1
+ import { html, css, LitElement, PropertyValues, nothing } from 'lit'
2
+ import { property, state } from 'lit/decorators.js'
3
+ import { repeat } from 'lit/directives/repeat.js'
4
+ import { InputData } from './definition-schema'
5
+
6
+ import '@material/web/icon/icon'
7
+ import '@material/web/tabs/tabs'
8
+ import '@material/web/tabs/primary-tab'
9
+ import '@material/web/tabs/secondary-tab'
10
+
11
+ type Theme = {
12
+ theme_name: string
13
+ theme_object: any
14
+ }
15
+ export class WidgetNavbar extends LitElement {
16
+ @property({ type: Object }) inputData?: InputData
17
+ @property({ type: Object }) theme?: Theme
18
+ @property({ type: String }) route?: string
19
+
20
+ @state() private themeBgColor?: string
21
+ @state() private themeTitleColor?: string
22
+
23
+ version: string = 'versionplaceholder'
24
+
25
+ update(changedProperties: Map<string, any>) {
26
+ if (changedProperties.has('theme')) {
27
+ this.registerTheme(this.theme)
28
+ }
29
+
30
+ super.update(changedProperties)
31
+ }
32
+
33
+ protected firstUpdated(_changedProperties: PropertyValues): void {
34
+ this.registerTheme(this.theme)
35
+ }
36
+
37
+ registerTheme(theme?: Theme) {
38
+ const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
39
+ const cssBgColor = getComputedStyle(this).getPropertyValue('--re-tile-background-color').trim()
40
+ this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
41
+ this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
42
+ }
43
+
44
+ handleNavItemClick(route?: string) {
45
+ // console.log('Navigating to:', item.route)
46
+ const event = new CustomEvent('nav-submit', {
47
+ detail: { path: route },
48
+ bubbles: true,
49
+ composed: true
50
+ })
51
+ this.dispatchEvent(event)
52
+ }
53
+
54
+ normalizeRoute(route?: string) {
55
+ if (!route) return '/'
56
+ return route
57
+ }
58
+
59
+ static styles = css`
60
+ :host {
61
+ display: block;
62
+ font-family: sans-serif;
63
+ box-sizing: border-box;
64
+ margin: auto;
65
+ }
66
+
67
+ .paging:not([active]) {
68
+ display: none !important;
69
+ }
70
+
71
+ .wrapper {
72
+ display: flex;
73
+ align-items: end;
74
+ height: 100%;
75
+ width: 100%;
76
+ box-sizing: border-box;
77
+ }
78
+
79
+ mdif4-icon {
80
+ font-family: 'Material Symbols Outlined';
81
+ }
82
+
83
+ .selected {
84
+ font-weight: bold;
85
+ background-color: rgba(0, 0, 0, 0.1);
86
+ }
87
+
88
+ h2 {
89
+ margin: 0;
90
+ padding: 0px;
91
+ font-size: 1.2em;
92
+ }
93
+ `
94
+
95
+ trimRoute(route?: string) {
96
+ if (!route) return ''
97
+ return '/' + route.split('/').filter(Boolean).join('/')
98
+ }
99
+
100
+ matchesRoute(itemRoute?: string) {
101
+ if (itemRoute === undefined) return false
102
+ const route = this.trimRoute(decodeURIComponent(this.route || '/'))
103
+ const subRoute = this.trimRoute(itemRoute)
104
+ if (itemRoute.startsWith('/')) {
105
+ return route.startsWith(subRoute)
106
+ } else {
107
+ return route.endsWith('/' + subRoute) || route === subRoute
108
+ }
109
+ }
110
+
111
+ render() {
112
+ const fontSize = this.inputData?.style?.fontSize ?? 16
113
+ const iconFontSize = (this.inputData?.style?.fontSize ?? 16) * 1.5
114
+ const fontColor = this.inputData?.style?.color || this.themeTitleColor || 'black'
115
+ const bgColor = this.inputData?.style?.backgroundColor || this.themeBgColor || 'white'
116
+ return html`
117
+ <div
118
+ class="wrapper"
119
+ style="background-color: ${bgColor}; color: ${fontColor};
120
+ font-weight: ${this.inputData?.style?.fontWeight};
121
+ font-size: ${fontSize}px;"
122
+ >
123
+ <h2
124
+ class="paging"
125
+ style=${this.inputData?.route ? 'cursor: pointer' : ''}
126
+ ?active=${this.inputData?.title}
127
+ @click=${() => this.handleNavItemClick(this.inputData?.route)}
128
+ >
129
+ ${this.inputData?.title}
130
+ </h2>
131
+ <mdif4-tab class="xnav-list">
132
+ ${repeat(
133
+ this.inputData?.navItems || [],
134
+ (item) => item.label,
135
+ (item) => html`
136
+ <mdif4-secondary-tab
137
+ ?active=${this.matchesRoute(item.route)}
138
+ style="font-size: ${fontSize}px;
139
+ --mdif4-secondary-tab-container-color: ${bgColor};
140
+ color: ${fontColor};"
141
+ @click=${() => this.handleNavItemClick(item.route)}
142
+ >
143
+ ${item.iconName
144
+ ? html`
145
+ <mdif4-icon
146
+ slot="icon"
147
+ style="font-size: ${iconFontSize}px;width: ${iconFontSize}px;color: ${fontColor}"
148
+ >
149
+ ${item.iconName}
150
+ </mdif4-icon>
151
+ `
152
+ : nothing}
153
+ ${item.label}
154
+ </mdif4-secondary-tab>
155
+ `
156
+ )}
157
+ </mdif4-tab>
158
+ </div>
159
+ `
160
+ }
161
+ }
162
+ window.customElements.define('widget-navbar-versionplaceholder', WidgetNavbar)