Skip to content

Commit 4b195c2

Browse files
authored
feat(theme-generator): add animation (#598)
* feat(theme-generator): add animation * fix(theme-generator): remove unnecessary logic * chore(theme-generator): update animation name
1 parent 439a2d2 commit 4b195c2

File tree

1 file changed

+72
-8
lines changed
  • packages/theme-generator/src/common/StickyThemeDisplay

1 file changed

+72
-8
lines changed
Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
<template>
2-
<div class="sticky-theme" :style="stickyThemeStyle">
3-
<div class="theme-status">
4-
<p class="theme-status-title">{{ title }}</p>
5-
<p class="theme-status-subtitle">{{ subtitleText }}</p>
2+
<div class="sticky-theme" :style="stickyThemeStyle" v-if="!!theme">
3+
<div class="theme-status"></div>
4+
<div v-if="isAnimating" class="theme-status color-transition"></div>
5+
<div class="theme-text">
6+
<p class="theme-text-title">{{ title }}</p>
7+
<p class="theme-text-subtitle">{{ subtitleText }}</p>
68
</div>
79
</div>
810
</template>
911
<script>
10-
import langMixin from "../i18n/mixin";
12+
import langMixin from '../i18n/mixin';
1113
export default {
12-
name: "StickyExport",
14+
name: 'StickyExport',
1315
props: {
1416
top: Number,
1517
theme: {
1618
type: Object,
1719
},
1820
},
1921
mixins: [langMixin],
22+
data() {
23+
return {
24+
isAnimating: false,
25+
brandColor: null,
26+
styleObserver: null,
27+
};
28+
},
2029
computed: {
2130
stickyThemeStyle() {
2231
return {
@@ -30,32 +39,73 @@ export default {
3039
return this.theme.subtitleText;
3140
},
3241
},
42+
mounted() {
43+
this.brandColor = getComputedStyle(document.documentElement).getPropertyValue('--td-brand-color').trim();
44+
this.setupStyleObserver();
45+
},
46+
methods: {
47+
setupStyleObserver() {
48+
this.styleObserver = new MutationObserver(this.checkBrandColorChange);
49+
this.styleObserver.observe(document.documentElement, {
50+
attributes: true,
51+
attributeFilter: ['style', 'class'],
52+
});
53+
},
54+
checkBrandColorChange() {
55+
const newColor = getComputedStyle(document.documentElement).getPropertyValue('--td-brand-color').trim();
56+
if (newColor && newColor !== this.brandColor) {
57+
this.brandColor = newColor;
58+
this.isAnimating = true;
59+
60+
setTimeout(() => {
61+
this.isAnimating = false;
62+
}, 1000);
63+
}
64+
},
65+
},
66+
beforeDestroy() {
67+
if (this.styleObserver) {
68+
this.styleObserver.disconnect();
69+
}
70+
},
3371
};
3472
</script>
73+
3574
<style scoped lang="less">
3675
.sticky-theme {
76+
position: relative;
3777
display: flex;
3878
flex-direction: column;
3979
align-items: center;
4080
padding: 8px;
81+
margin-bottom: 5px;
4182
left: 0;
4283
}
4384
4485
.theme-status {
86+
position: absolute;
4587
background-color: var(--td-brand-color);
88+
transition: background-color 1s ease;
4689
width: 332px;
4790
height: 72px;
4891
padding: 8px 12px;
4992
border-radius: 12px;
93+
z-index: 0;
94+
inset: 0;
95+
}
96+
97+
.theme-text {
98+
width: 100%;
99+
padding: 2px 8px;
100+
z-index: 1;
50101
51102
&-title {
52103
font-size: 20px;
53104
line-height: 24px;
54105
font-weight: 700;
55106
color: #fff;
56107
margin: 0 0 10px 0;
57-
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
58-
"Liberation Mono", monospace;
108+
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
59109
}
60110
61111
&-subtitle {
@@ -65,4 +115,18 @@ export default {
65115
margin: 0;
66116
}
67117
}
118+
119+
.color-transition {
120+
animation: prev-to-current 1s ease;
121+
}
122+
123+
@keyframes prev-to-current {
124+
from {
125+
clip-path: polygon(0 0, 0 0, calc(tan(8deg) * -100vh) 100%, calc(tan(8deg) * -100vh) 100%);
126+
}
127+
128+
to {
129+
clip-path: polygon(0 0, calc((tan(8deg) * 100vh) + 100%) 0, 100% 100%, calc(tan(8deg) * -100vh) 100%);
130+
}
131+
}
68132
</style>

0 commit comments

Comments
 (0)