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