Skip to content

Commit d35c4e4

Browse files
committed
fix: add initialHeight and snapPoints getters
1 parent 07041d2 commit d35c4e4

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/index.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)