Skip to content

Commit 6f90bca

Browse files
committed
added renderNextToEachOther prop, improvements
1 parent ccbede1 commit 6f90bca

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ vertical | boolean | De
4646
draggable | boolean | Default: `false`.<br> Allows to scroll by dragging content.
4747
pagination | boolean | Default: `false`.<br> Renders Slider with children, arrowRight, arrowLeft and dots (number of dots same as children length)
4848
startAt | {<br>&nbsp;startIndex: number<br>&nbsp;center?: boolean<br>}| Default: `undefined`.<br> Defines start position of scroller (index of element)
49-
paginationConfig | {<br>&nbsp; infinite?: boolean,<br>&nbsp; unactiveDotsColor?: string,<br>&nbsp; activeDotColor?: string,<br>&nbsp; transitionTime?: number,<br>&nbsp; minOffsetToChangeSlide?: number,<br>&nbsp; draggable?: boolean,<br>withScroll?: boolean<br>} | Default: `undefined`.<br> `infinite` is optional boolean that allows user to scroll to first element from lsat after clicking next and in opposite way<br> `uncativeDotsColor` is optional string that defines unactive color of dots, default: `gray`<br> `activeDotColor` is optional string that defines active color of dot, default: `green`<br> `transitionTime` is optional number that sets transition time between slides Default: `1s` <br>`minOffsetToChangeSlide` is optional number that defines minimal offset needed to change slide in pixels Default: `150px`<br> `draggable` is optional boolean that enables switching slides by dragging them Default: `false` `withScroll` is optional boolean that enables -> for horizontal scroll pagination and for pagination scrollable inner wrapper<br>
49+
paginationConfig | {<br>&nbsp; infinite?: boolean,<br>&nbsp; unactiveDotsColor?: string,<br>&nbsp; activeDotColor?: string,<br>&nbsp; transitionTime?: number,<br>&nbsp; minOffsetToChangeSlide?: number,<br>&nbsp; draggable?: boolean,<br>withScroll?: boolean<br>} | Default: `undefined`.<br> `infinite` is optional boolean that allows user to scroll to first element from lsat after clicking next and in opposite way<br> `uncativeDotsColor` is optional string that defines unactive color of dots, default: `gray`<br> `activeDotColor` is optional string that defines active color of dot, default: `green`<br> `transitionTime` is optional number that sets transition time between slides Default: `1s` <br>`minOffsetToChangeSlide` is optional number that defines minimal offset needed to change slide in pixels Default: `150px`<br> `draggable` is optional boolean that enables switching slides by dragging them Default: `false`<br>`withScroll` is optional boolean that enables -> for horizontal scroll pagination and for pagination scrollable inner wrapper<br>`renderNextToEachOther` is optional boolean that enables to render children next to each other
5050
renderPagination | ({<br>&nbsp; selectedDot: number,<br>&nbsp; childrenCount: number,<br>&nbsp; onNext(): void,<br>&nbsp; onPrev(): void,<br>&nbsp; onDotClick(index: number): void<br>}) => JSX.Element | Default: `undefined`.<br> Replaces original pagination, first element is arrowLeft and last element is arrowRight, elements in between are 'dots'<br> `selectedDot` is an index of selectedDot<br> `childrenCount` number of children <br>`onNext` function that triggers next slide<br> `onPrev` function that triggers previous slide<br> `onDotClick` is a function that requires index of clicked dot, triggers transition to selected slide
5151

5252
## Usage

index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ type PaginationConfig = {
4343

4444
draggable?: boolean
4545

46+
/**
47+
Default false.
48+
Allows to render elements next to each other
49+
*/
50+
51+
renderNextToEachOther?: boolean
52+
4653
/**
4754
Default false.
4855
Allows scroll with pagination

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-smart-scroller",
3-
"version": "1.1.18",
3+
"version": "1.1.19",
44
"description": "React-smart-scroller is a library that allows you to create highly customizable horizontal or vertical scroller in easy way. You can modify track styles or pass your own thumb (own component)",
55
"main": "dist/index.js",
66
"module": "dist/react-smart-scroller.esm.js",

src/components/ReactSmartScrollerPagination.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
150150
const { paginationIndex, scrollValue } = this.state
151151
const { paginationConfig } = this.props
152152

153-
if (overflowRef && paginationConfig && paginationConfig.withScroll && paginationIndex < this.numberOfViews - 1) {
153+
if (overflowRef && paginationConfig && paginationConfig?.withScroll && paginationIndex < this.numberOfViews - 1) {
154154
const index = paginationIndex + 1
155155
const newScrollValue = overflowRef.children.item(paginationIndex)?.clientWidth || 0
156156

@@ -176,7 +176,13 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
176176

177177
if (overflowRef && paginationIndex < this.numberOfViews - 1) {
178178
const index = paginationIndex + 1
179-
const newScrollValue = this.props.paginationConfig?.withScroll
179+
const isLast = overflowRef.clientWidth + Math.abs(this.state.scrollValue) >= overflowRef.scrollWidth
180+
181+
if (isLast) {
182+
return
183+
}
184+
185+
const newScrollValue = this.props.paginationConfig?.withScroll || this.props.paginationConfig?.renderNextToEachOther
180186
? scrollValue - (overflowRef.children.item(paginationIndex)?.clientWidth || 0)
181187
: scrollValue - overflowRef.offsetWidth
182188

@@ -194,7 +200,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
194200
const { paginationIndex, scrollValue } = this.state
195201
const { paginationConfig } = this.props
196202

197-
if (overflowRef && paginationConfig && paginationConfig.withScroll && paginationIndex > 0) {
203+
if (overflowRef && paginationConfig && paginationConfig?.withScroll && paginationIndex > 0) {
198204
const index = paginationIndex - 1
199205
const newScrollValue = overflowRef.children.item(index)?.clientWidth || 0
200206

@@ -211,7 +217,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
211217

212218
if (overflowRef && paginationIndex === 0 && paginationConfig && paginationConfig.infinite) {
213219
const index = this.numberOfViews - 1
214-
const newScrollValue = this.props.paginationConfig?.withScroll
220+
const newScrollValue = this.props.paginationConfig?.withScroll || this.props.paginationConfig?.renderNextToEachOther
215221
? index + (overflowRef.children.item(index)?.clientWidth || 0)
216222
: index * overflowRef.offsetWidth
217223

@@ -225,7 +231,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
225231

226232
if (overflowRef && paginationIndex > 0) {
227233
const index = paginationIndex - 1
228-
const newScrollValue = this.props.paginationConfig?.withScroll
234+
const newScrollValue = this.props.paginationConfig?.withScroll || this.props.paginationConfig?.renderNextToEachOther
229235
? scrollValue + (overflowRef.children.item(index)?.clientWidth || 0)
230236
: scrollValue + overflowRef.offsetWidth
231237

@@ -243,7 +249,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
243249
const { paginationIndex } = this.state
244250
const { paginationConfig } = this.props
245251

246-
if (overflowRef && paginationConfig && paginationConfig.withScroll) {
252+
if (overflowRef && paginationConfig && (paginationConfig?.withScroll || paginationConfig?.renderNextToEachOther)) {
247253
const newScrollValue = (overflowRef?.children.item(index) as HTMLDivElement)?.offsetLeft || 0
248254

249255
overflowRef.scroll({
@@ -258,7 +264,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
258264
}
259265

260266
if (overflowRef && index !== paginationIndex) {
261-
const newScrollValue = this.props.paginationConfig?.withScroll
267+
const newScrollValue = this.props.paginationConfig?.withScroll || this.props.paginationConfig?.renderNextToEachOther
262268
? -((overflowRef?.children.item(index) as HTMLDivElement)?.offsetLeft || 0)
263269
: -(index * overflowRef.clientWidth)
264270

@@ -432,7 +438,7 @@ export class ReactSmartScrollerPagination extends React.Component<ReactSmartScro
432438
? `paddingLeft: ${padding}px`
433439
: undefined
434440
const flexBasis = cols ? `calc(100% / ${cols})` : 'unset'
435-
const width = this.props.paginationConfig?.withScroll ? 'unset' : undefined
441+
const width = (this.props.paginationConfig?.withScroll || this.props.paginationConfig?.renderNextToEachOther) ? 'unset' : undefined
436442

437443
return (
438444
<ChildrenWrapper

src/lib/types/reactSmartScroller.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export type ReactSmartScrollerProps = {
2828
transitionTime?: number,
2929
minOffsetToChangeSlide?: number,
3030
draggable?: boolean,
31-
withScroll?: boolean
31+
withScroll?: boolean,
32+
renderNextToEachOther?: boolean
3233
},
3334
style?: React.CSSProperties,
3435
renderPagination?(options: RenderPaginationProps): JSX.Element

0 commit comments

Comments
 (0)