From 64a841c69ead262666dd0754218585d0f05cf735 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 23 Jun 2024 19:05:33 +0200 Subject: WIP: New color calculations --- src/objects/_checkbox.scss | 271 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 src/objects/_checkbox.scss (limited to 'src/objects/_checkbox.scss') diff --git a/src/objects/_checkbox.scss b/src/objects/_checkbox.scss new file mode 100644 index 0000000..8e9e64c --- /dev/null +++ b/src/objects/_checkbox.scss @@ -0,0 +1,271 @@ +@use 'iro-sass/src/index' as iro; +@use '../functions' as fn; + +@include iro.props-namespace('checkbox') { + @include iro.props-store(( + --dims: ( + --size: fn.global-dim(--size --175), + --label-gap: fn.global-dim(--size --125), + --border: fn.global-dim(--border --medium), + --pad-i: fn.global-dim(--size --65), + --pad-b: fn.global-dim(--size --65), + --rounding: fn.global-dim(--rounding), + --spacing-sibling: fn.global-dim(--size --300), + ), + --colors: ( + --box-border: fn.global-color(--text-mute), + --box-bg: fn.global-color(--base --75), + + --hover: ( + --label: fn.global-color(--heading), + --box-border: fn.global-color(--text), + ), + --accent: ( + --box-border: fn.global-color(--accent --900), + + --hover: ( + --box-border: fn.global-color(--accent --1000), + ), + ), + --key-focus: ( + --bg: fn.global-color(--focus-static --400), + --label: fn.global-color(--focus-static --400-text), + --box-border: fn.global-color(--focus-static --1000), + --box-bg: fn.global-color(--focus-static --1000-text), + ), + --disabled: ( + --label: fn.global-color(--text-disabled), + --box-border: fn.global-color(--border-strong), + --box-bg: fn.global-color(--base --75), + ) + ), + )); + + @include iro.bem-object(iro.props-namespace()) { + display: inline-flex; + position: relative; + align-items: flex-start; + margin-inline: calc(-1 * fn.dim(--pad-i)) calc(fn.dim(--spacing-sibling) - fn.dim(--pad-b)); + padding-block: fn.dim(--pad-b); + padding-inline: fn.dim(--pad-i); + + @include iro.bem-elem('bg') { + display: block; + position: absolute; + z-index: -1; + inset-block: 0; + inset-inline: 0; + border-radius: fn.dim(--rounding); + pointer-events: none; + } + + @include iro.bem-elem('box') { + display: block; + position: relative; + flex: 0 0 auto; + inline-size: fn.dim(--size); + block-size: fn.dim(--size); + margin-block-start: calc(.5 * (fn.global-dim(--font --standard --line-height) * 1em - fn.dim(--size))); + border-radius: fn.dim(--border); + background-color: fn.color(--box-border); + + &::before, + &::after { + content: ''; + display: block; + position: absolute; + } + + &::before { + z-index: 2; + inset-block-start: fn.dim(--border); + inset-inline-start: fn.dim(--border); + inline-size: calc(fn.dim(--size) - 2 * fn.dim(--border)); + block-size: calc(fn.dim(--size) - 2 * fn.dim(--border)); + transition: transform .2s ease; + background-color: fn.color(--box-bg); + } + + &::after { + z-index: 3; + inset-block-start: calc(.5 * fn.dim(--size) - 1px); + inset-inline-start: calc(1.5 * fn.dim(--border)); + box-sizing: border-box; + inline-size: calc(fn.dim(--size) - 3 * fn.dim(--border)); + block-size: 0; + transform: scale(0); + transition: transform .2s ease; + border-block-width: 0 2px; + border-inline-width: 0 2px; + border-style: solid; + border-radius: 2px; + border-color: fn.color(--box-bg); + } + } + + @include iro.bem-elem('check-icon') { + display: block; + position: absolute; + z-index: 2; + inset-block-start: calc(1 * fn.dim(--border)); + inset-inline-start: calc(1 * fn.dim(--border)); + inline-size: calc(100% - 2 * fn.dim(--border)); + block-size: calc(100% - 2 * fn.dim(--border)); + margin: 0; + transform: scale(0); + transform-origin: 40% 90%; + transition: transform .2s ease; + stroke-width: iro.fn-px-to-rem(3px); + color: fn.color(--box-bg); + } + + @include iro.bem-elem('label') { + align-self: baseline; + margin-left: fn.dim(--label-gap); + } + + @include iro.bem-elem('native') { + position: absolute; + inset-block-start: 0; + inset-inline-start: 0; + inline-size: 100%; + block-size: 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('box') { + background-color: fn.color(--hover --box-border); + } + } + + &:checked { + @include iro.bem-sibling-elem('box') { + &::before { + transform: scale(0); + } + + @include iro.bem-elem('check-icon') { + transform: scale(1); + } + } + } + + &:indeterminate { + @include iro.bem-sibling-elem('box') { + &::before { + transform: scale(0); + } + + &::after { + transform: scale(1); + } + + @include iro.bem-elem('check-icon') { + transform: scale(0); + } + } + } + + &:disabled { + @include iro.bem-sibling-elem('label') { + color: fn.color(--disabled --label); + } + + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--disabled --box-border); + + &::before { + background-color: fn.color(--disabled --box-bg); + } + } + } + + &:focus-visible { + @include iro.bem-sibling-elem('bg') { + background-color: fn.color(--key-focus --bg); + } + + @include iro.bem-sibling-elem('label') { + color: fn.color(--key-focus --label); + } + + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--key-focus --box-border); + + &::before { + background-color: fn.color(--key-focus --box-bg); + } + } + } + } + + @include iro.bem-modifier('standalone') { + @include iro.bem-elem('box') { + margin-block-start: 0; + } + } + + @include iro.bem-modifier('accent') { + @include iro.bem-elem('native') { + &:checked { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--accent --box-border); + } + + &:hover { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--accent --hover --box-border); + } + } + } + + &:indeterminate { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--accent --box-border); + } + + &:hover { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--accent --hover --box-border); + } + } + } + + &:disabled { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--disabled --box-border); + + &::before { + background-color: fn.color(--disabled --box-bg); + } + } + + &:checked { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--disabled --box-border); + } + } + + &:indeterminate { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--disabled --box-border); + } + } + } + + &:focus-visible { + @include iro.bem-sibling-elem('box') { + background-color: fn.color(--key-focus --box-border); + } + } + } + } + } +} -- cgit v1.2.3-70-g09d2