@record-evolution/widget-navbutton 1.0.1

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/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@record-evolution/widget-navbutton",
3
+ "description": "Webcomponent widget-navbutton following open-wc recommendations",
4
+ "license": "MIT",
5
+ "author": "widget-navbutton",
6
+ "version": "1.0.1",
7
+ "type": "module",
8
+ "main": "dist/widget-navbutton.js",
9
+ "types": "dist/src/widget-navbutton.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "src"
13
+ ],
14
+ "scripts": {
15
+ "analyze": "cem analyze --litelement",
16
+ "start": "concurrently -k -r \"npm run watch\" \"wds\"",
17
+ "build": "node rename-material-package.js && rollup -c rollup.config.js",
18
+ "watch": "node rename-material-package.js && rollup -w -c rollup.config.js",
19
+ "link": "npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-navbutton",
20
+ "unlink": "npm unlink --global && cd ../RESWARM/frontend && npm unlink @record-evolution/widget-navbutton && npm i @record-evolution/widget-navbutton",
21
+ "types": "cat src/definition-schema.json | json2ts > src/definition-schema.d.ts",
22
+ "release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag"
23
+ },
24
+ "dependencies": {
25
+ "lit": "^3.3.1",
26
+ "@material/web": "^2.4.0"
27
+ },
28
+ "devDependencies": {
29
+ "@custom-elements-manifest/analyzer": "^0.10.5",
30
+ "@rollup/plugin-babel": "^6.0.4",
31
+ "@rollup/plugin-commonjs": "^28.0.6",
32
+ "@rollup/plugin-node-resolve": "^16.0.1",
33
+ "@rollup/plugin-replace": "^6.0.2",
34
+ "@rollup/plugin-typescript": "^12.1.4",
35
+ "@web/dev-server": "^0.4.6",
36
+ "concurrently": "^9.2.1",
37
+ "json-schema-to-typescript": "^15.0.4",
38
+ "tslib": "^2.8.1",
39
+ "typescript": "^5.9.2"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/RecordEvolution/widget-navbutton.git"
44
+ },
45
+ "keywords": [
46
+ "widget",
47
+ "navbutton"
48
+ ],
49
+ "bugs": {
50
+ "url": "https://github.com/RecordEvolution/widget-navbutton/issues"
51
+ },
52
+ "homepage": "https://github.com/RecordEvolution/widget-navbutton#readme"
53
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "title": "Back",
3
+ "iconName": "arrow_back",
4
+ "route": "",
5
+ "style": {
6
+ "fontSize": 16,
7
+ "fontWeight": 400
8
+ }
9
+ }
@@ -0,0 +1,35 @@
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
+ /**
14
+ * Font size in pixels
15
+ */
16
+ export type FontSize = number;
17
+
18
+ export interface InputData {
19
+ title?: TitleSettings;
20
+ route?: TitleNavigation;
21
+ style?: ButtonStyle;
22
+ [k: string]: unknown;
23
+ }
24
+ export interface ButtonStyle {
25
+ fontSize?: FontSize;
26
+ color?: FontColor;
27
+ backgroundColor?: BackgroundColor;
28
+ [k: string]: unknown;
29
+ }
30
+ export interface FontColor {
31
+ [k: string]: unknown;
32
+ }
33
+ export interface BackgroundColor {
34
+ [k: string]: unknown;
35
+ }
@@ -0,0 +1,43 @@
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": 2,
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": "Button Style",
18
+ "order": 3,
19
+ "type": "object",
20
+ "properties": {
21
+ "fontSize": {
22
+ "title": "Font Size",
23
+ "order": 1,
24
+ "description": "Font size in pixels",
25
+ "dataDrivenDisabled": true,
26
+ "type": "number"
27
+ },
28
+ "color": {
29
+ "title": "Font Color",
30
+ "order": 4,
31
+ "type": "color",
32
+ "dataDrivenDisabled": true
33
+ },
34
+ "backgroundColor": {
35
+ "title": "Background Color",
36
+ "order": 4,
37
+ "type": "color",
38
+ "dataDrivenDisabled": true
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,107 @@
1
+ import { html, css, LitElement, PropertyValues } from 'lit'
2
+ import { customElement, property, state } from 'lit/decorators.js'
3
+ import { InputData } from './definition-schema'
4
+
5
+ import '@material/web/icon/icon.js'
6
+ import '@material/web/button/filled-button.js'
7
+ import '@material/web/ripple/ripple.js'
8
+
9
+ type Theme = {
10
+ theme_name: string
11
+ theme_object: any
12
+ }
13
+
14
+ @customElement('widget-navbutton-versionplaceholder')
15
+ export class WidgetNavbutton 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:', route, this.route)
46
+ let goto: string
47
+ if (this.inputData?.route === '') {
48
+ goto = this.route?.split('/').filter(Boolean).slice(0, -1).join('/') || '/'
49
+ } else {
50
+ goto = this.inputData?.route || '/'
51
+ }
52
+ const event = new CustomEvent('nav-submit', {
53
+ detail: { path: goto },
54
+ bubbles: true,
55
+ composed: true
56
+ })
57
+ this.dispatchEvent(event)
58
+ }
59
+
60
+ static styles = css`
61
+ :host {
62
+ display: flex;
63
+ align-items: center;
64
+ font-family: sans-serif;
65
+ box-sizing: border-box;
66
+ margin: auto;
67
+ padding: 12px;
68
+ }
69
+
70
+ mdif5-icon {
71
+ font-family: 'Material Symbols Outlined';
72
+ }
73
+ mdif5-filled-button {
74
+ --mdif5-filled-button-container-shape: 4px;
75
+ --mdif5-filled-button-container-shadow-color: none;
76
+ --md-sys-color-primary: #006a6a;
77
+ --md-ripple-hover-color: var(--md-sys-color-primary);
78
+ --md-ripple-pressed-color: var(--md-sys-color-primary);
79
+ }
80
+ `
81
+
82
+ render() {
83
+ const fontSize = this.inputData?.style?.fontSize ?? 16
84
+ const iconFontSize = (this.inputData?.style?.fontSize ?? 16) * 1.5
85
+ const fontColor = this.inputData?.style?.color || this.themeTitleColor || 'black'
86
+ const bgColor = this.inputData?.style?.backgroundColor || this.themeBgColor || 'white'
87
+ const gap = fontSize * 0.4
88
+ return html`
89
+ <mdif5-filled-button
90
+ style="font-size: ${fontSize}px;
91
+ --mdif5-filled-button-label-text-color: ${fontColor};
92
+ --mdif5-filled-button-hover-label-text-color: ${fontColor};
93
+ --mdif5-filled-button-pressed-label-text-color: ${fontColor};
94
+ --mdif5-filled-button-focus-label-text-color: ${fontColor};
95
+ --mdif5-filled-button-container-color: ${bgColor};
96
+ "
97
+ @click=${() => this.handleNavItemClick(this.inputData?.route)}
98
+ >
99
+ ${this.inputData?.title}
100
+ <mdif5-ripple></mdif5-ripple>
101
+ <mdif5-icon slot="icon" style="font-size: ${iconFontSize}px; color: ${fontColor}"
102
+ >${this.inputData?.iconName}</mdif5-icon
103
+ >
104
+ </mdif5-filled-button>
105
+ `
106
+ }
107
+ }