@record-evolution/widget-sidenav 1.0.1 → 1.0.3

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.
@@ -7,6 +7,12 @@
7
7
  "order": 1,
8
8
  "type": "string"
9
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
+ },
10
16
  "style": {
11
17
  "title": "Item Style",
12
18
  "order": 3,
@@ -60,7 +66,7 @@
60
66
  "route": {
61
67
  "title": "Navigation Route",
62
68
  "order": 3,
63
- "description": "Navigation to perform on click. Example: /settings/profile, /settings",
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'.",
64
70
  "type": "string"
65
71
  }
66
72
  }
@@ -1,5 +1,5 @@
1
1
  import { html, css, LitElement, PropertyValues } from 'lit'
2
- import { property, state } from 'lit/decorators.js'
2
+ import { customElement, property, state } from 'lit/decorators.js'
3
3
  import { repeat } from 'lit/directives/repeat.js'
4
4
  import { InputData } from './definition-schema'
5
5
 
@@ -9,7 +9,8 @@ type Theme = {
9
9
  theme_name: string
10
10
  theme_object: any
11
11
  }
12
- export class WidgetTextbox extends LitElement {
12
+ @customElement('widget-sidenav-versionplaceholder')
13
+ export class WidgetSidenav extends LitElement {
13
14
  @property({ type: Object }) inputData?: InputData
14
15
  @property({ type: Object }) theme?: Theme
15
16
  @property({ type: String }) route?: string
@@ -38,19 +39,30 @@ export class WidgetTextbox extends LitElement {
38
39
  this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
39
40
  }
40
41
 
41
- handleNavItemClick(item: { label?: string; iconName?: string; route?: string }) {
42
- console.log('Navigating to:', item.route)
42
+ handleNavItemClick(route?: string) {
43
+ // console.log('Navigating to:', item.route)
43
44
  const event = new CustomEvent('nav-submit', {
44
- detail: { path: item.route },
45
+ detail: { path: route },
45
46
  bubbles: true,
46
47
  composed: true
47
48
  })
48
49
  this.dispatchEvent(event)
49
50
  }
50
51
 
51
- normalizeRoute(route?: string) {
52
- if (!route) return '/'
53
- return route
52
+ trimRoute(route?: string) {
53
+ if (!route) return ''
54
+ return '/' + route.split('/').filter(Boolean).join('/')
55
+ }
56
+
57
+ matchesRoute(itemRoute?: string) {
58
+ if (itemRoute === undefined) return false
59
+ const route = this.trimRoute(decodeURIComponent(this.route || '/'))
60
+ const subRoute = this.trimRoute(itemRoute)
61
+ if (itemRoute.startsWith('/')) {
62
+ return route.startsWith(subRoute)
63
+ } else {
64
+ return route.endsWith('/' + subRoute) || route === subRoute
65
+ }
54
66
  }
55
67
 
56
68
  static styles = css`
@@ -71,7 +83,6 @@ export class WidgetTextbox extends LitElement {
71
83
  height: 100%;
72
84
  width: 100%;
73
85
  padding: 12px;
74
- gap: 12px;
75
86
  box-sizing: border-box;
76
87
  }
77
88
 
@@ -93,12 +104,11 @@ export class WidgetTextbox extends LitElement {
93
104
  border-radius: 4px;
94
105
  }
95
106
 
96
- md-icon {
107
+ mdif2-icon {
97
108
  font-family: 'Material Symbols Outlined';
98
109
  }
99
110
 
100
111
  .selected {
101
- font-weight: bold;
102
112
  background-color: rgba(0, 0, 0, 0.1);
103
113
  }
104
114
 
@@ -111,9 +121,8 @@ export class WidgetTextbox extends LitElement {
111
121
 
112
122
  render() {
113
123
  const fontSize = this.inputData?.style?.fontSize ?? 16
114
- const iconFontSize = this.inputData?.style?.fontSize ?? 16 * 1.5
124
+ const iconFontSize = (this.inputData?.style?.fontSize ?? 16) * 1.5
115
125
  const gap = fontSize * 0.4
116
- const lastRouteSegment = decodeURIComponent(this.route?.split('/').pop() || '')
117
126
  return html`
118
127
  <div
119
128
  class="wrapper"
@@ -122,22 +131,31 @@ export class WidgetTextbox extends LitElement {
122
131
  font-weight: ${this.inputData?.style?.fontWeight};
123
132
  font-size: ${fontSize}px;"
124
133
  >
125
- <h2 class="paging" ?active=${this.inputData?.title}>${this.inputData?.title}</h2>
134
+ <h2
135
+ class="paging"
136
+ style=${this.inputData?.route ? 'cursor: pointer' : ''}
137
+ ?active=${this.inputData?.title}
138
+ @click=${() => this.handleNavItemClick(this.inputData?.route)}
139
+ >
140
+ ${this.inputData?.title}
141
+ </h2>
126
142
  <div class="nav-list">
127
143
  ${repeat(
128
144
  this.inputData?.navItems || [],
129
145
  (item) => item.label,
130
146
  (item) => html`
131
147
  <div
132
- class="nav-item ${lastRouteSegment === item.route ? 'selected' : ''}"
148
+ class="nav-item ${this.matchesRoute(item.route) ? 'selected' : ''}"
133
149
  style="gap: ${gap}px;"
134
- @click=${() => this.handleNavItemClick(item)}
150
+ @click=${() => this.handleNavItemClick(item.route)}
135
151
  >
136
152
  ${item.iconName
137
- ? html`<md-icon
138
- style="font-size: ${iconFontSize}px;width: ${iconFontSize}px;height: ${iconFontSize}px;"
139
- >${item.iconName}</md-icon
140
- >`
153
+ ? html`
154
+ <mdif2-icon
155
+ style="font-size: ${iconFontSize}px;width: ${iconFontSize}px;"
156
+ >${item.iconName}
157
+ </mdif2-icon>
158
+ `
141
159
  : ''}
142
160
  ${item.label}
143
161
  </div>
@@ -148,4 +166,3 @@ export class WidgetTextbox extends LitElement {
148
166
  `
149
167
  }
150
168
  }
151
- window.customElements.define('widget-sidenav-versionplaceholder', WidgetTextbox)