@@ -4,11 +4,14 @@ import { TitleBar } from "./title-bar"
4
4
import { MiniBrowserStep , useSteps } from "./use-steps"
5
5
import { useClasser , Classes } from "@code-hike/classer"
6
6
7
+ type Transition = "none" | "slide"
8
+
7
9
export type MiniBrowserHikeProps = {
8
10
progress ?: number
9
11
backward ?: boolean
10
12
classes ?: Classes
11
13
steps ?: MiniBrowserStep [ ]
14
+ transition ?: Transition
12
15
} & React . PropsWithoutRef < JSX . IntrinsicElements [ "div" ] >
13
16
14
17
const MiniBrowserHike = React . forwardRef <
@@ -21,6 +24,7 @@ function MiniBrowserWithRef(
21
24
progress = 0 ,
22
25
backward = false ,
23
26
steps : ogSteps ,
27
+ transition = "none" ,
24
28
classes,
25
29
...props
26
30
} : MiniBrowserHikeProps ,
@@ -29,16 +33,6 @@ function MiniBrowserWithRef(
29
33
const c = useClasser ( "ch-mini-browser" , classes )
30
34
const steps = useSteps ( ogSteps )
31
35
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
-
42
36
const stepIndex = Math . round ( progress )
43
37
44
38
const { zoom, displayUrl, loadUrl, children } = steps [
@@ -51,8 +45,7 @@ function MiniBrowserWithRef(
51
45
zoom = { zoom }
52
46
className = { `${ c ( "" ) } ${ props . className || "" } ` }
53
47
style = { {
54
- transform : `translateX(${ x } px)` ,
55
- opacity : o * o ,
48
+ ...transitionStyle ( { progress, transition } ) ,
56
49
...props . style ,
57
50
} }
58
51
classes = { classes }
@@ -65,4 +58,24 @@ function MiniBrowserWithRef(
65
58
)
66
59
}
67
60
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
+
68
81
export { MiniBrowserHike }
0 commit comments