Skip to content

Commit 2543f65

Browse files
authored
Merge pull request #21 from ItsMrAkhil/custom-dot-wrapper
Add custom dot wrapper
2 parents 5044abb + 9cedf98 commit 2543f65

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Props | Type | Default Value | Description
7878
`showDots` | `Boolean` | `true` | Show navigation or pagination dots below the slider
7979
`infinite` | `Boolean` | `true` | Infinitely slide cards.
8080
`Dot` | `React Node` | Default | Customized pagination button (`Active slide Dot` will get `active` as `Boolean` prop.)
81+
`DotsWrapper` | `Styled Element` | Default | Customized wrapper for your <Dot /> component to change the view of dots wrapper like position, background, etc. `Note: It should be a styled ul, otherwise you may not see any Dot Components.`
8182
`LeftArrow` | `React Node` | Default | Customized left arrow button. It'll get `disabled Boolean` prop if first Dot is active and infinite is false.
8283
`RightArrow` | `React Node` | Default | Customized right arrow button. It'll get `disabled Boolean` prop if last Dot is active and infinite is false.
8384
`children` | `React Node` | null | Cards are components which you want to show in the carousel
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import styled from 'styled-components';
22

3-
const Dots = styled.ul`
3+
const DotsWrapper = styled.ul`
44
display: block;
55
list-style: none;
66
text-align: center;
77
padding: 0px;
88
margin: 0px;
99
`;
1010

11-
export default Dots;
11+
export default DotsWrapper;

src/components/Slider.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import DefaultRightArrow from './RightArrow';
99
import DefaultLeftArrow from './LeftArrow';
1010
import SliderWrapper from './SliderWrapper';
1111
import SliderList from './SliderList';
12-
import Dots from './Dots';
12+
import DefaultDotsWrapper from './DotsWrapper';
1313
import DefaultDot from './Dot';
1414
import Timer from '../utils/Timer';
1515

@@ -178,7 +178,7 @@ class Slider extends React.Component {
178178
const {
179179
children, cardsToShow,
180180
showDots, showArrows,
181-
pauseOnMouseOver,
181+
pauseOnMouseOver, DotsWrapper,
182182
...otherProps
183183
} = this.props;
184184
const { initialCard, childWidth } = this.state;
@@ -196,9 +196,9 @@ class Slider extends React.Component {
196196
</SliderTrack>
197197
{showArrows && !this.state.hideArrows && this.renderRightArrow()}
198198
</SliderWrapper>
199-
<Dots>
199+
<DotsWrapper>
200200
{showDots && this.renderDots()}
201-
</Dots>
201+
</DotsWrapper>
202202
</div>
203203
);
204204
}
@@ -210,6 +210,7 @@ Slider.defaultProps = {
210210
LeftArrow: <DefaultLeftArrow />,
211211
RightArrow: <DefaultRightArrow />,
212212
Dot: <DefaultDot />,
213+
DotsWrapper: DefaultDotsWrapper,
213214
cardsToShow: null,
214215
afterSlide: null,
215216
beforeSlide: null,
@@ -245,6 +246,7 @@ Slider.propTypes = {
245246
padding: PropTypes.string,
246247
margin: PropTypes.string,
247248
hideArrowsOnNoSlides: PropTypes.bool,
249+
DotsWrapper: PropTypes.func,
248250
};
249251

250252
export default Slider;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import React from 'react';
22

3-
import Dots from '../Dots';
3+
import DotsWrapper from '../DotsWrapper';
44

5-
describe('<Dots />', () => {
5+
describe('<DotsWrapper />', () => {
66
it('Should render a <div> tag', () => {
7-
const renderedComponent = shallow(<Dots />);
7+
const renderedComponent = shallow(<DotsWrapper />);
88
expect(renderedComponent.type()).toEqual('ul');
99
});
1010

1111
it('Should have a className attribute', () => {
12-
const renderedComponent = shallow(<Dots />);
12+
const renderedComponent = shallow(<DotsWrapper />);
1313
expect(renderedComponent.prop('className')).toBeDefined();
1414
});
1515

1616
it('Should adopt a valid attribute', () => {
1717
const id = 'test-id';
18-
const renderedComponent = shallow(<Dots id={id} />);
18+
const renderedComponent = shallow(<DotsWrapper id={id} />);
1919
expect(renderedComponent.prop('id')).toEqual(id);
2020
});
2121

2222
it('Should not adopt an invalid attribute', () => {
23-
const renderedComponent = shallow(<Dots attribute="test" />);
23+
const renderedComponent = shallow(<DotsWrapper attribute="test" />);
2424
expect(renderedComponent.prop('attribute')).toBeUndefined();
2525
});
2626
});

src/components/__tests__/__snapshots__/Slider.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ShallowWrapper {
66
Symbol(enzyme.__root__): [Circular],
77
Symbol(enzyme.__unrendered__): <Slider
88
Dot={<styled.li />}
9+
DotsWrapper={[Function]}
910
LeftArrow={<styled.button />}
1011
RightArrow={<styled.button />}
1112
afterSlide={null}
@@ -497,6 +498,7 @@ ShallowWrapper {
497498
Symbol(enzyme.__root__): [Circular],
498499
Symbol(enzyme.__unrendered__): <Slider
499500
Dot={<styled.li />}
501+
DotsWrapper={[Function]}
500502
LeftArrow={<styled.button />}
501503
RightArrow={<styled.button />}
502504
afterSlide={null}

0 commit comments

Comments
 (0)