@registrucentras/rc-ses-react-components 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/form/inputs/Select/Select.utils.d.ts +9 -0
- package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +5 -0
- package/dist/components/form/inputs/Select/index.d.ts +18 -8
- package/dist/components/overlays/BottomSheet/index.d.ts +17 -0
- package/dist/components/overlays/BottomSheet/useSwipeToDismiss.d.ts +17 -0
- package/dist/library/index.d.ts +2 -1
- package/dist/library/types.d.ts +2 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3492 -3081
- package/package.json +1 -1
- package/src/components/form/inputs/Select/Select.utils.ts +24 -0
- package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +46 -0
- package/src/components/form/inputs/Select/index.test.tsx +127 -0
- package/src/components/form/inputs/Select/index.tsx +426 -181
- package/src/components/overlays/BottomSheet/index.test.tsx +256 -0
- package/src/components/overlays/BottomSheet/index.tsx +242 -0
- package/src/components/overlays/BottomSheet/useSwipeToDismiss.test.ts +295 -0
- package/src/components/overlays/BottomSheet/useSwipeToDismiss.ts +138 -0
- package/src/i18n/namespaces/input/en.json +11 -0
- package/src/i18n/namespaces/input/lt.json +11 -0
- package/src/library/index.ts +2 -0
- package/src/library/types.ts +2 -0
- package/src/stories/atoms/Select.stories.tsx +33 -5
- package/src/stories/organisms/BottomSheet.stories.tsx +291 -0
- package/src/theme/light/MuiAutocomplete.ts +43 -19
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react'
|
|
2
|
+
import { PointerEvent as ReactPointerEvent } from 'react'
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import useSwipeToDismiss from './useSwipeToDismiss'
|
|
6
|
+
|
|
7
|
+
const makePointerEvent = (
|
|
8
|
+
clientY: number,
|
|
9
|
+
overrides: Partial<ReactPointerEvent<HTMLElement>> = {},
|
|
10
|
+
) =>
|
|
11
|
+
({
|
|
12
|
+
clientY,
|
|
13
|
+
pointerId: 1,
|
|
14
|
+
isPrimary: true,
|
|
15
|
+
pointerType: 'touch',
|
|
16
|
+
button: 0,
|
|
17
|
+
currentTarget: { setPointerCapture: vi.fn(), releasePointerCapture: vi.fn() },
|
|
18
|
+
...overrides,
|
|
19
|
+
}) as unknown as ReactPointerEvent<HTMLElement>
|
|
20
|
+
|
|
21
|
+
describe('useSwipeToDismiss', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
vi.useFakeTimers({ toFake: ['performance'] })
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
vi.useRealTimers()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('tracks the drag distance on the paper node while dragging', () => {
|
|
31
|
+
const onDismiss = vi.fn()
|
|
32
|
+
const { result } = renderHook(() =>
|
|
33
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
34
|
+
)
|
|
35
|
+
const node = document.createElement('div')
|
|
36
|
+
result.current.paperRef.current = node
|
|
37
|
+
|
|
38
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
39
|
+
act(() => result.current.handleProps.onPointerMove(makePointerEvent(40)))
|
|
40
|
+
|
|
41
|
+
expect(node.style.transform).toBe('translateY(40px)')
|
|
42
|
+
expect(node.style.transition).toBe('none')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('snaps back and does not dismiss when the drag stays under the threshold', () => {
|
|
46
|
+
const onDismiss = vi.fn()
|
|
47
|
+
const { result } = renderHook(() =>
|
|
48
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
49
|
+
)
|
|
50
|
+
const node = document.createElement('div')
|
|
51
|
+
result.current.paperRef.current = node
|
|
52
|
+
|
|
53
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
54
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(20)))
|
|
55
|
+
|
|
56
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
57
|
+
expect(node.style.transform).toBe('')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('dismisses immediately, with no artificial delay, once the drag distance exceeds the threshold', () => {
|
|
61
|
+
const onDismiss = vi.fn()
|
|
62
|
+
const { result } = renderHook(() =>
|
|
63
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
64
|
+
)
|
|
65
|
+
const node = document.createElement('div')
|
|
66
|
+
result.current.paperRef.current = node
|
|
67
|
+
|
|
68
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
69
|
+
act(() => vi.advanceTimersByTime(400))
|
|
70
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
71
|
+
|
|
72
|
+
expect(onDismiss).toHaveBeenCalledTimes(1)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('dismisses on a fast flick even under the distance threshold', () => {
|
|
76
|
+
const onDismiss = vi.fn()
|
|
77
|
+
const { result } = renderHook(() =>
|
|
78
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
79
|
+
)
|
|
80
|
+
const node = document.createElement('div')
|
|
81
|
+
result.current.paperRef.current = node
|
|
82
|
+
|
|
83
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
84
|
+
act(() => vi.advanceTimersByTime(10))
|
|
85
|
+
act(() => result.current.handleProps.onPointerMove(makePointerEvent(20)))
|
|
86
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(20)))
|
|
87
|
+
|
|
88
|
+
expect(onDismiss).toHaveBeenCalledTimes(1)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('ignores a second drag started while a dismiss is already committed', () => {
|
|
92
|
+
const onDismiss = vi.fn()
|
|
93
|
+
const { result } = renderHook(() =>
|
|
94
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
95
|
+
)
|
|
96
|
+
const node = document.createElement('div')
|
|
97
|
+
result.current.paperRef.current = node
|
|
98
|
+
|
|
99
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
100
|
+
act(() => vi.advanceTimersByTime(400))
|
|
101
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
102
|
+
expect(onDismiss).toHaveBeenCalledTimes(1)
|
|
103
|
+
|
|
104
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
105
|
+
act(() => vi.advanceTimersByTime(400))
|
|
106
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
107
|
+
|
|
108
|
+
expect(onDismiss).toHaveBeenCalledTimes(1)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('resets a leftover drag transform once the sheet opens again', () => {
|
|
112
|
+
const onDismiss = vi.fn()
|
|
113
|
+
const { result, rerender } = renderHook(
|
|
114
|
+
({ open }: { open: boolean }) =>
|
|
115
|
+
useSwipeToDismiss({ open, disableTransform: false, onDismiss }),
|
|
116
|
+
{ initialProps: { open: false } },
|
|
117
|
+
)
|
|
118
|
+
const node = document.createElement('div')
|
|
119
|
+
node.style.transform = 'translateY(150px)'
|
|
120
|
+
node.style.transition = 'none'
|
|
121
|
+
result.current.paperRef.current = node
|
|
122
|
+
|
|
123
|
+
rerender({ open: true })
|
|
124
|
+
|
|
125
|
+
expect(node.style.transform).toBe('')
|
|
126
|
+
expect(node.style.transition).toBe('')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('allows a new drag again once the sheet has reopened after a dismiss', () => {
|
|
130
|
+
const onDismiss = vi.fn()
|
|
131
|
+
const { result, rerender } = renderHook(
|
|
132
|
+
({ open }: { open: boolean }) =>
|
|
133
|
+
useSwipeToDismiss({ open, disableTransform: false, onDismiss }),
|
|
134
|
+
{ initialProps: { open: true } },
|
|
135
|
+
)
|
|
136
|
+
const node = document.createElement('div')
|
|
137
|
+
result.current.paperRef.current = node
|
|
138
|
+
|
|
139
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
140
|
+
act(() => vi.advanceTimersByTime(400))
|
|
141
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
142
|
+
expect(onDismiss).toHaveBeenCalledTimes(1)
|
|
143
|
+
|
|
144
|
+
rerender({ open: false })
|
|
145
|
+
rerender({ open: true })
|
|
146
|
+
|
|
147
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
148
|
+
act(() => vi.advanceTimersByTime(400))
|
|
149
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
150
|
+
|
|
151
|
+
expect(onDismiss).toHaveBeenCalledTimes(2)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('ignores a pointer-up with no matching pointer-down', () => {
|
|
155
|
+
const onDismiss = vi.fn()
|
|
156
|
+
const { result } = renderHook(() =>
|
|
157
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
161
|
+
|
|
162
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('does not apply a visual transform when disableTransform is set (reduced motion)', () => {
|
|
166
|
+
const onDismiss = vi.fn()
|
|
167
|
+
const { result } = renderHook(() =>
|
|
168
|
+
useSwipeToDismiss({ open: true, disableTransform: true, onDismiss }),
|
|
169
|
+
)
|
|
170
|
+
const node = document.createElement('div')
|
|
171
|
+
result.current.paperRef.current = node
|
|
172
|
+
|
|
173
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
174
|
+
act(() => result.current.handleProps.onPointerMove(makePointerEvent(40)))
|
|
175
|
+
|
|
176
|
+
expect(node.style.transform).toBe('')
|
|
177
|
+
expect(node.style.transition).toBe('')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('releases pointer capture when the drag ends', () => {
|
|
181
|
+
const onDismiss = vi.fn()
|
|
182
|
+
const { result } = renderHook(() =>
|
|
183
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
184
|
+
)
|
|
185
|
+
const node = document.createElement('div')
|
|
186
|
+
result.current.paperRef.current = node
|
|
187
|
+
|
|
188
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
189
|
+
const upEvent = makePointerEvent(20)
|
|
190
|
+
act(() => result.current.handleProps.onPointerUp(upEvent))
|
|
191
|
+
|
|
192
|
+
expect(upEvent.currentTarget.releasePointerCapture).toHaveBeenCalledWith(1)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('passes the triggering pointer event through to onDismiss', () => {
|
|
196
|
+
const onDismiss = vi.fn()
|
|
197
|
+
const { result } = renderHook(() =>
|
|
198
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
199
|
+
)
|
|
200
|
+
const node = document.createElement('div')
|
|
201
|
+
result.current.paperRef.current = node
|
|
202
|
+
|
|
203
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
204
|
+
const upEvent = makePointerEvent(150)
|
|
205
|
+
act(() => result.current.handleProps.onPointerUp(upEvent))
|
|
206
|
+
|
|
207
|
+
expect(onDismiss).toHaveBeenCalledWith(upEvent)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('never dismisses on pointercancel, regardless of distance - snaps back instead', () => {
|
|
211
|
+
const onDismiss = vi.fn()
|
|
212
|
+
const { result } = renderHook(() =>
|
|
213
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
214
|
+
)
|
|
215
|
+
const node = document.createElement('div')
|
|
216
|
+
result.current.paperRef.current = node
|
|
217
|
+
|
|
218
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
219
|
+
act(() => result.current.handleProps.onPointerCancel(makePointerEvent(150)))
|
|
220
|
+
|
|
221
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
222
|
+
expect(node.style.transform).toBe('')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('releases pointer capture on pointercancel too', () => {
|
|
226
|
+
const onDismiss = vi.fn()
|
|
227
|
+
const { result } = renderHook(() =>
|
|
228
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
229
|
+
)
|
|
230
|
+
const node = document.createElement('div')
|
|
231
|
+
result.current.paperRef.current = node
|
|
232
|
+
|
|
233
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
234
|
+
const cancelEvent = makePointerEvent(20)
|
|
235
|
+
act(() => result.current.handleProps.onPointerCancel(cancelEvent))
|
|
236
|
+
|
|
237
|
+
expect(cancelEvent.currentTarget.releasePointerCapture).toHaveBeenCalledWith(1)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('ignores a non-primary pointer', () => {
|
|
241
|
+
const onDismiss = vi.fn()
|
|
242
|
+
const { result } = renderHook(() =>
|
|
243
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
244
|
+
)
|
|
245
|
+
const node = document.createElement('div')
|
|
246
|
+
result.current.paperRef.current = node
|
|
247
|
+
|
|
248
|
+
act(() =>
|
|
249
|
+
result.current.handleProps.onPointerDown(makePointerEvent(0, { isPrimary: false })),
|
|
250
|
+
)
|
|
251
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
252
|
+
|
|
253
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
254
|
+
expect(node.style.transform).toBe('')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('ignores a non-left mouse button', () => {
|
|
258
|
+
const onDismiss = vi.fn()
|
|
259
|
+
const { result } = renderHook(() =>
|
|
260
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
261
|
+
)
|
|
262
|
+
const node = document.createElement('div')
|
|
263
|
+
result.current.paperRef.current = node
|
|
264
|
+
|
|
265
|
+
act(() =>
|
|
266
|
+
result.current.handleProps.onPointerDown(
|
|
267
|
+
makePointerEvent(0, { pointerType: 'mouse', button: 2 }),
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(150)))
|
|
271
|
+
|
|
272
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
273
|
+
expect(node.style.transform).toBe('')
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('uses release velocity, not the whole-gesture average - a fast start held still before release does not dismiss', () => {
|
|
277
|
+
const onDismiss = vi.fn()
|
|
278
|
+
const { result } = renderHook(() =>
|
|
279
|
+
useSwipeToDismiss({ open: true, disableTransform: false, onDismiss }),
|
|
280
|
+
)
|
|
281
|
+
const node = document.createElement('div')
|
|
282
|
+
result.current.paperRef.current = node
|
|
283
|
+
|
|
284
|
+
act(() => result.current.handleProps.onPointerDown(makePointerEvent(0)))
|
|
285
|
+
act(() => vi.advanceTimersByTime(5))
|
|
286
|
+
// A fast 60px move (would read as > DISMISS_VELOCITY_PX_PER_MS if averaged
|
|
287
|
+
// over the whole gesture including the hold below).
|
|
288
|
+
act(() => result.current.handleProps.onPointerMove(makePointerEvent(60)))
|
|
289
|
+
act(() => vi.advanceTimersByTime(95))
|
|
290
|
+
// Released at the same position - release velocity is ~0.
|
|
291
|
+
act(() => result.current.handleProps.onPointerUp(makePointerEvent(60)))
|
|
292
|
+
|
|
293
|
+
expect(onDismiss).not.toHaveBeenCalled()
|
|
294
|
+
})
|
|
295
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PointerEvent as ReactPointerEvent,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react'
|
|
8
|
+
|
|
9
|
+
const DISMISS_DISTANCE_PX = 96
|
|
10
|
+
const DISMISS_VELOCITY_PX_PER_MS = 0.5
|
|
11
|
+
const SNAP_BACK_MS = 200
|
|
12
|
+
const STATIONARY_AFTER_MS = 50
|
|
13
|
+
|
|
14
|
+
export interface UseSwipeToDismissOptions {
|
|
15
|
+
open: boolean
|
|
16
|
+
disableTransform: boolean
|
|
17
|
+
onDismiss: (event: ReactPointerEvent<HTMLElement>) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface DragState {
|
|
21
|
+
startY: number
|
|
22
|
+
lastMoveY: number
|
|
23
|
+
lastMoveTime: number
|
|
24
|
+
velocity: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function useSwipeToDismiss({
|
|
28
|
+
open,
|
|
29
|
+
disableTransform,
|
|
30
|
+
onDismiss,
|
|
31
|
+
}: UseSwipeToDismissOptions) {
|
|
32
|
+
const paperRef = useRef<HTMLDivElement | null>(null)
|
|
33
|
+
const dragState = useRef<DragState | null>(null)
|
|
34
|
+
const isDismissingRef = useRef(false)
|
|
35
|
+
const [isDragging, setIsDragging] = useState(false)
|
|
36
|
+
|
|
37
|
+
const applyTransform = useCallback(
|
|
38
|
+
(offsetPx: number, transition: string) => {
|
|
39
|
+
const node = paperRef.current
|
|
40
|
+
if (!node || disableTransform) return
|
|
41
|
+
node.style.transition = transition
|
|
42
|
+
node.style.transform = offsetPx > 0 ? `translateY(${offsetPx}px)` : ''
|
|
43
|
+
},
|
|
44
|
+
[disableTransform],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!open) return
|
|
49
|
+
isDismissingRef.current = false
|
|
50
|
+
const node = paperRef.current
|
|
51
|
+
if (node) {
|
|
52
|
+
node.style.transition = ''
|
|
53
|
+
node.style.transform = ''
|
|
54
|
+
}
|
|
55
|
+
}, [open])
|
|
56
|
+
|
|
57
|
+
const handlePointerDown = useCallback((event: ReactPointerEvent<HTMLElement>) => {
|
|
58
|
+
if (isDismissingRef.current) return
|
|
59
|
+
if (!event.isPrimary || (event.pointerType === 'mouse' && event.button !== 0)) return
|
|
60
|
+
|
|
61
|
+
const now = performance.now()
|
|
62
|
+
dragState.current = {
|
|
63
|
+
startY: event.clientY,
|
|
64
|
+
lastMoveY: event.clientY,
|
|
65
|
+
lastMoveTime: now,
|
|
66
|
+
velocity: 0,
|
|
67
|
+
}
|
|
68
|
+
setIsDragging(true)
|
|
69
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
70
|
+
}, [])
|
|
71
|
+
|
|
72
|
+
const handlePointerMove = useCallback(
|
|
73
|
+
(event: ReactPointerEvent<HTMLElement>) => {
|
|
74
|
+
const state = dragState.current
|
|
75
|
+
if (!state) return
|
|
76
|
+
const offsetPx = Math.max(0, event.clientY - state.startY)
|
|
77
|
+
applyTransform(offsetPx, 'none')
|
|
78
|
+
|
|
79
|
+
const now = performance.now()
|
|
80
|
+
const elapsedMs = Math.max(1, now - state.lastMoveTime)
|
|
81
|
+
state.velocity = Math.max(0, event.clientY - state.lastMoveY) / elapsedMs
|
|
82
|
+
state.lastMoveY = event.clientY
|
|
83
|
+
state.lastMoveTime = now
|
|
84
|
+
},
|
|
85
|
+
[applyTransform],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const endDrag = useCallback(
|
|
89
|
+
(event: ReactPointerEvent<HTMLElement>) => {
|
|
90
|
+
const state = dragState.current
|
|
91
|
+
if (!state) return
|
|
92
|
+
dragState.current = null
|
|
93
|
+
setIsDragging(false)
|
|
94
|
+
event.currentTarget.releasePointerCapture(event.pointerId)
|
|
95
|
+
|
|
96
|
+
const offsetPx = Math.max(0, event.clientY - state.startY)
|
|
97
|
+
const timeSinceLastMoveMs = performance.now() - state.lastMoveTime
|
|
98
|
+
const releaseVelocity =
|
|
99
|
+
timeSinceLastMoveMs <= STATIONARY_AFTER_MS ? state.velocity : 0
|
|
100
|
+
|
|
101
|
+
const shouldDismiss =
|
|
102
|
+
offsetPx > DISMISS_DISTANCE_PX || releaseVelocity > DISMISS_VELOCITY_PX_PER_MS
|
|
103
|
+
|
|
104
|
+
if (shouldDismiss) {
|
|
105
|
+
isDismissingRef.current = true
|
|
106
|
+
onDismiss(event)
|
|
107
|
+
} else {
|
|
108
|
+
applyTransform(0, `transform ${SNAP_BACK_MS}ms ease-out`)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[applyTransform, onDismiss],
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const cancelDrag = useCallback(
|
|
115
|
+
(event: ReactPointerEvent<HTMLElement>) => {
|
|
116
|
+
const state = dragState.current
|
|
117
|
+
if (!state) return
|
|
118
|
+
dragState.current = null
|
|
119
|
+
setIsDragging(false)
|
|
120
|
+
event.currentTarget.releasePointerCapture(event.pointerId)
|
|
121
|
+
applyTransform(0, `transform ${SNAP_BACK_MS}ms ease-out`)
|
|
122
|
+
},
|
|
123
|
+
[applyTransform],
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
paperRef,
|
|
128
|
+
isDragging,
|
|
129
|
+
handleProps: {
|
|
130
|
+
onPointerDown: handlePointerDown,
|
|
131
|
+
onPointerMove: handlePointerMove,
|
|
132
|
+
onPointerUp: endDrag,
|
|
133
|
+
onPointerCancel: cancelDrag,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default useSwipeToDismiss
|
|
@@ -56,6 +56,11 @@
|
|
|
56
56
|
"searchAriaLabel": "Open search"
|
|
57
57
|
},
|
|
58
58
|
|
|
59
|
+
"RcSesSelect": {
|
|
60
|
+
"searchPlaceholder": "Search",
|
|
61
|
+
"selectAllLabel": "All"
|
|
62
|
+
},
|
|
63
|
+
|
|
59
64
|
"RcSesSearchInput": {
|
|
60
65
|
"clearValueAriaLabel": "Clear search value",
|
|
61
66
|
"searchButtonLabel": "Search"
|
|
@@ -83,6 +88,12 @@
|
|
|
83
88
|
},
|
|
84
89
|
"cancel": "Cancel"
|
|
85
90
|
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
"RcSesBottomSheet": {
|
|
94
|
+
"aria": {
|
|
95
|
+
"back": "Back"
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
99
|
}
|
|
@@ -56,6 +56,11 @@
|
|
|
56
56
|
"searchAriaLabel": "Ieškoti"
|
|
57
57
|
},
|
|
58
58
|
|
|
59
|
+
"RcSesSelect": {
|
|
60
|
+
"searchPlaceholder": "Ieškoti",
|
|
61
|
+
"selectAllLabel": "Visi"
|
|
62
|
+
},
|
|
63
|
+
|
|
59
64
|
"RcSesSearchInput": {
|
|
60
65
|
"clearValueAriaLabel": "Išvalyti paieškos reikšmę",
|
|
61
66
|
"searchButtonLabel": "Ieškoti"
|
|
@@ -83,6 +88,12 @@
|
|
|
83
88
|
},
|
|
84
89
|
"cancel": "Atšaukti"
|
|
85
90
|
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
"RcSesBottomSheet": {
|
|
94
|
+
"aria": {
|
|
95
|
+
"back": "Atgal"
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
99
|
}
|
package/src/library/index.ts
CHANGED
|
@@ -62,6 +62,7 @@ import ServiceWizardStepper from '@/components/layout/ServiceWizardStepper'
|
|
|
62
62
|
import RcSesFullPageLoader from '@/components/loaders/FullPageLoader'
|
|
63
63
|
import RcSesLoader from '@/components/loaders/Loader'
|
|
64
64
|
import RcSesLoadingSpinner from '@/components/loaders/LoadingSpinner'
|
|
65
|
+
import RcSesBottomSheet from '@/components/overlays/BottomSheet'
|
|
65
66
|
import RcSesDialog from '@/components/overlays/Dialog'
|
|
66
67
|
import RcSesModal from '@/components/overlays/Modal'
|
|
67
68
|
import RcSesTheme from '@/theme/light'
|
|
@@ -99,6 +100,7 @@ export {
|
|
|
99
100
|
RcSesModal,
|
|
100
101
|
RcSesStepCard,
|
|
101
102
|
RcSesSwitch,
|
|
103
|
+
RcSesBottomSheet,
|
|
102
104
|
}
|
|
103
105
|
export { RcSesSegmentedControl }
|
|
104
106
|
export { RcSesSideNavLayout }
|
package/src/library/types.ts
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
RcSesLoadingSpinnerProps,
|
|
53
53
|
RcSesSpinnerColor,
|
|
54
54
|
} from '@/components/loaders/LoadingSpinner'
|
|
55
|
+
import { RcSesBottomSheetProps } from '@/components/overlays/BottomSheet'
|
|
55
56
|
import { DialogSize, RcSesDialogProps } from '@/components/overlays/Dialog'
|
|
56
57
|
import { ModalVariant, RcSesModalProps } from '@/components/overlays/Modal'
|
|
57
58
|
import { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
@@ -100,3 +101,4 @@ export type {
|
|
|
100
101
|
}
|
|
101
102
|
export type { RcSesDialogProps, DialogSize }
|
|
102
103
|
export type { RcSesModalProps, ModalVariant }
|
|
104
|
+
export type { RcSesBottomSheetProps }
|
|
@@ -240,6 +240,7 @@ export const Main: Story = {
|
|
|
240
240
|
interface VariantsFormModel {
|
|
241
241
|
singleSelect: string | null
|
|
242
242
|
groupedSelect: string | null
|
|
243
|
+
groupedMultiSelect: string[]
|
|
243
244
|
singleSearchSelect: string | null
|
|
244
245
|
descriptionSelect: string | null
|
|
245
246
|
multiSelect: string[]
|
|
@@ -272,11 +273,11 @@ const groupedVariantOptions: ({
|
|
|
272
273
|
value: string
|
|
273
274
|
label: string
|
|
274
275
|
})[] = [
|
|
275
|
-
{ value: 'group-1-option-1', label: '1st option', group: '
|
|
276
|
-
{ value: 'group-1-option-2', label: '2st option', group: '
|
|
277
|
-
{ value: 'group-1-option-3', label: '3rd option', group: '
|
|
278
|
-
{ value: 'group-2-option-4', label: '4th option', group: '
|
|
279
|
-
{ value: 'group-2-option-5', label: '5th option', group: '
|
|
276
|
+
{ value: 'group-1-option-1', label: '1st option', group: 'Group 1' },
|
|
277
|
+
{ value: 'group-1-option-2', label: '2st option', group: 'Group 1' },
|
|
278
|
+
{ value: 'group-1-option-3', label: '3rd option', group: 'Group 1' },
|
|
279
|
+
{ value: 'group-2-option-4', label: '4th option', group: 'Group 2' },
|
|
280
|
+
{ value: 'group-2-option-5', label: '5th option', group: 'Group 2' },
|
|
280
281
|
]
|
|
281
282
|
|
|
282
283
|
const optionsWithDescriptions = [
|
|
@@ -333,6 +334,7 @@ export const AllVariants: Story = {
|
|
|
333
334
|
defaultValues: {
|
|
334
335
|
singleSelect: null,
|
|
335
336
|
groupedSelect: null,
|
|
337
|
+
groupedMultiSelect: ['group-2-option-4', 'group-2-option-5'],
|
|
336
338
|
singleSearchSelect: null,
|
|
337
339
|
descriptionSelect: 'option-3',
|
|
338
340
|
multiSelect: ['option-1', 'option-3'],
|
|
@@ -405,6 +407,32 @@ export const AllVariants: Story = {
|
|
|
405
407
|
/>
|
|
406
408
|
</VariantCard>
|
|
407
409
|
|
|
410
|
+
<VariantCard
|
|
411
|
+
title='Grouped multi select + search'
|
|
412
|
+
description='Grupė yra pati savarankiškai pažymima reikšmė - pažymėjus grupę pažymimi visi jos nariai, nužymėjus bet kurį narį grupė automatiškai nužymima.'
|
|
413
|
+
>
|
|
414
|
+
<RcSesSelect
|
|
415
|
+
id='grouped-multi-select'
|
|
416
|
+
name='groupedMultiSelect'
|
|
417
|
+
control={control}
|
|
418
|
+
label='Pasirinkti'
|
|
419
|
+
slotProps={{
|
|
420
|
+
wrapper: { labelOnTop: true },
|
|
421
|
+
field: {
|
|
422
|
+
groupBy: (option) =>
|
|
423
|
+
groupedVariantOptions.find(
|
|
424
|
+
(groupedOption) => groupedOption.value === option.value,
|
|
425
|
+
)?.group ?? '',
|
|
426
|
+
},
|
|
427
|
+
}}
|
|
428
|
+
multiple
|
|
429
|
+
dropdownSearch
|
|
430
|
+
selectAll
|
|
431
|
+
dropdownSearchPlaceholder='Ieškoti'
|
|
432
|
+
options={groupedVariantOptions}
|
|
433
|
+
/>
|
|
434
|
+
</VariantCard>
|
|
435
|
+
|
|
408
436
|
<VariantCard title='Basic + search' description='Bazinis variantas su paieska.'>
|
|
409
437
|
<RcSesSelect
|
|
410
438
|
id='single-search-select'
|