Skip to content

Commit 9ff430a

Browse files
authored
Merge pull request #4 from ItsMrAkhil/dot-configurable
Make Dot component configurable
2 parents eab438f + cacabf5 commit 9ff430a

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/components/Dot.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import PropTypes from 'prop-types';
43

54
const Dot = styled.li.attrs({
65
children: ({ onClick }) => <button onClick={onClick}></button>, // eslint-disable-line react/prop-types
@@ -25,8 +24,4 @@ const Dot = styled.li.attrs({
2524
}
2625
`;
2726

28-
Dot.propTypes = {
29-
onClick: PropTypes.func.isRequired,
30-
};
31-
3227
export default Dot;

src/components/Slider.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DefaultLeftArrow from './LeftArrow';
88
import SliderWrapper from './SliderWrapper';
99
import SliderList from './SliderList';
1010
import Dots from './Dots';
11-
import Dot from './Dot';
11+
import DefaultDot from './Dot';
1212

1313
class Slider extends React.Component {
1414
constructor(props) {
@@ -86,16 +86,16 @@ class Slider extends React.Component {
8686

8787
renderDots() {
8888
const dots = [];
89-
const { children } = this.props;
89+
const { children, Dot } = this.props;
9090
const numberOfChildren = children ? children.length || 1 : 0;
9191
let i;
9292
for (i = 0; i <= numberOfChildren - this.state.cardsToShow; i += 1) {
9393
const index = i;
94-
dots.push(<Dot
95-
active={index === this.state.initialCard}
96-
key={i}
97-
onClick={() => this.changeInitialCard(index)}
98-
/>);
94+
dots.push(React.cloneElement(Dot, {
95+
active: index === this.state.initialCard,
96+
key: index,
97+
onClick: () => this.changeInitialCard(index),
98+
}));
9999
}
100100
return dots;
101101
}
@@ -145,6 +145,7 @@ Slider.defaultProps = {
145145
showArrows: true,
146146
LeftArrow: <DefaultLeftArrow />,
147147
RightArrow: <DefaultRightArrow />,
148+
Dot: <DefaultDot />,
148149
cardsToShow: null,
149150
afterSlide: null,
150151
beforeSlide: null,
@@ -153,6 +154,7 @@ Slider.defaultProps = {
153154
Slider.propTypes = {
154155
LeftArrow: PropTypes.node,
155156
RightArrow: PropTypes.node,
157+
Dot: PropTypes.node,
156158
showArrows: PropTypes.bool,
157159
showDots: PropTypes.bool,
158160
children: PropTypes.node.isRequired,

0 commit comments

Comments
 (0)