@use 'iro-sass/src/index' as iro; @use '../functions' as fn; @include iro.props-namespace('switch') { @include iro.props-store(( --dims: ( --width: iro.fn-px-to-rem(26px), --height: iro.fn-px-to-rem(14px), --label-gap: .6rem, --border-width: fn.global-dim(--border-width --medium), --pad-x: .3rem, --pad-y: .3rem, --margin-right: fn.global-dim(--spacing --x --md), ), ), 'dims'); @include iro.props-store(( --colors: ( --track-bg: fn.global-color(--obj), --handle-border: fn.global-color(--fg-hi), --handle-bg: fn.global-color(--bg-hi), --hover: ( --label: fn.global-color(--fg-lo), --handle-border: fn.global-color(--fg), ), --accent: ( --handle-border: fn.global-color(--accent --primary), --hover: ( --handle-border: fn.global-color(--accent --primary-lo), ), ), --key-focus: ( --label: fn.global-color(--focus --text), --track-bg: fn.global-color(--focus --fill), --handle-border: fn.global-color(--focus --fill), --shadow: fn.global-color(--focus --shadow), ), --disabled: ( --label: fn.global-color(--fg-hi3), --track-bg: fn.global-color(--obj), --handle-border: fn.global-color(--obj-lo), --handle-bg: fn.global-color(--bg-hi), ) ), ), 'colors'); @include iro.bem-object(iro.props-namespace()) { display: inline-flex; position: relative; align-items: flex-start; margin-right: calc(-1 * fn.dim(--pad-x) + fn.dim(--margin-right)); margin-left: calc(-1 * fn.dim(--pad-x)); padding: fn.dim(--pad-y) fn.dim(--pad-x); @include iro.bem-elem('indicator') { display: block; position: relative; box-sizing: border-box; flex: 0 0 auto; width: fn.dim(--width); height: fn.dim(--height); margin-top: calc(.5 * (fn.global-dim(--font --standard --line-height) * 1em - fn.dim(--height))); transition: background-color .2s ease; border-radius: 2em; background-color: fn.color(--track-bg); &::after { content: ''; display: block; position: absolute; z-index: 10; top: 50%; left: 0; width: calc(fn.dim(--height) - 2 * fn.dim(--border-width)); height: calc(fn.dim(--height) - 2 * fn.dim(--border-width)); transform: translateY(-50%); transition: left .2s ease; border: fn.dim(--border-width) solid fn.color(--handle-border); border-radius: fn.dim(--width); background-color: fn.color(--handle-bg); } } @include iro.bem-elem('label') { align-self: baseline; margin-left: fn.dim(--label-gap); } @include iro.bem-elem('native') { position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; opacity: .0001; &:hover { @include iro.bem-sibling-elem('label') { color: fn.color(--hover --label); } @include iro.bem-sibling-elem('indicator') { &::after { border-color: fn.color(--hover --handle-border); } } } &:checked { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--handle-border); &::after { left: calc(fn.dim(--width) - fn.dim(--height) + .5px); border-color: fn.color(--handle-border); } } &:hover { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--hover --handle-border); &::after { border-color: fn.color(--hover --handle-border); } } } } &:disabled { @include iro.bem-sibling-elem('label') { color: fn.color(--disabled --label); } @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--disabled --track-bg); &::after { border-color: fn.color(--disabled --handle-border); background-color: fn.color(--disabled --handle-bg); } } &:checked { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--disabled --handle-border); &::after { border-color: fn.color(--disabled --handle-border); } } } } @include iro.bem-at-theme('keyboard') { &:focus { @include iro.bem-sibling-elem('label') { color: fn.color(--key-focus --label); } @include iro.bem-sibling-elem('indicator') { &::after { border-color: fn.color(--key-focus --handle-border); box-shadow: fn.color(--key-focus --shadow); } } &:checked { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--key-focus --track-bg); } } } } } @include iro.bem-modifier('accent') { @include iro.bem-elem('native') { &:checked { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--accent --handle-border); &::after { border-color: fn.color(--accent --handle-border); } } &:hover { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--accent --hover --handle-border); &::after { border-color: fn.color(--accent --hover --handle-border); } } } } &:disabled { @include iro.bem-sibling-elem('label') { color: fn.color(--disabled --label); } &:checked { @include iro.bem-sibling-elem('indicator') { background-color: fn.color(--disabled --handle-border); &::after { border-color: fn.color(--disabled --handle-border); } } } } } } } }