Files
youlai-app/src/styles/_mixins.scss
T

170 lines
3.5 KiB
SCSS

// ==========================================================================
// BEM Mixins
// ==========================================================================
// 提供便捷的 BEM 命名方式,简化 CSS 类的编写
/// BEM Block 基础 mixin
/// @param {String} $name - Block 名称
/// @example
/// @include b(button) { ... }
/// => .button { ... }
@mixin b($name) {
.#{$name} {
@content;
}
}
/// BEM Element mixin
/// @param {String} $name - Element 名称
/// @example
/// @include e(icon) { ... }
/// => .block__icon { ... }
@mixin e($name) {
&__#{$name} {
@content;
}
}
/// BEM Modifier mixin
/// @param {String} $name - Modifier 名称
/// @example
/// @include m(primary) { ... }
/// => .block--primary { ... }
@mixin m($name) {
&--#{$name} {
@content;
}
}
/// 组合使用示例
/// @example
/// @include b(card) {
/// padding: 16rpx;
///
/// @include e(header) {
/// font-weight: bold;
/// }
///
/// @include m(highlight) {
/// background: yellow;
/// }
/// }
/// => .card { padding: 16rpx; }
/// .card__header { font-weight: bold; }
/// .card--highlight { background: yellow; }
// ==========================================================================
// 布局 Mixins
// ==========================================================================
/// Flex 居中布局
@mixin flex-center {
display: flex;
align-items: center;
justify-content: center;
}
/// Flex 两端对齐
@mixin flex-between {
display: flex;
align-items: center;
justify-content: space-between;
}
/// Flex 垂直居中
@mixin flex-col-center {
display: flex;
flex-direction: column;
align-items: center;
}
/// 绝对定位撑满
@mixin absolute-fill {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/// 固定定位撑满
@mixin fixed-fill {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
// ==========================================================================
// 文字 Mixins
// ==========================================================================
/// 文字省略(单行)
@mixin ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/// 文字省略(多行)
/// @param {Number} $lines - 行数
@mixin ellipsis-lines($lines: 2) {
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: $lines;
-webkit-box-orient: vertical;
}
// ==========================================================================
// 安全区域 Mixins
// ==========================================================================
/// 底部安全区域
@mixin safe-area-bottom {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
/// 顶部安全区域
@mixin safe-area-top {
padding-top: constant(safe-area-inset-top);
padding-top: env(safe-area-inset-top);
}
/// 固定底部(带安全区域)
@mixin fixed-bottom {
position: fixed;
right: 0;
bottom: 0;
left: 0;
@include safe-area-bottom;
}
// ==========================================================================
// 暗黑模式 Mixins
// ==========================================================================
/// 暗黑模式样式
/// @example
/// @include when-dark {
/// background: #1f2937;
/// }
@mixin when-dark {
:global(.wot-theme-dark) & {
@content;
}
}
/// 浅色模式样式
/// @example
/// @include when-light {
/// background: #ffffff;
/// }
@mixin when-light {
:global(:not(.wot-theme-dark)) & {
@content;
}
}