mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-26 04:27:26 +08:00
refactor(theme-chalk): message css var & add getCssVarName (#6488)
* refactor(theme-chalk): message css var & add getCssVarName * Update closable.vue
This commit is contained in:
@ -10,6 +10,7 @@ import { ElMessage } from 'element-plus'
|
||||
const open = () => {
|
||||
ElMessage('this is a message.')
|
||||
}
|
||||
|
||||
const openVn = () => {
|
||||
ElMessage({
|
||||
message: h('p', null, [
|
||||
|
@ -1,7 +1,6 @@
|
||||
@use 'sass:map';
|
||||
|
||||
@use 'mixins/mixins' as *;
|
||||
@use 'mixins/function' as *;
|
||||
@use 'common/var' as *;
|
||||
|
||||
@include b(check-tag) {
|
||||
|
@ -432,6 +432,7 @@ $message: map.merge(
|
||||
(
|
||||
'min-width': 380px,
|
||||
'bg-color': #edf2fc,
|
||||
'border-color': var(--el-border-color-lighter),
|
||||
'padding': 15px 15px 15px 20px,
|
||||
'close-size': 16px,
|
||||
'close-icon-color': var(--el-text-color-placeholder),
|
||||
@ -1245,7 +1246,7 @@ $transition: map.merge(
|
||||
$transition-duration: () !default;
|
||||
$transition-duration: map.merge(
|
||||
(
|
||||
'default': 0.3s,
|
||||
'': 0.3s,
|
||||
'fast': 0.2s,
|
||||
),
|
||||
$transition-duration
|
||||
|
@ -9,21 +9,20 @@
|
||||
}
|
||||
|
||||
@include b(message) {
|
||||
min-width: var(--el-message-min-width);
|
||||
min-width: getCssVar('message', 'min-width');
|
||||
box-sizing: border-box;
|
||||
border-radius: var(--el-border-radius-base);
|
||||
border-width: var(--el-border-width-base);
|
||||
border-style: var(--el-border-style-base);
|
||||
border-color: var(--el-border-color-lighter);
|
||||
border-color: getCssVar('message', 'border-color');
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 20px;
|
||||
transform: translateX(-50%);
|
||||
background-color: var(--el-message-bg-color);
|
||||
transition: opacity 0.3s, transform 0.4s, top 0.4s;
|
||||
background-color: var(--el-message-bg-color);
|
||||
background-color: getCssVar('message', 'bg-color');
|
||||
transition: opacity var(--el-transition-duration), transform 0.4s, top 0.4s;
|
||||
padding: var(--el-message-padding);
|
||||
padding: getCssVar('message', 'padding');
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@ -41,23 +40,26 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@include m(info) {
|
||||
.#{$namespace}-message__content {
|
||||
color: var(--el-message-info-text-color);
|
||||
}
|
||||
}
|
||||
|
||||
@each $type in (success, info, warning, error) {
|
||||
@include m($type) {
|
||||
background-color: map.get($colors, $type, 'light-9');
|
||||
border-color: map.get($colors, $type, 'light-8');
|
||||
|
||||
--el-message-text-color: var(--el-color-#{$type});
|
||||
@include css-var-from-global(
|
||||
('message', 'bg-color'),
|
||||
('color', $type, 'light-9')
|
||||
);
|
||||
@include css-var-from-global(
|
||||
('message', 'border-color'),
|
||||
('color', $type, 'light-8')
|
||||
);
|
||||
@include css-var-from-global(('message', 'text-color'), ('color', $type));
|
||||
|
||||
.#{$namespace}-message__content {
|
||||
color: var(--el-message-text-color);
|
||||
color: getCssVar('message', 'text-color');
|
||||
}
|
||||
}
|
||||
|
||||
& .#{$namespace}-message-icon--#{$type} {
|
||||
color: getCssVar('message', 'text-color');
|
||||
}
|
||||
}
|
||||
|
||||
@include e(icon) {
|
||||
@ -85,21 +87,14 @@
|
||||
right: 15px;
|
||||
transform: translateY(-50%);
|
||||
cursor: pointer;
|
||||
color: var(--el-message-close-icon-color);
|
||||
font-size: var(--el-message-close-size, map.get($message, 'close-size'));
|
||||
color: getCssVar('message', 'close-icon-color');
|
||||
font-size: getCssVar('message', 'close-size');
|
||||
|
||||
&:focus {
|
||||
outline-width: 0;
|
||||
}
|
||||
&:hover {
|
||||
color: var(--el-message-close-hover-color);
|
||||
}
|
||||
}
|
||||
|
||||
@each $type in (success, info, warning, error) {
|
||||
& .#{$namespace}-message-icon--#{$type} {
|
||||
--el-message-text-color: var(--el-color-#{$type});
|
||||
color: var(--el-message-text-color);
|
||||
color: getCssVar('message', 'close-hover-color');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,31 +5,44 @@
|
||||
@use '../common/var' as *;
|
||||
|
||||
@mixin set-css-color-type-light($type, $i) {
|
||||
--el-color-#{$type}-light-#{$i}: #{map.get($colors, $type, 'light-#{$i}')};
|
||||
#{getCssVarName('color', $type, 'light', $i)}: #{map.get(
|
||||
$colors,
|
||||
$type,
|
||||
'light-#{$i}'
|
||||
)};
|
||||
}
|
||||
|
||||
@mixin set-css-color-type($type) {
|
||||
--el-color-#{$type}: #{map.get($colors, $type, 'base')};
|
||||
#{getCssVarName('color', $type)}: #{map.get($colors, $type, 'base')};
|
||||
@each $i in (3, 5, 7, 8, 9) {
|
||||
@include set-css-color-type-light($type, $i);
|
||||
}
|
||||
--el-color-#{$type}-dark-2: #{map.get($colors, $type, 'dark-2')};
|
||||
#{getCssVarName('color', $type, 'dark-2')}: #{map.get(
|
||||
$colors,
|
||||
$type,
|
||||
'dark-2'
|
||||
)};
|
||||
}
|
||||
|
||||
@mixin set-css-var-type($name, $type, $variables) {
|
||||
--el-#{$name}-#{$type}: #{map.get($variables, $type)};
|
||||
#{getCssVarName($name, $type)}: #{map.get($variables, $type)};
|
||||
}
|
||||
|
||||
// set all css var for component by map
|
||||
@mixin set-component-css-var($name, $variables) {
|
||||
@each $attribute, $value in $variables {
|
||||
--el-#{$name}-#{$attribute}: #{$value};
|
||||
@if $attribute == '' {
|
||||
#{getCssVarName($name)}: #{$value};
|
||||
} @else {
|
||||
#{getCssVarName($name, $attribute)}: #{$value};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin set-css-color-rgb($type) {
|
||||
$color: map.get($colors, $type, 'base');
|
||||
--el-color-#{$type}-rgb: #{red($color)}, #{green($color)}, #{blue($color)};
|
||||
#{getCssVarName('color', $type, 'rgb')}: #{red($color)}, #{green($color)},
|
||||
#{blue($color)};
|
||||
}
|
||||
|
||||
// generate css var from existing css var
|
||||
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
|
||||
// join var name
|
||||
// joinVarName('button', 'text-color') => '--el-button-text-color'
|
||||
// joinVarName(('button', 'text-color')) => '--el-button-text-color'
|
||||
@function joinVarName($list) {
|
||||
$name: '--' + config.$namespace;
|
||||
@each $item in $list {
|
||||
@ -54,6 +54,11 @@
|
||||
@return $name;
|
||||
}
|
||||
|
||||
// getCssVarName('button', 'text-color') => '--el-button-text-color'
|
||||
@function getCssVarName($args...) {
|
||||
@return joinVarName($args);
|
||||
}
|
||||
|
||||
// getCssVar('button', 'text-color') => var(--el-button-text-color)
|
||||
@function getCssVar($args...) {
|
||||
@return var(#{joinVarName($args)});
|
||||
|
@ -1,6 +1,7 @@
|
||||
@use 'function' as *;
|
||||
@use '../common/var' as *;
|
||||
@forward 'config';
|
||||
@forward 'function';
|
||||
@use 'config' as *;
|
||||
|
||||
// Break-points
|
||||
|
@ -1,7 +1,6 @@
|
||||
@use 'sass:map';
|
||||
|
||||
@use 'mixins/mixins' as *;
|
||||
@use 'mixins/function' as *;
|
||||
@use 'mixins/var' as *;
|
||||
@use 'common/var' as *;
|
||||
|
||||
|
@ -74,8 +74,7 @@
|
||||
-------------------------- */
|
||||
// refer to this website to get the bezier motion function detail
|
||||
// https://cubic-bezier.com/#p1,p2,p3,p4 (change px as your function parameter)
|
||||
--el-transition-duration: #{map.get($transition-duration, 'default')};
|
||||
--el-transition-duration-fast: #{map.get($transition-duration, 'fast')};
|
||||
@include set-component-css-var('transition-duration', $transition-duration);
|
||||
|
||||
@include set-component-css-var('transition-function', $transition-function);
|
||||
@include set-component-css-var('transition', $transition);
|
||||
|
Reference in New Issue
Block a user