Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.0 #72

Merged
merged 62 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
bddabbb
Update dependency eslint to v9.9.1
renovate[bot] Aug 23, 2024
6e20af1
save progress
awidener3 Aug 19, 2024
31e8cc9
implement grid
awidener3 Aug 21, 2024
96c727a
add clear button
awidener3 Aug 22, 2024
0a94666
update scrollbars
awidener3 Aug 22, 2024
d087a79
styling for selects
awidener3 Aug 22, 2024
bfb8764
save progress
awidener3 Aug 23, 2024
5669b22
various tweaks
awidener3 Aug 26, 2024
3e8772e
tweaks to spacing, remove watch package
awidener3 Aug 29, 2024
87a011a
match styling to previous version
awidener3 Sep 1, 2024
52e2c74
tweaks
awidener3 Sep 4, 2024
b8f56d1
remove ref files
awidener3 Sep 4, 2024
9e0b067
add utility classes
awidener3 Sep 5, 2024
dee1238
add container query
awidener3 Sep 5, 2024
d1f8463
comment cleanup
awidener3 Sep 5, 2024
07d9f69
updates to low flow
awidener3 Sep 9, 2024
a880273
add span-full class, update README
awidener3 Sep 9, 2024
595b962
tweaks to match original version
awidener3 Sep 9, 2024
8e56007
switch to sass
awidener3 Sep 9, 2024
dc77559
updated package.json and README
awidener3 Sep 9, 2024
75a9480
clear button updates
awidener3 Sep 9, 2024
eae6668
add darkening nested fieldsets, update CHANGELOG
awidener3 Sep 9, 2024
d7d7fc4
update README
awidener3 Sep 9, 2024
1ca7efe
cleanup pass
awidener3 Sep 10, 2024
eff0104
updates for firefox
awidener3 Sep 10, 2024
7be60d8
fix textarea resizer, update icon colors
awidener3 Sep 10, 2024
d819a42
update col- to colspan-
awidener3 Sep 10, 2024
dc2f14e
add colspan- support for fieldsets
awidener3 Sep 10, 2024
7182ed9
removed fieldset requirement for responsive grid
awidener3 Sep 11, 2024
1d282ed
fix container queries
awidener3 Sep 11, 2024
8bb911e
tweaks
kethinov Sep 11, 2024
46645b3
add default gap to items in semantic forms
awidener3 Sep 11, 2024
21c4fc7
update map
awidener3 Sep 11, 2024
8ffce27
remove .css.map
awidener3 Sep 11, 2024
687e3ab
add .css.map to gitignore
awidener3 Sep 11, 2024
90182d9
smaller box shadow on field focus borders
kethinov Sep 11, 2024
b9ea94e
Merge branch 'css-rewrite' of https://github.com/awidener3/semanticfo…
kethinov Sep 11, 2024
90982dd
add colspan- classes to lowflow
awidener3 Sep 12, 2024
4467974
add validation styles
awidener3 Sep 12, 2024
8942e97
lowflow now responsively grows if no class is added
awidener3 Sep 12, 2024
5e771ea
update CHANGELOG
awidener3 Sep 12, 2024
cc9fa3b
adjust image inputs
awidener3 Sep 12, 2024
cc86896
update image button
awidener3 Sep 12, 2024
5861312
add help text
awidener3 Sep 12, 2024
069009d
update sample help text to show wrapping
awidener3 Sep 12, 2024
9937746
update README
awidener3 Sep 12, 2024
01b9eef
changelog
kethinov Sep 13, 2024
9edf205
various tweaks
awidener3 Sep 13, 2024
88413ae
update html validation
awidener3 Sep 13, 2024
09cd20c
add p tag support, fix clear button tabindex
awidener3 Sep 13, 2024
006f720
update p tag rules
awidener3 Sep 13, 2024
7e217ec
update p tag again
awidener3 Sep 13, 2024
17516d0
set clear button to tabindex to -1
awidener3 Sep 13, 2024
e24aac0
upgrade required asterisk, add placeholder fade
awidener3 Sep 13, 2024
bc04a87
tweaks to textarea, update README
awidener3 Sep 13, 2024
32f8c96
tweaks
awidener3 Sep 13, 2024
30dec68
small aesthetic adjustment
kethinov Sep 13, 2024
25ae709
Merge branch 'css-rewrite' of https://github.com/awidener3/semanticfo…
kethinov Sep 13, 2024
8f2c1ce
slight improvement for buttons on firefox
kethinov Sep 15, 2024
a3fffb9
consistent borders for invalid fields
kethinov Sep 15, 2024
d748b4d
crisper borders on nested fieldsets
kethinov Sep 15, 2024
cb067b4
final edits
kethinov Sep 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ typings/
# dotenv environment variables file
.env

# sass map
*.css.map
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# semanticforms changelog
# Semantic Forms changelog

## Next version

- Put your changes here...

## 4.0.0

- Breaking: Overhauled entire codebase to drive it using mostly CSS grid instead of flexbox. This makes everything more flexible overall and fit more designs better. However the CSS and markup changes will likely cause breaking changes to previous integrations, so when upgrading make some time to visually test all your pages to alter any CSS overrides you had in place accordingly. You also might want to make some markup changes to make use of new available classes to tweak the fit of individual form fields on specific forms.
- Altered fields to fit available space better at various screen sizes.
- Added multiple utility classes that define how wide inputs will span in the responsive layout.
- Added support for input type=image.
- Added support for secondary labels.
- Added styling for invalid form fields.
- Added asterisk that appears on required inputs.
- Improved accessibility considerably. Now has 100% Lighthouse score.
- Added feature to progressively nest fieldsets with progressively darker/lighter background colors.
- Fixed bug causing clear button appearing on disabled inputs.
- Fixed bug causing clear button to overlap with scrollbars on textareas.
- Fixed bug causing nested fieldset to have incorrect padding and margins.
- Fixed various other small bugs.
- Replaced the `less` CSS preprocessor with `sass`.
- Updated various dependencies.

## 3.2.1

- Fixed a bug that could cause checkboxes and radio buttons to not submit their values to the server properly.
Expand Down Expand Up @@ -59,7 +77,7 @@

## 3.0.0

- Removed defualt two column layout. Now defaults to as many columns as the container is wide.
- Removed default two column layout. Now defaults to as many columns as the container is wide.
- Added `x2` class you can put on `dd` elements to double the width of a form. Does not apply on small screens.

## 2.1.2
Expand Down
204 changes: 182 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

[![npm](https://img.shields.io/npm/v/semantic-forms.svg)](https://www.npmjs.com/package/semantic-forms)

A pattern library of forms based on semantic HTML enhanced with a modern UX.
A pattern library of attractive forms for your website with the following design goals:

- Attractive, modern float label visual design.
- Responsive layout based on modern CSS grid technique.
- Clear fields.
- Light and dark mode.
- Invalid field styling.
- Good accessibility.
- Semantic HTML (no div soup).
- Uses a progressive enhancement approach so that core functionality and most of the features still work with JavaScript disabled.
- Sets no global styles and is scoped by a single class name `semanticForms` applied to `<form>` elements.
- No dependencies.

See a [live demo here](https://kethinov.github.io/semanticforms/semanticForms.html).

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.

# Usage

Include the `semanticForms.css` and `semanticForms.js` files from this repo into your project.
Expand All @@ -18,17 +31,21 @@ Then apply the `semanticForms` class to your `<form>` elements:
</form>
```

Then apply the JavaScript enhancements:

```javascript
window.semanticForms()
```

Then the CSS/JS enhancements to your forms will apply automatically, assuming the markup structure you use is one of the supported patterns.

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)`.
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)`.

# Features

Overview of pattern library features:

## Float label inputs

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.
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.

### Example

Expand All @@ -52,25 +69,141 @@ The float label input pattern is notoriously difficult to implement in a fashion
</form>
```

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:
### Add help text

Adjust the horizontal offset of the clear field's click event click area (the default is 21):
Include a label in the `<dd>` element with a matching `for` attribute to place help text beneath the input:

```html
<form class="semanticForms" data-clearfield-horizontal-offset="21">
<!-- your form here -->
<form class="semanticForms">
<dl>
<dt><label for="password">Password</label></dt>
<dd>
<input id="password" name="password" type="password" placeholder="Enter a password" minlength="8" required>
<label for="password">Must be at least 8 characters long.</label>
</dd>
</dl>
</form>
```

Adjust the vertical offset of the clear field's click event click area (the default is 5):
## Responsive columns

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.

### Set number of columns for a group of forms

You can limit the number of columns on your forms using the `colspan-#` class on a `<dl>` element:

```html
<form class="semanticForms" data-clearfield-vertical-offset="5">
<!-- your form here -->
<form class="semanticForms">
<dl class="colspan-2">
<dt><label for="input-a">Input A</label></dt>
<dd><input type="text" id="input-a" name="input-a"></dd>

<dt><label for="input-b">Input B</label></dt>
<dd><input type="text" id="input-b" name="input-b"></dd>

<!-- wraps to the next row -->
<dt><label for="input-c">Input C</label></dt>
<dd><input type="text" id="input-c" name="input-c"></dd>
</dl>
</form>
```

You can also apply the class to a `<fieldset>` which will apply that styling to all nested `<dl>` elements:

```html
<form class="semanticForms">
<fieldset class="colspan-3">
<!-- inherits 3 column class -->
<dl>
<dt><label for="input-a">Input A</label></dt>
<dd><input type="text" id="input-a" name="input-a"></dd>

<dt><label for="input-b">Input B</label></dt>
<dd><input type="text" id="input-b" name="input-b"></dd>

<dt><label for="input-c">Input C</label></dt>
<dd><input type="text" id="input-c" name="input-c"></dd>
</dl>

<!-- has 4 columns -->
<dl class="colspan-4">
<dt><label for="input-d">Input D</label></dt>
<dd><input type="text" id="input-d" name="input-d"></dd>

<dt><label for="input-e">Input E</label></dt>
<dd><input type="text" id="input-e" name="input-e"></dd>

<dt><label for="input-f">Input F</label></dt>
<dd><input type="text" id="input-f" name="input-f"></dd>
</dl>
</fieldset>
</form>
```

### Set number of columns a single input field takes up
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`:


```html
<form class="semanticForms">
<fieldset>
<dl>
<dt><label for="input-a">Input A</label></dt>
<!-- 1 column -->
<dd class="colspan-1"><input type="text" id="input-a" name="input-a"></dd>

<dt><label for="input-b">Input B</label></dt>
<!-- 2 columns -->
<dd class="colspan-2"><input type="text" id="input-b" name="input-b"></dd>

<dt><label for="input-c">Input C</label></dt>
<!-- 5 columns (max) -->
<dd class="colspan-5"><input type="text" id="input-c" name="input-c"></dd>
</dl>
</fieldset>
</form>
```

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.
`colspan-full` can also be used to force an input to take up the entire width of a form:

```html
<form class="semanticForms">
<fieldset>
<dl>
<dt><label for="input-a">Input A</label></dt>
<!-- this spans 2 columns on row 1 -->
<dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>

<dt><label for="input-b">Input B</label></dt>
<!-- this spans the full width of row 2 -->
<dd class="colspan-full"><input type="text" id="input-b" name="input-b"></dd>

<!-- this spans 1 column on row 3 -->
<dt><label for="input-c">Input C</label></dt>
<dd><input type="text" id="input-c" name="input-c"></dd>
</dl>
</fieldset>
</form>
```

#### Set number of columns a single input field takes up on the low flow (JavaScript disabled flow)

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>`:

```html
<form class="semanticForms">
<fieldset>
<dl>
<div>
<dt><label for="input-a">Input A</label></dt>
<!-- this spans 2 columns on row 1 -->
<dd class="colspan-2"><input type="text" id="input-a" name="input-a"></dd>
</div>
</dl>
</fieldset>
</form>
```

## Button groups

Expand Down Expand Up @@ -154,21 +287,48 @@ Not too different than other inputs:
</form>
```

## Other features
## Validation styles

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:

```html
<form class="semanticForms">
<dl>
<dt><label for="input" data-no-asterisk>Input label</label></dt>
<dd><input type="text" name="input" id="input" required>
</dl>
</form>
```

You can adjust the tooltip text of the asterisk with the `data-asterisk-text` attribute:

```html
<form class="semanticForms">
<dl>
<dt><label for="input" data-asterisk-text="This is a custom tooltip.">Input label</label></dt>
<dd><input type="text" name="input" id="input" required>
</dl>
</form>
```
## Dark mode

To set the dark mode, apply an additional class of `dark` to your `<form>` elements to force the dark mode.

## Low flow (JavaScript disabled) mode

The low flow will be displayed if JS is disabled.

- Custom-styled select boxes with a custom drawn arrow graphic driven by SVG embedded in the CSS.
- Custom-styled submit buttons to match the aesthetic of the custom-styled forms.
- Responsive: on wide screens, the forms split into multiple columns. On smaller screens, they collapse to a single column.
- Dark mode: apply an additional class of `dark` to your `<form>` elements to use the dark mode.
- 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.
You can also activate the low flow (JavaScript disabled) mode manually by adding the `lowFlow` class to your `<form>` element.

See `semanticForms.html` or the [live demo](https://kethinov.github.io/semanticforms/semanticForms.html) for a full demo of all the markup patterns.
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.

# Contributing

- Fork/clone this repo.
- `npm ci`
- Make your changes. If you want to alter the CSS, do the changes in the `.less` files.
- `npm run build`. The build step compiles the LESS file into CSS.
- Make your changes. If you want to alter the CSS, do the changes in the `.scss` files.
- `npm run build`. The build step compiles the SCSS file into CSS.
- You can also run `npm run watch` automatically compiles the CSS file after a change is detected in the SCSS file.
- Test your changes by opening `semanticForms.html` in your browser.
- If you want to test your work on an actual HTTP server, run `npm run dev` or `npm run d`.
- Commit, push, open pull request.
Loading