Skip to content

Commit 7c307c3

Browse files
committed
slider updates
1 parent 46a3821 commit 7c307c3

File tree

3 files changed

+101
-31
lines changed

3 files changed

+101
-31
lines changed

src/shared/components/Contentful/ContentSlider/ContentSlider.jsx

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,66 @@ class ContentSlider extends Component {
3636
const {
3737
children, theme, autoStart, duration, id, containerStyle,
3838
slidesToShow, framePadding, withoutControls, vertical, cellSpacing,
39-
cellAlign, wrapAround, heightMode, arrowTheme,
39+
cellAlign, wrapAround, heightMode, arrowTheme, hideSliderDots, themeName,
40+
arrowLeftImage, arrowRightImage,
4041
} = this.props;
42+
const renderControls = {
43+
renderCenterLeftControls: ({ previousSlide }) => (
44+
<a
45+
onClick={previousSlide}
46+
onKeyPress={previousSlide}
47+
role="button"
48+
tabIndex={0}
49+
className={theme.controlLeft}
50+
>
51+
{arrowRightImage && <img src={arrowRightImage.fields.file.url} alt="Slider left arrow" />}
52+
{!arrowRightImage && (arrowTheme === 'Gray' ? <GrayArrowNext /> : <WhiteArrowNext />)}
53+
</a>
54+
),
55+
renderCenterRightControls: ({ nextSlide }) => (
56+
<a
57+
onClick={nextSlide}
58+
onKeyPress={nextSlide}
59+
role="button"
60+
tabIndex={0}
61+
className={theme.controlRight}
62+
>
63+
{arrowLeftImage && <img src={arrowLeftImage.fields.file.url} alt="Slider right arrow" />}
64+
{!arrowLeftImage && (arrowTheme === 'Gray' ? <GrayArrowPrev /> : <WhiteArrowPrev />)}
65+
</a>
66+
),
67+
};
68+
if (hideSliderDots) {
69+
renderControls.renderBottomCenterControls = () => null;
70+
}
71+
if (themeName === 'Controls Bottom Right') {
72+
renderControls.renderCenterLeftControls = () => null;
73+
renderControls.renderCenterRightControls = () => null;
74+
renderControls.renderBottomRightControls = ({ previousSlide, nextSlide }) => (
75+
<div className={theme.bottomRightControls}>
76+
<a
77+
onClick={previousSlide}
78+
onKeyPress={previousSlide}
79+
role="button"
80+
tabIndex={0}
81+
className={theme.controlLeft}
82+
>
83+
{arrowLeftImage && <img src={arrowLeftImage.fields.file.url} alt="Slider left arrow" />}
84+
{!arrowLeftImage && (arrowTheme === 'Gray' ? <GrayArrowPrev /> : <WhiteArrowPrev />)}
85+
</a>
86+
<a
87+
onClick={nextSlide}
88+
onKeyPress={nextSlide}
89+
role="button"
90+
tabIndex={0}
91+
className={theme.controlRight}
92+
>
93+
{arrowRightImage && <img src={arrowRightImage.fields.file.url} alt="Slider right arrow" />}
94+
{!arrowRightImage && (arrowTheme === 'Gray' ? <GrayArrowNext /> : <WhiteArrowNext />)}
95+
</a>
96+
</div>
97+
);
98+
}
4199

42100
return (
43101
<div
@@ -59,28 +117,7 @@ class ContentSlider extends Component {
59117
vertical={vertical}
60118
cellSpacing={cellSpacing}
61119
wrapAround={wrapAround}
62-
renderCenterLeftControls={({ previousSlide }) => (
63-
<a
64-
onClick={previousSlide}
65-
onKeyPress={previousSlide}
66-
role="button"
67-
tabIndex={0}
68-
className={theme.controlLeft}
69-
>
70-
{arrowTheme === 'Gray' ? <GrayArrowPrev /> : <WhiteArrowPrev />}
71-
</a>
72-
)}
73-
renderCenterRightControls={({ nextSlide }) => (
74-
<a
75-
onClick={nextSlide}
76-
onKeyPress={nextSlide}
77-
role="button"
78-
tabIndex={0}
79-
className={theme.controlRight}
80-
>
81-
{arrowTheme === 'Gray' ? <GrayArrowNext /> : <WhiteArrowNext />}
82-
</a>
83-
)}
120+
{...renderControls}
84121
>
85122
{children}
86123
</CarouselInject>
@@ -103,21 +140,18 @@ ContentSlider.defaultProps = {
103140
wrapAround: true,
104141
heightMode: 'max',
105142
arrowTheme: 'Gray',
143+
hideSliderDots: false,
144+
themeName: 'Default',
145+
arrowLeftImage: null,
146+
arrowRightImage: null,
106147
};
107148

108149
ContentSlider.propTypes = {
109150
id: PT.string.isRequired,
110151
children: PT.node.isRequired,
111152
autoStart: PT.bool,
112153
duration: PT.number,
113-
theme: PT.shape({
114-
container: PT.string,
115-
content: PT.string,
116-
controlLeft: PT.string,
117-
controlRight: PT.string,
118-
multiContent: PT.any,
119-
singleContent: PT.any,
120-
}),
154+
theme: PT.shape(),
121155
containerStyle: PT.shape(),
122156
slidesToShow: PT.number,
123157
framePadding: PT.string,
@@ -128,6 +162,10 @@ ContentSlider.propTypes = {
128162
wrapAround: PT.bool,
129163
heightMode: PT.string,
130164
arrowTheme: PT.string,
165+
hideSliderDots: PT.bool,
166+
themeName: PT.string,
167+
arrowLeftImage: PT.shape(),
168+
arrowRightImage: PT.shape(),
131169
};
132170

133171
export default themr('Contentful-Slider', defaultTheme)(ContentSlider);

src/shared/components/Contentful/ContentSlider/index.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ function ContentSliderItemsLoader(props) {
3636
environment,
3737
heightMode,
3838
arrowTheme,
39+
hideSliderDots,
40+
arrowLeftImage,
41+
arrowRightImage,
3942
} = props;
4043

4144
return (
@@ -58,6 +61,10 @@ function ContentSliderItemsLoader(props) {
5861
wrapAround={wrapAround}
5962
heightMode={heightMode}
6063
arrowTheme={arrowTheme}
64+
hideSliderDots={hideSliderDots}
65+
themeName={theme}
66+
arrowLeftImage={arrowLeftImage}
67+
arrowRightImage={arrowRightImage}
6168
>
6269
{
6370
ids.map(itemId => (
@@ -94,6 +101,9 @@ ContentSliderItemsLoader.defaultProps = {
94101
environment: null,
95102
heightMode: 'current',
96103
arrowTheme: 'Gray',
104+
hideSliderDots: false,
105+
arrowLeftImage: null,
106+
arrowRightImage: null,
97107
};
98108

99109
ContentSliderItemsLoader.propTypes = {
@@ -115,6 +125,9 @@ ContentSliderItemsLoader.propTypes = {
115125
wrapAround: PT.bool,
116126
heightMode: PT.string,
117127
arrowTheme: PT.string,
128+
hideSliderDots: PT.bool,
129+
arrowLeftImage: PT.shape(),
130+
arrowRightImage: PT.shape(),
118131
};
119132

120133
export default function ContentfulSlider(props) {
@@ -152,6 +165,9 @@ export default function ContentfulSlider(props) {
152165
wrapAround={fields.wrapAround}
153166
heightMode={fields.heightMode}
154167
arrowTheme={fields.arrowTheme}
168+
hideSliderDots={fields.hideSliderDots}
169+
arrowLeftImage={fields.arrowLeftImage}
170+
arrowRightImage={fields.arrowRightImage}
155171
/>
156172
);
157173
}}

src/shared/components/Contentful/ContentSlider/themes/default.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@
4646
margin-right: 15px;
4747
}
4848
}
49+
50+
.bottomRightControls {
51+
display: flex;
52+
position: absolute;
53+
right: 0;
54+
bottom: -50px;
55+
56+
a.controlLeft {
57+
margin: 0;
58+
margin-right: 20px;
59+
}
60+
61+
a.controlRight {
62+
margin: 0;
63+
}
64+
}

0 commit comments

Comments
 (0)