@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 +21 -0
- package/README.md +35 -0
- package/dist/src/default-data.json +19 -0
- package/dist/src/definition-schema.d.ts +50 -0
- package/dist/src/definition-schema.json +76 -0
- package/dist/src/widget-navbar.ts +162 -0
- package/dist/widget-navbar.js +1792 -0
- package/dist/widget-navbar.js.map +1 -0
- package/package.json +49 -0
- package/src/default-data.json +19 -0
- package/src/definition-schema.d.ts +50 -0
- package/src/definition-schema.json +76 -0
- package/src/widget-navbar.ts +162 -0
|
@@ -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)
|