@ironflock/widget-toolbar 0.0.0-stage → 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/README.md CHANGED
@@ -1,3 +1,111 @@
1
- # Temporary Holding Version
1
+ # @ironflock/widget-toolbar
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A toolbar for IronFlock apps: buttons, switches, sliders, choice groups and dropdowns
4
+ in one bar on a board. Each tool writes its value into a table column, which the app's
5
+ backend receives as a new row when it subscribes to the table, and/or sets a URL
6
+ parameter that the other widgets on the page filter on. The tools show the stored or
7
+ current value, the bar runs horizontally or as a vertical strip, and tools that do not
8
+ fit the tile move into a ⋮ menu.
9
+
10
+ A [Lit](https://lit.dev) web component for [IronFlock](https://ironflock.com) boards.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm i @ironflock/widget-toolbar
16
+ ```
17
+
18
+ `lit` and `@material/web` are imported from the page: IronFlock Studio provides them
19
+ through its import map. The page also has to load the Roboto and Material Symbols
20
+ Outlined fonts, as Studio does.
21
+
22
+ ## Usage
23
+
24
+ The package version is part of the tag name (`widget-toolbar-<version>`), so several
25
+ versions can be registered on one page. Build the tag from the version of the package
26
+ you installed, as `demo/index.html` does from `package.json`, and set the config, the
27
+ theme and the route as properties:
28
+
29
+ ```js
30
+ import '@ironflock/widget-toolbar'
31
+ import pkg from '@ironflock/widget-toolbar/package.json' with { type: 'json' }
32
+
33
+ const widget = document.createElement(`widget-toolbar-${pkg.version}`)
34
+ widget.inputData = {
35
+ tools: [
36
+ { label: 'Live', control: 'switch', parameterKey: 'live' },
37
+ {
38
+ label: 'Period',
39
+ control: 'choice',
40
+ parameterKey: 'period',
41
+ options: [
42
+ { label: 'Day', value: 'day' },
43
+ { label: 'Week', value: 'week' }
44
+ ]
45
+ }
46
+ ]
47
+ }
48
+ widget.theme = { theme_name: 'light', theme_object: lightTheme }
49
+ widget.route = '/machines?period=day'
50
+ document.body.append(widget)
51
+ ```
52
+
53
+ ## The tools
54
+
55
+ | Tool | Shows | Writes |
56
+ | --- | --- | --- |
57
+ | `button` | a button, drawn active while its value is the current one | its Button Value on each click (`true` when empty; an empty value removes the URL parameter) |
58
+ | `switch` | an on/off switch | On Value / Off Value (default `true` / `false`; an empty Off Value removes the URL parameter) |
59
+ | `slider` | a slider with its value and unit | the number, when released |
60
+ | `choice` | the options side by side | the picked option's value |
61
+ | `dropdown` | the picked option, the others in a list | the picked option's value |
62
+ | `label`, `separator`, `spacer` | text, a line, free space | nothing |
63
+
64
+ Every interactive tool can:
65
+
66
+ - write into a column (`targetColumn`), with `extraColumns` and the toolbar's
67
+ `sharedColumns` (such as the record id) in the same row;
68
+ - set a URL parameter (`parameterKey`);
69
+ - or both.
70
+
71
+ To show what is stored, bind the tool's `value` to the latest value of the column it
72
+ writes; after a click the tool keeps the new value for up to 10 seconds until the
73
+ binding agrees. A tool with a URL parameter shows the parameter's value. `confirmText`
74
+ asks before writing. A tool is disabled while a key column has no value.
75
+
76
+ ## Events
77
+
78
+ The widget writes nothing itself. Studio handles two events:
79
+
80
+ | Event | `detail` |
81
+ | --- | --- |
82
+ | `data-submit` | `[{ swarm_app_databackend_key, table_name, column_name, value }]`: one item per column of the row; Studio groups them per table, adds `tsp` and publishes the row |
83
+ | `param-submit` | `{ params: { [key]: string \| undefined } }`: merged into the page URL; `undefined` removes the key |
84
+
85
+ ## inputData
86
+
87
+ `src/definition-schema.json` describes every field. The `ToolbarConfiguration` type in
88
+ `src/definition-schema.d.ts` is generated from it with `npm run types`.
89
+ `src/default-data.json` is a working example, and it is also the config a new board
90
+ tile starts with.
91
+
92
+ ## Theming
93
+
94
+ - `theme`: `{ theme_name, theme_object }`, an ECharts theme. `theme_object` can be
95
+ missing. Its first palette colour is the default accent.
96
+ - `--re-text-color`: when this CSS custom property is set on the widget or an
97
+ ancestor, it colours the text instead of the theme's title colour.
98
+ - `--re-tile-background-color` and `--re-background-color`: the menu and the
99
+ confirmation dialog are painted opaque in their combination.
100
+
101
+ The widget paints no background of its own, so the board's tile shows through.
102
+
103
+ ## Development
104
+
105
+ | Command | What it does |
106
+ | --- | --- |
107
+ | `npm start` | Dev server on port 8000 with the demo in `demo/index.html`, plus a watch build |
108
+ | `npm run build` | Type check, then the library build to `dist/widget-toolbar.js` |
109
+ | `npm test` | Unit tests of the tool logic and the layout |
110
+ | `npm run types` | Regenerate `src/definition-schema.d.ts` after editing `src/definition-schema.json` |
111
+ | `just release-patch` | A release pull request; its merge publishes to npm in CI and tags the version (`just merge`: a pull request that releases nothing) |