Skip to content

Commit

Permalink
refactor(forms)!: move :user-valid, :user-invalid into a new packag…
Browse files Browse the repository at this point in the history
…e `@form-validation` (#41)
  • Loading branch information
lowlighter committed Jul 10, 2024
1 parent 2031aa7 commit 1ecbb97
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/mod.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ <h1 id="layouts"><a href="#layouts">Layouts</a></h1>
<h1 id="utilities"><a href="#utilities">Utilities</a></h1>
<!--/styles/@utilities/mod.html-->
</section>
<section>
<h1 id="form-validation"><a href="#form-validation">Form validation</a></h1>
<!--/styles/@form-validation/mod.html-->
</section>
<section>
<h1 id="syntax-highlighting"><a href="#syntax-highlighting">Syntax highlighting</a></h1>
<!--/styles/@syntax-highlighting/mod.html-->
Expand Down
6 changes: 5 additions & 1 deletion app/sections/custom-build.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ <h3><a href="#custom-build">🛠️ Create a custom build</a></h3>
Istanbul coverage reports<br>
<small>Additional classes intended to be used with the <a href="https://istanbul.js.org/" target="_blank">istanbul.js</a> coverage reports.</small>
</label>
<label>
<input type="checkbox" name="extra" value="@form-validation" checked>
Form validation<br>
<small>Style <code data-hl="css">:user-valid, :user-invalid</code> states for inputs-like elements.</small>
</label>
<label>
<input type="checkbox" name="extra" value="@discrete-scrollbars" checked>
Discrete scrollbars<br>
Expand Down Expand Up @@ -368,7 +373,6 @@ <h3><a href="#custom-build">🛠️ Create a custom build</a></h3>
</fieldset>
</details>
<fieldset>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<legend>Customization</legend>
<label class="width">
Extra CSS content
Expand Down
11 changes: 11 additions & 0 deletions styles/@form-validation/mod.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
textarea:user-invalid,
select:user-invalid,
input:not([type="radio"],[type="checkbox"],[type="range"],[type="submit"],[type="image"]):user-invalid {
border: 1px solid var(--danger);
}

textarea:user-valid,
select:user-valid,
input:not([type="radio"],[type="checkbox"],[type="range"],[type="submit"],[type="image"]):user-valid {
border: 1px solid var(--success);
}
17 changes: 17 additions & 0 deletions styles/@form-validation/mod.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p>
<em>matcha.css</em> provides rules that automatically colors the borders of inputs based on their validation status.
</p>
<ul>
<li><code data-hl="css">:user-valid</code> has <code><span class="success"></span> --success</code> borders.</li>
<li><code data-hl="css">:user-invalid</code> has <code><span class="danger"></span> --danger</code> borders.</li>
</ul>
<div class="example">
<p class="note">*No validation except the ones operated by the browser are performed.</p>
<form method="get" onsubmit="event.preventDefault()">
<label>
URL:
<small>Type an URL below. If it is valid, it'll appear in <code><span class="success"></span> --success</code> while it'll appear in <code><span class="danger"></span> --danger</code> if not.</small>
<input required type="url" placeholder="https://example.com">
</label>
</form>
</div>
9 changes: 6 additions & 3 deletions styles/forms/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ <h2 id="input">
</p>
<ul>
<li><code data-hl="css">:disabled</code> has a muted background and a <code data-hl="css">not-allowed</code> cursor.</li>
<li><code data-hl="css">:user-valid</code> has <code><span class="success"></span> --success</code> borders.</li>
<li><code data-hl="css">:user-invalid</code> has <code><span class="danger"></span> --danger</code> borders.</li>
</ul>
<div class="example">
<p class="note">*No validation except the ones operated by the browser are performed.</p>
Expand Down Expand Up @@ -138,4 +136,9 @@ <h2 id="input">
</fieldset>
</form>
</div>
</section>
</section>
<div class="flash variant">
<p>
<em>matcha.css</em> provides rules that automatically colors the borders of inputs based on their validation status.
</p>
</div>
12 changes: 0 additions & 12 deletions styles/forms/mod.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ textarea {
cursor: not-allowed;
}

textarea:user-invalid,
select:user-invalid,
input:not([type="radio"],[type="checkbox"],[type="range"],[type="submit"],[type="image"]):user-invalid {
border: 1px solid var(--danger);
}

textarea:user-valid,
select:user-valid,
input:not([type="radio"],[type="checkbox"],[type="range"],[type="submit"],[type="image"]):user-valid {
border: 1px solid var(--success);
}

/* Select */
select {
width: 100%;
Expand Down
2 changes: 0 additions & 2 deletions styles/forms/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ <h2 id="select">
</p>
<ul>
<li><code data-hl="css">:disabled</code> has a muted background and a <code data-hl="css">not-allowed</code> cursor.</li>
<li><code data-hl="css">:user-valid</code> has <code><span class="success"></span> --success</code> borders.</li>
<li><code data-hl="css">:user-invalid</code> has <code><span class="danger"></span> --danger</code> borders.</li>
</ul>
<div class="example">
<form method="get" onsubmit="event.preventDefault()">
Expand Down
2 changes: 0 additions & 2 deletions styles/forms/textarea.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ <h2 id="textarea">
</p>
<ul>
<li><code data-hl="css">:disabled</code> has a muted background and a <code data-hl="css">not-allowed</code> cursor.</li>
<li><code data-hl="css">:user-valid</code> has <code><span class="success"></span> --success</code> borders.</li>
<li><code data-hl="css">:user-invalid</code> has <code><span class="danger"></span> --danger</code> borders.</li>
</ul>
<div class="example">
<form method="get" onsubmit="event.preventDefault()">
Expand Down

0 comments on commit 1ecbb97

Please sign in to comment.