Skip to content

Commit

Permalink
fix: 处理text组件渐变样式失效的问题 (#785)
Browse files Browse the repository at this point in the history
Co-authored-by: blankzhang <blankzhang@blankzhangdeMac-mini.local>
  • Loading branch information
zym19960704 and blankzhang committed Apr 29, 2024
1 parent a620cf8 commit b16fb4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/text/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@
--f-text-text-color: @text-color-tag-mark;
background:var(--f-hover-color-light) ;
}

&-gradient {
-webkit-background-clip:text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
}
9 changes: 6 additions & 3 deletions components/text/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ export default defineComponent({
setup(props) {
useTheme();

const isGradient = computed(() => {
return props.gradient && props.gradient.from && props.gradient.to;
});

const textClass = computed(() => ({
[prefixCls]: true,
[`${prefixCls}-type--${props.type}`]: props.type,
[`${prefixCls}-size--${props.size}`]: props.size,
[`${prefixCls}-text--strong`]: props.strong,
[`${prefixCls}-text--italic`]: props.italic,
[`${prefixCls}-tag--mark`]: props.tag === 'mark', // 定义mark样式
[`${prefixCls}-gradient`]: isGradient.value,
}));

const gradientStyle = computed(() => {
if (props.gradient && props.gradient.from && props.gradient.to) {
if (isGradient.value) {
const deg = degfy(props.gradient.deg || 0);
return {
backgroundImage: `linear-gradient(${deg}, ${props.gradient.from}, ${props.gradient.to})`,
backgroundClip: 'text',
textFillColor: 'transparent',
};
}
return {};
Expand Down

0 comments on commit b16fb4a

Please sign in to comment.