Skip to content
Merged
Changes from all 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
16 changes: 7 additions & 9 deletions packages/ui/src/components/text-shimmer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
active?: boolean
offset?: number
}) => {
const text = createMemo(() => props.text ?? "")
const active = createMemo(() => props.active ?? true)
const offset = createMemo(() => props.offset ?? 0)
const [run, setRun] = createSignal(active())
Expand Down Expand Up @@ -36,17 +37,14 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
clearTimeout(timer)
})

const shimmerSize = createMemo(() => {
const len = Math.max(props.text.length, 1)
return Math.max(300, Math.round(200 + 1400 / len))
})
const len = createMemo(() => Math.max(text().length, 1))
const shimmerSize = createMemo(() => Math.max(300, Math.round(200 + 1400 / len())))

// duration = len × (size - 1) / velocity → uniform perceived sweep speed
const VELOCITY = 0.01375 // ch per ms, ~10% faster than original 0.0125 baseline
const shimmerDuration = createMemo(() => {
const len = Math.max(props.text.length, 1)
const s = shimmerSize() / 100
return Math.max(1000, Math.min(2500, Math.round((len * (s - 1)) / VELOCITY)))
return Math.max(1000, Math.min(2500, Math.round((len() * (s - 1)) / VELOCITY)))
})

return (
Expand All @@ -55,7 +53,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
data-component="text-shimmer"
data-active={active() ? "true" : "false"}
class={props.class}
aria-label={props.text}
aria-label={text()}
style={{
"--text-shimmer-swap": `${swap}ms`,
"--text-shimmer-index": `${offset()}`,
Expand All @@ -65,10 +63,10 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
>
<span data-slot="text-shimmer-char">
<span data-slot="text-shimmer-char-base" aria-hidden="true">
{props.text}
{text()}
</span>
<span data-slot="text-shimmer-char-shimmer" data-run={run() ? "true" : "false"} aria-hidden="true">
{props.text}
{text()}
</span>
</span>
</Dynamic>
Expand Down
Loading