@rpg-engine/long-bow 0.5.71 → 0.5.73
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/ImageCarousel/SimpleImageCarousel.d.ts +3 -2
- package/dist/long-bow.cjs.development.js +42 -32
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +42 -32
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/ImageCarousel/SimpleImageCarousel.tsx +47 -32
- package/src/stories/SimpleImageCarousel.stories.tsx +2 -3
- package/src/assets/images/backpack.png +0 -0
- package/src/assets/images/depot.png +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpg-engine/long-bow",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.73",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"uuid": "^8.3.2"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
+
"@capacitor/core": "^4.6.3",
|
|
85
86
|
"@rollup/plugin-image": "^2.1.1",
|
|
86
87
|
"@rpg-engine/shared": "^0.9.19",
|
|
87
88
|
"dayjs": "^1.11.2",
|
|
@@ -1,58 +1,74 @@
|
|
|
1
|
+
import { Capacitor } from '@capacitor/core';
|
|
1
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
3
|
import styled, { keyframes } from 'styled-components';
|
|
3
4
|
import SelectArrow from '../Arrow/SelectArrow';
|
|
4
5
|
|
|
5
6
|
export interface ISimpleImageCarousel {
|
|
6
|
-
|
|
7
|
+
basePath: string;
|
|
8
|
+
imagesSrc: string[];
|
|
7
9
|
styles?: React.CSSProperties;
|
|
8
10
|
autoCycle?: boolean;
|
|
9
11
|
autoCycleDelay?: number;
|
|
10
12
|
stopAutoCyclingOnInteraction?: boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const getTransformedBasePath = (basePath: string): string => {
|
|
16
|
+
if (Capacitor.isNativePlatform()) {
|
|
17
|
+
return Capacitor.convertFileSrc(basePath);
|
|
18
|
+
}
|
|
19
|
+
return basePath;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const SimpleImageCarousel = ({
|
|
23
|
+
basePath,
|
|
24
|
+
imagesSrc,
|
|
15
25
|
styles,
|
|
16
26
|
autoCycle = false,
|
|
17
27
|
autoCycleDelay = 3000,
|
|
18
28
|
stopAutoCyclingOnInteraction = false,
|
|
19
|
-
}) => {
|
|
29
|
+
}: ISimpleImageCarousel) => {
|
|
20
30
|
const [currentImage, setCurrentImage] = useState(0);
|
|
21
|
-
const
|
|
31
|
+
const isInteracted = useRef<boolean>(false);
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
prevImage => (prevImage - 1 + images?.length) % images?.length
|
|
26
|
-
);
|
|
27
|
-
if (stopAutoCyclingOnInteraction && autoCycleId.current) {
|
|
28
|
-
clearInterval(autoCycleId.current);
|
|
29
|
-
autoCycleId.current = null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
let timer: NodeJS.Timeout | null = null;
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
36
|
+
if (autoCycle && !isInteracted.current) {
|
|
37
|
+
timer = setInterval(() => {
|
|
38
|
+
if (stopAutoCyclingOnInteraction && isInteracted.current) {
|
|
39
|
+
clearInterval(timer!);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
if (autoCycle) {
|
|
43
|
-
autoCycleId.current = setInterval(() => {
|
|
44
|
-
setCurrentImage(prevImage => (prevImage + 1) % images?.length);
|
|
43
|
+
handleRightClick(true);
|
|
45
44
|
}, autoCycleDelay);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
return () => {
|
|
49
|
-
if (
|
|
50
|
-
clearInterval(
|
|
48
|
+
if (timer) {
|
|
49
|
+
clearInterval(timer);
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
|
-
}, [autoCycle, autoCycleDelay
|
|
52
|
+
}, [autoCycle, autoCycleDelay]);
|
|
53
|
+
|
|
54
|
+
const handleLeftClick = () => {
|
|
55
|
+
isInteracted.current = true;
|
|
56
|
+
setCurrentImage(oldImage =>
|
|
57
|
+
oldImage === 0 ? imagesSrc.length - 1 : oldImage - 1
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const handleRightClick = (isAutomatedClick: boolean = false) => {
|
|
62
|
+
if (!isAutomatedClick) {
|
|
63
|
+
isInteracted.current = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setCurrentImage(oldImage =>
|
|
67
|
+
oldImage === imagesSrc.length - 1 ? 0 : oldImage + 1
|
|
68
|
+
);
|
|
69
|
+
};
|
|
54
70
|
|
|
55
|
-
const hasMoreThanOneImage =
|
|
71
|
+
const hasMoreThanOneImage = imagesSrc.length > 1;
|
|
56
72
|
|
|
57
73
|
return (
|
|
58
74
|
<ImageContainer style={styles}>
|
|
@@ -65,8 +81,8 @@ export const SimpleImageCarousel: React.FC<ISimpleImageCarousel> = ({
|
|
|
65
81
|
<Carousel>
|
|
66
82
|
<FadeInCarouselImg
|
|
67
83
|
key={currentImage}
|
|
68
|
-
src={
|
|
69
|
-
alt={
|
|
84
|
+
src={`${getTransformedBasePath(basePath)}/${imagesSrc[currentImage]}`}
|
|
85
|
+
alt={imagesSrc[currentImage]}
|
|
70
86
|
/>
|
|
71
87
|
</Carousel>
|
|
72
88
|
</ImageContainer>
|
|
@@ -82,7 +98,6 @@ const ImageContainer = styled.div`
|
|
|
82
98
|
margin-right: 0.5rem;
|
|
83
99
|
max-width: 400px;
|
|
84
100
|
position: relative;
|
|
85
|
-
width: 400px;
|
|
86
101
|
`;
|
|
87
102
|
|
|
88
103
|
const CustomLeftArrow = styled(SelectArrow)`
|
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
} from '../components/ImageCarousel/SimpleImageCarousel';
|
|
8
8
|
|
|
9
9
|
import styled from 'styled-components';
|
|
10
|
-
import image1 from '../assets/images/backpack.png';
|
|
11
|
-
import image2 from '../assets/images/depot.png';
|
|
12
10
|
import { RPGUIRoot } from '../components/RPGUI/RPGUIRoot';
|
|
13
11
|
|
|
14
12
|
const meta: Meta = {
|
|
@@ -39,7 +37,8 @@ const CenteredContainer = styled.div`
|
|
|
39
37
|
export const SimpleImageCarouselStory = Template.bind({});
|
|
40
38
|
|
|
41
39
|
SimpleImageCarouselStory.args = {
|
|
42
|
-
|
|
40
|
+
imagesSrc: ['./images/backpack.png', './images/depot.png'],
|
|
41
|
+
basePath: 'http://localhost:6006',
|
|
43
42
|
autoCycle: true,
|
|
44
43
|
stopAutoCyclingOnInteraction: true,
|
|
45
44
|
};
|
|
Binary file
|
|
Binary file
|