amis2/scss/_mixins.scss
吴多益 33686a375e
SCSS 基于 CSS custom properties 重构,支持通过配置来控制展现风格 (#1190)
* 使用自定义 css 属性初步,支持大部分组件的展现

* button 大部分可以看了

* cxd 和 dark 大部分正常

* 修复一些细节样式错误;补充 css 变量的文档

* 修复几个脚本发现的错误

* 完善一下注释

* 修复一些样式不一致问题

* 修复可能存在的 css xss

* 恢复 font-variant 功能

* 修复绝大部分 @if 相关的问题

* 恢复之前的注释

* 修复小错误,并将所有 background-color 改成 background,这样就能设置渐变色

* 修复 button group 在 cxd 下不一致问题

* 缩小查看配置和复制配置的宽度,留出更多空间

* 修复一些潜在的错误

* 恢复 utilities 中 label 背景色的设置

* 修复错误的 css 变量

* 补充 IE11 Variables Polyfill
2020-12-21 10:08:40 +08:00

453 lines
8.8 KiB
SCSS
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 媒体查询最小阈值
@mixin media-breakpoint-up($name, $breakpoints: $breakpoints) {
$min: breakpoint-min($name, $breakpoints);
@if $min {
@media (min-width: $min) {
@content;
}
} @else {
@content;
}
}
//媒体查询最大阈值
@mixin media-breakpoint-down($name, $breakpoints: $breakpoints) {
$max: breakpoint-max($name, $breakpoints);
@if $max {
@media (max-width: $max) {
@content;
}
} @else {
@content;
}
}
//媒体查询中间阈值
@mixin media-breakpoint-between($min, $max, $breakpoints: $breakpoints) {
$min: breakpoint-min($min, $breakpoints);
$max: breakpoint-max($max, $breakpoints);
@media (min-width: $min) and (max-width: $max) {
@content;
}
}
@mixin media-device($name, $devices: $devices) {
$n: map-get($devices, $name);
@media #{$n} {
@content;
}
}
@mixin clearfix() {
&::before,
&::after {
display: table;
content: '';
}
&::after {
clear: both;
}
}
// @deprecated 不建议用了
@mixin color-schema($bg-color: #555, $percent: 15%, $sat-percent: 100%) {
background: saturate(darken($bg-color, $percent), $sat-percent);
}
// @deprecated 不建议用了
@mixin color-schema-lt($bg-color: #555, $percent: 15%, $sat-percent: 100%) {
background: desaturate(lighten($bg-color, $percent), $sat-percent);
}
// @deprecated 不建议用了
@mixin color-variant(
$bg-color: #555,
$lt-percent: 10%,
$lter-percent: 15%,
$dk-percent: 10%,
$dker-percent: 15%
) {
background: $bg-color;
&.lt,
& .lt {
@include color-schema-lt($bg-color, $lt-percent, 2.5%);
}
&.lter,
& .lter {
@include color-schema-lt($bg-color, $lter-percent, 5%);
}
&.dk,
& .dk {
@include color-schema($bg-color, $dk-percent, 2.5%);
}
&.dker,
& .dker {
@include color-schema($bg-color, $dker-percent, 5%);
}
&.bg,
& .bg {
background: $bg-color;
}
}
// @deprecated 不建议用了
@mixin font-variant($bg-color) {
$font-color: desaturate(lighten($bg-color, 40%), 10%);
$link-color: desaturate(lighten($bg-color, 50%), 10%);
$hover-color: #fff;
color: $font-color;
& a,
& .#{$ns}Button--link {
color: $link-color;
&:hover {
color: $hover-color;
}
}
& .open > a {
&,
&:hover,
&:focus {
color: $hover-color;
}
}
& .text-muted {
color: darken($text-color, 10%) !important;
}
& .text-lt {
color: lighten($text-color, 25%) !important;
}
// &.auto,
// & .auto {
// & .list-group-item {
// border-color: darken($bg-color, 5%) !important;
// background: transparent;
// &:hover,
// &:focus,
// &:active,
// &.active {
// @include color-schema($bg-color, 5%, 2.5% !important);
// }
// }
// }
}
// @deprecated 不建议用了
@mixin text-wariant($bg-color, $name) {
a.bg-#{'' + $name}:hover {
background: darken($bg-color, 5%);
}
a.text-#{'' + $name}:hover {
color: darken($bg-color, 5%);
}
.text-#{'' + $name} {
color: $bg-color;
}
.text-#{'' + $name}-lt {
color: darken($bg-color, 5%);
}
.text-#{'' + $name}-lter {
color: darken($bg-color, 10%);
}
.text-#{'' + $name}-dk {
color: darken($bg-color, 5%);
}
.text-#{'' + $name}-dker {
color: darken($bg-color, 10%);
}
}
@mixin hover {
&:hover {
@content;
}
}
@mixin focus {
&:focus {
@content;
}
}
@mixin hover-focus {
&:hover:focus {
@content;
}
}
@mixin hover-active {
&:hover:active {
@content;
}
}
@mixin button-size(
$padding-y,
$padding-x,
$font-size,
$line-height,
$border-radius,
$height: auto,
$iconWdith: px2rem(20px)
) {
padding: $padding-y $padding-x;
font-size: $font-size;
line-height: $line-height;
border-radius: $border-radius;
height: $height;
.#{$ns}Button-icon:first-child:not(:last-child):not(.pull-right),
> svg.icon:not(:last-child):not(.pull-right),
> .pull-left {
margin-right: $padding-x;
}
.#{$ns}Button-icon:last-child:not(:first-child):not(.pull-left),
> .pull-right {
margin-left: $padding-x;
}
}
@mixin button-variant(
$background,
$border: $background,
$color: $white,
$hover-background: darken($background, 7.5%),
$hover-border: darken($border, 10%),
$hover-color: $color,
$active-background: darken($background, 10%),
$active-border: darken($border, 12.5%),
$active-color: $color
) {
color: $color;
background: $background;
border-color: $border;
box-shadow: var(--Button-boxShadow);
@include hover {
// todo: 无法支持 css 变量
// @if ($color != $hover-color) {
color: $hover-color;
// }
// @if ($background != $hover-background) {
background: $hover-background;
// }
// @if ($border != $hover-border) {
border-color: $hover-border;
// }
}
// @include focus {
// color: $color;
// background: $background;
// border-color: $border;
// box-shadow: var(--Button-boxShadow);
// }
@include hover-focus {
// color: $hover-color;
// background: $hover-background;
// border-color: $hover-border;
box-shadow: var(--Button-boxShadow);
}
&:active,
&.is-active {
@if ($active-color != $color) {
color: $active-color;
}
@if ($active-background != $background) {
background: $active-background;
}
@if ($active-border != $border) {
border-color: $active-border;
}
}
&.is-disabled,
&:disabled {
@if variable-exists(Button-onDisabled-bg) and
$Button-onDisabled-bg !=
$background
{
background: $Button-onDisabled-bg;
}
@if variable-exists(Button-onDisabled-color) and
$Button-onDisabled-color !=
$color
{
color: $Button-onDisabled-color;
}
@if variable-exists(Button-onDisabled-borderColor) and
var(--Button-onDisabled-borderColor) !=
$border
{
border-color: var(--Button-onDisabled-borderColor);
}
}
}
@mixin input-clear {
padding: px2rem(3px);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
margin-left: auto;
svg {
fill: var(--Form-input-iconColor);
top: 0;
width: px2rem(10px);
height: px2rem(10px);
}
&:hover svg {
fill: var(--Form-input-onHover-iconColor);
}
}
@mixin input-input {
display: flex;
background: var(--Form-input-bg);
border: var(--Form-input-borderWidth) solid var(--Form-input-borderColor);
border-radius: var(--Form-input-borderRadius);
// height: var(--Form-input-height);
line-height: var(--Form-input-lineHeight);
padding: var(--Form-input-paddingY) var(--Form-input-paddingX);
font-size: var(--Form-input-fontSize);
flex-wrap: wrap;
justify-content: flex-start;
input {
flex-basis: px2rem(80px);
flex-grow: 1;
outline: none;
background: transparent;
border: none;
color: var(--Form-input-color);
width: 100%;
height: calc(var(--Form-input-lineHeight) * var(--Form-input-fontSize));
&::placeholder {
color: var(--Form-input-placeholderColor);
user-select: none;
}
}
}
@mixin input-text {
position: relative;
max-width: 100%;
&.is-inline {
display: inline-block;
width: var(--Form-control-widthBase);
}
&-input {
@include input-input();
}
&.is-error > &-input {
border-color: var(--Form-input-onError-borderColor);
background: var(--Form-input-onError-bg);
}
&.is-focused > &-input {
border-color: var(--Form-input-onFocused-borderColor);
box-shadow: var(--Form-input-boxShadow);
background: var(--Form-input-onFocused-bg);
}
&.is-error.is-focused > &-input {
border-color: var(--Form-input-onError-borderColor);
}
&.is-disabled > &-input {
color: var(--text--muted-color);
background: var(--Form-input-onDisabled-bg);
border-color: var(--Form-input-onDisabled-borderColor);
}
&-spinner {
line-height: calc(
var(--Form-input-lineHeight) * var(--Form-input-fontSize)
);
}
&-clear {
@include input-clear();
}
// 需要能撑开
@include media-breakpoint-up(sm) {
&.#{$ns}Form-control--sizeXs > &-input,
&.#{$ns}Form-control--sizeSm > &-input,
&.#{$ns}Form-control--sizeMd > &-input,
&.#{$ns}Form-control--sizeLg > &-input {
min-width: 100%;
display: inline-flex;
}
}
}
@mixin checkboxes-placeholder {
height: var(--Form-input-height);
line-height: var(--Form-input-lineHeight);
font-size: var(--Form-input-fontSize);
padding: calc(
(
var(--Form-input-height) - var(--Form-input-lineHeight) *
var(--Form-input-fontSize)
) / 2
)
var(--gap-sm);
color: var(--text--muted-color);
}
@mixin label-variant($color) {
background: $color;
// todo不支持了
// &[href] {
// &:hover,
// &:focus {
// background: darken($color, 10%);
// }
// }
}
@mixin icon-color {
color: var(--icon-color);
&:hover {
color: var(--icon-onHover-color);
}
}