Skip to content

Commit fe25e75

Browse files
authored
Feature/pass through drag callbacks (#161)
* renamed onDragStart and onDragEnd These names were misleading. They are not related in any way to React’s event types. * allow event propagation Not sure why we are stopping event propagation in the slider tray. We should allow events to bubble up to maximize configurability for Pure React Carousel consumers. Commenting out for now, will remove completely if no bugs arise from this change. * Created Example 11 Created a new example carousel to demonstrait how to pass events to the Slider tray element. * fix incorrect value for preserveAspectRatio * removing commented-out code * added “missing” prop types * forgot to update tests with fakeOnDragMove, End * rename onDragStart to fakeOnDragStart
1 parent d4ca2da commit fe25e75

File tree

6 files changed

+241
-71
lines changed

6 files changed

+241
-71
lines changed

src/App/App.jsx

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ import {
1010
Example8,
1111
Example9,
1212
Example10,
13+
Example11,
1314
} from './examples';
1415
import s from './style.scss';
1516

16-
17-
// function demoClick(ev) {
18-
// console.log('ev', Object.assign({}, ev));
19-
// }
20-
2117
class DevelopmentApp extends React.Component {
2218
constructor() {
2319
super();
@@ -43,32 +39,40 @@ class DevelopmentApp extends React.Component {
4339
<div className={s.firstSlideCenterHoriz}>
4440
<h1 className={s.heroHeadline}>Pure React Carousel</h1>
4541
<p className={s.heroText}>
46-
Pure React Carousel is a suite of unopinionated React components that a
47-
developer can use to create robust carousels with almost no limits on DOM structure
48-
or styling.
42+
Pure React Carousel is a suite of unopinionated React components that a developer
43+
can use to create robust carousels with almost no limits on DOM structure or
44+
styling.
4945
</p>
5046
<p className={s.heroText}>
5147
If you&apos;re tired of fighting some other developer&apos;s CSS and DOM structure,
5248
this carousel is for you.
5349
</p>
5450
<ul className={s.heroList}>
55-
<li><a href="#un">What is &quot;unopinionated?&quot;</a></li>
56-
<li><a href="#rw">Real World Example</a></li>
57-
<li><a href="#de">Demo Examples</a></li>
51+
<li>
52+
<a href="#un">What is &quot;unopinionated?&quot;</a>
53+
</li>
54+
<li>
55+
<a href="#rw">Real World Example</a>
56+
</li>
57+
<li>
58+
<a href="#de">Demo Examples</a>
59+
</li>
5860
<li>
5961
<a href="https://github.com/express-labs/pure-react-carousel">
6062
Documentation
6163
<svg
6264
className={s.externalLink}
6365
xmlns="http://www.w3.org/2000/svg"
6466
viewBox="0 0 24 24"
65-
preserveAspectRatio="xMidyMid meet"
67+
preserveAspectRatio="xMidYMid meet"
6668
>
6769
<path d="M5 3c-1.093 0-2 .907-2 2v14c0 1.093.907 2 2 2h14c1.093 0 2-.907 2-2v-7h-2v7H5V5h7V3H5zm9 0v2h3.586l-9.293 9.293 1.414 1.414L19 6.414V10h2V3h-7z" />
6870
</svg>
6971
</a>
7072
</li>
71-
<li><a href="#el">Express Labs</a></li>
73+
<li>
74+
<a href="#el">Express Labs</a>
75+
</li>
7276
</ul>
7377
</div>
7478
</div>
@@ -82,36 +86,48 @@ class DevelopmentApp extends React.Component {
8286
</p>
8387
<p>
8488
The components in Pure React Carousel provide the bare-minimum of styling and javascript
85-
required to function correctly as a carousel. Just like using table HTML tags
86-
will give you a bare-bones table that you will need to style, Pure React Carousel
87-
requires that you provide additional styles and optional javascript in order to meet
88-
your project&apos;s specific functionality and branding requirements.
89+
required to function correctly as a carousel. Just like using table HTML tags will give
90+
you a bare-bones table that you will need to style, Pure React Carousel requires that
91+
you provide additional styles and optional javascript in order to meet your
92+
project&apos;s specific functionality and branding requirements.
8993
</p>
9094
<p>
91-
The benefit of Pure React Carousel is that our components are focused on one task:
92-
being an WCAG accessible carousel. Besides that, our goal is to get out of your way.
95+
The benefit of Pure React Carousel is that our components are focused on one task: being
96+
an WCAG accessible carousel. Besides that, our goal is to get out of your way.
9397
</p>
9498
</div>
9599
<div id="rw" className={s.examples}>
96100
<div className={s.examplesInnerCenter}>
97101
<h2 className={s.headline}>Real World Example</h2>
98102
<p>
99-
Here are two examples of what can be acheived with Pure React Carousel. This is how
100-
we use the suite of components on the Express.com website.
103+
Here are two examples of what can be acheived with Pure React Carousel. This is how we
104+
use the suite of components on the Express.com website.
105+
</p>
106+
<p>
107+
<img
108+
className={s.responsiveImg}
109+
src="./media/pdp-women.gif"
110+
alt="example of pure react carousel on the product detail page for a dress on Express.com"
111+
/>
112+
</p>
113+
<p>
114+
<img
115+
className={s.responsiveImg}
116+
src="./media/pdp-men.gif"
117+
alt="example of pure react carousel on the product detail page for a shirt on Express.com"
118+
/>
101119
</p>
102-
<p><img className={s.responsiveImg} src="./media/pdp-women.gif" alt="example of pure react carousel on the product detail page for a dress on Express.com" /></p>
103-
<p><img className={s.responsiveImg} src="./media/pdp-men.gif" alt="example of pure react carousel on the product detail page for a shirt on Express.com" /></p>
104120
</div>
105121
</div>
106122
<div id="de" className={s.examplesDemo}>
107123
<div className={s.examplesInner}>
108124
<h2 className={s.headline}>Default Carousel Examples</h2>
109125
<h3 className={s.headline}>Why are these examples so... ugly?</h3>
110126
<p>
111-
These examples are completely un-styled. Pure React Carousel does not come with
112-
styles that must be defeated in order to match your organization&apos;s branding. So,
113-
to distract you from the seeming lack of finess, most of our examples
114-
involve pictures of cats!
127+
These examples are completely un-styled. Pure React Carousel does not come with styles
128+
that must be defeated in order to match your organization&apos;s branding. So, to
129+
distract you from the seeming lack of finess, most of our examples involve pictures of
130+
cats!
115131
</p>
116132
<p>
117133
<label>
@@ -125,83 +141,93 @@ class DevelopmentApp extends React.Component {
125141
<option value="5">Horizontal Carousel (With Master Loading Spinner)</option>
126142
<option value="6">Simple Carousel with vertically alligned nav buttons</option>
127143
<option value="7">Simple Carousel with react-redux</option>
128-
<option value="8">Horizontal Carousel (With lockOnWindowScroll set to TRUE)</option>
144+
<option value="8">
145+
Horizontal Carousel (With lockOnWindowScroll set to TRUE)
146+
</option>
129147
<option value="9">Horizontal Carousel Auto Play</option>
148+
<option value="10">Carousel with custom spinner component.</option>
149+
<option value="11">Simple carousel with event callbacks on Slider.</option>
130150
</select>
131151
</label>
132152
</p>
133153

134154
<div className={s.example}>
135-
{ (value === '0' || value === '1') && (
155+
{(value === '0' || value === '1') && (
136156
<section id="example--1">
137157
<hr />
138158
<Example1 />
139159
</section>
140160
)}
141161

142-
{ (value === '0' || value === '2') && (
162+
{(value === '0' || value === '2') && (
143163
<section id="example--2">
144164
<hr />
145165
<Example2 />
146166
</section>
147167
)}
148168

149-
{ (value === '0' || value === '3') && (
169+
{(value === '0' || value === '3') && (
150170
<section id="example--3">
151171
<hr />
152172
<Example3 />
153173
</section>
154174
)}
155175

156-
{ (value === '0' || value === '4') && (
176+
{(value === '0' || value === '4') && (
157177
<section id="example--4">
158178
<hr />
159179
<Example4 />
160180
</section>
161181
)}
162182

163-
{ (value === '0' || value === '5') && (
183+
{(value === '0' || value === '5') && (
164184
<section id="example--5">
165185
<hr />
166186
<Example5 />
167187
</section>
168188
)}
169189

170-
{ (value === '0' || value === '6') && (
190+
{(value === '0' || value === '6') && (
171191
<section id="example--6">
172192
<hr />
173193
<Example6 />
174194
</section>
175195
)}
176196

177-
{ (value === '0' || value === '7') && (
197+
{(value === '0' || value === '7') && (
178198
<section id="example--7">
179199
<hr />
180200
<Example7 />
181201
</section>
182202
)}
183203

184-
{ (value === '0' || value === '8') && (
204+
{(value === '0' || value === '8') && (
185205
<section id="example--8">
186206
<hr />
187207
<Example8 />
188208
</section>
189209
)}
190210

191-
{ (value === '0' || value === '9') && (
211+
{(value === '0' || value === '9') && (
192212
<section id="example--9">
193213
<hr />
194214
<Example9 />
195215
</section>
196216
)}
197217

198-
{ (value === '0' || value === '10') && (
218+
{(value === '0' || value === '10') && (
199219
<section id="example--10">
200220
<hr />
201221
<Example10 />
202222
</section>
203223
)}
204224

225+
{(value === '0' || value === '11') && (
226+
<section id="example--11">
227+
<hr />
228+
<Example11 />
229+
</section>
230+
)}
205231
</div>
206232
</div>
207233
</div>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import React from 'react';
2+
import {
3+
ButtonBack,
4+
ButtonFirst,
5+
ButtonLast,
6+
ButtonNext,
7+
CarouselProvider,
8+
DotGroup,
9+
Image,
10+
Slide,
11+
Slider,
12+
} from '../../..';
13+
14+
import s from '../../style.scss';
15+
16+
function eventLogger(ev) {
17+
// eslint-disable-next-line no-console
18+
console.log(ev.type, ev.target);
19+
}
20+
21+
export default () => (
22+
<CarouselProvider
23+
visibleSlides={2}
24+
totalSlides={6}
25+
naturalSlideWidth={400}
26+
naturalSlideHeight={500}
27+
>
28+
<h2 className={s.headline}>Carousel with custom event handlers.</h2>
29+
<p>
30+
Simple carousel with custom event handlers attachet to the
31+
{' '}
32+
<code>&lt;Slider /&gt;</code>
33+
{' '}
34+
component&apos;s
35+
{' '}
36+
<code>trayProps</code>
37+
{' '}
38+
property. Open your browser devloper tools and look at
39+
the console log, then manipulate the carousel.
40+
</p>
41+
<Slider
42+
className={s.slider}
43+
trayProps={{
44+
// clipboard events? Sure why not.
45+
onCopy: eventLogger,
46+
onCut: eventLogger,
47+
onPaste: eventLogger,
48+
49+
// composition events
50+
onCompositionEnd: eventLogger,
51+
onCompositionStart: eventLogger,
52+
onCompositionUpdate: eventLogger,
53+
54+
// keyboard events
55+
onKeyDown: eventLogger,
56+
onKeyPress: eventLogger,
57+
onKeyUp: eventLogger,
58+
59+
// focus events,
60+
onFocus: eventLogger,
61+
onBlur: eventLogger,
62+
63+
// form events,
64+
onChange: eventLogger,
65+
onInput: eventLogger,
66+
onInvalid: eventLogger,
67+
onSubmit: eventLogger,
68+
69+
// mouse events
70+
onClick: eventLogger,
71+
onContextMenu: eventLogger,
72+
onDoubleClick: eventLogger,
73+
onDrag: eventLogger,
74+
onDragEnd: eventLogger,
75+
onDragEnter: eventLogger,
76+
onDragExit: eventLogger,
77+
onDragLeave: eventLogger,
78+
onDragOver: eventLogger,
79+
onDragStart: eventLogger,
80+
onDrop: eventLogger,
81+
onMouseDown: eventLogger,
82+
onMouseEnter: eventLogger,
83+
onMouseLeave: eventLogger,
84+
// onMouseMove: eventLogger,
85+
onMouseOut: eventLogger,
86+
onMouseOver: eventLogger,
87+
onMouseUp: eventLogger,
88+
89+
// touch events
90+
onTouchCancel: eventLogger,
91+
onTouchEnd: eventLogger,
92+
// onTouchMove: eventLogger,
93+
onTouchStart: eventLogger,
94+
95+
// pointer events
96+
onPointerDown: eventLogger,
97+
// onPointerMove: eventLogger,
98+
onPointerUp: eventLogger,
99+
onPointerCancel: eventLogger,
100+
onGotPointerCapture: eventLogger,
101+
onLostPointerCapture: eventLogger,
102+
onPointerEnter: eventLogger,
103+
onPointerLeave: eventLogger,
104+
onPointerOver: eventLogger,
105+
onPointerOut: eventLogger,
106+
107+
draggable: true,
108+
}}
109+
>
110+
<Slide tag="a" index={0}>
111+
<Image src="./media/img01.jpeg" />
112+
</Slide>
113+
<Slide tag="a" index={1}>
114+
<Image src="./media/img02.jpeg" />
115+
</Slide>
116+
<Slide tag="a" index={2}>
117+
<Image src="./media/img03.jpeg" />
118+
</Slide>
119+
<Slide tag="a" index={3}>
120+
<Image src="./media/img04.jpeg" />
121+
</Slide>
122+
<Slide tag="a" index={4}>
123+
<Image src="./media/img05.jpeg" />
124+
</Slide>
125+
<Slide tag="a" index={5}>
126+
<Image src="./media/img06.jpeg" />
127+
</Slide>
128+
</Slider>
129+
<ButtonFirst>First</ButtonFirst>
130+
<ButtonBack>Back</ButtonBack>
131+
<ButtonNext>Next</ButtonNext>
132+
<ButtonLast>Last</ButtonLast>
133+
<DotGroup dotNumbers />
134+
</CarouselProvider>
135+
);

src/App/examples/Example11/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Example11 from './Example11';
2+
3+
export default Example11;

src/App/examples/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export { default as Example7 } from './Example7';
88
export { default as Example8 } from './Example8';
99
export { default as Example9 } from './Example9';
1010
export { default as Example10 } from './Example10';
11+
export { default as Example11 } from './Example11';

0 commit comments

Comments
 (0)