semantic-forms 5.0.5 → 5.0.7

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,379 +1 @@
1
- # Semantic Forms
2
-
3
- [![Build Status](https://github.com/rooseveltframework/semantic-forms/workflows/CI/badge.svg
4
- )](https://github.com/rooseveltframework/semantic-forms/actions?query=workflow%3ACI) [![npm](https://img.shields.io/npm/v/semantic-forms.svg)](https://www.npmjs.com/package/semantic-forms)
5
-
6
- A pattern library of attractive forms for your website with the following design goals:
7
-
8
- - Attractive, modern float label visual design.
9
- - Responsive layout based on modern CSS grid technique.
10
- - Clear fields.
11
- - Light and dark mode.
12
- - Invalid field styling.
13
- - Good accessibility.
14
- - Semantic HTML (no div soup).
15
- - Uses a progressive enhancement approach so that core functionality and most of the features still work with JavaScript disabled.
16
- - Sets no global styles and is scoped by a single class name `semanticForms` applied to `<form>` elements.
17
- - No dependencies.
18
-
19
- See a [live demo here](https://rooseveltframework.github.io/semantic-forms/test/semanticForms.html).
20
-
21
- 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.
22
-
23
- ## Install
24
-
25
- `npm install semantic-forms`
26
-
27
- The package is distributed with the following builds available:
28
-
29
- - `dist/semantic-forms.cjs`: CommonJS bundle: `const semanticForms = require('semantic-forms')`
30
- - `dist/semantic-forms.js`: Standalone bundle that can be included via `<script>` tags. Declares a global variable called: `semanticForms`
31
- - `dist/semantic-forms.min.js`: Minified standalone bundle that can be included via `<script>` tags. Declares a global variable called: `semanticForms`
32
- - `dist/semantic-forms.mjs`: ES module: `import semanticForms from 'semantic-forms'`
33
- - `dist/semantic-forms.min.mjs`: Minified ES module: `import semanticForms from 'semantic-forms/min'`
34
-
35
- ## Usage
36
-
37
- Include the `dist/semantic-forms.css` and whichever of the above versions of the JS file you prefer from this repo into your project.
38
-
39
- Then apply the `semanticForms` class to your `<form>` elements:
40
-
41
- ```html
42
- <form class="semanticForms">
43
- <!-- your form here -->
44
- </form>
45
- ```
46
-
47
- Then apply the JavaScript enhancements:
48
-
49
- ```javascript
50
- semanticForms()
51
- ```
52
-
53
- Then the CSS/JS enhancements to your forms will apply automatically, assuming the markup structure you use is one of the supported patterns.
54
-
55
- 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 `semanticForms.reinitialize()` again. If you only want to reinitialize one form instead of all of them, call `semanticForms.reinitialize(formElement)`.
56
-
57
- ## Features
58
-
59
- ### Float label inputs
60
-
61
- 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.
62
-
63
- #### Example
64
-
65
- ```html
66
- <form class="semanticForms">
67
- <dl>
68
- <dt><label for="name">Name</label></dt>
69
- <dd><input id="name" name="name" type="text" placeholder="e.g. John Smith"></dd>
70
- </dl>
71
- </form>
72
- ```
73
-
74
- #### Or with a `<textarea>`
75
-
76
- ```html
77
- <form class="semanticForms">
78
- <dl>
79
- <dt><label for="textarea">Textarea</label></dt>
80
- <dd><textarea id="textarea" name="textarea" rows="5" cols="50" placeholder="e.g. Long string of text"></textarea></dd>
81
- </dl>
82
- </form>
83
- ```
84
-
85
- #### Add help text
86
-
87
- Include a label in the `<dd>` element with a matching `for` attribute to place help text beneath the input:
88
-
89
- ```html
90
- <form class="semanticForms">
91
- <dl>
92
- <dt><label for="password">Password</label></dt>
93
- <dd>
94
- <input id="password" name="password" type="password" placeholder="Enter a password" minlength="8" required>
95
- <label for="password">Must be at least 8 characters long.</label>
96
- </dd>
97
- </dl>
98
- </form>
99
- ```
100
-
101
- #### Customizing input fields
102
-
103
- By default, input fields will display an X icon to clear the text and password fields will also display a show/hide toggle for displaying the password in plain text. You can customize this behavior as follows:
104
-
105
- - Customize the hover text of the clear field button by applying a `data-clear-field-text="your text"` attribute to the input.
106
-
107
- - Customize the hover text of the show password button by applying a `data-show-password-text="your text"` attribute to the input.
108
-
109
- - Customize the hover text of the hide password button by applying a `data-hide-password-text="your text"` attribute to the input.
110
-
111
- - Prevent the show/hide toggle from appearing on password fields by applying a `data-no-reveal` attribute to the input.
112
-
113
- - Show a help text icon next to labels of inputs that contain a `title` attribute by applying a `data-show-help-icon` attribute to the label.
114
-
115
- - Note that checkboxes and radios should have a `title` attribute on the label instead of the inputs.
116
-
117
- ### Responsive columns
118
-
119
- 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.
120
-
121
- #### Set number of columns for a group of forms
122
-
123
- You can limit the number of columns on your forms using the `colspan-#` class on a `<dl>` element:
124
-
125
- ```html
126
- <form class="semanticForms">
127
- <dl class="colspan-2">
128
- <dt><label for="input-a">Input A</label></dt>
129
- <dd><input type="text" id="input-a" name="input-a"></dd>
130
-
131
- <dt><label for="input-b">Input B</label></dt>
132
- <dd><input type="text" id="input-b" name="input-b"></dd>
133
-
134
- <!-- wraps to the next row -->
135
- <dt><label for="input-c">Input C</label></dt>
136
- <dd><input type="text" id="input-c" name="input-c"></dd>
137
- </dl>
138
- </form>
139
- ```
140
-
141
- You can also apply the class to a `<fieldset>` which will apply that styling to all nested `<dl>` elements:
142
-
143
- ```html
144
- <form class="semanticForms">
145
- <fieldset class="colspan-3">
146
- <!-- inherits 3 column class -->
147
- <dl>
148
- <dt><label for="input-a">Input A</label></dt>
149
- <dd><input type="text" id="input-a" name="input-a"></dd>
150
-
151
- <dt><label for="input-b">Input B</label></dt>
152
- <dd><input type="text" id="input-b" name="input-b"></dd>
153
-
154
- <dt><label for="input-c">Input C</label></dt>
155
- <dd><input type="text" id="input-c" name="input-c"></dd>
156
- </dl>
157
-
158
- <!-- has 4 columns -->
159
- <dl class="colspan-4">
160
- <dt><label for="input-d">Input D</label></dt>
161
- <dd><input type="text" id="input-d" name="input-d"></dd>
162
-
163
- <dt><label for="input-e">Input E</label></dt>
164
- <dd><input type="text" id="input-e" name="input-e"></dd>
165
-
166
- <dt><label for="input-f">Input F</label></dt>
167
- <dd><input type="text" id="input-f" name="input-f"></dd>
168
- </dl>
169
- </fieldset>
170
- </form>
171
- ```
172
-
173
- #### Set number of columns a single input field takes up
174
-
175
- 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`:
176
-
177
- ```html
178
- <form class="semanticForms">
179
- <fieldset>
180
- <dl>
181
- <dt><label for="input-a">Input A</label></dt>
182
- <!-- 1 column -->
183
- <dd class="colspan-1"><input type="text" id="input-a" name="input-a"></dd>
184
-
185
- <dt><label for="input-b">Input B</label></dt>
186
- <!-- 2 columns -->
187
- <dd class="colspan-2"><input type="text" id="input-b" name="input-b"></dd>
188
-
189
- <dt><label for="input-c">Input C</label></dt>
190
- <!-- 5 columns (max) -->
191
- <dd class="colspan-5"><input type="text" id="input-c" name="input-c"></dd>
192
- </dl>
193
- </fieldset>
194
- </form>
195
- ```
196
-
197
- `colspan-full` can also be used to force an input to take up the entire width of a form:
198
-
199
- ```html
200
- <form class="semanticForms">
201
- <fieldset>
202
- <dl>
203
- <dt><label for="input-a">Input A</label></dt>
204
- <!-- this spans 2 columns on row 1 -->
205
- <dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>
206
-
207
- <dt><label for="input-b">Input B</label></dt>
208
- <!-- this spans the full width of row 2 -->
209
- <dd class="colspan-full"><input type="text" id="input-b" name="input-b"></dd>
210
-
211
- <!-- this spans 1 column on row 3 -->
212
- <dt><label for="input-c">Input C</label></dt>
213
- <dd><input type="text" id="input-c" name="input-c"></dd>
214
- </dl>
215
- </fieldset>
216
- </form>
217
- ```
218
-
219
- ##### Set number of columns a single input field takes up on the low flow (JavaScript disabled flow)
220
-
221
- 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>`:
222
-
223
- ```html
224
- <form class="semanticForms">
225
- <fieldset>
226
- <dl>
227
- <div>
228
- <dt><label for="input-a">Input A</label></dt>
229
- <!-- this spans 2 columns on row 1 -->
230
- <dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>
231
- </div>
232
- </dl>
233
- </fieldset>
234
- </form>
235
- ```
236
-
237
- ### Button groups
238
-
239
- You can align buttons side-by-side, or in left/right/center groups.
240
-
241
- #### Non-grouped example
242
-
243
- Nothing fancy here:
244
-
245
- ```html
246
- <button type="submit" name="submit">Non-grouped submit button</button>
247
- <button type="submit" name="submit">Another one</button>
248
- ```
249
-
250
- #### Button groups
251
-
252
- Driven by flexbox to intelligently align the buttons based on how many are in the group:
253
-
254
- ```html
255
- <!-- aligns left/right -->
256
- <menu>
257
- <li><button type="submit" name="submit">Button 1</button></li>
258
- <li><button type="submit" name="submit">Button 2</button></li>
259
- </menu>
260
-
261
- <!-- aligns left/center/right -->
262
- <menu>
263
- <li><button type="submit" name="submit">Button 1</button></li>
264
- <li><button type="submit" name="submit">Button 2</button></li>
265
- <li><button type="submit" name="submit">Button 3</button></li>
266
- </menu>
267
- ```
268
-
269
- ### Checkboxes and radio buttons
270
-
271
- Checkboxes and radio buttons need to follow the following markup structure:
272
-
273
- #### A single checkbox
274
-
275
- Not too different than other inputs:
276
-
277
- ```html
278
- <form class="semanticForms">
279
- <dl>
280
- <dt><label for="some_field_name">Single checkbox</label></dt>
281
- <dd><input type="checkbox" name="some_field_name" id="some_field_name"></dd>
282
- </dl>
283
- </form>
284
- ```
285
-
286
- #### Checkbox group
287
-
288
- ```html
289
- <form class="semanticForms">
290
- <dl>
291
- <dt><label data-for="some_field_name">Checkboxes:</label></dt>
292
- <dd class="checkboxes">
293
- <ul id="some_field_name_checkboxes">
294
- <li><input type="checkbox" name="some_field_name" id="some_field_name_checkboxes_one"> <label for="some_field_name_checkboxes_one">One</label></li>
295
- <li><input type="checkbox" name="some_field_name" id="some_field_name_checkboxes_two"> <label for="some_field_name_checkboxes_two">Two</label></li>
296
- <li><input type="checkbox" name="some_field_name" id="some_field_name_checkboxes_three"> <label for="some_field_name_checkboxes_three">Three</label></li>
297
- </ul>
298
- </dd>
299
- </dl>
300
- </form>
301
- ```
302
-
303
- #### Radio buttons
304
-
305
- ```html
306
- <form class="semanticForms">
307
- <dl>
308
- <dt><label data-for="some_field_name">Radios:</label></dt>
309
- <dd class="radios">
310
- <ul id="some_field_name">
311
- <li><input type="radio" name="some_field_name" id="r_one"> <label for="r_one">One</label></li>
312
- <li><input type="radio" name="some_field_name" id="r_two"> <label for="r_two">Two</label></li>
313
- <li><input type="radio" name="some_field_name" id="r_three"> <label for="r_three">Three</label></li>
314
- </ul>
315
- </dd>
316
- </dl>
317
- </form>
318
- ```
319
-
320
- ### Validation styles
321
-
322
- 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:
323
-
324
- ```html
325
- <form class="semanticForms">
326
- <dl>
327
- <dt><label for="input" data-no-asterisk>Input label</label></dt>
328
- <dd><input type="text" name="input" id="input" required>
329
- </dl>
330
- </form>
331
- ```
332
-
333
- You can set a paragraph of text below a field to only appear when a field is invalid with the `data-invalid-text` attribute:
334
-
335
- ```html
336
- <form class="semanticForms">
337
- <dl>
338
- <dt><label for="password">Password label</label><dt>
339
- <dd>
340
- <input type="password" name="password" id="password" minlength="8">
341
- <p data-invalid-text>Password must be at least 8 characters long.</p>
342
- </dd>
343
- </dl>
344
- </form>
345
- ```
346
-
347
- You can adjust the tooltip text of the asterisk with the `data-asterisk-text` attribute:
348
-
349
- ```html
350
- <form class="semanticForms">
351
- <dl>
352
- <dt><label for="input" data-asterisk-text="This is a custom tooltip.">Input label</label></dt>
353
- <dd><input type="text" name="input" id="input" required>
354
- </dl>
355
- </form>
356
- ```
357
-
358
- ### Dark mode
359
-
360
- To set the dark mode, apply an additional class of `dark` to your `<form>` elements to force the dark mode.
361
-
362
- ### Low flow (JavaScript disabled) mode
363
-
364
- The low flow will be displayed if JS is disabled.
365
-
366
- You can also activate the low flow (JavaScript disabled) mode manually by adding the `lowFlow` class to your `<form>` element.
367
-
368
- 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.
369
-
370
- ## Contributing
371
-
372
- - Fork/clone this repo.
373
- - `npm ci`
374
- - Make your changes. If you want to alter the CSS, do the changes in the `.scss` files.
375
- - `npm run build`. The build step compiles the SCSS file into CSS.
376
- - You can also run `npm run watch` automatically compiles the CSS file after a change is detected in the SCSS file.
377
- - Test your changes by opening `semanticForms.html` in your browser.
378
- - If you want to test your work on an actual HTTP server, run `npm run dev` or `npm run d`, and then visit http://localhost:3000/test/semanticForms
379
- - Commit, push, open pull request.
1
+ See documentation [here](https://rooseveltframework.org/docs/semantic-forms/latest).