File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* eslint-disable react/prop-types */
2+ import React from 'react'
3+
4+ const wrapperStyle = {
5+ position : 'absolute' ,
6+ top : 0 ,
7+ bottom : 0 ,
8+ zIndex : 1 ,
9+ alignItems : 'center' ,
10+ display : 'flex' ,
11+ width : 'auto'
12+ }
13+
14+ const buttonStyle = {
15+ cursor : 'pointer' ,
16+ border : 0 ,
17+ background : 'transparent' ,
18+ fontSize : 72 ,
19+ padding : 15 ,
20+ margin : 10
21+ }
22+
23+ export default function CustomArrowLeft ( { onClick} ) {
24+ return (
25+ < div style = { wrapperStyle } >
26+ < button onClick = { onClick } style = { buttonStyle } >
27+ < span role = "img" aria-label = "Left" >
28+ 👈
29+ </ span >
30+ </ button >
31+ </ div >
32+ )
33+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Api from '../doc-components/Api'
66import DynamicContent from ' ../doc-components/DynamicContent'
77import Dots from ' ../doc-components/Dots'
88import Number from ' ../doc-components/Number'
9+ import CustomArrowLeft from ' ../doc-components/CustomArrowLeft'
910import ' ../src/index.scss'
1011
1112<ReactSlidy >
@@ -53,7 +54,7 @@ you could also load the CSS directly from HTML:
5354```
5455
5556## Customization 👩🎨
56- If you're using SASS, you could modify the next variables:
57+ If you're using SASS, you could modify the following variables:
5758
5859``` sass
5960$react-slidy-c-background: transparent !default;
@@ -324,6 +325,15 @@ If you have slides with different heights you need to specify the maxHeight to b
324325< / div>
325326```
326327
328+ #### Using custom arrows
329+
330+ <ReactSlidy ArrowLeft = { CustomArrowLeft } >
331+ <img src = " /1.jpg" />
332+ <img src = " /2.jpg" />
333+ <img src = " /3.jpg" />
334+ <img src = " /4.jpg" />
335+ </ReactSlidy >
336+
327337## API 📖
328338
329339<Api />
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const CLASSNAMES = {
1212}
1313
1414const ReactSlidy = ( {
15+ ArrowLeft,
16+ ArrowRight,
1517 children,
1618 classNameBase = 'react-Slidy' ,
1719 doAfterDestroy = noop ,
@@ -86,6 +88,8 @@ const ReactSlidy = ({
8688 . join ( ' ' )
8789
8890 const reactSlidySliderProps = {
91+ ArrowLeft,
92+ ArrowRight,
8993 children,
9094 classNameBase,
9195 doAfterDestroy,
@@ -117,6 +121,10 @@ const ReactSlidy = ({
117121}
118122
119123ReactSlidy . propTypes = {
124+ /** Component to be used as the left arrow for the slider */
125+ ArrowLeft : PropTypes . elementType ,
126+ /** Component to be used as the right arrow for the slider */
127+ ArrowRight : PropTypes . elementType ,
120128 /** Children to be used as slides for the slider */
121129 children : PropTypes . oneOfType ( [ PropTypes . array , PropTypes . object ] ) . isRequired ,
122130 /** Class base to create all clases for elements. Styles might break if you modify it. */
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ const renderItem = numOfSlides => (item, index) => {
4040}
4141
4242export default function ReactSlidySlider ( {
43+ ArrowLeft,
44+ ArrowRight,
4345 children,
4446 classNameBase,
4547 doAfterDestroy,
@@ -134,24 +136,39 @@ export default function ReactSlidySlider({
134136 const handlePrev = e => slidyInstance . prev ( e )
135137 const handleNext = e => items . length > numOfSlides && slidyInstance . next ( e )
136138
139+ const renderLeftArrow = ( ) => {
140+ const disabled = index === 0
141+ const props = { disabled, onClick : handlePrev }
142+ if ( ArrowLeft ) return < ArrowLeft { ...props } />
143+ return (
144+ < span
145+ arial-label = "Previous"
146+ className = { `${ classNameBase } -prev` }
147+ role = "button"
148+ { ...props }
149+ />
150+ )
151+ }
152+ const renderRightArrow = ( ) => {
153+ const disabled = items . length <= numOfSlides || index === items . length - 1
154+ const props = { disabled, onClick : handleNext }
155+ if ( ArrowRight ) return < ArrowRight { ...props } />
156+ return (
157+ < span
158+ arial-label = "Next"
159+ className = { `${ classNameBase } -next` }
160+ role = "button"
161+ { ...props }
162+ />
163+ )
164+ }
165+
137166 return (
138167 < >
139168 { showArrows && (
140169 < >
141- < span
142- arial-label = "Previous"
143- className = { `${ classNameBase } -prev` }
144- role = "button"
145- disabled = { index === 0 }
146- onClick = { handlePrev }
147- />
148- < span
149- arial-label = "Next"
150- className = { `${ classNameBase } -next` }
151- disabled = { items . length <= numOfSlides || index === items . length - 1 }
152- role = "button"
153- onClick = { handleNext }
154- />
170+ { renderLeftArrow ( ) }
171+ { renderRightArrow ( ) }
155172 </ >
156173 ) }
157174 < div ref = { sliderContainerDOMEl } >
You can’t perform that action at this time.
0 commit comments