Skip to content

Commit 9571aec

Browse files
committed
Isolate arrow common styles
1 parent 28e0079 commit 9571aec

5 files changed

Lines changed: 105 additions & 56 deletions

File tree

doc-components/CustomArrowLeft.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

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: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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'
9+
import {CustomArrowLeft, CustomArrowRight} from '../doc-components/CustomArrows'
1010
import '../src/index.scss'
1111

1212
<ReactSlidy>
@@ -307,8 +307,8 @@ If you have slides with different heights you need to specify the maxHeight to b
307307

308308
<div>
309309
<ReactSlidy imageObjectFit="contain">
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" />
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" />
312312
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2018/03/26/19414824/2152752.jpg" />
313313
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1982123.jpg" />
314314
</ReactSlidy>
@@ -317,22 +317,59 @@ If you have slides with different heights you need to specify the maxHeight to b
317317
```js showButton
318318
<div>
319319
<ReactSlidy imageObjectFit="contain">
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" />
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" />
323323
<img style={{maxHeight: '300px'}} src="https://d.fotocasa.es/promotion/2017/03/23/19298958/1982123.jpg" />
324324
</ReactSlidy>
325325
</div>
326326
```
327327

328328
#### Using custom arrows
329329

330-
<ReactSlidy ArrowLeft={CustomArrowLeft}>
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}>
331367
<img src="/1.jpg" />
332368
<img src="/2.jpg" />
333369
<img src="/3.jpg" />
334370
<img src="/4.jpg" />
335371
</ReactSlidy>
372+
```
336373

337374
## API 📖
338375

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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ export default function ReactSlidySlider({
139139
const renderLeftArrow = () => {
140140
const disabled = index === 0
141141
const props = {disabled, onClick: handlePrev}
142-
if (ArrowLeft) return <ArrowLeft {...props} />
142+
const leftArrowClasses = `${classNameBase}-arrow ${classNameBase}-arrowLeft`
143+
if (ArrowLeft) return <ArrowLeft {...props} className={leftArrowClasses} />
144+
143145
return (
144146
<span
145147
arial-label="Previous"
146-
className={`${classNameBase}-prev`}
148+
className={`${leftArrowClasses} ${classNameBase}-prev`}
147149
role="button"
148150
{...props}
149151
/>
@@ -152,11 +154,14 @@ export default function ReactSlidySlider({
152154
const renderRightArrow = () => {
153155
const disabled = items.length <= numOfSlides || index === items.length - 1
154156
const props = {disabled, onClick: handleNext}
155-
if (ArrowRight) return <ArrowRight {...props} />
157+
const rightArrowClasses = `${classNameBase}-arrow ${classNameBase}-arrowRight`
158+
if (ArrowRight)
159+
return <ArrowRight {...props} className={rightArrowClasses} />
160+
156161
return (
157162
<span
158163
arial-label="Next"
159-
className={`${classNameBase}-next`}
164+
className={`${rightArrowClasses} ${classNameBase}-next`}
160165
role="button"
161166
{...props}
162167
/>

0 commit comments

Comments
 (0)