Skip to content

feat: start index props #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### 2.1.2 (June 16, 2021)

- add 'startIndex' props.
- can set start index of image slider

### 2.1.1 (June 16, 2021)

- fix issue in SSR mode
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ If You want to see more detail source,<br>
| **navStyle** | `Number` | `Optional` | Arrow Navgation Style,<br>1 or 2 | `1` |
| **navSize** | `Number` | `Optional` | Arrow Size | 50 |
| **navMargin** | `Number` | `Optional` | Arrow Margin | 30 |
| **showNavs** | `Boolean` | `Optional` | Toggle Arrow Navgation | `true` |
| **showNavs** | `Boolean` | `Optional` | Toggle Arrow |
| **startIndex** | `Number` | `Optional` | start Index of Slide | 0 |
| **showBullets** | `Boolean` | `Optional` | Toggle Bullets | `true` |
| **useGPURender** | `Boolean` | `Optional` | Toggle GPU Render | `true` |
| **bgColor** | `String` | `Optional` | slider container's css background-color property | `#000000` |
Expand Down
1 change: 1 addition & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const App: React.FC = () => {
images={IMAGES}
showBullets={sliderOptions.showBullets}
showNavs={sliderOptions.showNavs}
startIndex={0}
useGPURender={sliderOptions.useGPURender}
navStyle={sliderOptions.navStyle}
navSize={sliderOptions.navSize}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-simple-image-slider",
"version": "2.1.1",
"version": "2.1.2",
"description": "simple image slider component for react",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/ImageSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type SimpleImageSliderProps = {
style?: React.CSSProperties;
showNavs: boolean;
showBullets: boolean;
startIndex?: number;
slideDuration?: number;
bgColor?: string;
useGPURender?: boolean;
Expand All @@ -30,6 +31,7 @@ const SimpleImageSlider: React.FC<SimpleImageSliderProps> = ({
images,
showNavs,
showBullets,
startIndex = 0,
style = undefined,
slideDuration = 0.5,
bgColor = '#000',
Expand All @@ -44,7 +46,7 @@ const SimpleImageSlider: React.FC<SimpleImageSliderProps> = ({
onCompleteSlide = undefined
}: SimpleImageSliderProps) => {
const rootStyle: React.CSSProperties = useMemo(() => styles.getRootContainer(width, height, bgColor), [width, height, bgColor]);
const [slideIdx, setSlideIdx] = useState(0);
const [slideIdx, setSlideIdx] = useState(startIndex < images.length ? startIndex : 0);
const [slideDirection, setSlideDirection] = useState(ImageSliderNavDirection.RIGHT);
const [isSliding, setIsSliding] = useState(false);
const [currentSliderStyle, setCurrentSlideStyle] = useState(styles.getImageSlide(images[0].url, slideDuration, 0, useGPURender));
Expand Down