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 +++++++------- tpl/objects/action-button.pug | 3 + tpl/objects/button.pug | 1 + tpl/views/action-button.pug | 22 ++++ tpl/views/button.pug | 15 ++- 6 files changed, 249 insertions(+), 120 deletions(-) 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}); } } diff --git a/tpl/objects/action-button.pug b/tpl/objects/action-button.pug index 976a646..c3a9b53 100644 --- a/tpl/objects/action-button.pug +++ b/tpl/objects/action-button.pug @@ -10,6 +10,9 @@ mixin action-button 'o-action-button--icon': !!attributes.icon && !block, 'is-selected': attributes.selected } + if (attributes.theme) { + classes['o-action-button--' + attributes.theme] = true + } if (attributes.size) { classes['o-action-button--' + attributes.size] = true } diff --git a/tpl/objects/button.pug b/tpl/objects/button.pug index 61ba0b6..b5fb8da 100644 --- a/tpl/objects/button.pug +++ b/tpl/objects/button.pug @@ -3,6 +3,7 @@ mixin a-button let classes = { 'o-button': true, 'o-button--block': attributes.block, + 'o-button--primary': attributes.primary, 'o-button--outline': attributes.outline, 'o-button--round': !!attributes.icon } diff --git a/tpl/views/action-button.pug b/tpl/views/action-button.pug index 2c94c68..8fbf9ea 100644 --- a/tpl/views/action-button.pug +++ b/tpl/views/action-button.pug @@ -85,3 +85,25 @@ mixin view-action-button +action-button(pill=true quiet=true disabled=true)= 'Disabled' = ' ' +action-button(pill=true quiet=true selected=true disabled=true)= 'Selected + disabled' + + each theme in ['static-black', 'static-white'] + - + const bg = theme.startsWith('static-black') ? 500 : 1000; + + .c-box(style=`background-color: var(--colors--blue-static--${bg});`) + +action-button(theme=theme)= 'Idle' + = ' ' + +action-button(theme=theme selected=true)= 'Selected' + = ' ' + +action-button(theme=theme disabled=true)= 'Disabled' + = ' ' + +action-button(theme=theme selected=true disabled=true)= 'Selected + disabled' + + .c-box(style=`background-color: var(--colors--blue-static--${bg});`) + +action-button(theme=theme quiet=true)= 'Idle' + = ' ' + +action-button(theme=theme quiet=true selected=true)= 'Selected' + = ' ' + +action-button(theme=theme quiet=true disabled=true)= 'Disabled' + = ' ' + +action-button(theme=theme quiet=true selected=true disabled=true)= 'Selected + disabled' diff --git a/tpl/views/button.pug b/tpl/views/button.pug index c476d9b..eacf302 100644 --- a/tpl/views/button.pug +++ b/tpl/views/button.pug @@ -45,7 +45,7 @@ mixin view-button +a-button(variant=theme outline=true icon='trash') +a-button(variant=theme outline=true disabled=true icon='trash') - each theme in ['static-black', 'static-black-primary', 'static-white', 'static-white-primary'] + each theme in ['static-black', 'static-white'] - const bg = theme.startsWith('static-black') ? 500 : 1000; @@ -61,3 +61,16 @@ mixin view-button +a-button(variant=theme disabled=true icon='trash') +a-button(variant=theme outline=true icon='trash') +a-button(variant=theme outline=true disabled=true icon='trash') + + .c-box(style=`background-color: var(--colors--blue-static--${bg});`) + .l-button-group + +a-button(variant=theme primary=true)= 'Button' + +a-button(variant=theme primary=true disabled=true)= 'Button' + +a-button(variant=theme primary=true outline=true)= 'Button' + +a-button(variant=theme primary=true outline=true disabled=true)= 'Button' + br + .l-button-group + +a-button(variant=theme primary=true icon='trash') + +a-button(variant=theme primary=true disabled=true icon='trash') + +a-button(variant=theme primary=true outline=true icon='trash') + +a-button(variant=theme primary=true outline=true disabled=true icon='trash') -- cgit v1.2.3-70-g09d2