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

feat: add selectFillMode config in theme.selectionStyle #2147

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "feat: add selectFillMode config in theme.selectionStyle #2132 #2027",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
8 changes: 8 additions & 0 deletions docs/assets/option/en/common/theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,11 @@ The highlight color of the entire column when selected
{{ use: common-color(
prefix = ${prefix}
) }}

##${prefix} selectFillMode(boolean)
Rui-Sun marked this conversation as resolved.
Show resolved Hide resolved
Fill color rules for the selected area
- `cover`: The fill color of the selected area will cover the background color of the cell (usually a color value with transparency)
Rui-Sun marked this conversation as resolved.
Show resolved Hide resolved
- `contain`: The fill color of the selected area will replace the background color of the cell
{{ use: common-color(
prefix = ${prefix}
) }}
8 changes: 8 additions & 0 deletions docs/assets/option/zh/common/theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,11 @@ body 单元格的样式配置
{{ use: common-color(
prefix = ${prefix}
) }}

##${prefix} selectFillMode(boolean)
选中区域的填充色规则
- `cover`: 选中区域的填充色会覆盖单元格的背景色(常用带透明度的颜色值)
- `contain`: 选中区域的填充色会替换单元格的背景色
{{ use: common-color(
prefix = ${prefix}
) }}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function createCellSelectBorder(
const bodyClickLineWidth = theme.selectionStyle?.cellBorderLineWidth;
const rect = createRect({
pickable: false,
fill: (theme.selectionStyle?.cellBgColor as any) ?? 'rgba(0, 0, 255,0.1)',
fill:
theme.selectionStyle?.selectFillMode === 'contain'
? false
: (theme.selectionStyle?.cellBgColor as any) ?? 'rgba(0, 0, 255,0.1)',

lineWidth: bodyClickLineWidth as number,
// stroke: bodyClickBorderColor as string,
Expand Down
8 changes: 8 additions & 0 deletions packages/vtable/src/state/select/is-cell-select-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export function isCellSelected(state: StateManager, col: number, row: number, ce
selectMode = undefined;
}
}
} else if (state.table.theme.selectionStyle.selectFillMode === 'contain') {
for (let i = 0; i < ranges.length; i++) {
const range = ranges[i];
if (range.start.col <= col && range.start.row <= row && range.end.col >= col && range.end.row >= row) {
selectMode = 'cellBgColor';
break;
}
}
}
return selectMode;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/vtable/src/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ export class TableTheme implements ITableThemeDefine {
},
get inlineRowBgColor(): string | undefined {
return selectionStyle?.inlineRowBgColor;
},
get selectFillMode(): 'cover' | 'contain' {
return selectionStyle?.selectFillMode ?? 'cover';
}
};
}
Expand Down Expand Up @@ -817,6 +820,12 @@ export class TableTheme implements ITableThemeDefine {
: undefined) ??
undefined
);
},
get cellBgColor(): ColorPropertyDefine | undefined {
if (that.selectionStyle.selectFillMode === 'contain') {
return style.select?.cellBgColor ?? that.selectionStyle.cellBgColor ?? undefined;
}
return undefined;
}
};
// }
Expand Down
2 changes: 2 additions & 0 deletions packages/vtable/src/ts-types/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ThemeStyle = ITextStyleOption & {
select?: {
inlineRowBgColor?: ColorPropertyDefine; //交互所在整行的背景颜色
inlineColumnBgColor?: ColorPropertyDefine; //交互所在整列的背景颜色
cellBgColor?: ColorPropertyDefine; //交互所在单元格的背景颜色
};
frameStyle?: FrameStyle;
};
Expand Down Expand Up @@ -142,6 +143,7 @@ export interface ITableThemeDefine {
cellBgColor?: string; //选择框背景颜色
inlineRowBgColor?: string; //交互所在整行的背景颜色
inlineColumnBgColor?: string; //交互所在整列的背景颜色
selectFillMode?: 'cover' | 'contain'; //选择框填充模式,cover表示选择框背景色覆盖在表格上(需要配饰透明度),contain表示背景色替换原有单元格的背景色
};

// style for axis
Expand Down
Loading