From 71af9d144c4dfc27c8824aec4d945897289ed440 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 26 Jun 2024 14:46:36 +0200 Subject: Add static themes to action button --- src/objects/_action-button.scss | 245 ++++++++++++++++++++++++++++------------ src/objects/_button.scss | 83 +++++++------- 2 files changed, 209 insertions(+), 119 deletions(-) (limited to 'src/objects') diff --git a/src/objects/_action-button.scss b/src/objects/_action-button.scss index 6dbdc2f..7a7ff46 100644 --- a/src/objects/_action-button.scss +++ b/src/objects/_action-button.scss @@ -1,7 +1,95 @@ +@use 'sass:list'; @use 'iro-sass/src/index' as iro; @use '../functions' as fn; -$sizes: 'sm' 'lg' 'xl' !default; +$sizes: 'sm' 'lg' 'xl' !default; +$static-themes: 'black' 'white' !default; + +@mixin static-theme($theme: ()) { + border-color: fn.color(list.join($theme, --disabled --border)); + background-color: fn.color(list.join($theme, --disabled --bg)); + color: fn.color(list.join($theme, --disabled --label)); + + &::after { + outline: fn.color(list.join($theme, --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(list.join($theme, --key-focus --outline)); + } + + &:link, + &:visited, + &:enabled { + border-color: fn.color(list.join($theme, --border)); + background-color: fn.color(list.join($theme, --bg)); + color: fn.color(list.join($theme, --label)); + + &:hover, + &:focus-visible { + border-color: fn.color(list.join($theme, --hover --border)); + background-color: fn.color(list.join($theme, --hover --bg)); + color: fn.color(list.join($theme, --hover --label)); + } + + &:active { + border-color: fn.color(list.join($theme, --active --border)); + background-color: fn.color(list.join($theme, --active --bg)); + color: fn.color(list.join($theme, --active --label)); + } + } + + @include iro.bem-modifier('quiet') { + border-color: transparent; + background-color: transparent; + color: fn.color(list.join($theme, --quiet --disabled --label)); + + &:link, + &:visited, + &:enabled { + border-color: transparent; + background-color: transparent; + color: fn.color(list.join($theme, --quiet --label)); + + &:hover, + &:focus-visible { + border-color: transparent; + background-color: fn.color(list.join($theme, --quiet --hover --bg)); + color: fn.color(list.join($theme, --quiet --hover --label)); + } + + &:active { + border-color: transparent; + background-color: fn.color(list.join($theme, --quiet --active --bg)); + color: fn.color(list.join($theme, --quiet --active --label)); + } + } + } + + @include iro.bem-is('selected') { + border-color: fn.color(list.join($theme, --selected --disabled --border)); + background-color: fn.color(list.join($theme, --selected --disabled --bg)); + color: fn.color(list.join($theme, --selected --disabled --label)); + + &:link, + &:visited, + &:enabled { + border-color: fn.color(list.join($theme, --selected --border)); + background-color: fn.color(list.join($theme, --selected --bg)); + color: fn.color(list.join($theme, --selected --label)); + + &:hover, + &:focus-visible { + border-color: fn.color(list.join($theme, --selected --hover --border)); + background-color: fn.color(list.join($theme, --selected --hover --bg)); + color: fn.color(list.join($theme, --selected --hover --label)); + } + + &:active { + border-color: fn.color(list.join($theme, --selected --active --border)); + background-color: fn.color(list.join($theme, --selected --active --bg)); + color: fn.color(list.join($theme, --selected --active --label)); + } + } + } +} @include iro.props-namespace('action-button') { @include iro.props-store(( @@ -59,6 +147,11 @@ $sizes: 'sm' 'lg' 'xl' !default; --label: fn.global-color(--border-strong), --border: fn.global-color(--border), ), + --key-focus: ( + --border: fn.global-color(--focus --border), + --outline: fn.global-color(--focus --outline), + ), + --selected: ( --bg: fn.global-color(--text-mute), --label: fn.global-color(--base --50), @@ -80,10 +173,7 @@ $sizes: 'sm' 'lg' 'xl' !default; --border: fn.global-color(--border-mute), ), ), - --key-focus: ( - --border: fn.global-color(--focus --border), - --outline: fn.global-color(--focus --outline), - ), + --quiet: ( --label: fn.global-color(--text), @@ -102,6 +192,76 @@ $sizes: 'sm' 'lg' 'xl' !default; ), )); + @each $theme in $static-themes { + @include iro.props-store(( + --colors: ( + --static-#{$theme}: ( + --bg: fn.global-color(--#{$theme}-transparent --100), + --label: fn.global-color(--#{$theme}-transparent --900), + --border: fn.global-color(--#{$theme}-transparent --400), + + --hover: ( + --bg: fn.global-color(--#{$theme}-transparent --300), + --label: fn.global-color(--#{$theme}-transparent --900), + --border: fn.global-color(--#{$theme}-transparent --500), + ), + --active: ( + --bg: fn.global-color(--#{$theme}-transparent --400), + --label: fn.global-color(--#{$theme}-transparent --900), + --border: fn.global-color(--#{$theme}-transparent --600), + ), + --disabled: ( + --bg: fn.global-color(--#{$theme}-transparent --100), + --label: fn.global-color(--#{$theme}-transparent --500), + --border: fn.global-color(--#{$theme}-transparent --300), + ), + --key-focus: ( + --border: fn.global-color(--#{$theme}-transparent --900), + --outline: fn.global-color(--#{$theme}-transparent --300), + ), + + --selected: ( + --bg: fn.global-color(--#{$theme}-transparent --800), + --label: fn.global-color(--#{$theme}-transparent --text), + --border: fn.global-color(--#{$theme}-transparent --100), + + --hover: ( + --bg: fn.global-color(--#{$theme}-transparent --900), + --label: fn.global-color(--#{$theme}-transparent --text), + --border: fn.global-color(--#{$theme}-transparent --100), + ), + --active: ( + --bg: fn.global-color(--#{$theme}-transparent --900), + --label: fn.global-color(--#{$theme}-transparent --text), + --border: fn.global-color(--#{$theme}-transparent --100), + ), + --disabled: ( + --bg: fn.global-color(--#{$theme}-transparent --200), + --label: fn.global-color(--#{$theme}-transparent --500), + --border: fn.global-color(--#{$theme}-transparent --100), + ), + ), + + --quiet: ( + --label: fn.global-color(--#{$theme}-transparent --900), + + --hover: ( + --bg: fn.global-color(--#{$theme}-transparent --300), + --label: fn.global-color(--#{$theme}-transparent --900), + ), + --active: ( + --bg: fn.global-color(--#{$theme}-transparent --400), + --label: fn.global-color(--#{$theme}-transparent --900), + ), + --disabled: ( + --label: fn.global-color(--#{$theme}-transparent --500), + ), + ), + ), + ) + )); + } + @include iro.bem-object(iro.props-namespace()) { display: inline-block; position: relative; @@ -132,81 +292,18 @@ $sizes: 'sm' 'lg' 'xl' !default; &:link, &:visited, &:enabled { - border-color: fn.color(--border); - background-color: fn.color(--bg); - color: fn.color(--label); - - &:hover, - &:focus-visible { - border-color: fn.color(--hover --border); - background-color: fn.color(--hover --bg); - color: fn.color(--hover --label); - } - - &:active { - border-color: fn.color(--active --border); - background-color: fn.color(--active --bg); - color: fn.color(--active --label); - } - &:focus-visible { &::after { display: block; } } } - - @include iro.bem-modifier('quiet') { - border-color: transparent; - background-color: transparent; - color: fn.color(--quiet --disabled --label); - - &:link, - &:visited, - &:enabled { - border-color: transparent; - background-color: transparent; - color: fn.color(--quiet --label); - - &:hover, - &:focus-visible { - border-color: transparent; - background-color: fn.color(--quiet --hover --bg); - color: fn.color(--quiet --hover --label); - } - - &:active { - border-color: transparent; - background-color: fn.color(--quiet --active --bg); - color: fn.color(--quiet --active --label); - } - } - } - - @include iro.bem-is('selected') { - border-color: fn.color(--selected --disabled --border); - background-color: fn.color(--selected --disabled --bg); - color: fn.color(--selected --disabled --label); - - &:link, - &:visited, - &:enabled { - border-color: fn.color(--selected --border); - background-color: fn.color(--selected --bg); - color: fn.color(--selected --label); - - &:hover, - &:focus-visible { - border-color: fn.color(--selected --hover --border); - background-color: fn.color(--selected --hover --bg); - color: fn.color(--selected --hover --label); - } - - &:active { - border-color: fn.color(--selected --active --border); - background-color: fn.color(--selected --active --bg); - color: fn.color(--selected --active --label); - } + + @include static-theme; + + @each $theme in $static-themes { + @include iro.bem-modifier(static-#{$theme}) { + @include static-theme(--static-#{$theme}); } } diff --git a/src/objects/_button.scss b/src/objects/_button.scss index 27d3726..98ac8ef 100644 --- a/src/objects/_button.scss +++ b/src/objects/_button.scss @@ -6,24 +6,22 @@ $sizes: 'sm' 'lg' 'xl' !default; $themes: 'accent' 'negative' !default; $static-themes: 'black' 'white' !default; -@mixin theme($theme: null) { - $key: if($theme == null, (), --#{$theme}); - +@mixin theme($theme: ()) { &:link, &:visited, &:enabled { border-color: transparent; - background-color: fn.color(list.join($key, --bg)); - color: fn.color(list.join($key, --label)); + background-color: fn.color(list.join($theme, --bg)); + color: fn.color(list.join($theme, --label)); } @include iro.bem-modifier('outline') { &:link, &:visited, &:enabled { - border-color: fn.color(list.join($key, --outline-border)); + border-color: fn.color(list.join($theme, --outline-border)); background-color: transparent; - color: fn.color(list.join($key, --outline-label)); + color: fn.color(list.join($theme, --outline-label)); } } @@ -33,35 +31,37 @@ $static-themes: 'black' 'white' !default; &:hover, &:focus-visible { border-color: transparent; - background-color: fn.color(list.join($key, --hover --bg)); - color: fn.color(list.join($key, --hover --label)); + background-color: fn.color(list.join($theme, --hover --bg)); + color: fn.color(list.join($theme, --hover --label)); } &:active { border-color: transparent; - background-color: fn.color(list.join($key, --active --bg)); - color: fn.color(list.join($key, --active --label)); + background-color: fn.color(list.join($theme, --active --bg)); + color: fn.color(list.join($theme, --active --label)); } } } -@mixin static-theme($theme, $disabled-theme: $theme) { - $key: --static-#{$disabled-theme}; - +@mixin static-theme($theme: ()) { border-color: transparent; - background-color: fn.color(list.join($key, --disabled --bg)); - color: fn.color(list.join($key, --disabled --label)); + background-color: fn.color(list.join($theme, --disabled --bg)); + color: fn.color(list.join($theme, --disabled --label)); + + &::after { + outline: fn.color(list.join($theme, --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(list.join($theme, --key-focus --outline)); + } @include iro.bem-modifier('outline') { - border-color: fn.color(list.join($key, --disabled --outline-border)); + border-color: fn.color(list.join($theme, --disabled --outline-border)); background-color: transparent; } - @include theme(static-#{$theme}); + @include theme($theme); - &::after { - outline: fn.color(list.join($key, --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(list.join($key, --key-focus --outline)); + @include iro.bem-modifier('primary') { + @include theme(list.join($theme, --primary)); } } @@ -190,20 +190,21 @@ $static-themes: 'black' 'white' !default; --border: fn.global-color(--#{$theme}-transparent --900), --outline: fn.global-color(--#{$theme}-transparent --300), ), - ), - --static-#{$theme}-primary: ( - --bg: fn.global-color(--#{$theme}-transparent --800), - --label: fn.global-color(--#{$theme}-transparent --text), - --outline-border: fn.global-color(--#{$theme}-transparent --800), - --outline-label: fn.global-color(--#{$theme}-transparent --900), - --hover: ( - --bg: fn.global-color(--#{$theme}-transparent --900), - --label: fn.global-color(--#{$theme}-transparent --text), - ), - --active: ( - --bg: fn.global-color(--#{$theme}-transparent --900), - --label: fn.global-color(--#{$theme}-transparent --text), + --primary: ( + --bg: fn.global-color(--#{$theme}-transparent --800), + --label: fn.global-color(--#{$theme}-transparent --text), + --outline-border: fn.global-color(--#{$theme}-transparent --800), + --outline-label: fn.global-color(--#{$theme}-transparent --900), + + --hover: ( + --bg: fn.global-color(--#{$theme}-transparent --900), + --label: fn.global-color(--#{$theme}-transparent --text), + ), + --active: ( + --bg: fn.global-color(--#{$theme}-transparent --900), + --label: fn.global-color(--#{$theme}-transparent --text), + ), ), ), ), @@ -265,25 +266,17 @@ $static-themes: 'black' 'white' !default; } } - @include theme(); - - @include iro.bem-modifier('primary') { - @include theme('primary'); - } + @include static-theme; @each $theme in $themes { @include iro.bem-modifier($theme) { - @include theme($theme); + @include theme(--#{$theme}); } } @each $theme in $static-themes { @include iro.bem-modifier(static-#{$theme}) { - @include static-theme($theme); - } - - @include iro.bem-modifier(static-#{$theme}-primary) { - @include static-theme(#{$theme}-primary, $theme); + @include static-theme(--static-#{$theme}); } } -- cgit v1.2.3-70-g09d2