Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(button): add ghost's cssvars for button #2235

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/theme/src/base/reset.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
@import '../custom.less';
@import './basic-var.less';

// 为了防止这些图标失去默认值,需要全局设置默认值

// 为了防止这些图标失去默认值,需要全局设置默认值 todo:以下是否有必要保留?
.tiny-icon-success {
fill: #5cb300;
}
Expand All @@ -34,6 +33,23 @@
.tiny-icon-text-type {
fill: #9185f0;
}

// .tiny-icon-loading 类名的动画效果。 它出现在多个组件中,故抽取到一起。
.@{css-prefix-iconfont}-loading {
line-height: 1;
animation: rotating 2s linear infinite;
}

@keyframes rotating {
0% {
transform: rotateZ(0deg);
}

100% {
transform: rotateZ(360deg);
}
}

// 高亮节点
.tiny-hl-query-node {
color: var(--ti-common-color-text-highlight) !important;
Expand Down
71 changes: 57 additions & 14 deletions packages/theme/src/button/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@
background-color: e(@bg);
border-color: e(@border);
}
// 幽灵 按钮 优先级为:两级类名
.color-ghost-mixin(@theme) {
@c: %('var(--tv-Button-text-color-ghost-%a)', @theme);
@border: %('var(--tv-Button-border-color-ghost-%a)', @theme);

color: e(@c);
border-color: e(@border);
}
// 激活态: 叠加到主题和plain 状态上。
.color-active-mixin(@theme, @plain) {
@bg: %('var(--tv-Button-bg-color%a-active-%a)', @plain, @theme);
@border: %('var(--tv-Button-border%a-color-active-%a)', @plain, @theme);
@border: %('var(--tv-Button-border-color%a-active-%a)', @plain, @theme);

&:active,
&:focus,
Expand All @@ -98,69 +106,104 @@
border-color: e(@border);
}
}
// 激活态: 叠加到 ghost 状态上。
.color-ghost-active-mixin(@theme) {
@border: %('var(--tv-Button-border-color-ghost-active-%a)', @theme);

&:active,
&:focus,
&:hover,
&.is-active {
border-color: e(@border);
}
}

&.@{button-prefix-cls}--default {
.color-theme-mixin(default);
.color-active-mixin(default, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(default);
.color-active-mixin(default, -plain);
}

&.is-ghost {
.color-ghost-mixin(default);
.color-ghost-active-mixin(default);
}
}
&.@{button-prefix-cls}--primary {
.color-theme-mixin(primary);
.color-active-mixin(primary, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(primary);
.color-active-mixin(primary, -plain);
}

&.is-ghost {
.color-ghost-mixin(primary);
.color-ghost-active-mixin(primary);
}
}
&.@{button-prefix-cls}--success {
.color-theme-mixin(success);
.color-active-mixin(success, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(success);
.color-active-mixin(success, -plain);
}

&.is-ghost {
.color-ghost-mixin(success);
.color-ghost-active-mixin(success);
}
}
&.@{button-prefix-cls}--warning {
.color-theme-mixin(warning);
.color-active-mixin(warning, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(warning);
.color-active-mixin(warning, -plain);
}

&.is-ghost {
.color-ghost-mixin(warning);
.color-ghost-active-mixin(warning);
}
}
&.@{button-prefix-cls}--danger {
.color-theme-mixin(danger);
.color-active-mixin(danger, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(danger);
.color-active-mixin(danger, -plain);
}

&.is-ghost {
.color-ghost-mixin(danger);
.color-ghost-active-mixin(danger);
}
}
&.@{button-prefix-cls}--info {
.color-theme-mixin(info);
.color-active-mixin(info, e(''));

&.is-plain,
&.is-ghost {
&.is-plain {
.color-plain-mixin(info);
.color-active-mixin(info, -plain);
}

&.is-ghost {
.color-ghost-mixin(info);
.color-ghost-active-mixin(info);
}
}

// ghost: 默认继承plain的状态, 但是bg 强制为透明,比禁用还高 优先级为:六级类名
// ghost:bg 强制为透明,比禁用还高 优先级为:六级类名
&.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost {
background-color: var(--tv-Button-bg-color-ghost);
Comment on lines +206 to 208
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor to Reduce Selector Specificity

The selector &.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost uses six repetitions of .is-ghost to increase specificity. This approach can reduce maintainability and readability of the code.

Consider refactoring to reduce the specificity without relying on repeated class names. One option is to restructure the CSS to avoid the need for such high specificity or to use more specific parent selectors if applicable.

For example, you could adjust the CSS hierarchy or use a more specific attribute selector:

- &.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost.is-ghost {
+ &.button-container &.is-ghost {

Or, if appropriate, introduce a modifier class that explicitly indicates the higher specificity:

&.is-ghost-high {
  background-color: var(--tv-Button-bg-color-ghost);
}

And apply this class where needed in the HTML:

<button class="tiny-button is-ghost is-ghost-high">Ghost Button</button>

This approach improves code maintainability by avoiding excessive class chaining.

}
Expand Down
50 changes: 47 additions & 3 deletions packages/theme/src/button/vars.less
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,41 @@
// info 主题时按钮朴素边框色
--tv-Button-border-color-plain-info: var(--tv-color-act-info-border-active-1);

// 幽灵态和plain是平级的关系. 如果同时存在,优先级不能保证稳定。

// 幽灵时按钮背景色
--tv-Button-bg-color-ghost: transparent; // 只影响 bg 和 text-color, 且bg全部为透明.

// 默认时按钮幽灵文本色
--tv-Button-text-color-ghost-default: var(--tv-color-text-secondary);
// 默认时按钮幽灵边框色
--tv-Button-border-color-ghost-default: #808080; // 没有这个边框色,可能设计师搞错了。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace hardcoded color #808080 with a CSS variable

The variable --tv-Button-border-color-ghost-default uses a hardcoded color #808080. For consistency and theming flexibility, consider defining and using a CSS variable for this color.

Apply this diff to replace the hardcoded color:

- --tv-Button-border-color-ghost-default: #808080; // 没有这个边框色,可能设计师搞错了。
+ --tv-Button-border-color-ghost-default: var(--tv-color-border-ghost-default); // Define this variable accordingly.

If --tv-color-border-ghost-default does not exist, please add it to the variables list or consult with the design team to determine the appropriate value.

Committable suggestion was skipped due to low confidence.


// primary 主题时按钮幽灵文本色
--tv-Button-text-colorghostn-primary: var(--tv-color-act-primary-text);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in variable name --tv-Button-text-colorghostn-primary

There's a typo in the variable name --tv-Button-text-colorghostn-primary. It should be --tv-Button-text-color-ghost-primary to maintain consistency with the naming convention and other variable names.

Apply this diff to correct the variable name:

- --tv-Button-text-colorghostn-primary: var(--tv-color-act-primary-text);
+ --tv-Button-text-color-ghost-primary: var(--tv-color-act-primary-text);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
--tv-Button-text-colorghostn-primary: var(--tv-color-act-primary-text);
--tv-Button-text-color-ghost-primary: var(--tv-color-act-primary-text);

// primary 主题时按钮幽灵边框色
--tv-Button-border-color-ghost-primary: var(--tv-color-act-primary-border-light);

// success 主题时按钮幽灵文本色
--tv-Button-text-color-ghost-success: var(--tv-color-act-success-text);
// success 主题时按钮幽灵边框色
--tv-Button-border-color-ghost-success: var(--tv-color-act-success-border);

// warning 主题时按钮幽灵文本色
--tv-Button-text-color-ghost-warning: var(--tv-color-act-warning-text);
// warning 主题时按钮幽灵边框色
--tv-Button-border-color-ghost-warning: var(--tv-color-act-warning-border);

// danger 主题时按钮幽灵文本色
--tv-Button-text-color-ghost-danger: var(--tv-color-act-danger-text);
// danger 主题时按钮幽灵边框色
--tv-Button-border-color-ghost-danger: var(--tv-color-act-danger-border);

// info 主题时按钮幽灵文本色
--tv-Button-text-color-ghost-info: var(--tv-color-act-info-text);
// info 主题时按钮幽灵边框色
--tv-Button-border-color-ghost-info: var(--tv-color-act-info-border);

//------------------------------------------------------------------------------ // level 2结束 ----------------

// 默认时按钮激活的背景色
Expand All @@ -181,7 +213,9 @@
// 默认时按钮激活的朴素背景色
--tv-Button-bg-color-plain-active-default: var(--tv-color-bg);
// 默认时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-default: var(--tv-color-bg); // 朴素激活都无边框
--tv-Button-border-color-plain-active-default: var(--tv-color-bg); // 朴素激活都无边框,所以等于背景色。
// 默认时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-default: #dbdbdb; // 暂无对应变量
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace hardcoded color value with a CSS variable

The variable --tv-Button-border-color-ghost-active-default uses a hardcoded color #dbdbdb. For consistency and easier theming, consider using a CSS variable instead.

Apply this diff to replace the hardcoded color:

- --tv-Button-border-color-ghost-active-default: #dbdbdb; // 暂无对应变量
+ --tv-Button-border-color-ghost-active-default: var(--tv-color-border-ghost-active-default); // Define this variable accordingly

Please work with the design team to define an appropriate variable for this color.

Committable suggestion was skipped due to low confidence.


// primary 主题时按钮激活的背景色
--tv-Button-bg-color-active-primary: var(--tv-color-act-primary-bg-active);
Expand All @@ -191,6 +225,8 @@
--tv-Button-bg-color-plain-active-primary: var(--tv-color-act-primary-bg-white-active);
// primary 主题时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-primary: var(--tv-color-act-primary-bg-white-active); // 无边框
// primary 主题时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-primary: var(--tv-color-act-primary-border-light-active-1);

// success 主题时按钮激活的背景色
--tv-Button-bg-color-active-success: var(--tv-color-act-success-bg-active);
Expand All @@ -200,6 +236,8 @@
--tv-Button-bg-color-plain-active-success: var(--tv-color-act-success-bg-light-active);
// success 主题时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-success: var(--tv-color-act-success-bg-light-active); // 无边框
// success 主题时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-success: var(--tv-color-act-success-border-active-1);

// warning 主题时按钮激活的背景色
--tv-Button-bg-color-active-warning: var(--tv-color-act-warning-bg-active);
Expand All @@ -209,6 +247,8 @@
--tv-Button-bg-color-plain-active-warning: var(--tv-color-act-warning-bg-light-active);
// warning 主题时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-warning: var(--tv-color-act-warning-bg-light-active); // 无边框
// warning 主题时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-warning: var(--tv-color-act-warning-border-active-1);

// danger 主题时按钮激活的背景色
--tv-Button-bg-color-active-danger: var(--tv-color-act-danger-bg-active);
Expand All @@ -218,6 +258,8 @@
--tv-Button-bg-color-plain-active-danger: var(--tv-color-act-danger-bg-light-active);
// danger 主题时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-danger: var(--tv-color-act-danger-bg-light-active);
// danger 主题时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-danger: var(--tv-color-act-danger-border-active-1);

// info 主题时按钮激活的背景色
--tv-Button-bg-color-active-info: var(--tv-color-act-info-bg-active);
Expand All @@ -226,10 +268,12 @@
// info 主题时按钮激活的朴素背景色
--tv-Button-bg-color-plain-active-info: var(--tv-color-act-info-bg-light-active);
// info 主题时按钮激活的朴素边框色
--tv-Button-border-color-plain-active-info: var(--tv-color-act-info-bg-light-active); // level3 结束------
--tv-Button-border-color-plain-active-info: var(--tv-color-act-info-bg-light-active);
// info 主题时按钮激活的幽灵边框色
--tv-Button-border-color-ghost-active-info: var(--tv-color-act-info-border-active-1); // level3 结束------

// 禁用时按钮文本色
--tv-Button-text-color-disabled: var(--tv-color-text-disabled); // 目前主题, disabled优先级高,所以变量少
--tv-Button-text-color-disabled: var(--tv-color-text-disabled); // 目前规则下,disabled优先级最高,所以变量少
// 禁用时按钮背景色
--tv-Button-bg-color-disabled: var(--tv-color-bg-disabled);
// 禁用时按钮边框色
Expand Down
34 changes: 9 additions & 25 deletions packages/theme/src/float-button/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
border-image: initial;
border-radius: var(--ti-float-button-border-radius);
background: var(--ti-float-button-normal-background-color);
box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
box-shadow:
0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 9px 28px 8px rgba(0, 0, 0, 0.05);
transition:
border 0.3s ease 0s,
color 0.3s ease 0s,
Expand All @@ -54,7 +57,7 @@
vertical-align: text-top;
}

&>img {
& > img {
margin-right: 4px;
vertical-align: middle;
}
Expand Down Expand Up @@ -129,7 +132,7 @@
var(--ti-float-button-normal-disabled-bg-color));
}

&+& {
& + & {
margin-left: 8px;
}

Expand Down Expand Up @@ -159,12 +162,9 @@
.@{svg-prefix-cls} {
fill: var(--ti-float-button-normal-text-color);
}


}
}


&.is-icon {
display: inline-flex;
justify-content: center;
Expand Down Expand Up @@ -457,7 +457,7 @@
var(--ti-float-button-size-large-min-width),
);

&+& {
& + & {
margin-left: var(--ti-float-button-size-large-margin-left);
}
}
Expand All @@ -469,7 +469,7 @@
var(--ti-float-button-size-medium-min-width),
);

&+& {
& + & {
margin-left: var(--ti-float-button-size-medium-margin-left);
}
}
Expand All @@ -481,7 +481,7 @@
var(--ti-float-button-size-small-min-width),
);

&+& {
& + & {
margin-left: var(--ti-float-button-size-small-margin-left);
}
}
Expand All @@ -494,19 +494,3 @@
);
}
}

.@{css-prefix-iconfont}-loading {
font-size: var(--ti-common-font-size-1);
line-height: 1;
animation: rotating 2s linear infinite;
}

@keyframes rotating {
0% {
transform: rotateZ(0deg);
}

100% {
transform: rotateZ(360deg);
}
}
Loading