fix(app): text-shimmer undefined length (#16475)
This commit is contained in:
@@ -8,6 +8,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
|
|||||||
active?: boolean
|
active?: boolean
|
||||||
offset?: number
|
offset?: number
|
||||||
}) => {
|
}) => {
|
||||||
|
const text = createMemo(() => props.text ?? "")
|
||||||
const active = createMemo(() => props.active ?? true)
|
const active = createMemo(() => props.active ?? true)
|
||||||
const offset = createMemo(() => props.offset ?? 0)
|
const offset = createMemo(() => props.offset ?? 0)
|
||||||
const [run, setRun] = createSignal(active())
|
const [run, setRun] = createSignal(active())
|
||||||
@@ -36,17 +37,14 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
|
|||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
})
|
})
|
||||||
|
|
||||||
const shimmerSize = createMemo(() => {
|
const len = createMemo(() => Math.max(text().length, 1))
|
||||||
const len = Math.max(props.text.length, 1)
|
const shimmerSize = createMemo(() => Math.max(300, Math.round(200 + 1400 / len())))
|
||||||
return Math.max(300, Math.round(200 + 1400 / len))
|
|
||||||
})
|
|
||||||
|
|
||||||
// duration = len × (size - 1) / velocity → uniform perceived sweep speed
|
// duration = len × (size - 1) / velocity → uniform perceived sweep speed
|
||||||
const VELOCITY = 0.01375 // ch per ms, ~10% faster than original 0.0125 baseline
|
const VELOCITY = 0.01375 // ch per ms, ~10% faster than original 0.0125 baseline
|
||||||
const shimmerDuration = createMemo(() => {
|
const shimmerDuration = createMemo(() => {
|
||||||
const len = Math.max(props.text.length, 1)
|
|
||||||
const s = shimmerSize() / 100
|
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 (
|
return (
|
||||||
@@ -55,7 +53,7 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
|
|||||||
data-component="text-shimmer"
|
data-component="text-shimmer"
|
||||||
data-active={active() ? "true" : "false"}
|
data-active={active() ? "true" : "false"}
|
||||||
class={props.class}
|
class={props.class}
|
||||||
aria-label={props.text}
|
aria-label={text()}
|
||||||
style={{
|
style={{
|
||||||
"--text-shimmer-swap": `${swap}ms`,
|
"--text-shimmer-swap": `${swap}ms`,
|
||||||
"--text-shimmer-index": `${offset()}`,
|
"--text-shimmer-index": `${offset()}`,
|
||||||
@@ -65,10 +63,10 @@ export const TextShimmer = <T extends ValidComponent = "span">(props: {
|
|||||||
>
|
>
|
||||||
<span data-slot="text-shimmer-char">
|
<span data-slot="text-shimmer-char">
|
||||||
<span data-slot="text-shimmer-char-base" aria-hidden="true">
|
<span data-slot="text-shimmer-char-base" aria-hidden="true">
|
||||||
{props.text}
|
{text()}
|
||||||
</span>
|
</span>
|
||||||
<span data-slot="text-shimmer-char-shimmer" data-run={run() ? "true" : "false"} aria-hidden="true">
|
<span data-slot="text-shimmer-char-shimmer" data-run={run() ? "true" : "false"} aria-hidden="true">
|
||||||
{props.text}
|
{text()}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</Dynamic>
|
</Dynamic>
|
||||||
|
|||||||
Reference in New Issue
Block a user