Skip to content

Commit ccf28a0

Browse files
arnaudambrotim-steele
authored andcommitted
Feature/dotgroup tuning (#151)
* Add disableDots props to DotsGroup In order to always allow the click on dots on DotsGroup if needed * add dist folder * fixing DOM problem * single dot select * added two props to DotGroup + tests + README
1 parent 54728f0 commit ccf28a0

File tree

4 files changed

+7313
-5
lines changed

4 files changed

+7313
-5
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/express-labs/pure-react-carousel.svg?branch=master)](https://travis-ci.org/express-labs/pure-react-carousel)
22
[![Known Vulnerabilities](https://snyk.io/test/github/express-labs/pure-react-carousel/badge.svg)](https://snyk.io/test/github/express-labs/pure-react-carousel)
33

4-
Created by
4+
Created by
55
[![Express Logo](https://raw.github.com/express-labs/pure-react-carousel/master/dev/media/express-logo.svg?sanitize=true)](http://www.express.com)
66

77
# pure-react-carousel
@@ -293,6 +293,8 @@ A compound component that creates a bunch of Dot's automatically for you.
293293
| children | [string|node|null] | null | No | Any JSX wrapped by this component will appear AFTER the dots. |
294294
| className | [string|null] | null | No | Optional className string that will be appended to the component's className string. |
295295
| dotNumbers | boolean | false | No | Setting to true automatically adds text numbers the dot buttons starting at 1. |
296+
| disableActiveDots | boolean | true | No | Setting to true make all dots, including active dots, enabled. |
297+
| showAsSelectedForCurrentSlideOnly | boolean | false | No | Setting to true show only the current slide dot as selected. |
296298

297299
#### The DotGroup component creates the following pseudo HTML by default:
298300

src/DotGroup/DotGroup.jsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,39 @@ const DotGroup = class DotGroup extends React.Component {
1313
totalSlides: PropTypes.number.isRequired,
1414
visibleSlides: PropTypes.number.isRequired,
1515
dotNumbers: PropTypes.bool,
16+
disableActiveDots: PropTypes.bool,
17+
showAsSelectedForCurrentSlideOnly: PropTypes.bool,
1618
}
1719

1820
static defaultProps = {
1921
children: null,
2022
className: null,
2123
dotNumbers: false,
24+
disableActiveDots: true,
25+
showAsSelectedForCurrentSlideOnly: false,
2226
}
2327

2428
renderDots() {
25-
const { currentSlide, totalSlides, visibleSlides } = this.props;
29+
const {
30+
currentSlide,
31+
totalSlides,
32+
visibleSlides,
33+
disableActiveDots,
34+
showAsSelectedForCurrentSlideOnly,
35+
} = this.props;
2636
const dots = [];
2737
for (let i = 0; i < totalSlides; i += 1) {
28-
const selected = i >= currentSlide && i < (currentSlide + visibleSlides);
38+
const multipleSelected = i >= currentSlide && i < (currentSlide + visibleSlides);
39+
const singleSelected = i === currentSlide;
40+
const selected = showAsSelectedForCurrentSlideOnly ? singleSelected : multipleSelected;
2941
const slide = i >= totalSlides - visibleSlides ? totalSlides - visibleSlides : i;
3042
dots.push(
31-
<Dot key={i} slide={slide} selected={selected} disabled={selected}>
43+
<Dot
44+
key={i}
45+
slide={slide}
46+
selected={selected}
47+
disabled={disableActiveDots ? selected : false}
48+
>
3249
<span className={cn['carousel__dot-group-dot']}>{this.props.dotNumbers && i + 1}</span>
3350
</Dot>,
3451
);
@@ -38,7 +55,15 @@ const DotGroup = class DotGroup extends React.Component {
3855

3956
render() {
4057
const {
41-
carouselStore, children, className, currentSlide, dotNumbers, totalSlides, visibleSlides,
58+
carouselStore,
59+
children,
60+
className,
61+
currentSlide,
62+
dotNumbers,
63+
totalSlides,
64+
visibleSlides,
65+
disableActiveDots,
66+
showAsSelectedForCurrentSlideOnly,
4267
...props
4368
} = this.props;
4469

src/DotGroup/__tests__/DotGroup.test.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,28 @@ describe('<DotGroup />', () => {
3434
expect(wrapper.find('span').at(1).text()).toEqual('');
3535
expect(wrapper.find('span').at(2).text()).toEqual('');
3636
});
37+
it('should render enabled active dots if disableActiveDots prop is false', () => {
38+
const wrapper = shallow(<DotGroup {...props} disableActiveDots={false} />);
39+
expect(wrapper.children().at(0).prop('disabled')).toEqual(false);
40+
expect(wrapper.children().at(1).prop('disabled')).toEqual(false);
41+
expect(wrapper.children().at(2).prop('disabled')).toEqual(false);
42+
});
43+
it('should render DISABLED dots if disableActiveDots prop is not set', () => {
44+
const wrapper = shallow(<DotGroup {...props} />);
45+
expect(wrapper.children().at(0).prop('disabled')).toEqual(false);
46+
expect(wrapper.children().at(1).prop('disabled')).toEqual(true);
47+
expect(wrapper.children().at(2).prop('disabled')).toEqual(true);
48+
});
49+
it('should render only current slide dot as selected if showAsSelectedForCurrentSlideOnly prop is true', () => {
50+
const wrapper = shallow(<DotGroup {...props} showAsSelectedForCurrentSlideOnly />);
51+
expect(wrapper.children().at(0).prop('selected')).toEqual(false);
52+
expect(wrapper.children().at(1).prop('selected')).toEqual(true);
53+
expect(wrapper.children().at(2).prop('selected')).toEqual(false);
54+
});
55+
it('should render all visible slides dot as selected if showAsSelectedForCurrentSlideOnly prop is not set', () => {
56+
const wrapper = shallow(<DotGroup {...props} />);
57+
expect(wrapper.children().at(0).prop('selected')).toEqual(false);
58+
expect(wrapper.children().at(1).prop('selected')).toEqual(true);
59+
expect(wrapper.children().at(2).prop('selected')).toEqual(true);
60+
});
3761
});

0 commit comments

Comments
 (0)