@basic-ui/core 0.0.34 → 0.0.37
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/build/cjs/index.js +17 -5
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +1 -1
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +2 -2
- package/build/esm/hooks/useGestureHandlers.d.ts +3 -0
- package/build/esm/hooks/useGestureHandlers.js +17 -5
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +960 -1018
- package/package.json +4 -4
- package/src/Accordion/Accordion.story.tsx +5 -4
- package/src/ComboBox/ComboBox.story.tsx +9 -8
- package/src/List/List.story.tsx +5 -4
- package/src/Menu/Menu.story.tsx +9 -8
- package/src/Modal/Modal.story.tsx +15 -14
- package/src/Modal/NavDrawer.story.tsx +5 -4
- package/src/Popper/Popper.story.tsx +13 -16
- package/src/RadioButton/RadioButton.story.tsx +12 -9
- package/src/Spinner/Spinner.story.tsx +5 -5
- package/src/Tabs/Tab.story.tsx +9 -8
- package/src/Tooltip/Tooltip.story.tsx +6 -5
- package/src/Tooltip/useTooltip.ts +1 -1
- package/src/hooks/useGestureHandlers.ts +22 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basic-ui/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "Accessible React Components used as building blocks for UI patterns",
|
|
5
5
|
"author": "Lucas Terra <lucasterra7@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
|
-
"react": "
|
|
37
|
-
"react-dom": "
|
|
36
|
+
"react": "^16.14.0 || ^17.0.0 || ^18.0.0",
|
|
37
|
+
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "78b668ff80ce86a4672b3f34ca2c1aaaf79c56eb"
|
|
40
40
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Accordion, AccordionBody, AccordionHeader, AccordionItem } from './';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import './styles.css';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export default {
|
|
6
|
+
title: 'components/Accordion',
|
|
7
|
+
};
|
|
7
8
|
|
|
8
9
|
function AccordionControlled() {
|
|
9
10
|
const [expandedId, setExpandedId] = useState(0);
|
|
@@ -67,6 +68,6 @@ function SingleAccordionItem() {
|
|
|
67
68
|
);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
export const Controlled = () => <AccordionControlled />;
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
export const SingleAccordionControlled = () => <SingleAccordionItem />;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
2
|
import type * as React from 'react';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import { ComboboxOption } from './ComboboxOption';
|
|
5
4
|
import { ComboboxList } from './ComboboxList';
|
|
6
5
|
import { ComboboxPopover } from './ComboboxPopover';
|
|
@@ -10,7 +9,9 @@ import { Combobox } from './Combobox';
|
|
|
10
9
|
import cities from './cities';
|
|
11
10
|
import './styles.css';
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export default {
|
|
13
|
+
title: 'components/Combobox',
|
|
14
|
+
};
|
|
14
15
|
|
|
15
16
|
function useCityMatch(searchTerm: string) {
|
|
16
17
|
return useMemo(() => {
|
|
@@ -108,11 +109,11 @@ export function ControlledClientSideExample({ initialValue = '' }) {
|
|
|
108
109
|
);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
export const UncontrolledClientSide = () => <UncontrolledClientSideExample />;
|
|
113
|
+
export const UncontrolledClientSideInitial = () => (
|
|
113
114
|
<UncontrolledClientSideExample initialValue="Aberdeen" />
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
);
|
|
116
|
+
export const ControlledClientSide = () => <ControlledClientSideExample />;
|
|
117
|
+
export const ControlledClientsideInitial = () => (
|
|
117
118
|
<ControlledClientSideExample initialValue="Aberdeen" />
|
|
118
|
-
)
|
|
119
|
+
);
|
package/src/List/List.story.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { List, ListItem } from './';
|
|
2
|
-
import { storiesOf } from '@storybook/react';
|
|
3
2
|
// import './styles.css';
|
|
4
3
|
|
|
4
|
+
export default {
|
|
5
|
+
title: 'components/List',
|
|
6
|
+
};
|
|
7
|
+
|
|
5
8
|
const Example = () => {
|
|
6
9
|
return (
|
|
7
10
|
<List>
|
|
@@ -12,6 +15,4 @@ const Example = () => {
|
|
|
12
15
|
);
|
|
13
16
|
};
|
|
14
17
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
stories.add('controlled', () => <Example />);
|
|
18
|
+
export const Controlled = () => <Example />;
|
package/src/Menu/Menu.story.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import type * as React from 'react';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import { Menu, MenuButton, MenuItem, MenuList, MenuPopover } from './';
|
|
5
4
|
import { animated, useSpring } from 'react-spring';
|
|
6
5
|
import './styles.css';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export default {
|
|
8
|
+
title: 'components/Menu',
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
const noop = () => {
|
|
11
12
|
// noop function to be used on onRest, as a cleanup
|
|
@@ -139,20 +140,20 @@ const MenuWithMultipleButtons = () => {
|
|
|
139
140
|
);
|
|
140
141
|
};
|
|
141
142
|
|
|
142
|
-
|
|
143
|
+
export const Controlled = () => (
|
|
143
144
|
<Wrapper>
|
|
144
145
|
<MenuControlled />
|
|
145
146
|
</Wrapper>
|
|
146
|
-
)
|
|
147
|
+
);
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
export const WithAnimationControlled = () => (
|
|
149
150
|
<Wrapper>
|
|
150
151
|
<MenuControlledWithAnimation />
|
|
151
152
|
</Wrapper>
|
|
152
|
-
)
|
|
153
|
+
);
|
|
153
154
|
|
|
154
|
-
|
|
155
|
+
export const WithMultipleButtons = () => (
|
|
155
156
|
<Wrapper>
|
|
156
157
|
<MenuWithMultipleButtons />
|
|
157
158
|
</Wrapper>
|
|
158
|
-
)
|
|
159
|
+
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { storiesOf } from '@storybook/react';
|
|
3
2
|
import { useSpring, animated } from 'react-spring';
|
|
4
3
|
import { Modal, ModalBackdrop } from './';
|
|
5
4
|
import { Portal } from '../Portal';
|
|
6
5
|
import './styles.css';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export default {
|
|
8
|
+
title: 'components/Modal',
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
const LoremIpsum = ({ numOfParagraphs = 20 }) => {
|
|
11
12
|
const content = [];
|
|
@@ -81,7 +82,7 @@ const Wrapper = ({ children }) => {
|
|
|
81
82
|
);
|
|
82
83
|
};
|
|
83
84
|
|
|
84
|
-
const
|
|
85
|
+
const SimpleModalControlledExample = () => {
|
|
85
86
|
const [open, setOpen] = useState(false);
|
|
86
87
|
|
|
87
88
|
const handleClose = () => {
|
|
@@ -106,7 +107,7 @@ const SimpleModalControlled = () => {
|
|
|
106
107
|
);
|
|
107
108
|
};
|
|
108
109
|
|
|
109
|
-
const
|
|
110
|
+
const NestedModalControlledExample = () => {
|
|
110
111
|
const [open, setOpen] = useState(false);
|
|
111
112
|
const [open2, setOpen2] = useState(false);
|
|
112
113
|
|
|
@@ -138,7 +139,7 @@ const NestedModalControlled = () => {
|
|
|
138
139
|
);
|
|
139
140
|
};
|
|
140
141
|
|
|
141
|
-
const
|
|
142
|
+
const SimpleModalControlledAnimatedExample = () => {
|
|
142
143
|
const [open, setOpen] = useState(false);
|
|
143
144
|
const [pointerEvents, setPointerEvents] = useState('none');
|
|
144
145
|
const [{ scale, opacity }, set] = useSpring(() => ({
|
|
@@ -223,20 +224,20 @@ const SimpleModalControlledAnimated = () => {
|
|
|
223
224
|
);
|
|
224
225
|
};
|
|
225
226
|
|
|
226
|
-
|
|
227
|
+
export const SimpleModalControlled = () => (
|
|
227
228
|
<Wrapper>
|
|
228
|
-
<
|
|
229
|
+
<SimpleModalControlledExample />
|
|
229
230
|
</Wrapper>
|
|
230
|
-
)
|
|
231
|
+
);
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
export const NestedModalControlled = () => (
|
|
233
234
|
<Wrapper>
|
|
234
|
-
<
|
|
235
|
+
<NestedModalControlledExample />
|
|
235
236
|
</Wrapper>
|
|
236
|
-
)
|
|
237
|
+
);
|
|
237
238
|
|
|
238
|
-
|
|
239
|
+
export const SimpleModalControlledAnimated = () => (
|
|
239
240
|
<Wrapper>
|
|
240
|
-
<
|
|
241
|
+
<SimpleModalControlledAnimatedExample />
|
|
241
242
|
</Wrapper>
|
|
242
|
-
)
|
|
243
|
+
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import { storiesOf } from '@storybook/react';
|
|
3
2
|
import { useSpring, animated } from 'react-spring';
|
|
4
3
|
import { Modal, ModalBackdrop } from './';
|
|
5
4
|
import { Portal } from '../Portal';
|
|
6
5
|
import './styles.css';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export default {
|
|
8
|
+
title: 'components/Modal/NavDrawer',
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
const LoremIpsum = ({ numOfParagraphs = 20 }) => {
|
|
11
12
|
const content = [];
|
|
@@ -150,8 +151,8 @@ const SimpleModalControlledAnimated = () => {
|
|
|
150
151
|
);
|
|
151
152
|
};
|
|
152
153
|
|
|
153
|
-
|
|
154
|
+
export const ControlledAnimated = () => (
|
|
154
155
|
<Wrapper>
|
|
155
156
|
<SimpleModalControlledAnimated />
|
|
156
157
|
</Wrapper>
|
|
157
|
-
)
|
|
158
|
+
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useRef, useState, useEffect } from 'react';
|
|
2
2
|
import { useSpring, animated } from 'react-spring';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import { Popper } from './Popper';
|
|
5
4
|
import { PopperArrow } from './PopperArrow';
|
|
6
5
|
import './styles.css';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export default {
|
|
8
|
+
title: 'components/Popper',
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
const noop = () => {
|
|
11
12
|
// noop function to be used on onRest, as a cleanup
|
|
@@ -188,7 +189,7 @@ const PopperFixedExample = ({ showAll = false, showArrow = false }) => {
|
|
|
188
189
|
);
|
|
189
190
|
};
|
|
190
191
|
|
|
191
|
-
const
|
|
192
|
+
const JumpingPopperExample = () => {
|
|
192
193
|
const [currentPopperIndex, setCurrentPopperIndex] = useState(0);
|
|
193
194
|
const ref1 = useRef();
|
|
194
195
|
const ref2 = useRef();
|
|
@@ -227,7 +228,7 @@ const JumpingPopper = () => {
|
|
|
227
228
|
);
|
|
228
229
|
};
|
|
229
230
|
|
|
230
|
-
const
|
|
231
|
+
const RerenderingPopperExample = () => {
|
|
231
232
|
const [value, setValue] = useState('');
|
|
232
233
|
const ref = useRef<HTMLButtonElement>(null);
|
|
233
234
|
return (
|
|
@@ -248,20 +249,16 @@ const RerenderingPopper = () => {
|
|
|
248
249
|
);
|
|
249
250
|
};
|
|
250
251
|
|
|
251
|
-
|
|
252
|
+
export const SinglePoint = () => <PopperExample />;
|
|
252
253
|
|
|
253
|
-
|
|
254
|
+
export const AllPoints = () => <PopperExample showAll={true} />;
|
|
254
255
|
|
|
255
|
-
|
|
256
|
-
<PopperExample showArrow={true} />
|
|
257
|
-
));
|
|
256
|
+
export const SinglePointWithArrow = () => <PopperExample showArrow={true} />;
|
|
258
257
|
|
|
259
|
-
|
|
258
|
+
export const AllPointsWithArrow = () => (
|
|
260
259
|
<PopperExample showAll={true} showArrow={true} />
|
|
261
|
-
)
|
|
260
|
+
);
|
|
262
261
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
stories.add('Re-rendering popper', () => <RerenderingPopper />);
|
|
267
|
-
stories.add('Jumping popper', () => <JumpingPopper />);
|
|
262
|
+
export const FixedPopperAllPoints = () => <PopperFixedExample showAll={true} />;
|
|
263
|
+
export const RerenderingPopper = () => <RerenderingPopperExample />;
|
|
264
|
+
export const JumpingPopper = () => <JumpingPopperExample />;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { RadioButton, RadioGroup } from './';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
// import './styles.css';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export default {
|
|
6
|
+
title: 'components/RadioButton',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const UncontrolledExample = (props: { initialValue?: string }) => {
|
|
7
10
|
return (
|
|
8
11
|
<RadioGroup defaultValue={props.initialValue}>
|
|
9
12
|
<label>
|
|
@@ -30,7 +33,7 @@ const Uncontrolled = (props: { initialValue?: string }) => {
|
|
|
30
33
|
);
|
|
31
34
|
};
|
|
32
35
|
|
|
33
|
-
const
|
|
36
|
+
const ControlledExample = () => {
|
|
34
37
|
const [value, setValue] = useState(undefined);
|
|
35
38
|
|
|
36
39
|
return (
|
|
@@ -64,10 +67,10 @@ const Controlled = () => {
|
|
|
64
67
|
);
|
|
65
68
|
};
|
|
66
69
|
|
|
67
|
-
const
|
|
70
|
+
export const Uncontrolled = () => <UncontrolledExample />;
|
|
71
|
+
|
|
72
|
+
export const UncontrolledWithInitialValue = () => (
|
|
73
|
+
<UncontrolledExample initialValue={'highly disagree'} />
|
|
74
|
+
);
|
|
68
75
|
|
|
69
|
-
|
|
70
|
-
stories.add('uncontrolled, initial value set', () => (
|
|
71
|
-
<Uncontrolled initialValue={'highly disagree'} />
|
|
72
|
-
));
|
|
73
|
-
stories.add('controlled', () => <Controlled />);
|
|
76
|
+
export const Controlled = () => <ControlledExample />;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Spinner, SpinnerButton } from './';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import './styles.css';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export default {
|
|
6
|
+
title: 'components/Spinner',
|
|
7
|
+
};
|
|
7
8
|
|
|
8
9
|
const Example = ({ vertical = false }) => {
|
|
9
10
|
const [value, setValue] = useState(0);
|
|
@@ -25,6 +26,5 @@ const Example = ({ vertical = false }) => {
|
|
|
25
26
|
);
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stories.add('vertical', () => <Example vertical={true} />);
|
|
29
|
+
export const Horizontal = () => <Example />;
|
|
30
|
+
export const Vertical = () => <Example vertical={true} />;
|
package/src/Tabs/Tab.story.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Tab, TabPanel, TabPanels, Tabs, TabList } from './';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import './styles.css';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export default {
|
|
6
|
+
title: 'components/Tab',
|
|
7
|
+
};
|
|
7
8
|
|
|
8
9
|
export const ExampleHorizontal = ({ manualActivation = false }) => {
|
|
9
10
|
const [index, setIndex] = useState(0);
|
|
@@ -67,12 +68,12 @@ export const ExampleVertical = ({ manualActivation = false }) => {
|
|
|
67
68
|
);
|
|
68
69
|
};
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
export const HorizontalControlled = () => <ExampleHorizontal />;
|
|
72
|
+
export const HorizontalControlledManualActivation = () => (
|
|
72
73
|
<ExampleHorizontal manualActivation={true} />
|
|
73
|
-
)
|
|
74
|
+
);
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
export const VerticalControlled = () => <ExampleVertical />;
|
|
77
|
+
export const VerticalControlledManualActivation = () => (
|
|
77
78
|
<ExampleVertical manualActivation={true} />
|
|
78
|
-
)
|
|
79
|
+
);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React, { useRef, forwardRef } from 'react';
|
|
2
2
|
import { Tooltip } from './';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
3
|
import { Popper } from '../Popper/Popper';
|
|
5
4
|
import { InjectedTooltipProps } from './useTooltip';
|
|
6
5
|
import './styles.css';
|
|
7
6
|
|
|
7
|
+
export default {
|
|
8
|
+
title: 'components/Tooltip',
|
|
9
|
+
};
|
|
10
|
+
|
|
8
11
|
const StyledTooltip = forwardRef<HTMLDivElement, InjectedTooltipProps>(
|
|
9
12
|
({ children, anchorEl, ...props }, ref) => {
|
|
10
13
|
return (
|
|
@@ -53,7 +56,5 @@ const ExampleWithHidingButton = () => {
|
|
|
53
56
|
);
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
stories.add('controlled', () => <Example />);
|
|
59
|
-
stories.add('with hiding button', () => <ExampleWithHidingButton />);
|
|
59
|
+
export const Controlled = () => <Example />;
|
|
60
|
+
export const WithHidingButton = () => <ExampleWithHidingButton />;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useRef, RefAttributes, useEffect, useState } from 'react';
|
|
2
2
|
import { assignMultipleRefs } from '../utils/assignRef';
|
|
3
3
|
import { wrapEvent } from '../utils/wrapEvent';
|
|
4
4
|
import { useId } from '../hooks/useId';
|
|
@@ -17,6 +17,7 @@ export interface GestureHandlersState {
|
|
|
17
17
|
yVelocity: number;
|
|
18
18
|
startTime: number;
|
|
19
19
|
down: boolean;
|
|
20
|
+
scrollLocked: boolean;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
type SetStateFunc<S> = (
|
|
@@ -31,6 +32,7 @@ export interface GestureHandlersReturn {
|
|
|
31
32
|
|
|
32
33
|
export interface GestureHandlerOptions {
|
|
33
34
|
ensureTargetIsContainer?: boolean;
|
|
35
|
+
minTouchDelta?: number;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export const initialGestureHandlersState: GestureHandlersState = {
|
|
@@ -49,6 +51,7 @@ export const initialGestureHandlersState: GestureHandlersState = {
|
|
|
49
51
|
yVelocity: 0,
|
|
50
52
|
startTime: 0,
|
|
51
53
|
down: false,
|
|
54
|
+
scrollLocked: false,
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
const FRAMERATE_CONST = 1000 / 60; // 60 fps
|
|
@@ -59,7 +62,7 @@ export function gestureHandlers(
|
|
|
59
62
|
containerRef?: React.MutableRefObject<HTMLElement | null>,
|
|
60
63
|
options: GestureHandlerOptions = {}
|
|
61
64
|
): GestureHandlersReturn {
|
|
62
|
-
const { ensureTargetIsContainer = false } = options;
|
|
65
|
+
const { ensureTargetIsContainer = false, minTouchDelta = 0 } = options;
|
|
63
66
|
|
|
64
67
|
// Common handlers
|
|
65
68
|
const handleUp = () => {
|
|
@@ -102,6 +105,7 @@ export function gestureHandlers(
|
|
|
102
105
|
yPrev: pageY,
|
|
103
106
|
startTime: Date.now(),
|
|
104
107
|
down: true,
|
|
108
|
+
scrollLocked: false,
|
|
105
109
|
};
|
|
106
110
|
|
|
107
111
|
return newState;
|
|
@@ -129,18 +133,33 @@ export function gestureHandlers(
|
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
set((state: GestureHandlersState) => {
|
|
136
|
+
function getDeltaSum(
|
|
137
|
+
currentPos: number,
|
|
138
|
+
initialPos: number,
|
|
139
|
+
prevPos: number
|
|
140
|
+
): number {
|
|
141
|
+
if (
|
|
142
|
+
state.scrollLocked ||
|
|
143
|
+
Math.abs(currentPos - initialPos) >= minTouchDelta
|
|
144
|
+
) {
|
|
145
|
+
state.scrollLocked = true;
|
|
146
|
+
return currentPos - prevPos;
|
|
147
|
+
}
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
const target =
|
|
133
152
|
(containerRef && containerRef.current) || (e as any).target;
|
|
134
153
|
|
|
135
154
|
const deltaTime = Date.now() - state.startTime;
|
|
136
155
|
|
|
137
156
|
const width = target ? target.offsetWidth : NaN;
|
|
138
|
-
const xDelta = pageX
|
|
157
|
+
const xDelta = state.xDelta + getDeltaSum(pageX, state.xInitial, state.x);
|
|
139
158
|
const xDeltaPercent = (xDelta * 100) / width;
|
|
140
159
|
const xVelocity = calcVelocity(xDelta, deltaTime, state.xVelocity);
|
|
141
160
|
|
|
142
161
|
const height = target ? target.offsetHeight : NaN;
|
|
143
|
-
const yDelta = pageY
|
|
162
|
+
const yDelta = state.yDelta + getDeltaSum(pageY, state.yInitial, state.y);
|
|
144
163
|
const yDeltaPercent = (yDelta * 100) / height;
|
|
145
164
|
const yVelocity = calcVelocity(yDelta, deltaTime, state.yVelocity);
|
|
146
165
|
|