Skip to content

Commit 28e0079

Browse files
committed
Add ArrowLeft and ArrowRight props
1 parent 4c31a8e commit 28e0079

4 files changed

Lines changed: 83 additions & 15 deletions

File tree

doc-components/CustomArrowLeft.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

pages/index.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Api from '../doc-components/Api'
66
import DynamicContent from '../doc-components/DynamicContent'
77
import Dots from '../doc-components/Dots'
88
import Number from '../doc-components/Number'
9+
import CustomArrowLeft from '../doc-components/CustomArrowLeft'
910
import '../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 />

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const CLASSNAMES = {
1212
}
1313

1414
const 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

119123
ReactSlidy.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. */

src/react-slidy-slider.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const renderItem = numOfSlides => (item, index) => {
4040
}
4141

4242
export 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}>

0 commit comments

Comments
 (0)