Skip to content

Commit 8d6fc80

Browse files
author
Marko Petzold
committed
use vite and externalize material
1 parent 550a126 commit 8d6fc80

10 files changed

Lines changed: 2218 additions & 8254 deletions

File tree

.github/workflows/build-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build and Publish to npm and unpkg
33
on:
44
push:
55
tags:
6-
- '*'
6+
- "*"
77

88
jobs:
99
build:
@@ -16,7 +16,7 @@ jobs:
1616
- name: Install Node.js
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: '18'
19+
node-version: "24"
2020

2121
- name: Install dependencies
2222
run: npm install --omit-dev --frozen-lockfile

README.md

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,100 @@
1-
# \<widget-form>
1+
# widget-form
22

3-
This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
3+
A Lit 3.x web component for creating dynamic forms with configurable fields. Part of the IronFlock widget ecosystem.
4+
5+
![screenshot](thumbnail.png)
46

57
## Installation
68

79
```bash
8-
npm i widget-form
10+
npm i @record-evolution/widget-form
911
```
1012

1113
## Usage
1214

1315
```html
1416
<script type="module">
15-
import 'widget-form/widget-form.js'
17+
import '@record-evolution/widget-form'
1618
</script>
1719

18-
<widget-form></widget-form>
20+
<widget-form-1.0.9></widget-form-1.0.9>
1921
```
2022

21-
## Expected data format
22-
23-
The following format represents the available data :
24-
25-
```js
26-
data: {
27-
settings: {
28-
title: string,
29-
subTitle: string,
30-
minGauge: number,
31-
maxGauge: number,
32-
style: {
33-
needleColor: string,
34-
sections: number,
35-
backgroundColor: string[]
36-
}
37-
}
38-
gaugeValue: Number
39-
}
40-
```
23+
> **Note:** The version number is part of the custom element tag name.
4124
42-
## Interfaces
25+
## Properties
4326

44-
```ts
45-
interface InputData {
46-
settings: Settings
47-
gaugeValue: number
48-
}
49-
```
27+
| Property | Type | Description |
28+
| ----------- | ----------- | ----------------------------- |
29+
| `inputData` | `InputData` | Form configuration and fields |
30+
| `theme` | `Theme` | Theme object for styling |
5031

51-
```ts
52-
interface Settings {
53-
title: string
54-
subTitle: string
55-
minGauge: number
56-
maxGauge: number
57-
style: Style
58-
}
59-
```
32+
## Events
6033

61-
```ts
62-
interface Style {
63-
needleColor: string
64-
sections: number
65-
backgroundColor: string[]
66-
}
67-
```
34+
| Event | Detail | Description |
35+
| ------------- | ----------------------------- | -------------------------------- |
36+
| `data-submit` | Array of field/value mappings | Fired when the form is submitted |
6837

69-
## Style options
38+
## Configuration
7039

71-
The following options are available for styling the value graph.
72-
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.
40+
The form is configured via the `inputData` property:
7341

74-
```
75-
interface Style {
76-
needleColor: string,
77-
sections: number,
78-
backgroundColor: string[]
79-
}
42+
```ts
43+
interface InputData {
44+
title?: string
45+
subTitle?: string
46+
formButton?: boolean // Show button to open form dialog
47+
formFields?: FormField[]
48+
}
8049
```
8150

82-
## Linting and formatting
51+
### Field Types
8352

84-
To scan the project for linting and formatting errors, run
53+
Each form field supports the following types:
8554

86-
```bash
87-
npm run lint
88-
```
55+
| Type | Description |
56+
| ------------- | ------------------------------ |
57+
| `textfield` | Single-line text input |
58+
| `numberfield` | Numeric input with min/max |
59+
| `checkbox` | Boolean checkbox |
60+
| `textarea` | Multi-line text input |
61+
| `dropdown` | Select from predefined options |
62+
| `datetime` | Date/time picker |
8963

90-
To automatically fix linting and formatting errors, run
64+
### Field Configuration
9165

92-
```bash
93-
npm run format
66+
```ts
67+
interface FormField {
68+
label: string
69+
type: 'dropdown' | 'textfield' | 'numberfield' | 'checkbox' | 'textarea' | 'datetime'
70+
hiddenField?: boolean // Hide field but still submit value
71+
required?: boolean // Field must be filled
72+
description?: string // Hint text shown below field
73+
targetColumn?: TargetColumn // Database column mapping
74+
defaultValue?: string
75+
min?: number // For numberfield
76+
max?: number // For numberfield
77+
validation?: string // Regex for textfield
78+
values?: DropdownValue[] // For dropdown type
79+
}
9480
```
9581

96-
## Tooling configs
82+
## Development
9783

98-
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
84+
```bash
85+
# Start dev server
86+
npm run start
9987

100-
If you customize the configuration a lot, you can consider moving them to individual files.
88+
# Build for production
89+
npm run build
10190

102-
## Local Demo with `web-dev-server`
91+
# Generate types from schema
92+
npm run types
10393

104-
```bash
105-
npm start
94+
# Build, bump version, and publish
95+
npm run release
10696
```
10797

108-
To run a local development server that serves the basic demo located in `demo/index.html`
98+
## License
99+
100+
MIT

demo/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
<script type="module">
5050
import { render } from 'lit'
5151
import { html, unsafeStatic } from 'lit/static-html.js'
52-
const packageJson = await fetch('../package.json').then((res) => res.json())
52+
import packageJson from '../package.json'
53+
import '../src/widget-form.js'
54+
import data from '../src/default-data.json'
55+
import themeObject from './themes/light.json'
56+
5357
const tag = unsafeStatic(`widget-form-${packageJson.version}`)
54-
import '../dist/widget-form.js'
55-
const data = await fetch('../src/default-data.json').then((res) => res.json())
56-
const themeObject = await fetch('themes/light.json').then((res) => res.json())
5758
const theme = { theme_name: 'light', theme_object: themeObject }
5859
render(
5960
html`

0 commit comments

Comments
 (0)