Skip to content

Commit 704bd9b

Browse files
committed
docs(changeset): Add option to control cursor visibility after compliting the type animation
1 parent bf52379 commit 704bd9b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.changeset/eleven-cups-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typingfx": minor
3+
---
4+
5+
Add option to control cursor visibility after compliting the type animation

lib/src/client/type-out/type-out.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ interface DefaultTypeOutProps extends HTMLProps<HTMLDivElement> {
1919
/** Whether to hide the blinking cursor. @default false */
2020
noCursor: boolean;
2121

22+
/** Whether to hide the blinking cursor after completing the anim. @default false */
23+
noCursorAfterAnimEnd: false;
24+
2225
/** Sequence of steps (lines or phrases) to animate through. */
2326
steps: ReactNode[];
2427

@@ -37,6 +40,7 @@ const defaultTypeOutProps: DefaultTypeOutProps = {
3740
speed: 20,
3841
delSpeed: 40,
3942
noCursor: false,
43+
noCursorAfterAnimEnd: false,
4044
steps: [""],
4145
repeat: Infinity,
4246
force: false,
@@ -50,6 +54,7 @@ const TypingAnimation = ({
5054
className,
5155
delSpeed,
5256
noCursor,
57+
noCursorAfterAnimEnd,
5358
repeat,
5459
speed,
5560
steps,
@@ -102,15 +107,15 @@ const TypingAnimation = ({
102107
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
103108
nextEl
104109
? nextEl.classList.add(styles.type)
105-
: (addAnimationListeners(elements as HTMLElement[][], repeat),
110+
: (addAnimationListeners(elements as HTMLElement[][], repeat, noCursorAfterAnimEnd),
106111
el.classList.add(styles.del));
107112
};
108113
el.addEventListener("animationend", animListener);
109114
}
110115

111116
requestAnimationFrame(() => elements[0][0].classList.add(styles.type));
112117
setProcessing(false);
113-
}, [animatedSteps, delSpeed, repeat, speed]);
118+
}, [animatedSteps, repeat, noCursorAfterAnimEnd]);
114119

115120
// Respect pause and pause on visibility hidden
116121
useEffect(() => {

lib/src/client/type-out/utils.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const updateAfterDelAnim = (el: HTMLElement) => {
9797
/**
9898
* Handles the chain of animation listeners for typing + deleting effects across steps.
9999
*/
100-
export const addAnimationListeners = (elements: HTMLElement[][], repeat: number) => {
100+
export const addAnimationListeners = (
101+
elements: HTMLElement[][],
102+
repeat: number,
103+
noCursorAfterAnimEnd: boolean,
104+
) => {
101105
const stepStartIndices = compareSteps(elements);
102106
let iCheck = 0;
103107
while (iCheck < elements.length && elements[iCheck].length === stepStartIndices[iCheck]) iCheck++;
@@ -122,7 +126,7 @@ export const addAnimationListeners = (elements: HTMLElement[][], repeat: number)
122126
if (nextEl) nextEl.classList.add(styles.type);
123127
else if (i !== elements.length - 1 || repeatCount++ < repeat)
124128
el.classList.add(styles.del);
125-
else el.classList.add(styles.cursor);
129+
else if (!noCursorAfterAnimEnd) el.classList.add(styles.cursor);
126130
} else {
127131
updateAfterDelAnim(el);
128132
if (

0 commit comments

Comments
 (0)