@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 CHANGED
@@ -1,104 +1,128 @@
1
- # \<widget-switch>
1
+ # widget-switch
2
2
 
3
- This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
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
+ ![screenshot](thumbnail.png)
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
- import 'widget-switch/widget-switch.js';
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
- ## Expected data format
22
-
23
- The following format represents the available data :
24
- ```js
25
- data: {
26
- settings: {
27
- title: string,
28
- subTitle: string,
29
- minGauge: number,
30
- maxGauge: number,
31
- style: {
32
- needleColor: string,
33
- sections: number,
34
- backgroundColor: string[]
35
- }
36
- }
37
- gaugeValue: Number
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
- ## Interfaces
53
+ ## State Mapping
42
54
 
43
- ```ts
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
- ## Style options
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
- ## Linting and formatting
59
+ ```json
60
+ { "on": "true, 1, active", "off": "false, 0, inactive" }
61
+ ```
78
62
 
79
- To scan the project for linting and formatting errors, run
63
+ **Numeric comparisons:**
80
64
 
81
- ```bash
82
- npm run lint
65
+ ```json
66
+ { "on": ">50", "off": "<=50" }
67
+ { "on": ">=100", "off": "<100" }
83
68
  ```
84
69
 
85
- To automatically fix linting and formatting errors, run
70
+ Supported operators: `<`, `<=`, `>`, `>=`
86
71
 
87
- ```bash
88
- npm run format
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
- ## Tooling configs
91
+ The widget supports theming via CSS custom properties or the `theme` property:
93
92
 
94
- For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
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
- If you customize the configuration a lot, you can consider moving them to individual files.
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
- ## Local Demo with `web-dev-server`
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
- To run a local development server that serves the basic demo located in `demo/index.html`
126
+ ## License
127
+
128
+ MIT