@registrucentras/rc-ses-react-components 2.0.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/README.md +4 -0
- package/dist/assets/icons/ShoppingCartIcon.d.ts +3 -0
- package/dist/components/common/CardShell/index.d.ts +1 -1
- package/dist/components/common/CardShell/types.d.ts +10 -0
- package/dist/components/common/ListWithIcons/ListWithIcons.types.d.ts +4 -1
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +34 -0
- package/dist/components/common/StepCard/index.d.ts +3 -0
- package/dist/components/common/StepCard/types.d.ts +39 -0
- package/dist/components/common/TitleBlock/types.d.ts +1 -1
- 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/layout/ServiceFormContainer/CardFormContainer/index.d.ts +3 -0
- package/dist/components/loaders/LoadingSpinner/index.d.ts +1 -4
- package/dist/components/overlays/BottomSheet/index.d.ts +17 -0
- package/dist/components/overlays/BottomSheet/useSwipeToDismiss.d.ts +17 -0
- package/dist/library/icons.d.ts +2 -1
- package/dist/library/index.d.ts +3 -1
- package/dist/library/types.d.ts +6 -3
- package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
- package/dist/registrucentras-rc-ses-react-components.js +3903 -3289
- package/dist/theme/cards.d.ts +12 -12
- package/dist/theme/light/MuiTypography.d.ts +14 -0
- package/dist/theme/palette.d.ts +124 -124
- package/dist/theme/spacing.d.ts +4 -0
- package/package.json +2 -1
- package/src/assets/icons/ShoppingCartIcon.tsx +16 -0
- package/src/components/common/Button/index.test.tsx +20 -11
- package/src/components/common/Button/index.tsx +8 -44
- package/src/components/common/CardShell/index.tsx +6 -2
- package/src/components/common/CardShell/types.ts +10 -0
- package/src/components/common/ListWithIcons/ListWithIcons.types.ts +22 -1
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +13 -4
- package/src/components/common/ListWithIcons/index.test.tsx +42 -0
- package/src/components/common/StepCard/StepCardFooter/index.test.tsx +162 -0
- package/src/components/common/StepCard/StepCardFooter/index.tsx +120 -0
- package/src/components/common/StepCard/index.test.tsx +120 -0
- package/src/components/common/StepCard/index.tsx +74 -0
- package/src/components/common/StepCard/types.ts +45 -0
- package/src/components/common/TitleBlock/types.ts +1 -1
- package/src/components/form/inputs/SearchableField.test.tsx +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/layout/ServiceFormContainer/CardFormContainer/index.tsx +3 -0
- package/src/components/loaders/LoadingSpinner/index.tsx +3 -26
- 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/examples/ListWithPagination/index.tsx +2 -1
- package/src/i18n/namespaces/common/en.json +7 -0
- package/src/i18n/namespaces/common/lt.json +7 -0
- package/src/i18n/namespaces/input/en.json +11 -0
- package/src/i18n/namespaces/input/lt.json +11 -0
- package/src/library/icons.ts +2 -0
- package/src/library/index.ts +4 -0
- package/src/library/types.ts +19 -2
- package/src/stories/atoms/Button.stories.tsx +202 -497
- package/src/stories/atoms/Select.stories.tsx +33 -5
- package/src/stories/foundations/ThemedMuiComponents.stories.tsx +2 -2
- package/src/stories/molecules/CardShell.stories.tsx +36 -2
- package/src/stories/molecules/DatePicker.stories.tsx +1 -2
- package/src/stories/molecules/ListWithIcons.stories.tsx +26 -0
- package/src/stories/molecules/Popover.stories.tsx +1 -1
- package/src/stories/molecules/StepCard.stories.tsx +181 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +2 -2
- package/src/stories/organisms/AdvancedListItem.stories.tsx +80 -0
- package/src/stories/organisms/BottomSheet.stories.tsx +291 -0
- package/src/stories/organisms/CardFormContainer.stories.tsx +1 -1
- package/src/stories/organisms/Dialog.stories.tsx +1 -2
- package/src/theme/light/MuiAutocomplete.ts +43 -19
- package/src/theme/light/MuiButton.tsx +54 -0
- package/src/theme/light/MuiCard.tsx +9 -7
- package/src/theme/light/MuiTypography.tsx +17 -0
- package/src/theme/palette.tsx +7 -7
- package/src/theme/spacing.ts +5 -0
|
@@ -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
|
|
@@ -8,6 +8,7 @@ import SelectableCardList, {
|
|
|
8
8
|
import ServiceHeader from '@/components/layout/ServiceHeader'
|
|
9
9
|
import ServicePage from '@/components/layout/ServicePage'
|
|
10
10
|
import { BarcodeIcon, MapPinAreaIcon, ScalesIcon } from '@/library'
|
|
11
|
+
import { error } from '@/theme/palette'
|
|
11
12
|
|
|
12
13
|
interface ApiItem {
|
|
13
14
|
id: string
|
|
@@ -42,7 +43,7 @@ const mapToSelectableItems = (data: ApiItem[]): SelectableCardListItemData[] =>
|
|
|
42
43
|
id: 'status',
|
|
43
44
|
icon: ScalesIcon,
|
|
44
45
|
text: item.legalStatusName,
|
|
45
|
-
textColor: item.legalStatusName === 'Neįregistruotas' ? '
|
|
46
|
+
textColor: item.legalStatusName === 'Neįregistruotas' ? error['600'] : undefined,
|
|
46
47
|
},
|
|
47
48
|
{
|
|
48
49
|
id: 'address',
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
"Button": {
|
|
12
12
|
"loading": "Loading"
|
|
13
13
|
},
|
|
14
|
+
"StepCard": {
|
|
15
|
+
"cancel": "Cancel",
|
|
16
|
+
"back": "Back",
|
|
17
|
+
"continue": "Continue",
|
|
18
|
+
"addToCart": "Add to cart",
|
|
19
|
+
"totalWithoutVat": "Total excl. VAT"
|
|
20
|
+
},
|
|
14
21
|
"SegmentedControl": {
|
|
15
22
|
"options": "Options",
|
|
16
23
|
"tabs": "Tabs"
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
"Button": {
|
|
12
12
|
"loading": "Kraunasi"
|
|
13
13
|
},
|
|
14
|
+
"StepCard": {
|
|
15
|
+
"cancel": "Atšaukti",
|
|
16
|
+
"back": "Atgal",
|
|
17
|
+
"continue": "Tęsti",
|
|
18
|
+
"addToCart": "Pridėti į krepšelį",
|
|
19
|
+
"totalWithoutVat": "Suma be PVM"
|
|
20
|
+
},
|
|
14
21
|
"SegmentedControl": {
|
|
15
22
|
"options": "Parinktys",
|
|
16
23
|
"tabs": "Skirtukai"
|
|
@@ -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/icons.ts
CHANGED
|
@@ -40,6 +40,7 @@ import ScalesIcon from '@/assets/icons/ScalesIcon'
|
|
|
40
40
|
import ScrollIcon from '@/assets/icons/ScrollIcon'
|
|
41
41
|
import SearchHelpIcon from '@/assets/icons/SearchHelpIcon'
|
|
42
42
|
import SearchXIcon from '@/assets/icons/SearchXIcon'
|
|
43
|
+
import ShoppingCartIcon from '@/assets/icons/ShoppingCartIcon'
|
|
43
44
|
import SpinnerGapBoldIcon from '@/assets/icons/SpinnerGapBoldIcon'
|
|
44
45
|
import TrashIcon from '@/assets/icons/TrashIcon'
|
|
45
46
|
import UploadSimpleIcon from '@/assets/icons/UploadSimpleIcon'
|
|
@@ -92,6 +93,7 @@ export {
|
|
|
92
93
|
ScrollIcon,
|
|
93
94
|
SearchHelpIcon,
|
|
94
95
|
SearchXIcon,
|
|
96
|
+
ShoppingCartIcon,
|
|
95
97
|
SpinnerGapBoldIcon,
|
|
96
98
|
TrashIcon,
|
|
97
99
|
UploadSimpleIcon,
|
package/src/library/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
RcSesSnackbarProvider,
|
|
29
29
|
useSnackbar,
|
|
30
30
|
} from '@/components/common/Snackbar/SnackbarProvider'
|
|
31
|
+
import RcSesStepCard from '@/components/common/StepCard'
|
|
31
32
|
import RcSesSwitch from '@/components/common/Switch'
|
|
32
33
|
import RcSesTab from '@/components/common/Tabs/Tab'
|
|
33
34
|
import RcSesTabPanel from '@/components/common/Tabs/TabPanel'
|
|
@@ -61,6 +62,7 @@ import ServiceWizardStepper from '@/components/layout/ServiceWizardStepper'
|
|
|
61
62
|
import RcSesFullPageLoader from '@/components/loaders/FullPageLoader'
|
|
62
63
|
import RcSesLoader from '@/components/loaders/Loader'
|
|
63
64
|
import RcSesLoadingSpinner from '@/components/loaders/LoadingSpinner'
|
|
65
|
+
import RcSesBottomSheet from '@/components/overlays/BottomSheet'
|
|
64
66
|
import RcSesDialog from '@/components/overlays/Dialog'
|
|
65
67
|
import RcSesModal from '@/components/overlays/Modal'
|
|
66
68
|
import RcSesTheme from '@/theme/light'
|
|
@@ -96,7 +98,9 @@ export {
|
|
|
96
98
|
RcSesSnackbar,
|
|
97
99
|
RcSesSnackbarProvider,
|
|
98
100
|
RcSesModal,
|
|
101
|
+
RcSesStepCard,
|
|
99
102
|
RcSesSwitch,
|
|
103
|
+
RcSesBottomSheet,
|
|
100
104
|
}
|
|
101
105
|
export { RcSesSegmentedControl }
|
|
102
106
|
export { RcSesSideNavLayout }
|
package/src/library/types.ts
CHANGED
|
@@ -11,7 +11,11 @@ import {
|
|
|
11
11
|
RcSesCardShellTestIds,
|
|
12
12
|
} from '@/components/common/CardShell/types'
|
|
13
13
|
import { ListWithIconsProps } from '@/components/common/ListWithIcons'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
ListWithIconsItemData,
|
|
16
|
+
ListWithIconsItemTone,
|
|
17
|
+
PaletteColor,
|
|
18
|
+
} from '@/components/common/ListWithIcons/ListWithIcons.types'
|
|
15
19
|
import {
|
|
16
20
|
RcSesSegmentOption,
|
|
17
21
|
RcSesSegmentedControlProps,
|
|
@@ -24,6 +28,10 @@ import {
|
|
|
24
28
|
} from '@/components/common/ServiceLinks/types'
|
|
25
29
|
import { RcSesSideNavItem, RcSesSideNavOverflow } from '@/components/common/SideNav'
|
|
26
30
|
import { RcSesSideNavLayoutProps } from '@/components/common/SideNav/SideNavLayout'
|
|
31
|
+
import {
|
|
32
|
+
RcSesStepCardProps,
|
|
33
|
+
RcSesStepCardTestIds,
|
|
34
|
+
} from '@/components/common/StepCard/types'
|
|
27
35
|
import {
|
|
28
36
|
RcSesTitleBlockProps,
|
|
29
37
|
RcSesTitleBlockTestIds,
|
|
@@ -44,11 +52,17 @@ import {
|
|
|
44
52
|
RcSesLoadingSpinnerProps,
|
|
45
53
|
RcSesSpinnerColor,
|
|
46
54
|
} from '@/components/loaders/LoadingSpinner'
|
|
55
|
+
import { RcSesBottomSheetProps } from '@/components/overlays/BottomSheet'
|
|
47
56
|
import { DialogSize, RcSesDialogProps } from '@/components/overlays/Dialog'
|
|
48
57
|
import { ModalVariant, RcSesModalProps } from '@/components/overlays/Modal'
|
|
49
58
|
import { ButtonProps } from '@/types/buttons/ButtonProps'
|
|
50
59
|
|
|
51
|
-
export type {
|
|
60
|
+
export type {
|
|
61
|
+
ListWithIconsProps,
|
|
62
|
+
ListWithIconsItemData,
|
|
63
|
+
ListWithIconsItemTone,
|
|
64
|
+
PaletteColor,
|
|
65
|
+
}
|
|
52
66
|
export type { RcSesServiceLinksProps, RcSesServiceLinkItem, RcSesServiceLinksTestIds }
|
|
53
67
|
export type { ButtonProps }
|
|
54
68
|
|
|
@@ -82,6 +96,9 @@ export type {
|
|
|
82
96
|
RcSesSideNavItem,
|
|
83
97
|
RcSesSideNavLayoutProps,
|
|
84
98
|
RcSesSideNavOverflow,
|
|
99
|
+
RcSesStepCardProps,
|
|
100
|
+
RcSesStepCardTestIds,
|
|
85
101
|
}
|
|
86
102
|
export type { RcSesDialogProps, DialogSize }
|
|
87
103
|
export type { RcSesModalProps, ModalVariant }
|
|
104
|
+
export type { RcSesBottomSheetProps }
|