|
1 | 1 | # \<widget-table> |
2 | 2 |
|
3 | | -This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation. |
| 3 | +A Lit 3.x web component for rendering data tables with sortable columns, powered by Vaadin Grid. Part of the IronFlock widget ecosystem. |
| 4 | + |
| 5 | + |
4 | 6 |
|
5 | 7 | ## Installation |
6 | 8 |
|
7 | 9 | ```bash |
8 | | -npm i widget-table |
| 10 | +npm i @record-evolution/widget-table |
9 | 11 | ``` |
10 | 12 |
|
| 13 | +**Peer Dependencies:** This widget requires `@vaadin/grid` to be installed in your application. |
| 14 | + |
11 | 15 | ## Usage |
12 | 16 |
|
13 | 17 | ```html |
14 | 18 | <script type="module"> |
15 | | - import 'widget-table/widget-table.js'; |
| 19 | + import '@record-evolution/widget-table' |
16 | 20 | </script> |
17 | 21 |
|
18 | | -<widget-table></widget-table> |
| 22 | +<widget-table-1.2.0></widget-table-1.2.0> |
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 | +```javascript |
| 26 | +const table = document.querySelector('widget-table-1.2.0') |
| 27 | +table.inputData = { |
| 28 | + title: 'Device Status', |
| 29 | + subTitle: 'Current readings', |
| 30 | + columns: [ |
| 31 | + { |
| 32 | + header: 'Device', |
| 33 | + type: 'string', |
| 34 | + values: [{ value: 'Sensor A' }, { value: 'Sensor B' }] |
| 35 | + }, |
| 36 | + { |
| 37 | + header: 'Status', |
| 38 | + type: 'state', |
| 39 | + values: [{ value: 'ONLINE' }, { value: 'OFFLINE' }], |
| 40 | + styling: { stateMap: "'ONLINE': 'green', 'OFFLINE': 'red'" } |
| 41 | + }, |
| 42 | + { |
| 43 | + header: 'Temperature', |
| 44 | + type: 'number', |
| 45 | + values: [{ value: '23.456' }, { value: '18.912' }], |
| 46 | + styling: { precision: 1 } |
| 47 | + } |
| 48 | + ] |
38 | 49 | } |
39 | 50 | ``` |
40 | 51 |
|
41 | | -## Interfaces |
| 52 | +## InputData Interface |
42 | 53 |
|
43 | 54 | ```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 | +interface InputData { |
| 56 | + title?: string |
| 57 | + subTitle?: string |
| 58 | + horizontalOverflow?: boolean |
| 59 | + styling?: { |
| 60 | + headerFontSize?: string // e.g. '14px' |
| 61 | + cellPaddingHorizontal?: string // e.g. '16px' or '1rem' |
| 62 | + cellPaddingVertical?: string // e.g. '8px' or '1rem' |
| 63 | + } |
| 64 | + columns?: Column[] |
| 65 | +} |
65 | 66 |
|
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 | | - } |
| 67 | +interface Column { |
| 68 | + header: string |
| 69 | + type: 'string' | 'number' | 'boolean' | 'state' | 'button' | 'image' |
| 70 | + values: { value: string; link?: string }[] |
| 71 | + styling?: { |
| 72 | + precision?: number // Decimal places for number type |
| 73 | + stateMap?: string // e.g. "'ONLINE': 'green', 'OFFLINE': 'red'" |
| 74 | + width?: string // Column width e.g. '150px' |
| 75 | + fontSize?: string |
| 76 | + fontWeight?: string // e.g. '800' for bold |
| 77 | + color?: string // Font color |
| 78 | + border?: string // e.g. '1px solid red' |
| 79 | + } |
| 80 | +} |
75 | 81 | ``` |
76 | 82 |
|
77 | | -## Linting and formatting |
| 83 | +## Column Types |
78 | 84 |
|
79 | | -To scan the project for linting and formatting errors, run |
| 85 | +| Type | Description | |
| 86 | +| --------- | --------------------------------------------------- | |
| 87 | +| `string` | Plain text display | |
| 88 | +| `number` | Numeric value with optional precision formatting | |
| 89 | +| `boolean` | Boolean display | |
| 90 | +| `state` | Status indicator with colored dot based on stateMap | |
| 91 | +| `button` | Clickable button with optional link | |
| 92 | +| `image` | Image display with optional link | |
80 | 93 |
|
81 | | -```bash |
82 | | -npm run lint |
83 | | -``` |
| 94 | +## Features |
84 | 95 |
|
85 | | -To automatically fix linting and formatting errors, run |
| 96 | +- **Sortable columns**: Click headers to sort ascending/descending |
| 97 | +- **Resizable columns**: Drag column borders to resize |
| 98 | +- **Horizontal overflow**: Enable scrolling for wide tables |
| 99 | +- **Theme support**: Integrates with IronFlock theming system |
| 100 | +- **State indicators**: Visual status dots with customizable color mapping |
86 | 101 |
|
87 | | -```bash |
88 | | -npm run format |
89 | | -``` |
| 102 | +## Theming |
| 103 | + |
| 104 | +The widget respects CSS custom properties: |
90 | 105 |
|
| 106 | +- `--re-text-color`: Text color override |
| 107 | +- `--re-tile-background-color`: Background color override |
91 | 108 |
|
92 | | -## Tooling configs |
| 109 | +Pass a theme object for ECharts-style theming: |
93 | 110 |
|
94 | | -For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project. |
| 111 | +```javascript |
| 112 | +table.theme = { |
| 113 | + theme_name: 'dark', |
| 114 | + theme_object: { |
| 115 | + /* theme config */ |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
95 | 119 |
|
96 | | -If you customize the configuration a lot, you can consider moving them to individual files. |
| 120 | +## Development |
| 121 | + |
| 122 | +```bash |
| 123 | +npm run start # Dev server at localhost:8000/demo/ |
| 124 | +npm run build # Production build to dist/ |
| 125 | +npm run types # Regenerate types from schema |
| 126 | +npm run release # Build, bump version, git push & tag |
| 127 | +``` |
97 | 128 |
|
98 | | -## Local Demo with `web-dev-server` |
| 129 | +## Local Demo |
99 | 130 |
|
100 | 131 | ```bash |
101 | 132 | npm start |
102 | 133 | ``` |
103 | 134 |
|
104 | | -To run a local development server that serves the basic demo located in `demo/index.html` |
| 135 | +Serves the demo at `demo/index.html` with sample data. |
0 commit comments