@matteodicristofalo/text-animations 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ pnpm add @matteodicristofalo/text-animations
14
14
 
15
15
  # Usage
16
16
 
17
- The first thing to do in order to use this library is to import it's CSS.
17
+ The first thing to do in order to use this library is to import its CSS.
18
18
 
19
19
  The following example is for a Next.js App but you can apply the same concept for different frameworks
20
20
 
@@ -42,55 +42,59 @@ export default function RootLayout({
42
42
 
43
43
  Once imported the CSS you can use the React components.
44
44
 
45
- ## SplitTextRevel
45
+ ## SplitTextReveal
46
46
 
47
47
  ```js
48
48
  "use client";
49
49
 
50
- import { SplitTextRevel } from "@matteodicristofalo/text-animations";
50
+ import { SplitTextReveal } from "@matteodicristofalo/text-animations";
51
51
 
52
52
  export function MyComponent() {
53
53
  return (
54
54
  <h1>
55
- <SplitTextRevel text="Hello World" />
55
+ <SplitTextReveal text="Hello World" />
56
56
  </h1>
57
57
  );
58
58
  }
59
59
  ```
60
60
 
61
- You can also choose how to split the text between one of this options:
61
+ You can decide how to split the text between one of this options:
62
62
 
63
- - char
63
+ - char (default)
64
64
  - word
65
65
  - sentence
66
66
 
67
67
  ```js
68
- <SplitTextRevel text="Hello World" splitType="word" />
68
+ <SplitTextReveal text="Hello World" splitType="word" />
69
69
  ```
70
70
 
71
71
  You can also configure the reveal animation by specifying:
72
72
 
73
- - duration
74
- - stagger
73
+ - duration (number in seconds)
74
+ - stagger (number in seconds)
75
+ - threshold (number between 0 and 1)
76
+ - once (boolean)
75
77
 
76
78
  ```js
77
79
  "use client";
78
80
 
79
81
  import { useMemo } from "react";
80
- import { SplitTextRevel } from "@matteodicristofalo/text-animations";
82
+ import { SplitTextReveal } from "@matteodicristofalo/text-animations";
81
83
 
82
84
  export function MyComponent() {
83
85
  const revealOptions = useMemo(
84
86
  () => ({
85
87
  duration: 1,
86
88
  stagger: 0.5,
89
+ threshold: 0.75,
90
+ once: false,
87
91
  }),
88
92
  []
89
93
  );
90
94
 
91
95
  return (
92
96
  <h1>
93
- <SplitTextRevel text="Hello World" revealOptions={revealOptions} />
97
+ <SplitTextReveal text="Hello World" revealOptions={revealOptions} />
94
98
  </h1>
95
99
  );
96
100
  }
@@ -112,7 +116,7 @@ export function MyComponent() {
112
116
  }
113
117
  ```
114
118
 
115
- Also here you can configure the aniimation
119
+ This component split always by char, the only thing you can configure is the rotate animation
116
120
 
117
121
  ```js
118
122
  "use client";
@@ -7,5 +7,7 @@ type SplitType = "sentence" | "word" | "char";
7
7
  type RevealOptions = {
8
8
  duration: number;
9
9
  stagger: number;
10
+ threshold: number;
11
+ once: boolean;
10
12
  };
11
13
  export {};
@@ -1,11 +1,9 @@
1
+ import React from "react";
1
2
  import type { StoryObj } from "@storybook/react";
2
3
  import { SplitTextReveal } from "./split-text-reveal";
3
4
  declare const meta: {
4
5
  title: string;
5
6
  component: typeof SplitTextReveal;
6
- parameters: {
7
- layout: string;
8
- };
9
7
  argTypes: {
10
8
  text: {
11
9
  control: "text";
@@ -20,7 +18,18 @@ declare const meta: {
20
18
  };
21
19
  };
22
20
  };
21
+ args: {
22
+ text: string;
23
+ splitType: "char";
24
+ };
25
+ render: (args: import("./split-test-reveal.types").SplitTextRevealProps) => React.JSX.Element;
23
26
  };
24
27
  export default meta;
25
28
  type Story = StoryObj<typeof meta>;
26
29
  export declare const Default: Story;
30
+ export declare const SplitByWord: Story;
31
+ export declare const SplitBySentence: Story;
32
+ export declare const Duration: Story;
33
+ export declare const Stagger: Story;
34
+ export declare const Threshold: Story;
35
+ export declare const NotOnce: Story;
@@ -1,11 +1,9 @@
1
+ import React from "react";
1
2
  import type { StoryObj } from "@storybook/react";
2
3
  import { SplitTextRotate } from "./split-text-rotate";
3
4
  declare const meta: {
4
5
  title: string;
5
6
  component: typeof SplitTextRotate;
6
- parameters: {
7
- layout: string;
8
- };
9
7
  argTypes: {
10
8
  text: {
11
9
  control: "text";
@@ -16,7 +14,13 @@ declare const meta: {
16
14
  };
17
15
  };
18
16
  };
17
+ args: {
18
+ text: string;
19
+ };
20
+ render: (args: import("./split-text-rotate.types").SplitTextRotateProps) => React.JSX.Element;
19
21
  };
20
22
  export default meta;
21
23
  type Story = StoryObj<typeof meta>;
22
24
  export declare const Default: Story;
25
+ export declare const Duration: Story;
26
+ export declare const Stagger: Story;
package/dist/index.js CHANGED
@@ -4,6 +4,9 @@ import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react'
4
4
  function round(num, digits) {
5
5
  return parseFloat(num.toFixed(digits));
6
6
  }
7
+ function clamp(n, min, max) {
8
+ return Math.min(Math.max(min, n), max);
9
+ }
7
10
 
8
11
  function sentences(text) {
9
12
  return segment(text, "sentence");
@@ -81,12 +84,25 @@ var styles$1 = {"text":"split-text-reveal-module_text__-9O5o","is-hidden":"split
81
84
 
82
85
  var DEFAULT_DURATION$1 = 0.5;
83
86
  var DEFAULT_STAGGER$1 = 0.01;
87
+ var MIN_THRESHOLD = 0;
88
+ var MAX_THRESHOLD = 1;
89
+ var DEFAULT_THRESHOLD = 0.25;
84
90
  function SplitTextReveal(_a) {
85
91
  var _b;
86
92
  var text = _a.text, _c = _a.splitType, splitType = _c === void 0 ? "char" : _c, revealOptions = _a.revealOptions;
87
- var _d = useState(false), hasBeenMounted = _d[0], setHasBeenMounted = _d[1];
88
93
  var ref = useRef(null);
89
- var memoizedOptions = useMemo(function () { return ({ once: true, threshold: 0.1 }); }, []);
94
+ var _d = useState(false), hasBeenMounted = _d[0], setHasBeenMounted = _d[1];
95
+ var memoizedOptions = useMemo(function () {
96
+ var _a;
97
+ var once = (_a = revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.once) !== null && _a !== void 0 ? _a : true;
98
+ var threshold = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.threshold)
99
+ ? clamp(revealOptions.threshold, MIN_THRESHOLD, MAX_THRESHOLD)
100
+ : DEFAULT_THRESHOLD;
101
+ return {
102
+ once: once,
103
+ threshold: threshold,
104
+ };
105
+ }, [revealOptions]);
90
106
  var isInView = useIntersectionObserver(ref, memoizedOptions);
91
107
  var transitionDuration = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.duration) || DEFAULT_DURATION$1;
92
108
  var transitionStagger = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.stagger) || DEFAULT_STAGGER$1;
@@ -1 +1,2 @@
1
1
  export declare function round(num: number, digits: number): number;
2
+ export declare function clamp(n: number, min: number, max: number): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matteodicristofalo/text-animations",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "React library to animate text",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && rollup -c",