@@ -5,10 +5,32 @@ import {
55 BottomSheetMachine ,
66 type BottomSheetEvent ,
77} from '@bottom-sheet/state-machine'
8+ import {
9+ assignSnapPoints ,
10+ assignInitialHeight ,
11+ defaultInitialHeight ,
12+ defaultSnapPoints ,
13+ } from '@bottom-sheet/state-machine'
14+ import type { GetInitialHeight , GetSnapPoints } from '@bottom-sheet/types'
15+
16+ export interface BottomSheetMachineProps {
17+ initialHeight ?: GetInitialHeight
18+ snapPoints ?: GetSnapPoints
19+ }
820
9- function createStore ( ) {
21+ function createStore ( {
22+ initialHeight = defaultInitialHeight ,
23+ snapPoints = defaultSnapPoints ,
24+ } : BottomSheetMachineProps = { } ) {
1025 console . debug ( 'createStore' )
11- const service = interpret ( BottomSheetMachine )
26+ const service = interpret (
27+ BottomSheetMachine . withConfig ( {
28+ actions : {
29+ setInitialHeight : assignInitialHeight ( initialHeight ) ,
30+ setSnapPoints : assignSnapPoints ( snapPoints ) ,
31+ } ,
32+ } )
33+ )
1234 let snapshot = service . initialState
1335 // transient is updated more frequently than the snapshot, outside of react render cycles
1436 let transient = snapshot
@@ -44,8 +66,8 @@ function createStore() {
4466 }
4567}
4668
47- export function useBottomSheetMachine ( ) {
48- const [ store ] = useState ( ( ) => createStore ( ) )
69+ export function useBottomSheetMachine ( props : BottomSheetMachineProps = { } ) {
70+ const [ store ] = useState ( ( ) => createStore ( props ) )
4971 /*
5072 // useState lets us create the store exactly once, which is a guarantee that useMemo doesn't provide
5173 const [store] = useState(() => {
0 commit comments