From a26948ccfd13043a33634c776e55785803827f25 Mon Sep 17 00:00:00 2001
From: Jiwen Bai <56228105@qq.com>
Date: Tue, 7 May 2024 16:47:03 +0800
Subject: [PATCH] feat: custom icon support fill null close #2654
---
.../spreadsheet/header-action-icons-spec.ts | 29 +++++++++++++++++++
packages/s2-core/src/cell/header-cell.ts | 5 +++-
packages/s2-core/src/common/icons/gui-icon.ts | 6 ++--
.../s2-core/src/common/interface/basic.ts | 6 ++--
4 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/packages/s2-core/__tests__/spreadsheet/header-action-icons-spec.ts b/packages/s2-core/__tests__/spreadsheet/header-action-icons-spec.ts
index 4a9390d360..b9891373d7 100644
--- a/packages/s2-core/__tests__/spreadsheet/header-action-icons-spec.ts
+++ b/packages/s2-core/__tests__/spreadsheet/header-action-icons-spec.ts
@@ -82,6 +82,35 @@ describe('HeaderActionIcons Tests', () => {
});
});
+ test('should custom icon origin fill', async () => {
+ s2.setOptions({
+ customSVGIcons: [
+ {
+ name: 'CustomIcon',
+ svg: ``,
+ },
+ ],
+ headerActionIcons: [
+ {
+ icons: [
+ {
+ name: 'CustomIcon',
+ position: 'right',
+ fill: null,
+ },
+ ],
+ belongsCell: 'rowCell',
+ },
+ ],
+ });
+
+ await s2.render(false);
+
+ s2.facet.getRowCells().forEach((cell) => {
+ expect(get(cell.getActionIcons()[0], 'cfg.fill')).toEqual(undefined);
+ });
+ });
+
test('should default hide icon', async () => {
const innerDefaultHide = jest.fn(() => true);
const defaultHide = jest.fn(() => false);
diff --git a/packages/s2-core/src/cell/header-cell.ts b/packages/s2-core/src/cell/header-cell.ts
index 4eeb6f75a0..84a1282405 100644
--- a/packages/s2-core/src/cell/header-cell.ts
+++ b/packages/s2-core/src/cell/header-cell.ts
@@ -203,7 +203,10 @@ export abstract class HeaderCell<
width: icon?.size,
height: icon?.size,
// 优先级: 单个 icon 颜色配置 > 全部 icon 颜色配置 > 主题 icon 颜色配置 > 文本默认颜色
- fill: options?.fill || icon?.fill || defaultTextFill,
+ fill:
+ options.fill === null
+ ? undefined
+ : options?.fill || icon?.fill || defaultTextFill,
cursor: 'pointer',
};
}
diff --git a/packages/s2-core/src/common/icons/gui-icon.ts b/packages/s2-core/src/common/icons/gui-icon.ts
index 590e57ad6e..fd4d96905b 100644
--- a/packages/s2-core/src/common/icons/gui-icon.ts
+++ b/packages/s2-core/src/common/icons/gui-icon.ts
@@ -16,7 +16,7 @@ const ImageCache: Record = {};
export interface GuiIconCfg extends Omit {
readonly name: string;
- readonly fill?: string;
+ readonly fill?: string | null;
}
/**
@@ -45,7 +45,7 @@ export class GuiIcon extends Group {
public getImage(
name: string,
cacheKey: string,
- fill?: string,
+ fill?: string | null,
): Promise {
return new Promise((resolve, reject): void => {
let svg = getIcon(name);
@@ -123,7 +123,7 @@ export class GuiIcon extends Group {
this.setImageAttrs({ name, fill });
}
- public setImageAttrs(attrs: Partial<{ name: string; fill: string }>) {
+ public setImageAttrs(attrs: Partial<{ name: string; fill: string | null }>) {
let { name, fill } = attrs;
const { iconImageShape: image } = this;
diff --git a/packages/s2-core/src/common/interface/basic.ts b/packages/s2-core/src/common/interface/basic.ts
index c20606702e..b062ac551c 100644
--- a/packages/s2-core/src/common/interface/basic.ts
+++ b/packages/s2-core/src/common/interface/basic.ts
@@ -286,7 +286,7 @@ export interface HeaderIconHoverParams extends HeaderIconClickParams {
}
export interface HeaderActionIconOptions extends HeaderActionIconBaseOptions {
- fill?: string;
+ fill?: string | null;
name: string;
x: number;
y: number;
@@ -296,9 +296,9 @@ export interface HeaderActionIconOptions extends HeaderActionIconBaseOptions {
export type HeaderActionNameOptions = HeaderActionIconBaseOptions & {
/**
* icon 颜色配置
- * @description 优先级: 单个 icon > 主题 icon 配置 > 文本颜色
+ * @description 优先级: 单个 icon > 主题 icon 配置 > 文本颜色,null 则使用图标原有颜色
*/
- fill?: string;
+ fill?: string | null;
/**
* icon 名称