From 4de75e0f305b2cb4a026073440f2bac7c34df817 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 25 Jun 2024 17:39:03 +0200 Subject: Focus indicator style --- src/objects/_switch.scss | 67 +++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) (limited to 'src/objects/_switch.scss') diff --git a/src/objects/_switch.scss b/src/objects/_switch.scss index 9ebb290..a67aa8d 100644 --- a/src/objects/_switch.scss +++ b/src/objects/_switch.scss @@ -12,6 +12,12 @@ --pad-b: fn.global-dim(--size --65), --rounding: fn.global-dim(--rounding), --spacing-sibling: fn.global-dim(--size --300), + + --key-focus: ( + --border: fn.global-dim(--key-focus --border), + --border-offset: fn.global-dim(--key-focus --border-offset), + --outline: fn.global-dim(--key-focus --border), + ), ), --colors: ( --track-bg: fn.global-color(--border), @@ -36,33 +42,34 @@ --handle-bg: fn.global-color(--base --50), ), --key-focus: ( - --bg: fn.global-color(--focus-static --400), - --label: fn.global-color(--focus-static --400-text), - --track-bg: fn.global-color(--focus-static --700), - --handle-border: fn.global-color(--focus-static --1000), - --handle-bg: fn.global-color(--focus-static --1000-text), + --label: fn.global-color(--focus --text), + --border: fn.global-color(--focus --border), + --outline: fn.global-color(--focus --outline), ), ), )); @include iro.bem-object(iro.props-namespace()) { - display: inline-flex; + display: inline-block; position: relative; - align-items: flex-start; - margin-inline: calc(-1 * fn.dim(--pad-i)) calc(fn.dim(--spacing-sibling) - fn.dim(--pad-i)); + margin-inline: + calc(-1 * fn.dim(--pad-i) - fn.dim(--key-focus --border-offset)) + calc(fn.dim(--spacing-sibling) - fn.dim(--pad-i) - fn.dim(--key-focus --border-offset)); padding-inline: fn.dim(--pad-i); padding-block: fn.dim(--pad-b); @include iro.bem-elem('indicator') { - display: block; - box-sizing: border-box; + display: inline-block; flex: 0 0 auto; inline-size: fn.dim(--width); block-size: fn.dim(--height); - margin-block-start: calc(.5 * (fn.global-dim(--font --standard --line-height) * 1em - fn.dim(--height))); + margin-block-start: calc(.5em * fn.global-dim(--font --standard --line-height) - .5 * fn.dim(--height) - fn.dim(--key-focus --border-offset)); transition: background-color .2s ease; + border: fn.dim(--key-focus --border-offset) solid transparent; border-radius: 2em; background-color: fn.color(--track-bg); + background-clip: padding-box; + vertical-align: top; &::after { content: ''; @@ -77,7 +84,6 @@ } @include iro.bem-elem('label') { - align-self: baseline; margin-inline-start: fn.dim(--label-gap); } @@ -94,7 +100,8 @@ overflow: hidden; border-radius: fn.dim(--rounding); - &:hover { + &:hover, + &:focus-visible { @include iro.bem-sibling-elem('label') { color: fn.color(--hover --label); } @@ -116,7 +123,8 @@ } } - &:hover { + &:hover, + &:focus-visible { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--hover --handle-border); @@ -153,25 +161,13 @@ } &:focus-visible { - background-color: fn.color(--key-focus --bg); - @include iro.bem-sibling-elem('label') { color: fn.color(--key-focus --label); } @include iro.bem-sibling-elem('indicator') { - background-color: fn.color(--key-focus --track-bg); - - &::after { - border-color: fn.color(--key-focus --handle-border); - background-color: fn.color(--key-focus --handle-bg); - } - } - - &:checked { - @include iro.bem-sibling-elem('indicator') { - background-color: fn.color(--key-focus --handle-border); - } + outline: fn.color(--key-focus --border) solid fn.dim(--key-focus --border); + box-shadow: 0 0 0 calc(fn.dim(--key-focus --border) + fn.dim(--key-focus --outline)) fn.color(--key-focus --outline); } } } @@ -193,7 +189,8 @@ } } - &:hover { + &:hover, + &:focus-visible { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--accent --hover --handle-border); @@ -219,18 +216,6 @@ } } } - - &:focus-visible { - &:checked { - @include iro.bem-sibling-elem('indicator') { - background-color: fn.color(--key-focus --handle-border); - - &::after { - border-color: fn.color(--key-focus --handle-border); - } - } - } - } } } } -- cgit v1.2.3-70-g09d2