@@ -4,11 +4,14 @@ import { TitleBar } from "./title-bar"
44import { MiniBrowserStep , useSteps } from "./use-steps"
55import { useClasser , Classes } from "@code-hike/classer"
66
7+ type Transition = "none" | "slide"
8+
79export type MiniBrowserHikeProps = {
810 progress ?: number
911 backward ?: boolean
1012 classes ?: Classes
1113 steps ?: MiniBrowserStep [ ]
14+ transition ?: Transition
1215} & React . PropsWithoutRef < JSX . IntrinsicElements [ "div" ] >
1316
1417const 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+
6881export { MiniBrowserHike }
0 commit comments