refactor: switch shine text to CSS shimmer

This commit is contained in:
Bohdan Triapitsyn
2026-04-03 19:38:37 +03:00
parent 246464a325
commit 2c56cb021f
2 changed files with 107 additions and 16 deletions
+12 -16
View File
@@ -21,23 +21,19 @@ const variants = [
{
variant: "shine",
component: ({ children, className, ...props }) => (
<motion.span
{...props}
className={cn(
"bg-[linear-gradient(110deg,color-mix(in_srgb,var(--surface-muted-foreground)_45%,transparent),35%,var(--surface-foreground),50%,color-mix(in_srgb,var(--surface-muted-foreground)_45%,transparent),75%,color-mix(in_srgb,var(--surface-muted-foreground)_45%,transparent))]",
"bg-[length:200%_100%] bg-clip-text text-transparent",
className
)}
initial={{ backgroundPosition: "200% 0" }}
animate={{ backgroundPosition: "-200% 0" }}
transition={{
repeat: Number.POSITIVE_INFINITY,
duration: 2,
ease: "linear",
}}
<span
{...props}
data-component="oc-text-shimmer"
data-active="true"
className={className}
>
{children}
</motion.span>
<span data-slot="text-shimmer-char">
<span data-slot="text-shimmer-char-base">{children}</span>
<span data-slot="text-shimmer-char-shimmer" data-run="true" aria-hidden="true">
{children}
</span>
</span>
</span>
),
},
{
+95
View File
@@ -287,6 +287,101 @@ textarea[data-chat-input="true"]:focus-visible {
}
}
[data-component="oc-text-shimmer"] {
--oc-text-shimmer-step: 45ms;
--oc-text-shimmer-duration: 1200ms;
--oc-text-shimmer-angle: 90deg;
--oc-text-shimmer-spread: 5.2ch;
--oc-text-shimmer-size: 360%;
--oc-text-shimmer-base-color: color-mix(in srgb, var(--surface-muted-foreground) 75%, transparent);
--oc-text-shimmer-peak-color: var(--surface-foreground);
--oc-text-shimmer-sweep: linear-gradient(
var(--oc-text-shimmer-angle),
transparent calc(50% - var(--oc-text-shimmer-spread)),
var(--oc-text-shimmer-peak-color) 50%,
transparent calc(50% + var(--oc-text-shimmer-spread))
);
--oc-text-shimmer-base: linear-gradient(var(--oc-text-shimmer-base-color), var(--oc-text-shimmer-base-color));
}
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char"] {
display: inline-grid;
white-space: inherit;
font: inherit;
letter-spacing: inherit;
line-height: inherit;
}
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-base"],
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
grid-area: 1 / 1;
white-space: inherit;
font: inherit;
letter-spacing: inherit;
line-height: inherit;
}
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-base"] {
color: inherit;
opacity: 0;
}
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
color: var(--surface-muted-foreground);
opacity: 1;
}
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] {
animation-name: oc-text-shimmer-sweep;
animation-duration: var(--oc-text-shimmer-duration);
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-fill-mode: both;
animation-delay: calc(var(--oc-text-shimmer-step) * -1);
will-change: background-position;
}
@keyframes oc-text-shimmer-sweep {
0% {
background-position:
100% 0,
0 0;
}
100% {
background-position:
0% 0,
0 0;
}
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
color: transparent;
-webkit-text-fill-color: transparent;
background-image: var(--oc-text-shimmer-sweep), var(--oc-text-shimmer-base);
background-size:
var(--oc-text-shimmer-size) 100%,
100% 100%;
background-position:
100% 0,
0 0;
background-repeat: no-repeat;
-webkit-background-clip: text;
background-clip: text;
}
}
@media (prefers-reduced-motion: reduce) {
[data-component="oc-text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
animation: none !important;
color: inherit;
-webkit-text-fill-color: currentColor;
background-image: none;
}
}
@keyframes gradient-shimmer {
0% {
stop-color: currentColor;