Skip to content

Commit 88efca2

Browse files
authored
Merge pull request #39 from kimcoder/feature/issue-36
feat: add Props, navSize, navMargin
2 parents e67ed4d + 031688c commit 88efca2

13 files changed

+119
-31
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ If You want to see more detail source,<br>
7575
| **style** | `String` | `Optional` | css object | |
7676
| **slideDuration** | `Number` | `Optional` | css transition-duration property | `0.5` |
7777
| **navStyle** | `Number` | `Optional` | Arrow Navgation Style,<br>1 or 2 | `1` |
78+
| **navSize** | `Number` | `Optional` | Arrow Size | 50 |
79+
| **navMargin** | `Number` | `Optional` | Arrow Margin | 30 |
7880
| **showNavs** | `Boolean` | `Optional` | Toggle Arrow Navgation | `true` |
7981
| **showBullets** | `Boolean` | `Optional` | Toggle Bullets | `true` |
8082
| **useGPURender** | `Boolean` | `Optional` | Toggle GPU Render | `true` |

example/App.tsx

+36-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import InputLabel from '@material-ui/core/InputLabel';
1212
import MenuItem from '@material-ui/core/MenuItem';
1313
import Select from '@material-ui/core/Select';
1414
import SimpleImageSlider from '../dist';
15+
import Input from '@material-ui/core/Input';
1516

1617
const IMAGES = [
1718
{ url: 'images/1.jpg' },
@@ -28,6 +29,8 @@ type SliderOptions = {
2829
showNavs: boolean;
2930
showBullets: boolean;
3031
navStyle: 1 | 2;
32+
navSize: number;
33+
navMargin: number;
3134
duration: number;
3235
bgColor: string;
3336
};
@@ -38,6 +41,8 @@ const App: React.FC = () => {
3841
showNavs: true,
3942
showBullets: true,
4043
navStyle: 1,
44+
navSize: 50,
45+
navMargin: 30,
4146
duration: 0.5,
4247
bgColor: '#000'
4348
});
@@ -70,23 +75,17 @@ const App: React.FC = () => {
7075
(key: string, value: boolean | number | string) => () => {
7176
console.log(`[App updateOptions] ${key} ${value}`);
7277
switch (key) {
73-
case 'useGPURender':
74-
setSliderOptions({ ...sliderOptions, useGPURender: value as boolean });
75-
break;
76-
case 'showNavs':
77-
setSliderOptions({ ...sliderOptions, showNavs: value as boolean });
78-
break;
79-
case 'showBullets':
80-
setSliderOptions({ ...sliderOptions, showBullets: value as boolean });
81-
break;
8278
case 'navStyle':
8379
setSliderOptions({ ...sliderOptions, navStyle: value as 1 | 2 });
8480
break;
81+
case 'useGPURender':
82+
case 'showNavs':
83+
case 'showBullets':
8584
case 'duration':
86-
setSliderOptions({ ...sliderOptions, duration: value as number });
87-
break;
8885
case 'bgColor':
89-
setSliderOptions({ ...sliderOptions, bgColor: value as string });
86+
case 'navSize':
87+
case 'navMargin':
88+
setSliderOptions({ ...sliderOptions, [key]: value });
9089
break;
9190
}
9291
},
@@ -125,6 +124,8 @@ const App: React.FC = () => {
125124
showNavs={sliderOptions.showNavs}
126125
useGPURender={sliderOptions.useGPURender}
127126
navStyle={sliderOptions.navStyle}
127+
navSize={sliderOptions.navSize}
128+
navMargin={sliderOptions.navMargin}
128129
slideDuration={sliderOptions.duration}
129130
onClick={onClick}
130131
onClickNav={onClickNav}
@@ -151,7 +152,7 @@ const App: React.FC = () => {
151152
</ListItem>
152153
))}
153154
<ListItem>
154-
<FormControl component="fieldset">
155+
<FormControl>
155156
<InputLabel>NavStyle</InputLabel>
156157
<Select value={sliderOptions.navStyle} onChange={onChangeSelect} inputProps={{ name: 'navStyle' }}>
157158
<MenuItem value={1}>1</MenuItem>
@@ -170,6 +171,28 @@ const App: React.FC = () => {
170171
</Select>
171172
</FormControl>
172173
</ListItem>
174+
<ListItem>
175+
<FormControl>
176+
<InputLabel>Navigation Size</InputLabel>
177+
<Input
178+
value={sliderOptions.navSize}
179+
type="number"
180+
name="navSize"
181+
onChange={(event) => updateOptions(event.target.name, event.target.value)()}
182+
/>
183+
</FormControl>
184+
</ListItem>
185+
<ListItem>
186+
<FormControl>
187+
<InputLabel>Navigation Margin</InputLabel>
188+
<Input
189+
value={sliderOptions.navMargin}
190+
type="number"
191+
name="navMargin"
192+
onChange={(event) => updateOptions(event.target.name, event.target.value)()}
193+
/>
194+
</FormControl>
195+
</ListItem>
173196
</List>
174197
</div>
175198
);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-simple-image-slider",
3-
"version": "2.0.4",
3+
"version": "2.1.0",
44
"description": "simple image slider component for react",
55
"main": "dist/index.js",
66
"scripts": {

src/ImageSlider.tsx

+18-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export type SimpleImageSliderProps = {
1414
slideDuration?: number;
1515
bgColor?: string;
1616
useGPURender?: boolean;
17+
navSize?: number;
18+
navMargin?: number;
1719
navStyle?: ImageSliderNavStyle;
1820
onClick?: (idx: number, event: React.SyntheticEvent) => void;
1921
onClickNav?: (toRight: boolean) => void;
@@ -32,6 +34,8 @@ const SimpleImageSlider: React.FC<SimpleImageSliderProps> = ({
3234
slideDuration = 0.5,
3335
bgColor = '#000',
3436
useGPURender = true,
37+
navSize = 50,
38+
navMargin = 30,
3539
navStyle = ImageSliderNavStyle.NORMAL,
3640
onClick = undefined,
3741
onClickNav = undefined,
@@ -125,10 +129,22 @@ const SimpleImageSlider: React.FC<SimpleImageSliderProps> = ({
125129

126130
{/* Render Navigation */}
127131
{showNavs && images.length > 0 && slideIdx > 0 && (
128-
<ImageSliderNavigation direction={ImageSliderNavDirection.LEFT} navStyle={navStyle} onClickNav={handleClickNav} />
132+
<ImageSliderNavigation
133+
direction={ImageSliderNavDirection.LEFT}
134+
navStyle={navStyle}
135+
navSize={navSize}
136+
navMargin={navMargin}
137+
onClickNav={handleClickNav}
138+
/>
129139
)}
130140
{showNavs && images.length > 0 && slideIdx < images.length - 1 && (
131-
<ImageSliderNavigation direction={ImageSliderNavDirection.RIGHT} navStyle={navStyle} onClickNav={handleClickNav} />
141+
<ImageSliderNavigation
142+
direction={ImageSliderNavDirection.RIGHT}
143+
navStyle={navStyle}
144+
navSize={navSize}
145+
navMargin={navMargin}
146+
onClickNav={handleClickNav}
147+
/>
132148
)}
133149

134150
{/* Render Bullets */}

src/ImageSliderNavigation.tsx

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import styles from './ImageSliderStyle';
3-
import ImageNavArrowLeft1 from './images/arrow-left-1.png';
4-
import ImageNavArrowLeft2 from './images/arrow-left-2.png';
5-
import ImageNavArrowRight1 from './images/arrow-right-1.png';
6-
import ImageNavArrowRight2 from './images/arrow-right-2.png';
3+
import ImageNavArrowBold from './images/arrow-bold.svg';
4+
import ImageNavArrowNormal from './images/arrow-normal.svg';
75

86
export enum ImageSliderNavStyle {
97
NORMAL = 1,
@@ -17,27 +15,21 @@ export enum ImageSliderNavDirection {
1715

1816
type ImageSliderNavigationProps = {
1917
navStyle: ImageSliderNavStyle;
18+
navSize: number;
19+
navMargin: number;
2020
direction: ImageSliderNavDirection;
2121
onClickNav: (direction: ImageSliderNavDirection) => (event: React.SyntheticEvent<HTMLButtonElement>) => void;
2222
};
2323

2424
const altNavArrowLeft = 'slide to left';
2525
const altNavArrowRight = 'slide to right';
26-
const images: { [key: string]: string } = {
27-
[`image-${ImageSliderNavDirection.LEFT}-${ImageSliderNavStyle.NORMAL}`]: ImageNavArrowLeft1,
28-
[`image-${ImageSliderNavDirection.RIGHT}-${ImageSliderNavStyle.NORMAL}`]: ImageNavArrowRight1,
29-
[`image-${ImageSliderNavDirection.LEFT}-${ImageSliderNavStyle.BOLD}`]: ImageNavArrowLeft2,
30-
[`image-${ImageSliderNavDirection.RIGHT}-${ImageSliderNavStyle.BOLD}`]: ImageNavArrowRight2
31-
};
3226

3327
const ImageSliderNavigation: React.FC<ImageSliderNavigationProps> = (props: ImageSliderNavigationProps) => {
3428
return (
35-
<button
36-
type="button"
37-
style={props.direction === ImageSliderNavDirection.LEFT ? styles.NavLeft : styles.NavRight}
38-
onClick={props.onClickNav(props.direction)}>
29+
<button type="button" style={styles.getNavStyle(props.direction, props.navSize, props.navMargin)} onClick={props.onClickNav(props.direction)}>
3930
<img
40-
src={images[`image-${props.direction}-${props.navStyle}`]}
31+
src={props.navStyle === ImageSliderNavStyle.NORMAL ? ImageNavArrowNormal : ImageNavArrowBold}
32+
style={{ width: '100%', ...(props.direction === ImageSliderNavDirection.RIGHT && { transform: 'rotate(180deg)' }) }}
4133
alt={props.direction === ImageSliderNavDirection.LEFT ? altNavArrowLeft : altNavArrowRight}
4234
/>
4335
</button>

src/ImageSliderStyle.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ImageSliderNavDirection } from './ImageSliderNavigation';
2+
13
const basic = {
24
display: 'block',
35
margin: '0',
@@ -69,5 +71,13 @@ export default {
6971
transition: `${duration}s`,
7072
backgroundImage: `url(${url})`,
7173
transform: isGpuRender ? `translate3d(${idx * 100}%, 0px, 0px)` : `translate(${idx * 100}%, 0px)`
74+
} as React.CSSProperties),
75+
getNavStyle: (direction: ImageSliderNavDirection, size: number, margin: number): React.CSSProperties =>
76+
({
77+
...basic,
78+
...basicNav,
79+
...(direction === ImageSliderNavDirection.LEFT ? { left: `${margin}px` } : { right: `${margin}px` }),
80+
marginTop: `-${Math.floor(size / 2)}px`,
81+
width: `${size}px`
7282
} as React.CSSProperties)
7383
};

src/global.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ declare module '*.png' {
22
const value: string;
33
export = value;
44
}
5+
6+
declare module '*.svg' {
7+
const value: string;
8+
export = value;
9+
}

src/images/arrow-bold.svg

+20
Loading

src/images/arrow-left-1.png

-379 Bytes
Binary file not shown.

src/images/arrow-left-2.png

-444 Bytes
Binary file not shown.

src/images/arrow-normal.svg

+20
Loading

src/images/arrow-right-1.png

-380 Bytes
Binary file not shown.

src/images/arrow-right-2.png

-440 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)