Skip to content

Commit 2f19297

Browse files
authored
refactor: switch to ripple (#15)
* refactor: switch to ripple * fix: apply nit
1 parent 2803b4b commit 2f19297

File tree

12 files changed

+121
-527
lines changed

12 files changed

+121
-527
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"typescript": "^5.1.6"
4848
},
4949
"dependencies": {
50-
"@rbxts/flipper": "^2.0.1",
5150
"@rbxts/react": "*",
5251
"@rbxts/react-roblox": "*",
52+
"@rbxts/ripple": "*",
5353
"@rbxts/services": "^1.5.1",
5454
"@rbxts/set-timeout": "^1.1.2"
5555
}

pnpm-lock.yaml

Lines changed: 36 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
export * from "@rbxts/flipper";
2-
31
export * from "./utils/binding";
42
export * from "./utils/hoarcekat";
53
export * from "./utils/math";
6-
export * from "./utils/motor";
74
export * from "./utils/testez";
85

96
export * from "./use-async";
@@ -25,7 +22,7 @@ export * from "./use-key-press";
2522
export * from "./use-latest";
2623
export * from "./use-latest-callback";
2724
export * from "./use-lifetime";
28-
export * from "./use-motor";
25+
export * from "./use-motion";
2926
export * from "./use-mount-effect";
3027
export * from "./use-mouse";
3128
export * from "./use-previous";

src/use-motion/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## 🪝 `useMotion`
2+
3+
```ts
4+
function useMotion<T extends MotionGoal>(initialValue: T): LuaTuple<[value: Binding<T>, motor: Motion<T>]>
5+
```
6+
7+
Creates a memoized Motion object set to the given initial value. Returns a binding that updates with the Motion, along with the Motion object.
8+
9+
### 📕 Parameters
10+
11+
- `initialValue` - The initial value of the motor.
12+
13+
### 📗 Returns
14+
15+
- A binding for the motor's value.
16+
- The motion object. See the [Ripple Repo](https://github.com/littensy/ripple) for the docs.
17+
18+
### 📘 Example
19+
20+
A button that fades in and out when hovered.
21+
22+
```tsx
23+
function Button() {
24+
const [hover, hoverMotor] = useMotion(0);
25+
26+
return (
27+
<textbutton
28+
Event={{
29+
MouseEnter: () => motion.spring(1, config.spring.stiff),
30+
MouseLeave: () => motion.spring(0, config.spring.stiff),
31+
}}
32+
Size={new UDim2(0, 100, 0, 100)}
33+
BackgroundTransparency={hover.map((t) => lerp(0.8, 0.5, t))}
34+
/>
35+
);
36+
}
37+
```

src/use-motion/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-motion";

src/use-motion/use-motion.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference types="@rbxts/testez/globals" />
2+
3+
import { renderHook } from "../utils/testez";
4+
import { useMotion } from "./use-motion";
5+
6+
export = () => {
7+
it("should return a motor", () => {
8+
const { result, unmount } = renderHook(() => {
9+
const [value, motion] = useMotion(0);
10+
return { value, motion };
11+
});
12+
13+
expect(result.current.value.getValue()).to.be.a("number");
14+
expect(result.current.value.getValue()).to.equal(0);
15+
expect(result.current.motion).to.be.a("table");
16+
17+
unmount();
18+
});
19+
};

0 commit comments

Comments
 (0)