@rpg-engine/long-bow 0.5.49 → 0.5.50
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 +10 -0
- package/dist/stories/SimpleImageCarousel.stories.d.ts +5 -0
- package/package.json +2 -2
- package/src/components/ImageCarousel/SimpleImageCarousel.tsx +132 -0
- package/src/stories/ImageCarousel.stories.tsx +1 -1
- package/src/stories/SimpleImageCarousel.stories.tsx +44 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ISimpleImageCarousel {
|
|
3
|
+
basePath: string;
|
|
4
|
+
imagesSrc: string[];
|
|
5
|
+
styles?: React.CSSProperties;
|
|
6
|
+
autoCycle?: boolean;
|
|
7
|
+
autoCycleDelay?: number;
|
|
8
|
+
stopAutoCyclingOnInteraction?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const SimpleImageCarousel: ({ basePath, imagesSrc, styles, autoCycle, autoCycleDelay, stopAutoCyclingOnInteraction, }: ISimpleImageCarousel) => JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { ISimpleImageCarousel } from '../components/ImageCarousel/SimpleImageCarousel';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const SimpleImageCarouselStory: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ISimpleImageCarousel>;
|
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.50",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@rollup/plugin-image": "^2.1.1",
|
|
86
|
-
"@rpg-engine/shared": "^0.9.
|
|
86
|
+
"@rpg-engine/shared": "^0.9.14",
|
|
87
87
|
"dayjs": "^1.11.2",
|
|
88
88
|
"font-awesome": "^4.7.0",
|
|
89
89
|
"fs-extra": "^10.1.0",
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import styled, { keyframes } from 'styled-components';
|
|
3
|
+
import SelectArrow from '../Arrow/SelectArrow';
|
|
4
|
+
|
|
5
|
+
export interface ISimpleImageCarousel {
|
|
6
|
+
basePath: string;
|
|
7
|
+
imagesSrc: string[];
|
|
8
|
+
styles?: React.CSSProperties;
|
|
9
|
+
autoCycle?: boolean;
|
|
10
|
+
autoCycleDelay?: number;
|
|
11
|
+
stopAutoCyclingOnInteraction?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SimpleImageCarousel = ({
|
|
15
|
+
basePath,
|
|
16
|
+
imagesSrc,
|
|
17
|
+
styles,
|
|
18
|
+
autoCycle = false,
|
|
19
|
+
autoCycleDelay = 3000,
|
|
20
|
+
stopAutoCyclingOnInteraction = false,
|
|
21
|
+
}: ISimpleImageCarousel) => {
|
|
22
|
+
const [currentImage, setCurrentImage] = useState(0);
|
|
23
|
+
const isInteracted = useRef<boolean>(false);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
let timer: NodeJS.Timeout | null = null;
|
|
27
|
+
|
|
28
|
+
if (autoCycle && !isInteracted.current) {
|
|
29
|
+
timer = setInterval(() => {
|
|
30
|
+
if (stopAutoCyclingOnInteraction && isInteracted.current) {
|
|
31
|
+
clearInterval(timer!);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
handleRightClick();
|
|
36
|
+
}, autoCycleDelay);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
if (timer) {
|
|
41
|
+
clearInterval(timer);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [autoCycle, autoCycleDelay]);
|
|
45
|
+
|
|
46
|
+
const handleLeftClick = () => {
|
|
47
|
+
isInteracted.current = true;
|
|
48
|
+
setCurrentImage(oldImage =>
|
|
49
|
+
oldImage === 0 ? imagesSrc.length - 1 : oldImage - 1
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleRightClick = () => {
|
|
54
|
+
isInteracted.current = true;
|
|
55
|
+
setCurrentImage(oldImage =>
|
|
56
|
+
oldImage === imagesSrc.length - 1 ? 0 : oldImage + 1
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const hasMoreThanOneImage = imagesSrc.length > 1;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ImageContainer style={styles}>
|
|
64
|
+
{hasMoreThanOneImage && (
|
|
65
|
+
<CustomLeftArrow direction="left" onPointerDown={handleLeftClick} />
|
|
66
|
+
)}
|
|
67
|
+
{hasMoreThanOneImage && (
|
|
68
|
+
<CustomRightArrow direction="right" onPointerDown={handleRightClick} />
|
|
69
|
+
)}
|
|
70
|
+
<Carousel>
|
|
71
|
+
<FadeInCarouselImg
|
|
72
|
+
key={currentImage}
|
|
73
|
+
src={`${basePath}/${imagesSrc[currentImage]}`}
|
|
74
|
+
alt={imagesSrc[currentImage]}
|
|
75
|
+
/>
|
|
76
|
+
</Carousel>
|
|
77
|
+
</ImageContainer>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const ImageContainer = styled.div`
|
|
82
|
+
flex: 1;
|
|
83
|
+
display: flex;
|
|
84
|
+
justify-content: center;
|
|
85
|
+
align-items: center;
|
|
86
|
+
height: 100%;
|
|
87
|
+
margin-right: 0.5rem;
|
|
88
|
+
max-width: 400px;
|
|
89
|
+
position: relative;
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const CustomLeftArrow = styled(SelectArrow)`
|
|
93
|
+
position: absolute;
|
|
94
|
+
left: -0.5rem;
|
|
95
|
+
top: 50%;
|
|
96
|
+
transform: translateY(-50%);
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
const CustomRightArrow = styled(SelectArrow)`
|
|
100
|
+
position: absolute;
|
|
101
|
+
right: -2.5rem;
|
|
102
|
+
top: 50%;
|
|
103
|
+
transform: translateY(-50%);
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
const Carousel = styled.div`
|
|
107
|
+
display: flex;
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const CarouselImg = styled.img`
|
|
111
|
+
flex: 0 0 auto;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: auto;
|
|
114
|
+
margin: 0 1rem;
|
|
115
|
+
border-radius: 5px;
|
|
116
|
+
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
|
|
117
|
+
scroll-snap-align: start;
|
|
118
|
+
margin-right: 3rem;
|
|
119
|
+
`;
|
|
120
|
+
|
|
121
|
+
const fadeIn = keyframes`
|
|
122
|
+
from {
|
|
123
|
+
opacity: 0;
|
|
124
|
+
}
|
|
125
|
+
to {
|
|
126
|
+
opacity: 1;
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
const FadeInCarouselImg = styled(CarouselImg)`
|
|
131
|
+
animation: ${fadeIn} 0.5s;
|
|
132
|
+
`;
|
|
@@ -9,7 +9,7 @@ import image from '../components/ImageCarousel/images/001.png';
|
|
|
9
9
|
import { RPGUIRoot } from '../components/RPGUI/RPGUIRoot';
|
|
10
10
|
|
|
11
11
|
const meta: Meta = {
|
|
12
|
-
title: '
|
|
12
|
+
title: 'Images/Image Carousel',
|
|
13
13
|
component: ImageCarousel,
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ISimpleImageCarousel,
|
|
6
|
+
SimpleImageCarousel,
|
|
7
|
+
} from '../components/ImageCarousel/SimpleImageCarousel';
|
|
8
|
+
|
|
9
|
+
import styled from 'styled-components';
|
|
10
|
+
import { RPGUIRoot } from '../components/RPGUI/RPGUIRoot';
|
|
11
|
+
|
|
12
|
+
const meta: Meta = {
|
|
13
|
+
title: 'Images/Simple Image Carousel',
|
|
14
|
+
component: SimpleImageCarousel,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
|
|
19
|
+
const Template: Story<ISimpleImageCarousel> = args => {
|
|
20
|
+
return (
|
|
21
|
+
<RPGUIRoot>
|
|
22
|
+
<CenteredContainer>
|
|
23
|
+
<SimpleImageCarousel {...args} />
|
|
24
|
+
</CenteredContainer>
|
|
25
|
+
</RPGUIRoot>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const CenteredContainer = styled.div`
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
height: 100%;
|
|
34
|
+
width: 100%;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const SimpleImageCarouselStory = Template.bind({});
|
|
38
|
+
|
|
39
|
+
SimpleImageCarouselStory.args = {
|
|
40
|
+
imagesSrc: ['./images/backpack.png', './images/depot.png'],
|
|
41
|
+
basePath: 'http://localhost:6006',
|
|
42
|
+
autoCycle: true,
|
|
43
|
+
stopAutoCyclingOnInteraction: true,
|
|
44
|
+
};
|