From 82dee6361c8ee4c213990c646a0d2100a9fd4644 Mon Sep 17 00:00:00 2001 From: Geoffrey Eisenbarth Date: Wed, 11 Dec 2024 13:19:08 -0600 Subject: Clean up. --- src/aria.css | 94 ++++++++++++++++++------------- www/docs/40-aria.md | 157 +++++++++++++++------------------------------------- 2 files changed, 99 insertions(+), 152 deletions(-) diff --git a/src/aria.css b/src/aria.css index 82b69a0..ed12c76 100644 --- a/src/aria.css +++ b/src/aria.css @@ -117,62 +117,76 @@ text-align: center; } -label:has([role=switch]:last-child) { - display: flex; - gap: var(--gap); - justify-content: space-between; -} - -label[for]:has(+ [role=switch]), -label[for] + [role=switch], -[role=switch]:has(+ label[for]), -[role=switch] + label[for] { - display: inline-block; - padding-block: calc(var(--gap) / 4); -} -[role=switch], [aria-pressed] { - --toggle-border-width: 0.15em; +input[type=checkbox][role=switch] { all: unset; appearance: none; - cursor: pointer; - display: grid !important; - grid-gap: 0; - transition: all 0.25s ease-in-out; - vertical-align: bottom; + + display: inline-grid; + vertical-align: middle; + grid-template-columns: repeat(2, 1rem); + aspect-ratio: 2 / 1; + margin-block: auto; &::before, &::after { content: ''; display: inline-block; - height: var(--rhythm); - border: var(--toggle-border-width) solid var(--graphical-fg); + + transition: transform .2s ease-in-out, background-color .2s ease-in-out, background-color .2s ease-in-out; } + &::before { - width: calc(2 * var(--rhythm)); - background-color: var(--bg); - border-radius: var(--rhythm); + grid-column: 1 / span 2; grid-row: 1; - grid-column: 1 / 3; + border: 1px solid var(--graphical-fg); + background: var(--bg); + border-radius: 9999rem; } + &::after { - width: var(--rhythm); - background-color: var(--interactive-bg); - border-radius: 50%; + --toggle-nub-margin: 2px; + grid-column: 1; grid-row: 1; - grid-column: 1 / 2; + margin: var(--toggle-nub-margin); + border-radius: 99999rem; + background: var(--graphical-fg); + } + + &:checked { + &::before { + border-color: var(--accent); + background: var(--accent); + } + &::after { + transform: translateX(calc(100% + 2 * var(--toggle-nub-margin))); + background: var(--bg); + } } - &:is(:checked, [aria-pressed=true]) { - &::before { background-color: var(--accent); } - &::after { grid-column: 2 / 3; } + + &:indeterminate { + &::after { + transform: translateX(calc(50% + var(--toggle-nub-margin))); + background: var(--bg); + border: 1px solid var(--graphical-fg); + } } - &:is(:hover, :focus-visible) { - /* Reset button styles */ - filter: unset; - box-shadow: none; + &:is(label > *):not(#specificity-hack) { + margin-block-end: auto; } - &:active { - box-shadow: none; - color: inherit; + &:not(label > *) { + padding-block: calc(var(--gap) / 4 + (var(--rhythm) - 1em) / 2); } + + :is(label:has(> &)) { + /* Lightning CSS requires :is() when nested selector doesn't start with & */ + display: flex; + gap: var(--gap); + flex-direction: row; + } + :is(label:has(+ &)) { + /* Lightning CSS requires :is() when nested selector doesn't start with & */ + width: 100%; + } + } diff --git a/www/docs/40-aria.md b/www/docs/40-aria.md index 3a21af4..396837f 100644 --- a/www/docs/40-aria.md +++ b/www/docs/40-aria.md @@ -203,11 +203,7 @@ To get the actual behavior of an accessible feed, you can use [Missing.js § ## Toggle Switch -Use `switch` role with `` or `aria-pressed` with ` - - -
- Button toggles, flipped - - -
- - ~~~ - -
-
- Button toggles - - -
-
- Button toggles, flipped - - -
-
- - TODO - - \ No newline at end of file + + -- cgit v1.2.3