Skip to content

Commit b9a2e6e

Browse files
committed
Add transition prop
1 parent bf79a22 commit b9a2e6e

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

packages/mini-browser/src/mini-browser-hike.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { TitleBar } from "./title-bar"
44
import { MiniBrowserStep, useSteps } from "./use-steps"
55
import { useClasser, Classes } from "@code-hike/classer"
66

7+
type Transition = "none" | "slide"
8+
79
export type MiniBrowserHikeProps = {
810
progress?: number
911
backward?: boolean
1012
classes?: Classes
1113
steps?: MiniBrowserStep[]
14+
transition?: Transition
1215
} & React.PropsWithoutRef<JSX.IntrinsicElements["div"]>
1316

1417
const MiniBrowserHike = React.forwardRef<
@@ -21,6 +24,7 @@ function MiniBrowserWithRef(
2124
progress = 0,
2225
backward = false,
2326
steps: ogSteps,
27+
transition = "none",
2428
classes,
2529
...props
2630
}: MiniBrowserHikeProps,
@@ -29,16 +33,6 @@ function MiniBrowserWithRef(
2933
const c = useClasser("ch-mini-browser", classes)
3034
const steps = useSteps(ogSteps)
3135

32-
// TODO readability and optional
33-
const X = 50
34-
const t = progress - Math.floor(progress)
35-
const x = t <= 0.5 ? -X * t : X - X * t
36-
const o = Math.abs(t - 0.5) * 2
37-
38-
// const stepIndex = backward
39-
// ? Math.floor(progress)
40-
// : Math.ceil(progress)
41-
4236
const stepIndex = Math.round(progress)
4337

4438
const { zoom, displayUrl, loadUrl, children } = steps[
@@ -51,8 +45,7 @@ function MiniBrowserWithRef(
5145
zoom={zoom}
5246
className={`${c("")} ${props.className || ""}`}
5347
style={{
54-
transform: `translateX(${x}px)`,
55-
opacity: o * o,
48+
...transitionStyle({ progress, transition }),
5649
...props.style,
5750
}}
5851
classes={classes}
@@ -65,4 +58,24 @@ function MiniBrowserWithRef(
6558
)
6659
}
6760

61+
function transitionStyle({
62+
progress,
63+
transition,
64+
}: {
65+
progress: number
66+
transition: Transition
67+
}) {
68+
if (transition === "slide") {
69+
const X = 50
70+
const t = progress - Math.floor(progress)
71+
const x = t <= 0.5 ? -X * t : X - X * t
72+
const o = Math.abs(t - 0.5) * 2
73+
return {
74+
transform: `translateX(${x}px)`,
75+
opacity: o * o,
76+
}
77+
}
78+
return {}
79+
}
80+
6881
export { MiniBrowserHike }

packages/scrollycoding/src/preview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function Preview({ filesHash, ...props }: PreviewProps) {
3434
<MiniBrowser
3535
url=""
3636
loadUrl={link}
37+
transition="slide"
3738
{...props}
3839
children={preview}
3940
/>

0 commit comments

Comments
 (0)