Skip to content

Commit 4246076

Browse files
authored
Merge pull request #2 from react18-tools/handle-updates
Handle updates
2 parents d6f47c0 + 304cbe0 commit 4246076

File tree

11 files changed

+375
-221
lines changed

11 files changed

+375
-221
lines changed

lib/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# typingfx
22

3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- eb0bd92: Use children as last step - this is more intuitive. When animation stops (in case of repeat < Infinity), children, if truthy, will be seen rendered.
8+
9+
### Minor Changes
10+
11+
- 704bd9b: Add option to control cursor visibility after compliting the type animation
12+
13+
### Patch Changes
14+
15+
- bf52379: fix: Handle cursor not shown after anim end when it ends with a number (a delay indicator).
16+
- 378bbdc: refactor: split utils in separate file. Export right prop types.
17+
- 9aab8c8: Fix step and children updates.
18+
- 1771179: Handle edge cases
19+
- b862fb0: Export utils for better test coverage as animationed is not supported in vitest env.
20+
321
## 0.0.1
422

523
### Patch Changes

lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typingfx",
33
"author": "Mayank Kumar Chaudhari (https://mayank-chaudhari.vercel.app)",
44
"private": false,
5-
"version": "0.0.0",
5+
"version": "1.0.0",
66
"description": "Customizable, smooth, and snappy typing animations for React — built for natural, human-like effects with minimal config.",
77
"license": "MPL-2.0",
88
"main": "./dist/index.js",
@@ -37,7 +37,6 @@
3737
"esbuild-plugin-rdi": "^0.0.0",
3838
"esbuild-plugin-react18": "0.2.6",
3939
"esbuild-plugin-react18-css": "^0.0.4",
40-
"jsdom": "^26.0.0",
4140
"react": "^19.1.0",
4241
"react-dom": "^19.1.0",
4342
"tsup": "^8.4.0",
@@ -46,6 +45,7 @@
4645
"vitest": "^3.1.1"
4746
},
4847
"dependencies": {
48+
"happy-dom": "^17.4.6",
4949
"r18gs": "^3.0.1"
5050
},
5151
"peerDependencies": {

lib/src/client/type-out/type-out.module.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@
4141
height: 0 !important;
4242
}
4343

44+
.cursor .cursor,
45+
.wait.del,
4446
.wait.type {
45-
animation-duration: var(--d);
4647
width: auto !important;
4748
height: auto !important;
4849
}
50+
51+
.wait.type {
52+
animation-duration: var(--d);
53+
}
4954
.wait.del {
5055
animation-duration: var(--r);
51-
width: auto !important;
52-
height: auto !important;
5356
}
5457

5558
.cursor .cursor::after,

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { act, render, screen, waitFor } from "@testing-library/react";
1+
import { render, screen } from "@testing-library/react";
22
import { TypeOut } from "./type-out"; // import the component
3-
import { describe, expect, it, vi } from "vitest";
3+
import { beforeAll, describe, expect, it } from "vitest";
44
import styles from "./type-out.module.scss";
5+
import {
6+
addAnimationListeners,
7+
listElements,
8+
setupTypingFX,
9+
updateAfterDelAnim,
10+
updateAfterTypeAnim,
11+
} from "./utils";
512

613
describe("TypeOut Component", () => {
714
// Test for Reduced Motion Preference
@@ -13,8 +20,12 @@ describe("TypeOut Component", () => {
1320
});
1421

1522
// Test for Force Prop: Ensures animation is shown even with reduced motion preference
16-
it("should override reduced-motion and show animation when force is true", () => {
17-
const { container } = render(<TypeOut steps={["Hello World", "I am using TypingFX"]} force />);
23+
it("should override reduced-motion and show animation when force is true", async ({ expect }) => {
24+
const { container } = render(
25+
<TypeOut steps={["Hello World", "I am using TypingFX"]} paused force />,
26+
);
27+
28+
await screen.findByText("TypingFX");
1829
// Check if typing animation is applied even if reduced-motion is preferred
1930
expect(container.getElementsByClassName(styles.typeout).length).toBe(1);
2031
});
@@ -38,3 +49,29 @@ describe("TypeOut Component", () => {
3849
expect(container.classList).not.toContain(styles.cursor);
3950
});
4051
});
52+
53+
describe.concurrent("Utils", () => {
54+
let list: HTMLElement[][];
55+
let typeOutEl: HTMLElement;
56+
beforeAll(() => {
57+
const { container } = render(<TypeOut steps={["Hello World", "I am using TypingFX"]} force />);
58+
typeOutEl = container.getElementsByClassName(styles.typeout)[0] as HTMLElement;
59+
list = listElements(typeOutEl);
60+
});
61+
it("setupTypingFX", ({ expect }) => {
62+
expect(setupTypingFX(null)).toBe(null);
63+
});
64+
65+
it("listElements", ({ expect }) => {
66+
expect(list.length).not.toBe(0);
67+
});
68+
69+
it("addAnimationListeners", ({ expect }) => {
70+
addAnimationListeners(list, 1, false);
71+
expect(list[0][0].classList).toContain(styles.hk);
72+
updateAfterTypeAnim(list[0][0]);
73+
expect(list[0][0].classList).not.toContain(styles.hk);
74+
updateAfterDelAnim(list[0][0]);
75+
expect(list[0][0].classList).toContain(styles.hk);
76+
});
77+
});

0 commit comments

Comments
 (0)