viewState.ts36 lines · main
1import { proxy } from 'valtio'
2
3import { type DialogSize, type ITouchHandlers, type IViewState } from './viewState.types'
4
5const initViewState = () => {
6 const state: IViewState = proxy({
7 initiated: false,
8 init: () => !state.initiated && (state.initiated = true),
9 open: false,
10 size: 'large',
11 touchHandlers: {
12 handleTouchStart: () => {},
13 handleTouchMove: () => {},
14 handleTouchEnd: () => {},
15 },
16 setOpen: (open) => {
17 state.init()
18 state.open = open
19 },
20 toggleOpen: () => {
21 state.init()
22 state.open = !state.open
23 },
24 setSize: (size) => {
25 state.size = size
26 },
27 setTouchHandlers: (handlers) => {
28 state.touchHandlers = handlers
29 },
30 })
31
32 return state
33}
34
35export { initViewState }
36export type { DialogSize, ITouchHandlers }