Skip to content

Commit e923bc1

Browse files
authored
Merge pull request #24 from desko27/feature/accept-arrow-renders
Feature/accept arrow renders
2 parents 4c31a8e + 9571aec commit e923bc1

5 files changed

Lines changed: 149 additions & 32 deletions

File tree

doc-components/CustomArrows.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable react/prop-types */
2+
import React from 'react'
3+
4+
const buttonStyle = {
5+
background: 'transparent',
6+
border: 0,
7+
cursor: 'pointer',
8+
fontSize: 72,
9+
height: '30%',
10+
margin: 'auto 10px',
11+
padding: 15
12+
}
13+
14+
function CustomArrow({emoji, ...props}) {
15+
return (
16+
<button {...props} style={buttonStyle}>
17+
<span role="img" aria-label="Arrow">
18+
{emoji}
19+
</span>
20+
</button>
21+
)
22+
}
23+
24+
export function CustomArrowLeft(props) {
25+
return <CustomArrow {...props} emoji="👈" />
26+
}
27+
28+
export function CustomArrowRight(props) {
29+
return <CustomArrow {...props} emoji="👉" />
30+
}

pages/index.mdx

Lines changed: 53 additions & 6 deletions
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, CustomArrowRight} from '../doc-components/CustomArrows'
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;
@@ -306,8 +307,8 @@ If you have slides with different heights you need to specify the maxHeight to b
306307

307308
<div>
308309
<ReactSlidy imageObjectFit="contain">
309-
<img style={{maxHeight: '300px'}}src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1873819.jpg" />
310-
<img style={{maxHeight: '300px'}}src="https://d.fotocasa.es/promotion/2018/02/12/19402331/2108283.jpg" />
310+
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1873819.jpg" />
311+
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2018/02/12/19402331/2108283.jpg" />
311312
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2018/03/26/19414824/2152752.jpg" />
312313
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1982123.jpg" />
313314
</ReactSlidy>
@@ -316,14 +317,60 @@ If you have slides with different heights you need to specify the maxHeight to b
316317
```js showButton
317318
<div>
318319
<ReactSlidy imageObjectFit="contain">
319-
<img style={{maxHeight: '300px'}}src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1873819.jpg" />
320-
<img style={{maxHeight: '300px'}}src="https://d.fotocasa.es/promotion/2018/02/12/19402331/2108283.jpg" />
321-
<img style={{maxHeight: '300px'}}src="https://d.fotocasa.es/promotion/2018/03/26/19414824/2152752.jpg" />
320+
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1873819.jpg" />
321+
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2018/02/12/19402331/2108283.jpg" />
322+
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2018/03/26/19414824/2152752.jpg" />
322323
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1982123.jpg" />
323324
</ReactSlidy>
324325
</div>
325326
```
326327

328+
#### Using custom arrows
329+
330+
<ReactSlidy ArrowLeft={CustomArrowLeft} ArrowRight={CustomArrowRight}>
331+
<img src="/1.jpg" />
332+
<img src="/2.jpg" />
333+
<img src="/3.jpg" />
334+
<img src="/4.jpg" />
335+
</ReactSlidy>
336+
337+
```js showButton
338+
const buttonStyle = {
339+
background: 'transparent',
340+
border: 0,
341+
cursor: 'pointer',
342+
fontSize: 72,
343+
height: '30%',
344+
margin: 'auto 10px',
345+
padding: 15
346+
}
347+
348+
function CustomArrow({emoji, ...props}) {
349+
return (
350+
<button {...props} style={buttonStyle}>
351+
<span role="img" aria-label="Arrow">
352+
{emoji}
353+
</span>
354+
</button>
355+
)
356+
}
357+
358+
function CustomArrowLeft(props) {
359+
return <CustomArrow {...props} emoji="👈" />
360+
}
361+
362+
function CustomArrowRight(props) {
363+
return <CustomArrow {...props} emoji="👉" />
364+
}
365+
366+
<ReactSlidy ArrowLeft={CustomArrowLeft} ArrowRight={CustomArrowRight}>
367+
<img src="/1.jpg" />
368+
<img src="/2.jpg" />
369+
<img src="/3.jpg" />
370+
<img src="/4.jpg" />
371+
</ReactSlidy>
372+
```
373+
327374
## API 📖
328375

329376
<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/index.scss

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,43 @@ $react-slidy-mh: 50px !default;
3030
position: relative;
3131
user-select: none;
3232

33-
&-prev,
34-
&-next {
33+
&-arrow {
3534
align-items: center;
36-
background: $react-slidy-c-nav-background;
3735
bottom: 0;
38-
cursor: pointer;
3936
display: flex;
40-
height: 20%;
41-
justify-content: center;
4237
margin: auto 0;
43-
min-height: 56px;
4438
opacity: 0;
4539
position: absolute;
4640
top: 0;
4741
transition: opacity 0.3s ease;
48-
width: 40px;
42+
width: auto;
4943
z-index: 1;
5044

45+
&Left {
46+
left: 0;
47+
}
48+
49+
&Right {
50+
right: 0;
51+
}
52+
5153
@media screen and (max-width: 850px) {
5254
display: none;
5355
}
5456
}
5557

58+
&-prev,
59+
&-next {
60+
background: $react-slidy-c-nav-background;
61+
cursor: pointer;
62+
height: 20%;
63+
justify-content: center;
64+
min-height: 56px;
65+
width: 40px;
66+
}
67+
5668
&-next {
5769
border-radius: 10px 0 0 10px;
58-
right: 0;
5970

6071
&::after {
6172
@include arrow('right');
@@ -64,7 +75,6 @@ $react-slidy-mh: 50px !default;
6475

6576
&-prev {
6677
border-radius: 0 10px 10px 0;
67-
left: 0;
6878

6979
&::after {
7080
@include arrow('left');
@@ -90,11 +100,11 @@ $react-slidy-mh: 50px !default;
90100
object-fit: cover;
91101
}
92102

93-
&:hover > span {
103+
&:hover > &-arrow {
94104
opacity: 1;
95105
}
96106

97-
&:hover > span[disabled] {
107+
&:hover > &-arrow[disabled] {
98108
opacity: 0.2;
99109
}
100110

src/react-slidy-slider.js

Lines changed: 36 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,44 @@ 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+
const leftArrowClasses = `${classNameBase}-arrow ${classNameBase}-arrowLeft`
143+
if (ArrowLeft) return <ArrowLeft {...props} className={leftArrowClasses} />
144+
145+
return (
146+
<span
147+
arial-label="Previous"
148+
className={`${leftArrowClasses} ${classNameBase}-prev`}
149+
role="button"
150+
{...props}
151+
/>
152+
)
153+
}
154+
const renderRightArrow = () => {
155+
const disabled = items.length <= numOfSlides || index === items.length - 1
156+
const props = {disabled, onClick: handleNext}
157+
const rightArrowClasses = `${classNameBase}-arrow ${classNameBase}-arrowRight`
158+
if (ArrowRight)
159+
return <ArrowRight {...props} className={rightArrowClasses} />
160+
161+
return (
162+
<span
163+
arial-label="Next"
164+
className={`${rightArrowClasses} ${classNameBase}-next`}
165+
role="button"
166+
{...props}
167+
/>
168+
)
169+
}
170+
137171
return (
138172
<>
139173
{showArrows && (
140174
<>
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-
/>
175+
{renderLeftArrow()}
176+
{renderRightArrow()}
155177
</>
156178
)}
157179
<div ref={sliderContainerDOMEl}>

0 commit comments

Comments
 (0)