Skip to content

Commit

Permalink
add icons for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Sep 26, 2023
1 parent 9c78bbe commit 892869f
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 23 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ LOCAL := $(PWD)/.local
export PATH := $(LOCAL)/bin:$(PATH)
export GOBIN := $(LOCAL)/bin

MDIVERSION := 7.2.96
LINTER := $(GOBIN)/golangci-lint
GORELEASER := $(GOBIN)/goreleaser

Expand All @@ -15,6 +16,23 @@ lint: $(LINTER)
$(LINTER) run
.PHONY: lint

# it will not download heavy eot and ttf
update-assets:
mkdir -p internal/assets/static/css
mkdir -p internal/assets/static/fonts
curl -L -f -o internal/assets/static/css/materialdesignicons.min.css "https://cdn.jsdelivr.net/npm/@mdi/font@$(MDIVERSION)/css/materialdesignicons.min.css"
cd internal/assets/static/css && cat materialdesignicons.min.css | \
tr -s ';{},' '\n' | \
grep url | \
sed -rn 's|.*?url\("([^"]+?)".*|\1|p' | \
grep -v '#' | \
grep -v '.eot' | \
grep -v '.ttf' | \
cut -d '?' -f 1 | \
xargs -I{} curl -L -f -o {} "https://cdn.jsdelivr.net/npm/@mdi/font@$(MDIVERSION)/css/{}"
.PHONY: update-assets


snapshot: $(GORELEASER)
$(GORELEASER) release --snapshot --clean
docker tag ghcr.io/reddec/$(notdir $(CURDIR)):$$(jq -r .version dist/metadata.json)-amd64 ghcr.io/reddec/$(notdir $(CURDIR)):latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ that any changes made are shared with the community. This promotes collaboration

Read docs for details: https://web-form.reddec.net/

![Screenshot 2023-09-24 211012](https://github.com/reddec/web-form/assets/6597086/605400e1-c660-4c95-a59a-ba20ab70d1ed)
![image](https://github.com/reddec/web-form/assets/6597086/b4dce0e1-30cf-492d-96a4-dbcc98eb787d)

## Installation

Expand Down
34 changes: 18 additions & 16 deletions docs/fields.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Fields

<!-- {% raw %} -->

Only field `name` is required for the field.
Expand All @@ -7,20 +8,21 @@ For all fields text values will be trimmed from leading and trailing white space

Configurations:

| Name | Type | Default | Description |
|---------------|---------------------|----------|---------------------------------------------------------------------|
| *`name`* | string | | column name in database and unique identifier of the field |
| `label` | string | `.name` | name of field if UI |
| `description` | string | | short description for the field, will be shown in UI as hint |
| `required` | boolean | false | is field required |
| `disabled` | boolean | false | is user allowed to edit field |
| `hidden` | boolean | false | do not show field in UI. Implicitly disables field |
| `default` | string | | default value for the field. Supports [template](template.md) |
| `type` | [type](#types) | `string` | field type |
| `pattern` | string | | validate user input by regular expression (only for `string` types) |
| `options` | [][Option](#option) | | enum of allowed values |
| `multiple` | boolean | false | allow multiple options |
| `multiline` | boolean | false | tell UI to show multi-line input. Has no effect for backend |
| Name | Type | Default | Description |
|---------------|---------------------|----------|--------------------------------------------------------------------------------------------|
| *`name`* | string | | column name in database and unique identifier of the field |
| `label` | string | `.name` | name of field if UI |
| `description` | string | | short description for the field, will be shown in UI as hint |
| `required` | boolean | false | is field required |
| `disabled` | boolean | false | is user allowed to edit field |
| `hidden` | boolean | false | do not show field in UI. Implicitly disables field |
| `default` | string | | default value for the field. Supports [template](template.md) |
| `type` | [type](#types) | `string` | field type |
| `pattern` | string | | validate user input by regular expression (only for `string` types) |
| `options` | [][Option](#option) | | enum of allowed values |
| `multiple` | boolean | false | allow multiple options |
| `multiline` | boolean | false | tell UI to show multi-line input. Has no effect for backend |
| `icon` | string | | (0.2.0+) icon name, currently supported only [MDI](https://pictogrammers.com/library/mdi/) |

Notes:

Expand All @@ -31,13 +33,13 @@ Notes:
- with `multiple: true` it acts as "any of" (multiple choice)
- otherwise it acts "one of" (single pick)
- if `multiple` is true, depending on [storage](stores.md), information will be stored as array or as plain string
- `icon` should contain type (`mdi`) and icon name. For example: `mdi mdi-cake`

The system has minimal trust to user input therefore:

- `hidden` or `disabled` fields are ignored even if it was provided in POST request
- `type` and `pattern` verification will be additionally checked on backend side


**Examples**

```yaml
Expand All @@ -53,6 +55,7 @@ The system has minimal trust to user input therefore:
default: '{{now | date "2006-01-02"}}'
description: We will give you a discount
type: date
icon: "mdi mdi-cake"

- name: client_id
label: Customer
Expand Down Expand Up @@ -87,7 +90,6 @@ The system has minimal trust to user input therefore:
description: Please use real phone number - we will contact you
```


## Types

| Type | Format | Example |
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ be http://localhost:8080/forms/order-pizza).
Once submitted - check `data` directory. It will contain your result. Of course, the main power comes with
proper [configuration](configuration.md).

![Screenshot 2023-09-24 211012](https://github.com/reddec/web-form/assets/6597086/605400e1-c660-4c95-a59a-ba20ab70d1ed)
![image](https://github.com/reddec/web-form/assets/6597086/b4dce0e1-30cf-492d-96a4-dbcc98eb787d)

## Examples

Expand Down
2 changes: 1 addition & 1 deletion examples/assets/img/semweb.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion examples/configs/shop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ fields:
default: '{{now | date "2006-01-02T15:04"}}'
required: true
type: date-time

icon: "mdi mdi-calendar-range"

- name: birthday
label: Your birthday
default: '{{now | date "2006-01-02"}}'
description: We will give you a discount
type: date
icon: "mdi mdi-cake"

- name: client_id
label: Customer
default: '{{.User}}' # from OIDC
required: true
disabled: true
icon: "mdi mdi-account"

- name: dough
label: Dough kind
default: "thin"
icon: "mdi mdi-bread-slice"
options:
- label: Hand made
value: hand-made
Expand All @@ -43,6 +46,7 @@ fields:
label: Pick cheese
required: true
multiple: true
icon: mdi mdi-cheese
options:
- label: Italian Mozzarella
value: mozzarella
Expand All @@ -54,17 +58,20 @@ fields:
- name: phone
label: Phone number
required: true
icon: mdi mdi-phone-dial
description: Please use real phone number - we will contact you

- name: email
label: EMail
pattern: '[^@]+@[^@]+'
default: "{{.Email}}" # from OIDC
required: true
icon: mdi mdi-email

- name: notify_sms
label: Notify by SMS
type: boolean
icon: mdi mdi-message-alert

- name: zip
label: ZIP code
Expand All @@ -75,6 +82,7 @@ fields:
label: Full address
required: true
multiline: true
icon: mdi mdi-map-marker

success: |
## Thank you!
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions internal/assets/static/css/materialdesignicons.min.css

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion internal/assets/views/form.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{or .Form.Title .Form.Name .Form.Table}}</title>
<link rel="stylesheet" href="../static/bulma.min.css">
<link rel="stylesheet" href="../static/css/bulma.min.css">
</head>
<body>

Expand All @@ -90,6 +90,11 @@
{{- if not $field.Hidden}}
<div class="field">
<label class="label">
{{- if $field.Icon}}
<span class="icon is-left">
<i class="{{$field.Icon}}"></i>
</span>
{{- end}}
{{or $field.Label $field.Name}}
{{- if $field.Required}}
<sup title="required field" class="has-text-danger">*</sup>
Expand Down Expand Up @@ -127,4 +132,5 @@
</form>
</div>
</body>
<link rel="stylesheet" href="../static/css/materialdesignicons.min.css">
</html>
3 changes: 2 additions & 1 deletion internal/assets/views/list.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>All forms</title>
<link rel="stylesheet" href="static/bulma.min.css">
<link rel="stylesheet" href="static/css/bulma.min.css">
</head>
<body>
<section class="section">
Expand All @@ -30,4 +30,5 @@
</div>
</section>
</body>
<link rel="stylesheet" href="static/css/materialdesignicons.min.css">
</html>
3 changes: 2 additions & 1 deletion internal/assets/views/result.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{or .Form.Title .Form.Name .Form.Table}}</title>
<link rel="stylesheet" href="../static/bulma.min.css">
<link rel="stylesheet" href="../static/css/bulma.min.css">
</head>
<body>
<section class="section">
Expand All @@ -24,4 +24,5 @@
</div>
</section>
</body>
<link rel="stylesheet" href="../static/css/materialdesignicons.min.css">
</html>
1 change: 1 addition & 0 deletions internal/schema/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Field struct {
Options []Option // allowed values. If [Field.Multiple] set, it acts as "any of", otherwise "one of".
Multiple bool // allow picking multiple options. Column type in database MUST be ARRAY of corresponding type.
Multiline bool // multiline input (for [TypeString] only)
Icon string // optional MDI icon
}

type Webhook struct {
Expand Down

0 comments on commit 892869f

Please sign in to comment.