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