Skip to content

Commit

Permalink
Merge pull request #39 from basementstudio/jb/disabled-debugging
Browse files Browse the repository at this point in the history
default `disabled` to `false`
  • Loading branch information
julianbenegas authored Jul 27, 2023
2 parents a0c8313 + cdfb587 commit d80dbb6
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 13 deletions.
19 changes: 19 additions & 0 deletions scrollytelling/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @bsmnt/scrollytelling

## 0.2.4

### Patch Changes

- 56586af: Default disabled value to false
- abe6bb9: Tweak disabled

## 0.2.4-next.1

### Patch Changes

- Tweak disabled

## 0.2.4-next.0

### Patch Changes

- Default disabled value to false

## 0.2.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion scrollytelling/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@bsmnt/scrollytelling",
"author": "JB <[email protected]>",
"version": "0.2.3",
"version": "0.2.4",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
20 changes: 12 additions & 8 deletions scrollytelling/src/components/animation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ export function Animation(props: {
disabled?: boolean;
}): React.ReactElement;

export function Animation(props: AnimationProps): React.ReactElement | null {
export function Animation({
tween,
children,
disabled = false,
}: AnimationProps): React.ReactElement | null {
const ref = React.useRef<HTMLElement>(null);
const id = React.useId();

const { timeline } = useScrollytelling();
const { getTimelineSpace } = useDispatcher();

React.useEffect(() => {
if (!timeline || !props.tween || props.disabled) return;
if (!timeline || !tween || disabled) return;

const addTweenToTimeline = (
tween: TweenWithChildrenDef | TweenWithTargetDef
Expand Down Expand Up @@ -75,24 +79,24 @@ export function Animation(props: AnimationProps): React.ReactElement | null {
} else return () => undefined;
};

if (Array.isArray(props.tween)) {
const cleanupTweens = props.tween.map((tween) => {
if (Array.isArray(tween)) {
const cleanupTweens = tween.map((tween) => {
const cleanup = addTweenToTimeline(tween);
return cleanup;
});
return () => {
cleanupTweens.forEach((cleanup) => cleanup?.());
};
} else {
const cleanup = addTweenToTimeline(props.tween);
const cleanup = addTweenToTimeline(tween);
return () => {
cleanup?.();
};
}
}, [getTimelineSpace, id, props.tween, timeline, props.disabled]);
}, [getTimelineSpace, id, tween, timeline, disabled]);

if (props.children) {
return <Slot ref={ref}>{props.children}</Slot>;
if (children) {
return <Slot ref={ref}>{children}</Slot>;
}
return null;
}
2 changes: 1 addition & 1 deletion scrollytelling/src/components/parallax/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface ParallaxProps {
export const Parallax: React.FC<ParallaxProps> = ({
children,
tween,
disabled,
disabled = false,
}): JSX.Element => {
if (!tween.movementY && !tween.movementX) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion scrollytelling/src/primitive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Scrollytelling = ({
scrub,
defaults,
toggleActions,
disabled,
disabled = false,
}: {
children?: React.ReactNode;
debug?: boolean;
Expand Down
23 changes: 23 additions & 0 deletions website/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# website

## 0.1.1

### Patch Changes

- Updated dependencies [56586af]
- Updated dependencies [abe6bb9]
- @bsmnt/scrollytelling@0.2.4

## 0.1.1-next.1

### Patch Changes

- Updated dependencies
- @bsmnt/scrollytelling@0.2.4-next.1

## 0.1.1-next.0

### Patch Changes

- Updated dependencies
- @bsmnt/scrollytelling@0.2.4-next.0
4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "website",
"private": true,
"version": "0.1.0",
"version": "0.1.1",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand All @@ -10,7 +10,7 @@
"lint": "next lint"
},
"dependencies": {
"@bsmnt/scrollytelling": "*",
"@bsmnt/scrollytelling": "0.2.4",
"@react-three/drei": "^9.65.3",
"@react-three/fiber": "^8.12.0",
"@types/three": "^0.150.1",
Expand Down
62 changes: 62 additions & 0 deletions website/src/app/debug/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use client";

import { useState } from "react";
import * as Scrollytelling from "~/lib/scrollytelling-client";

const texts = ["one", "two", "three"];

export default function Page() {
const [isDisabled, setIsDisabled] = useState<boolean | undefined>(undefined);

return (
<main>
<div
style={{
position: "fixed",
top: 0,
right: 0,
zIndex: 100,
}}
>
<button onClick={() => setIsDisabled((p) => false)}>
Toggle Disabled
</button>
<p>Disabled: {JSON.stringify(isDisabled)}</p>
</div>
<div
style={{
height: "100vh",
backgroundColor: "blue",
}}
/>
{texts.map((text, i) => {
return (
<Scrollytelling.Root disabled={isDisabled} key={i}>
<div style={{ height: "200vh", background: "black" }}>
<div style={{ position: "sticky", top: 0 }}>
<Scrollytelling.Animation
tween={{
start: 0,
end: 100,
to: { scale: 1.5 },
}}
disabled={isDisabled}
>
<h1
style={{
fontSize: "5rem",
transformOrigin: "top left",
}}
>
{text}
</h1>
</Scrollytelling.Animation>
</div>
</div>
</Scrollytelling.Root>
);
})}
<div style={{ height: "100vh", backgroundColor: "red" }} />
</main>
);
}

1 comment on commit d80dbb6

@vercel
Copy link

@vercel vercel bot commented on d80dbb6 Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.