Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: extract button styles to mixin #3075

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 11 additions & 110 deletions src/elements/button/common/button-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,11 @@ $icon-only: ':where([data-slot-names~=icon], [icon-name]):not([data-slot-names~=
outline: none !important;

--sbb-button-icon-size: var(--sbb-size-icon-ui-small);
--sbb-button-color-disabled-background: var(--sbb-color-milk);
--sbb-button-color-disabled-border: var(--sbb-color-smoke);
--sbb-button-color-disabled-text: var(--sbb-color-granite);
--sbb-button-shadow-1-offset-y: var(--sbb-shadow-elevation-level-3-shadow-1-offset-y);
--sbb-button-shadow-2-offset-y: var(--sbb-shadow-elevation-level-3-shadow-2-offset-y);
--sbb-button-shadow-1-blur: var(--sbb-shadow-elevation-level-3-shadow-1-blur);
--sbb-button-shadow-2-blur: var(--sbb-shadow-elevation-level-3-shadow-2-blur);
--sbb-button-shadow-1-color: var(--sbb-color-red-alpha-20);
--sbb-button-shadow-2-color: var(--sbb-color-red125-alpha-20);
--sbb-button-border-style: solid;
--sbb-button-border-disabled-style: dashed;
--sbb-button-border-width: var(--sbb-border-width-2x);
--sbb-button-border-disabled-width: var(--sbb-border-width-1x);
--sbb-button-border-radius: var(--sbb-border-radius-infinity);
--sbb-button-min-height: var(--sbb-size-element-m);
--sbb-button-transition-duration: var(
--sbb-disable-animation-zero-time,
var(--sbb-animation-duration-2x)
);
--sbb-button-transition-easing-function: var(--sbb-animation-easing);
--sbb-button-padding-block-min: var(--sbb-spacing-fixed-1x);
--sbb-button-padding-inline: var(--sbb-spacing-fixed-8x);
--sbb-button-gap: var(--sbb-spacing-fixed-2x);
--sbb-button-inset: 0;
--sbb-button-box-shadow: transparent;
--sbb-button-box-shadow-definition: var(--sbb-shadow-elevation-level-3-shadow-2-offset-x)
var(--sbb-button-shadow-2-offset-y) var(--sbb-button-shadow-2-blur)
var(--sbb-shadow-elevation-level-3-shadow-2-spread) var(--sbb-button-shadow-2-color),
var(--sbb-shadow-elevation-level-3-shadow-1-offset-x) var(--sbb-button-shadow-1-offset-y)
var(--sbb-button-shadow-1-blur) var(--sbb-shadow-elevation-level-3-shadow-1-spread)
var(--sbb-button-shadow-1-color);

@include sbb.mq($from: medium) {
--sbb-button-padding-inline: var(--sbb-spacing-fixed-10x);
}

@include sbb.if-forced-colors {
--sbb-button-color-default-border: CanvasText !important;
--sbb-button-color-active-border: Highlight !important;
--sbb-button-color-default-background: Canvas !important;
--sbb-button-color-hover-background: Canvas !important;
--sbb-button-color-active-background: Canvas !important;
--sbb-button-color-disabled-background: Canvas !important;
--sbb-button-color-disabled-text: GrayText !important;
@include sbb.button-variables;

@include sbb.if-forced-colors {
// For static cases, button and link roles will override it.
--sbb-button-color-default-text: CanvasText !important;
--sbb-button-color-hover-text: CanvasText !important;
Expand Down Expand Up @@ -87,104 +47,47 @@ $icon-only: ':where([data-slot-names~=icon], [icon-name]):not([data-slot-names~=
}

:host([size='m']) {
--sbb-button-min-height: var(--sbb-size-element-s);
--sbb-button-padding-inline: var(--sbb-spacing-fixed-5x);

@include sbb.mq($from: medium) {
--sbb-button-padding-inline: var(--sbb-spacing-fixed-8x);
}
@include sbb.button-size-m;
}

:host([size='s']) {
--sbb-button-min-height: var(--sbb-size-element-xs);
--sbb-button-padding-inline: var(--sbb-spacing-fixed-4x);
--sbb-button-gap: var(--sbb-spacing-fixed-1x);

@include sbb.mq($from: medium) {
--sbb-button-padding-inline: var(--sbb-spacing-fixed-5x);
}
@include sbb.button-size-s;
}

:host(#{$icon-only}) {
--sbb-button-padding-inline: 0;
}

:host(:not([disabled], :active, [data-active]):hover) {
@include sbb.hover-mq($hover: true) {
--sbb-button-translate-y-content-hover: #{sbb.px-to-rem-build(-1)};
--sbb-button-shadow-1-offset-y: calc(
0.5 * var(--sbb-shadow-elevation-level-3-shadow-1-offset-y)
);
--sbb-button-shadow-1-blur: calc(0.5 * var(--sbb-shadow-elevation-level-3-shadow-1-blur));
--sbb-button-shadow-2-blur: calc(0.5 * var(--sbb-shadow-elevation-level-3-shadow-2-blur));
}

@include sbb.if-forced-colors {
--sbb-button-color-hover-border: Highlight !important;
}
@include sbb.button-hover;
}

.sbb-action-base {
@include sbb.text-xs--bold;
@include sbb.button-base;

// Reset for link variant
text-decoration: none;
width: 100%;
position: relative;
display: flex;
gap: var(--sbb-button-gap);
align-items: center;
justify-content: center;
text-align: left;
transition-duration: var(--sbb-button-transition-duration);
transition-timing-function: var(--sbb-button-transition-easing-function);
transition-property: color;
min-height: var(--sbb-button-min-height);
border-radius: var(--sbb-button-border-radius);

// The padding block value is only a minimal padding to preserve a padding if the content becomes larger than intended.
// Positioning of the content is made by flexbox vertical centering.
// The real padding displayed is larger than the defined value below.
padding-block: var(--sbb-button-padding-block-min);
padding-inline: var(--sbb-button-padding-inline);
color: var(--sbb-button-color-default-text);
cursor: pointer;
user-select: none;
outline: none;

// Renders background and border in the background absolute to enable the hover animation
&::before {
position: absolute;
content: '';
inset: var(--sbb-button-inset);
border: var(--sbb-button-border-width) var(--sbb-button-border-style)
var(--sbb-button-color-default-border);
border-radius: var(--sbb-button-border-radius);
background-color: var(--sbb-button-color-default-background);
transition-duration: var(--sbb-button-transition-duration);
transition-timing-function: var(--sbb-button-transition-easing-function);
transition-property: inset, background-color, border-color, box-shadow;
box-shadow: var(--sbb-button-box-shadow);
@include sbb.button-base-before;

:host([disabled]) & {
background-color: var(--sbb-button-color-disabled-background);
border-width: var(--sbb-button-border-disabled-width);
border-color: var(--sbb-button-color-disabled-border);
border-style: var(--sbb-button-border-disabled-style);
@include sbb.button-disabled-before;
}

:host(:not([disabled], :active, [data-active]):hover) & {
@include sbb.hover-mq($hover: true) {
inset: calc(var(--sbb-button-border-width) * -1);
background-color: var(--sbb-button-color-hover-background);
border-color: var(--sbb-button-color-hover-border);
}
@include sbb.button-hover-before;
}

:host(:not([disabled]):is(:active, [data-active])) & {
color: var(--sbb-button-color-active-text);
background-color: var(--sbb-button-color-active-background);
border-color: var(--sbb-button-color-active-border);
@include sbb.button-active;
}
}

Expand All @@ -194,9 +97,7 @@ $icon-only: ':where([data-slot-names~=icon], [icon-name]):not([data-slot-names~=
}

:host([disabled]) & {
color: var(--sbb-button-color-disabled-text);
cursor: default;
pointer-events: none;
@include sbb.button-disabled;
}

:host(:not([disabled], :active, [data-active]):hover) & {
Expand Down
Loading
Loading