@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(15px), --label-gap: .6rem, --border-width: fn.dim(--border-width --medium, $global: true), --padding-x: .3rem, --padding-y: .3rem, --margin-right: fn.dim(--spacing --x --md, $global: true), ), ), 'dims'); @include iro.props-store(( --colors: ( --track-bg: fn.color(--obj, $global: true), --handle-border: fn.color(--fg-hi, $global: true), --handle-bg: fn.color(--bg-hi, $global: true), --hover: ( --label: fn.color(--fg-lo, $global: true), --handle-border: fn.color(--fg, $global: true), ), --accent: ( --handle-border: fn.color(--accent --primary, $global: true), --hover: ( --handle-border: fn.color(--accent --primary-lo, $global: true), ), ), --key-focus: ( --label: fn.color(--focus --text, $global: true), --track-bg: fn.color(--focus --fill, $global: true), --handle-border: fn.color(--focus --fill, $global: true), --shadow: fn.color(--focus --shadow, $global: true), ), --disabled: ( --label: fn.color(--fg-hi3, $global: true), --track-bg: fn.color(--obj, $global: true), --handle-border: fn.color(--obj-lo, $global: true), --handle-bg: fn.color(--bg-hi, $global: true), ) ), ), 'colors'); @include iro.bem-object(iro.props-namespace()) { display: inline-flex; position: relative; align-items: flex-start; margin-right: calc(-1 * fn.dim(--padding-x) + fn.dim(--margin-right)); margin-left: calc(-1 * fn.dim(--padding-x)); padding: fn.dim(--padding-y) fn.dim(--padding-x); // sass-lint:disable-line shorthand-values @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 * ($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); } } } } } } } }