From 9512fa889c7b7512455ade77afe8cf30e474c4d1 Mon Sep 17 00:00:00 2001 From: GioChkhaidze Date: Sun, 6 Sep 2026 15:52:38 +0000 Subject: [PATCH 1/3] Extract dedup code to shimmer core --- .../ui/src/components/text-shimmer-core.tsx | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 packages/ui/src/components/text-shimmer-core.tsx diff --git a/packages/ui/src/components/text-shimmer-core.tsx b/packages/ui/src/components/text-shimmer-core.tsx new file mode 100644 index 00000000..a85dac00 --- /dev/null +++ b/packages/ui/src/components/text-shimmer-core.tsx @@ -0,0 +1,75 @@ +import { createEffect, createMemo, createSignal, onCleanup, type JSX, type ValidComponent } from "solid-js" +import { Dynamic } from "solid-js/web" + + +export type TextShimmerCoreProps = { + text: string + class?: string + as?: T + active?: boolean + offset?: number + component: string + charSlot: string + bareSlot: string + shimmerSlot: string + swapVar: string + indexVar: string +} + +export const TextShimmerCore = ( + props: TextShimmerCoreProps +) => { + const text = createMemo(() => props.text ?? "") + const active = createMemo(() => props.active ?? true) + const offset = createMemo(() => props.offset ?? 0) + const [run, setRun] = createSignal(active()) + const swap = 220 + let timer: ReturnType | undefined + + createEffect(() => { + if (timer) { + clearTimeout(timer) + timer = undefined + } + + if (active()) { + setRun(true) + return + } + + timer = setTimeout(() => { + timer = undefined + setRun(false) + }, swap) + }) + + onCleanup(() => { + if (!timer) return + clearTimeout(timer) + }) + + return ( + + + + + + + ) +} + +export function buildTextSimmerStyle(swapVar: string, indexVar: string, + swap: number, offset: number) { + return {[swapVar]: `${swap}ms`, [indexVar]: `${offset}` } as JSX.CSSProperties +} From 98d8cc4afcf56cf0fcb817565a82fdbd9caec4b5 Mon Sep 17 00:00:00 2001 From: GioChkhaidze Date: Sun, 6 Sep 2026 16:01:39 +0000 Subject: [PATCH 2/3] Fix shared logic & reuse in shimmer & v2 --- .../ui/src/components/text-shimmer-core.tsx | 9 ++- packages/ui/src/components/text-shimmer.tsx | 65 ++++--------------- .../ui/src/v2/components/text-shimmer-v2.tsx | 65 ++++--------------- 3 files changed, 28 insertions(+), 111 deletions(-) diff --git a/packages/ui/src/components/text-shimmer-core.tsx b/packages/ui/src/components/text-shimmer-core.tsx index a85dac00..b475258d 100644 --- a/packages/ui/src/components/text-shimmer-core.tsx +++ b/packages/ui/src/components/text-shimmer-core.tsx @@ -1,7 +1,6 @@ import { createEffect, createMemo, createSignal, onCleanup, type JSX, type ValidComponent } from "solid-js" import { Dynamic } from "solid-js/web" - export type TextShimmerCoreProps = { text: string class?: string @@ -10,7 +9,7 @@ export type TextShimmerCoreProps = { offset?: number component: string charSlot: string - bareSlot: string + baseSlot: string shimmerSlot: string swapVar: string indexVar: string @@ -55,10 +54,10 @@ export const TextShimmerCore = ( data-active={active() ? "true" : "false"} class={props.class} aria-label={text()} - style={buildTextSimmerStyle(props.swapVar, props.indexVar, swap, offset())} + style={buildTextShimmerStyle(props.swapVar, props.indexVar, swap, offset())} > -