@record-evolution/widget-switch 1.1.1 → 1.1.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.
- package/README.md +92 -68
- package/dist/widget-switch.js +180 -3022
- package/dist/widget-switch.js.map +1 -1
- package/package.json +15 -29
- package/src/definition-schema.d.ts +51 -30
- package/src/definition-schema.json +15 -9
- package/src/widget-switch.ts +43 -5
- package/dist/src/widget-switch.d.ts +0 -37
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,104 +1,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# widget-switch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
IronFlock widget: A Lit 3.x web component that renders toggle switches using Material Design 3 components. Supports multiple switches with configurable state mapping and IoT device action triggers.
|
|
4
|
+
|
|
5
|
+

|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
npm i widget-switch
|
|
10
|
+
npm i @record-evolution/widget-switch
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
**Peer Dependencies:** This widget requires `@material/web` to be available at runtime via import map or bundled separately.
|
|
14
|
+
|
|
11
15
|
## Usage
|
|
12
16
|
|
|
13
17
|
```html
|
|
14
18
|
<script type="module">
|
|
15
|
-
|
|
19
|
+
import '@record-evolution/widget-switch'
|
|
16
20
|
</script>
|
|
17
21
|
|
|
18
|
-
<widget-switch></widget-switch>
|
|
22
|
+
<widget-switch-1.1.1></widget-switch-1.1.1>
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
> **Note:** The element tag includes the version number (e.g., `widget-switch-1.1.1`). This is replaced at build time via `@rollup/plugin-replace`.
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
The widget accepts an `inputData` property with the following structure:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
interface InputData {
|
|
33
|
+
title?: string
|
|
34
|
+
subTitle?: string
|
|
35
|
+
dataseries?: Array<{
|
|
36
|
+
label?: string
|
|
37
|
+
value?: string
|
|
38
|
+
stateMap?: {
|
|
39
|
+
on: string // Value(s) representing ON state
|
|
40
|
+
off: string // Value(s) representing OFF state
|
|
41
|
+
}
|
|
42
|
+
actionDevice?: string
|
|
43
|
+
actionApp?: string
|
|
44
|
+
actionTopic?: string
|
|
45
|
+
styling?: {
|
|
46
|
+
labelColor?: string
|
|
47
|
+
valueColor?: string
|
|
48
|
+
}
|
|
49
|
+
}>
|
|
38
50
|
}
|
|
39
51
|
```
|
|
40
52
|
|
|
41
|
-
##
|
|
53
|
+
## State Mapping
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
interface InputData {
|
|
45
|
-
settings: Settings
|
|
46
|
-
gaugeValue: number
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
```ts
|
|
50
|
-
interface Settings {
|
|
51
|
-
title: string,
|
|
52
|
-
subTitle: string,
|
|
53
|
-
minGauge: number,
|
|
54
|
-
maxGauge: number,
|
|
55
|
-
style: Style
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
```ts
|
|
59
|
-
interface Style {
|
|
60
|
-
needleColor: string,
|
|
61
|
-
sections: number,
|
|
62
|
-
backgroundColor: string[]
|
|
63
|
-
}
|
|
64
|
-
```
|
|
55
|
+
The `stateMap` configuration determines how values are interpreted as ON/OFF states:
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
The following options are available for styling the value graph.
|
|
68
|
-
The `sections` option splits the value area into by default three same sized sections. Therefore three different colors can be provided to the `backgroundColor` by default.
|
|
69
|
-
```
|
|
70
|
-
interface Style {
|
|
71
|
-
needleColor: string,
|
|
72
|
-
sections: number,
|
|
73
|
-
backgroundColor: string[]
|
|
74
|
-
}
|
|
75
|
-
```
|
|
57
|
+
**Exact values:**
|
|
76
58
|
|
|
77
|
-
|
|
59
|
+
```json
|
|
60
|
+
{ "on": "true, 1, active", "off": "false, 0, inactive" }
|
|
61
|
+
```
|
|
78
62
|
|
|
79
|
-
|
|
63
|
+
**Numeric comparisons:**
|
|
80
64
|
|
|
81
|
-
```
|
|
82
|
-
|
|
65
|
+
```json
|
|
66
|
+
{ "on": ">50", "off": "<=50" }
|
|
67
|
+
{ "on": ">=100", "off": "<100" }
|
|
83
68
|
```
|
|
84
69
|
|
|
85
|
-
|
|
70
|
+
Supported operators: `<`, `<=`, `>`, `>=`
|
|
86
71
|
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
## Action Events
|
|
73
|
+
|
|
74
|
+
When a switch is toggled, the widget dispatches an `action-submit` custom event:
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
element.addEventListener('action-submit', (e) => {
|
|
78
|
+
console.log(e.detail)
|
|
79
|
+
// {
|
|
80
|
+
// args: true/false, // New switch state
|
|
81
|
+
// actionApp: "...", // Target app
|
|
82
|
+
// actionDevice: "...", // Target device ID
|
|
83
|
+
// actionTopic: "...", // Action topic to call
|
|
84
|
+
// label: "..." // Switch label
|
|
85
|
+
// }
|
|
86
|
+
})
|
|
89
87
|
```
|
|
90
88
|
|
|
89
|
+
## Theming
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
The widget supports theming via CSS custom properties or the `theme` property:
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
**CSS Custom Properties:**
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
widget-switch-1.1.1 {
|
|
97
|
+
--re-text-color: #333;
|
|
98
|
+
--re-tile-background-color: #fff;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
**Theme Object:**
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
element.theme = {
|
|
106
|
+
theme_name: 'dark',
|
|
107
|
+
theme_object: {
|
|
108
|
+
backgroundColor: '#1a1a1a',
|
|
109
|
+
title: {
|
|
110
|
+
textStyle: { color: '#fff' },
|
|
111
|
+
subtextStyle: { color: '#aaa' }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
97
116
|
|
|
98
|
-
##
|
|
117
|
+
## Development
|
|
99
118
|
|
|
100
119
|
```bash
|
|
101
|
-
npm start
|
|
120
|
+
npm run start # Dev server at localhost:8000/demo/
|
|
121
|
+
npm run build # Production build to dist/
|
|
122
|
+
npm run types # Regenerate TypeScript types from schema
|
|
123
|
+
npm run release # Build, bump version, push to git with tag
|
|
102
124
|
```
|
|
103
125
|
|
|
104
|
-
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT
|