semantic-forms 3.2.1 → 4.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
@@ -2,9 +2,22 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/semantic-forms.svg)](https://www.npmjs.com/package/semantic-forms)
4
4
 
5
- A pattern library of forms based on semantic HTML enhanced with a modern UX.
5
+ A pattern library of attractive forms for your website with the following design goals:
6
6
 
7
- See a [live demo here](https://kethinov.github.io/semanticforms/semanticForms.html).
7
+ - Attractive, modern float label visual design.
8
+ - Responsive layout based on modern CSS grid technique.
9
+ - Clear fields.
10
+ - Light and dark mode.
11
+ - Invalid field styling.
12
+ - Good accessibility.
13
+ - Semantic HTML (no div soup).
14
+ - Uses a progressive enhancement approach so that core functionality and most of the features still work with JavaScript disabled.
15
+ - Sets no global styles and is scoped by a single class name `semanticForms` applied to `<form>` elements.
16
+ - No dependencies.
17
+
18
+ See a [live demo here](https://rooseveltframework.github.io/semantic-forms/semanticForms.html).
19
+
20
+ This module was built and is maintained by the [Roosevelt web framework](https://github.com/rooseveltframework/roosevelt) [team](https://github.com/orgs/rooseveltframework/people), but it can be used independently of Roosevelt as well.
8
21
 
9
22
  # Usage
10
23
 
@@ -18,17 +31,21 @@ Then apply the `semanticForms` class to your `<form>` elements:
18
31
  </form>
19
32
  ```
20
33
 
34
+ Then apply the JavaScript enhancements:
35
+
36
+ ```javascript
37
+ window.semanticForms()
38
+ ```
39
+
21
40
  Then the CSS/JS enhancements to your forms will apply automatically, assuming the markup structure you use is one of the supported patterns.
22
41
 
23
- This library also monitors changes to the DOM and will enhance any additional `semanticForms` forms you insert, but the monitoring may not be perfect. If you want to re-scan for new forms to enhance manually, simply call `window.semanticForms()`. If you only want to reinitialize one form instead of all of them, call `window.semanticForms.reinitialize(formName)`.
42
+ If you make changes to the DOM after Semantic Forms is activated and want to activate any additional `semanticForms` forms you insert, you can re-scan for new forms by calling `window.semanticForms()` again. If you only want to reinitialize one form instead of all of them, call `window.semanticForms.reinitialize(formElement)`.
24
43
 
25
44
  # Features
26
45
 
27
- Overview of pattern library features:
28
-
29
46
  ## Float label inputs
30
47
 
31
- The float label input pattern is notoriously difficult to implement in a fashion that doesn't degrade HTML semantics or accessibility. This pattern library implements a solution that solves that problem. Your label doesn't need to be a sibling of your input like with other implementations. This implementation also has a custom clear field driven by SVG embedded in the CSS.
48
+ The float label input pattern is notoriously difficult to implement in a fashion that doesn't degrade HTML semantics or accessibility. This pattern library implements a solution that solves that problem. Your label doesn't need to be a sibling of your input like with other implementations. This implementation also has a custom clear button for each input.
32
49
 
33
50
  ### Example
34
51
 
@@ -52,25 +69,141 @@ The float label input pattern is notoriously difficult to implement in a fashion
52
69
  </form>
53
70
  ```
54
71
 
55
- If you would like to manipulate the size of the area on the input field reserved for the click event of the clear field, apply one or both of the following `data-` attributes to your form:
72
+ ### Add help text
56
73
 
57
- Adjust the horizontal offset of the clear field's click event click area (the default is 21):
74
+ Include a label in the `<dd>` element with a matching `for` attribute to place help text beneath the input:
58
75
 
59
76
  ```html
60
- <form class="semanticForms" data-clearfield-horizontal-offset="21">
61
- <!-- your form here -->
77
+ <form class="semanticForms">
78
+ <dl>
79
+ <dt><label for="password">Password</label></dt>
80
+ <dd>
81
+ <input id="password" name="password" type="password" placeholder="Enter a password" minlength="8" required>
82
+ <label for="password">Must be at least 8 characters long.</label>
83
+ </dd>
84
+ </dl>
62
85
  </form>
63
86
  ```
64
87
 
65
- Adjust the vertical offset of the clear field's click event click area (the default is 5):
88
+ ## Responsive columns
89
+
90
+ This feature makes it so the form fields will grow, shrink, expand the number of columns, or reduce the number of columns based on how much space exists in the container. You can customize it by applying various `colspan-#` classes to various elements in the form markup structure.
91
+
92
+ ### Set number of columns for a group of forms
93
+
94
+ You can limit the number of columns on your forms using the `colspan-#` class on a `<dl>` element:
66
95
 
67
96
  ```html
68
- <form class="semanticForms" data-clearfield-vertical-offset="5">
69
- <!-- your form here -->
97
+ <form class="semanticForms">
98
+ <dl class="colspan-2">
99
+ <dt><label for="input-a">Input A</label></dt>
100
+ <dd><input type="text" id="input-a" name="input-a"></dd>
101
+
102
+ <dt><label for="input-b">Input B</label></dt>
103
+ <dd><input type="text" id="input-b" name="input-b"></dd>
104
+
105
+ <!-- wraps to the next row -->
106
+ <dt><label for="input-c">Input C</label></dt>
107
+ <dd><input type="text" id="input-c" name="input-c"></dd>
108
+ </dl>
109
+ </form>
110
+ ```
111
+
112
+ You can also apply the class to a `<fieldset>` which will apply that styling to all nested `<dl>` elements:
113
+
114
+ ```html
115
+ <form class="semanticForms">
116
+ <fieldset class="colspan-3">
117
+ <!-- inherits 3 column class -->
118
+ <dl>
119
+ <dt><label for="input-a">Input A</label></dt>
120
+ <dd><input type="text" id="input-a" name="input-a"></dd>
121
+
122
+ <dt><label for="input-b">Input B</label></dt>
123
+ <dd><input type="text" id="input-b" name="input-b"></dd>
124
+
125
+ <dt><label for="input-c">Input C</label></dt>
126
+ <dd><input type="text" id="input-c" name="input-c"></dd>
127
+ </dl>
128
+
129
+ <!-- has 4 columns -->
130
+ <dl class="colspan-4">
131
+ <dt><label for="input-d">Input D</label></dt>
132
+ <dd><input type="text" id="input-d" name="input-d"></dd>
133
+
134
+ <dt><label for="input-e">Input E</label></dt>
135
+ <dd><input type="text" id="input-e" name="input-e"></dd>
136
+
137
+ <dt><label for="input-f">Input F</label></dt>
138
+ <dd><input type="text" id="input-f" name="input-f"></dd>
139
+ </dl>
140
+ </fieldset>
141
+ </form>
142
+ ```
143
+
144
+ ### Set number of columns a single input field takes up
145
+ You can specify the number of columns an input will span using the `colspan-#` class on the `<dd>` element. The inputs are responsive and will shrink according to available space. Available numbered classes are `colspan-1` through `colspan-5`:
146
+
147
+
148
+ ```html
149
+ <form class="semanticForms">
150
+ <fieldset>
151
+ <dl>
152
+ <dt><label for="input-a">Input A</label></dt>
153
+ <!-- 1 column -->
154
+ <dd class="colspan-1"><input type="text" id="input-a" name="input-a"></dd>
155
+
156
+ <dt><label for="input-b">Input B</label></dt>
157
+ <!-- 2 columns -->
158
+ <dd class="colspan-2"><input type="text" id="input-b" name="input-b"></dd>
159
+
160
+ <dt><label for="input-c">Input C</label></dt>
161
+ <!-- 5 columns (max) -->
162
+ <dd class="colspan-5"><input type="text" id="input-c" name="input-c"></dd>
163
+ </dl>
164
+ </fieldset>
165
+ </form>
166
+ ```
167
+
168
+ `colspan-full` can also be used to force an input to take up the entire width of a form:
169
+
170
+ ```html
171
+ <form class="semanticForms">
172
+ <fieldset>
173
+ <dl>
174
+ <dt><label for="input-a">Input A</label></dt>
175
+ <!-- this spans 2 columns on row 1 -->
176
+ <dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>
177
+
178
+ <dt><label for="input-b">Input B</label></dt>
179
+ <!-- this spans the full width of row 2 -->
180
+ <dd class="colspan-full"><input type="text" id="input-b" name="input-b"></dd>
181
+
182
+ <!-- this spans 1 column on row 3 -->
183
+ <dt><label for="input-c">Input C</label></dt>
184
+ <dd><input type="text" id="input-c" name="input-c"></dd>
185
+ </dl>
186
+ </fieldset>
70
187
  </form>
71
188
  ```
72
189
 
73
- If you want to double the width of the input field (on screens with the extra space), add a `x2` class to the `dd` element.
190
+ #### Set number of columns a single input field takes up on the low flow (JavaScript disabled flow)
191
+
192
+ To apply `colspan-#` styles to low flow (JavaScript disabled flow) form inputs, you will need to manually wrap your `<dt>` and `<dd>` elements in a `<div>`:
193
+
194
+ ```html
195
+ <form class="semanticForms">
196
+ <fieldset>
197
+ <dl>
198
+ <div>
199
+ <dt><label for="input-a">Input A</label></dt>
200
+ <!-- this spans 2 columns on row 1 -->
201
+ <dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>
202
+ </div>
203
+ </dl>
204
+ </fieldset>
205
+ </form>
206
+ ```
74
207
 
75
208
  ## Button groups
76
209
 
@@ -154,21 +287,62 @@ Not too different than other inputs:
154
287
  </form>
155
288
  ```
156
289
 
157
- ## Other features
290
+ ## Validation styles
291
+
292
+ Inputs with the `required` attribute will result in a visual indicator (*) being added to its label. You can disable this indicator with the `data-no-asterisk` attribute on the label element:
293
+
294
+ ```html
295
+ <form class="semanticForms">
296
+ <dl>
297
+ <dt><label for="input" data-no-asterisk>Input label</label></dt>
298
+ <dd><input type="text" name="input" id="input" required>
299
+ </dl>
300
+ </form>
301
+ ```
302
+
303
+ You can set a paragraph of text below a field to only appear when a field is invalid with the `data-invalid-text` attribute:
304
+
305
+ ```html
306
+ <form class="semanticForms">
307
+ <dl>
308
+ <dt><label for="password">Password label</label><dt>
309
+ <dd>
310
+ <input type="password" name="password" id="password" minlength="8">
311
+ <p data-invalid-text>Password must be at least 8 characters long.</p>
312
+ </dd>
313
+ </dl>
314
+ </form>
315
+ ```
316
+
317
+ You can adjust the tooltip text of the asterisk with the `data-asterisk-text` attribute:
318
+
319
+ ```html
320
+ <form class="semanticForms">
321
+ <dl>
322
+ <dt><label for="input" data-asterisk-text="This is a custom tooltip.">Input label</label></dt>
323
+ <dd><input type="text" name="input" id="input" required>
324
+ </dl>
325
+ </form>
326
+ ```
327
+ ## Dark mode
328
+
329
+ To set the dark mode, apply an additional class of `dark` to your `<form>` elements to force the dark mode.
330
+
331
+ ## Low flow (JavaScript disabled) mode
332
+
333
+ The low flow will be displayed if JS is disabled.
158
334
 
159
- - Custom-styled select boxes with a custom drawn arrow graphic driven by SVG embedded in the CSS.
160
- - Custom-styled submit buttons to match the aesthetic of the custom-styled forms.
161
- - Responsive: on wide screens, the forms split into multiple columns. On smaller screens, they collapse to a single column.
162
- - Dark mode: apply an additional class of `dark` to your `<form>` elements to use the dark mode.
163
- - Low-flow mode that displays on old browsers, JS-disabled browsers, or can be activated manually by adding the `lowFlow` class to your `<form>` element. The low-flow mode reverts the float label pattern to traditional labels and collapses the forms to single column mode, but preserves the other visual design enhancements driven purely by CSS.
335
+ You can also activate the low flow (JavaScript disabled) mode manually by adding the `lowFlow` class to your `<form>` element.
164
336
 
165
- See `semanticForms.html` or the [live demo](https://kethinov.github.io/semanticforms/semanticForms.html) for a full demo of all the markup patterns.
337
+ The low-flow mode reverts the float label pattern to traditional labels and doesn't include other JS-exclusive enhancements, but preserves the other visual design enhancements driven purely by CSS.
166
338
 
167
339
  # Contributing
168
340
 
169
341
  - Fork/clone this repo.
170
342
  - `npm ci`
171
- - Make your changes. If you want to alter the CSS, do the changes in the `.less` files.
172
- - `npm run build`. The build step compiles the LESS file into CSS.
343
+ - Make your changes. If you want to alter the CSS, do the changes in the `.scss` files.
344
+ - `npm run build`. The build step compiles the SCSS file into CSS.
345
+ - You can also run `npm run watch` automatically compiles the CSS file after a change is detected in the SCSS file.
173
346
  - Test your changes by opening `semanticForms.html` in your browser.
347
+ - If you want to test your work on an actual HTTP server, run `npm run dev` or `npm run d`.
174
348
  - Commit, push, open pull request.
package/package.json CHANGED
@@ -1,34 +1,45 @@
1
1
  {
2
2
  "name": "semantic-forms",
3
3
  "description": "Semantic Forms",
4
- "author": "Eric Newport <kethinov@gmail.com>",
5
- "version": "3.2.1",
4
+ "author": "Roosevelt Framework Team <rooseveltframework@gmail.com>",
5
+ "contributors": [
6
+ {
7
+ "name": "Contributors",
8
+ "url": "https://github.com/rooseveltframework/semantic-forms/graphs/contributors"
9
+ }
10
+ ],
11
+ "version": "4.0.1",
6
12
  "files": [
7
13
  "semanticForms.css",
8
14
  "semanticForms.js",
9
- "semanticForms.less"
15
+ "semanticForms.scss"
10
16
  ],
11
- "homepage": "https://github.com/kethinov/semanticforms",
17
+ "homepage": "https://github.com/rooseveltframework/semantic-forms",
12
18
  "license": "CC-BY-4.0",
13
19
  "main": "semanticForms.js",
14
20
  "readmeFilename": "README.md",
15
- "dependencies": {},
16
21
  "devDependencies": {
17
- "less": "4.2.0",
18
- "eslint": "9.5.0",
22
+ "eslint": "9.10.0",
19
23
  "eslint-plugin-html": "8.1.1",
20
- "standard": "17.1.0"
24
+ "nodemon": "3.1.4",
25
+ "sass": "1.78.0",
26
+ "serve": "14.2.3",
27
+ "standard": "17.1.2"
21
28
  },
22
29
  "scripts": {
23
30
  "test": "echo \"TODO: tests\"",
24
31
  "coverage": "echo \"TODO: test coverage\"",
25
32
  "lint": "standard && standard --plugin html *.html",
26
33
  "lint-fix": "standard --fix && standard --plugin html *.html --fix",
27
- "build": "lessc semanticForms.less semanticForms.css"
34
+ "d": "nodemon --exec \"npm run build && serve\"",
35
+ "dev": "nodemon --exec \"npm run build && serve\"",
36
+ "development": "nodemon --exec \"npm run build && serve\"",
37
+ "build": "sass semanticForms.scss semanticForms.css",
38
+ "watch": "sass --watch semanticForms.scss semanticForms.css"
28
39
  },
29
40
  "repository": {
30
41
  "type": "git",
31
- "url": "git://github.com/kethinov/semanticforms.git"
42
+ "url": "git://github.com/rooseveltframework/semantic-forms.git"
32
43
  },
33
44
  "keywords": [
34
45
  "semantic",
@@ -36,8 +47,5 @@
36
47
  "float",
37
48
  "label"
38
49
  ],
39
- "funding": {
40
- "type": "individual",
41
- "url": "https://github.com/sponsors/kethinov"
42
- }
50
+ "funding": "https://www.paypal.com/donate/?hosted_button_id=2L2X8GRXZCGJ6"
43
51
  }