mirror of https://github.com/twbs/bootstrap.git
352 lines
9.7 KiB
SCSS
352 lines
9.7 KiB
SCSS
@use "sass:color";
|
|
@use "sass:list";
|
|
@use "sass:map";
|
|
@use "sass:meta";
|
|
@use "../colors" as *;
|
|
@use "../config" as *;
|
|
@use "../theme" as *;
|
|
@use "../variables" as *;
|
|
@use "../theme" as *;
|
|
@use "../functions" as *;
|
|
@use "../vendor/rfs" as *;
|
|
@use "../mixins/border-radius" as *;
|
|
@use "../mixins/box-shadow" as *;
|
|
@use "../mixins/focus-ring" as *;
|
|
@use "../mixins/gradients" as *;
|
|
@use "../mixins/transition" as *;
|
|
@use "button-variables" as *;
|
|
|
|
// scss-docs-start btn-variants
|
|
$button-variants: (
|
|
"solid": (
|
|
"base": (
|
|
"bg": "bg",
|
|
"color": "contrast",
|
|
"border-color": "bg"
|
|
),
|
|
"hover": (
|
|
"bg": "bg",
|
|
"border-color": "bg",
|
|
"color": "contrast"
|
|
),
|
|
"active": (
|
|
"bg": "bg",
|
|
"border-color": "bg",
|
|
"color": "contrast"
|
|
)
|
|
),
|
|
"outline": (
|
|
"base": (
|
|
"bg": "transparent",
|
|
"color": "text",
|
|
"border-color": "border"
|
|
),
|
|
"hover": (
|
|
"bg": "bg",
|
|
"color": "contrast",
|
|
"border-color": "bg"
|
|
),
|
|
"active": (
|
|
"bg": "bg",
|
|
"color": "contrast",
|
|
"border-color": "bg"
|
|
)
|
|
),
|
|
"subtle": (
|
|
"base": (
|
|
"bg": "bg-subtle",
|
|
"color": "text",
|
|
"border-color": "transparent"
|
|
),
|
|
"hover": (
|
|
"bg": ("bg-muted", "bg-subtle"),
|
|
"color": "text"
|
|
),
|
|
"active": (
|
|
"bg": "bg-subtle",
|
|
"color": "text"
|
|
)
|
|
),
|
|
"text": (
|
|
"base": (
|
|
"color": "text",
|
|
"bg": "transparent",
|
|
"border-color": "transparent"
|
|
),
|
|
"hover": (
|
|
"color": "text",
|
|
"bg": "bg-subtle"
|
|
),
|
|
"active": (
|
|
"color": "text",
|
|
"bg": "bg-subtle"
|
|
)
|
|
)
|
|
) !default;
|
|
// scss-docs-end btn-variants
|
|
|
|
|
|
// Helper function to get nested map values using dot notation
|
|
@function get-nested-value($map, $keys) {
|
|
$value: $map;
|
|
@each $key in $keys {
|
|
@if type-of($value) == "map" {
|
|
$value: map-get($value, $key);
|
|
} @else {
|
|
@return null;
|
|
}
|
|
}
|
|
@return $value;
|
|
}
|
|
|
|
// Helper function to split dot notation string into list
|
|
@function split-keys($key) {
|
|
$keys: ();
|
|
$parts: str-slice($key, 1);
|
|
@each $part in $parts {
|
|
$keys: append($keys, $part);
|
|
}
|
|
@return $keys;
|
|
}
|
|
|
|
// Main button style generator mixin
|
|
// scss-docs-start btn-variant-mixin
|
|
@mixin button-variant($color, $variant) {
|
|
$variant-styles: map.get($button-variants, $variant);
|
|
|
|
@if $variant-styles {
|
|
// Base properties
|
|
@each $property, $value in map.get($variant-styles, "base") {
|
|
@if $value == "transparent" {
|
|
--#{$prefix}btn-#{$property}: transparent;
|
|
} @else {
|
|
--#{$prefix}btn-#{$property}: var(--#{$prefix}#{$color}-#{$value});
|
|
}
|
|
}
|
|
|
|
// Hover state
|
|
&:hover {
|
|
@each $property, $value in map.get($variant-styles, "hover") {
|
|
@if $value == "transparent" {
|
|
--#{$prefix}btn-hover-#{$property}: transparent;
|
|
} @else if meta.type-of($value) == "list" {
|
|
$first-value: list.nth($value, 1);
|
|
$second-value: list.nth($value, 2);
|
|
--#{$prefix}btn-hover-#{$property}: color-mix(in oklch, var(--#{$prefix}#{$color}-#{$first-value}) 50%, var(--#{$prefix}#{$color}-#{$second-value}));
|
|
} @else if $value == "bg-subtle" {
|
|
--#{$prefix}btn-hover-#{$property}: var(--#{$prefix}#{$color}-#{$value});
|
|
} @else {
|
|
--#{$prefix}btn-hover-#{$property}: oklch(from var(--#{$prefix}#{$color}-#{$value}) calc(l * .95) calc(c * 1.1) h);
|
|
}
|
|
}
|
|
}
|
|
|
|
&:focus-visible {
|
|
outline-color: var(--#{$prefix}#{$color}-focus-ring);
|
|
}
|
|
|
|
// Active state
|
|
&:active,
|
|
&.active {
|
|
@each $property, $value in map.get($variant-styles, "active") {
|
|
@if $value == "transparent" {
|
|
--#{$prefix}btn-active-#{$property}: transparent;
|
|
} @else if $value == "bg-subtle" {
|
|
--#{$prefix}btn-active-#{$property}: var(--#{$prefix}#{$color}-#{$value});
|
|
} @else {
|
|
--#{$prefix}btn-active-#{$property}: oklch(from var(--#{$prefix}#{$color}-#{$value}) calc(l * .9) calc(c * 1.15) h);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// scss-docs-end btn-variant-mixin
|
|
|
|
// Generate all button variants
|
|
@each $color, $_ in $new-theme-colors {
|
|
@each $variant, $_ in $button-variants {
|
|
.btn-#{$color}-#{$variant} {
|
|
@include button-variant($color, $variant);
|
|
}
|
|
}
|
|
}
|
|
|
|
// scss-docs-start btn-size-mixin
|
|
@mixin button-size($padding-y, $padding-x, $font-size, $border-radius) {
|
|
--#{$prefix}btn-padding-y: #{$padding-y};
|
|
--#{$prefix}btn-padding-x: #{$padding-x};
|
|
@include rfs($font-size, --#{$prefix}btn-font-size);
|
|
--#{$prefix}btn-border-radius: #{$border-radius};
|
|
}
|
|
// scss-docs-end btn-size-mixin
|
|
|
|
|
|
//
|
|
// Base styles
|
|
//
|
|
|
|
@layer components {
|
|
.btn {
|
|
// scss-docs-start btn-css-vars
|
|
--#{$prefix}btn-padding-x: #{$btn-padding-x};
|
|
--#{$prefix}btn-padding-y: #{$btn-padding-y};
|
|
--#{$prefix}btn-font-family: #{$btn-font-family};
|
|
@include rfs($btn-font-size, --#{$prefix}btn-font-size);
|
|
--#{$prefix}btn-font-weight: #{$btn-font-weight};
|
|
--#{$prefix}btn-line-height: #{$btn-line-height};
|
|
--#{$prefix}btn-color: #{$btn-color};
|
|
--#{$prefix}btn-bg: transparent;
|
|
--#{$prefix}btn-border-width: #{$btn-border-width};
|
|
--#{$prefix}btn-border-color: transparent;
|
|
--#{$prefix}btn-border-radius: #{$btn-border-radius};
|
|
--#{$prefix}btn-hover-border-color: transparent;
|
|
--#{$prefix}btn-box-shadow: #{$btn-box-shadow};
|
|
--#{$prefix}btn-disabled-opacity: #{$btn-disabled-opacity};
|
|
// --#{$prefix}btn-focus-box-shadow: 0 0 0 #{$btn-focus-width} rgba(var(--#{$prefix}btn-focus-shadow-rgb), .5);
|
|
// scss-docs-end btn-css-vars
|
|
|
|
display: inline-block;
|
|
padding: var(--#{$prefix}btn-padding-y) var(--#{$prefix}btn-padding-x);
|
|
font-family: var(--#{$prefix}btn-font-family);
|
|
@include font-size(var(--#{$prefix}btn-font-size));
|
|
font-weight: var(--#{$prefix}btn-font-weight);
|
|
line-height: var(--#{$prefix}btn-line-height);
|
|
color: var(--#{$prefix}btn-color);
|
|
text-align: center;
|
|
text-decoration: if($link-decoration == none, null, none);
|
|
white-space: $btn-white-space;
|
|
vertical-align: middle;
|
|
cursor: if($enable-button-pointers, pointer, null);
|
|
user-select: none;
|
|
border: var(--#{$prefix}btn-border-width) solid var(--#{$prefix}btn-border-color);
|
|
@include border-radius(var(--#{$prefix}btn-border-radius));
|
|
@include gradient-bg(var(--#{$prefix}btn-bg));
|
|
@include box-shadow(var(--#{$prefix}btn-box-shadow));
|
|
@include transition($btn-transition);
|
|
|
|
&:hover {
|
|
color: var(--#{$prefix}btn-hover-color);
|
|
text-decoration: if($link-hover-decoration == underline, none, null);
|
|
background-color: var(--#{$prefix}btn-hover-bg);
|
|
border-color: var(--#{$prefix}btn-hover-border-color);
|
|
}
|
|
|
|
.btn-check + &:hover {
|
|
// override for the checkbox/radio buttons
|
|
color: var(--#{$prefix}btn-color);
|
|
background-color: var(--#{$prefix}btn-bg);
|
|
border-color: var(--#{$prefix}btn-border-color);
|
|
}
|
|
|
|
&:focus-visible {
|
|
@include focus-ring(true);
|
|
--#{$prefix}focus-ring-offset: 1px;
|
|
}
|
|
|
|
.btn-check:focus-visible + & {
|
|
@include focus-ring(true);
|
|
}
|
|
|
|
.btn-check:checked + &,
|
|
:not(.btn-check) + &:active,
|
|
&:first-child:active,
|
|
&.active,
|
|
&.show {
|
|
color: var(--#{$prefix}btn-active-color);
|
|
background-color: var(--#{$prefix}btn-active-bg);
|
|
// Remove CSS gradients if they're enabled
|
|
background-image: if($enable-gradients, none, null);
|
|
border-color: var(--#{$prefix}btn-active-border-color);
|
|
@include box-shadow(var(--#{$prefix}btn-active-shadow));
|
|
|
|
&:focus-visible {
|
|
@include focus-ring(true);
|
|
}
|
|
}
|
|
|
|
.btn-check:checked:focus-visible + & {
|
|
@include focus-ring(true);
|
|
}
|
|
|
|
&:disabled,
|
|
&.disabled,
|
|
fieldset:disabled & {
|
|
color: var(--#{$prefix}btn-disabled-color);
|
|
pointer-events: none;
|
|
background-color: var(--#{$prefix}btn-disabled-bg);
|
|
background-image: if($enable-gradients, none, null);
|
|
border-color: var(--#{$prefix}btn-disabled-border-color);
|
|
opacity: var(--#{$prefix}btn-disabled-opacity);
|
|
@include box-shadow(none);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Link buttons
|
|
//
|
|
|
|
// Make a button look and behave like a link
|
|
.btn-link {
|
|
--#{$prefix}btn-font-weight: #{$font-weight-normal};
|
|
--#{$prefix}btn-color: #{$btn-link-color};
|
|
--#{$prefix}btn-bg: transparent;
|
|
--#{$prefix}btn-border-color: transparent;
|
|
--#{$prefix}btn-hover-color: #{$btn-link-hover-color};
|
|
--#{$prefix}btn-hover-border-color: transparent;
|
|
--#{$prefix}btn-active-color: #{$btn-link-hover-color};
|
|
--#{$prefix}btn-active-border-color: transparent;
|
|
--#{$prefix}btn-disabled-color: #{$btn-link-disabled-color};
|
|
--#{$prefix}btn-disabled-border-color: transparent;
|
|
--#{$prefix}btn-box-shadow: 0 0 0 #000; // Can't use `none` as keyword negates all values when used with multiple shadows
|
|
// --#{$prefix}btn-focus-shadow-rgb: #{$btn-link-focus-shadow-rgb};
|
|
|
|
text-decoration: $link-decoration;
|
|
@if $enable-gradients {
|
|
background-image: none;
|
|
}
|
|
|
|
&:hover,
|
|
&:focus-visible {
|
|
text-decoration: $link-hover-decoration;
|
|
}
|
|
|
|
&:focus-visible {
|
|
color: var(--#{$prefix}btn-color);
|
|
}
|
|
|
|
&:hover {
|
|
color: var(--#{$prefix}btn-hover-color);
|
|
}
|
|
|
|
// No need for an active state here
|
|
}
|
|
|
|
|
|
//
|
|
// Button Sizes
|
|
//
|
|
|
|
.btn-lg {
|
|
@include button-size($btn-padding-y-lg, $btn-padding-x-lg, $btn-font-size-lg, $btn-border-radius-lg);
|
|
}
|
|
|
|
.btn-sm {
|
|
@include button-size($btn-padding-y-sm, $btn-padding-x-sm, $btn-font-size-sm, $btn-border-radius-sm);
|
|
}
|
|
|
|
.btn-check {
|
|
position: absolute;
|
|
clip: rect(0, 0, 0, 0);
|
|
pointer-events: none;
|
|
|
|
&[disabled],
|
|
&:disabled {
|
|
+ .btn {
|
|
pointer-events: none;
|
|
filter: none;
|
|
opacity: .65;
|
|
}
|
|
}
|
|
}
|
|
}
|