Skip to content

Commit a0f8bb3

Browse files
authored
Merge pull request #314 from maxmarinich/dnd-link
Add DNDLink component
2 parents 8453c27 + 5ba72fb commit a0f8bb3

File tree

8 files changed

+226
-85
lines changed

8 files changed

+226
-85
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ npm-debug.log
6969
dist
7070
lib
7171
static
72+
73+
!src/lib

README.md

+109-82
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,25 @@ React Alice Carousel is a React component for building content galleries, conten
3333
- TypeScript
3434

3535
## Installation
36+
3637
```apacheconfig
3738
npm i react-alice-carousel
3839
```
40+
3941
#### Style import
42+
4043
```
4144
# CSS
4245
@import "react-alice-carousel/lib/alice-carousel.css";
4346
```
47+
4448
```
4549
# SCSS
4650
@import "react-alice-carousel/lib/scss/alice-carousel.scss";
4751
```
52+
4853
## Usage
54+
4955
```javascript
5056
import React from 'react';
5157
import AliceCarousel from 'react-alice-carousel';
@@ -54,19 +60,16 @@ import 'react-alice-carousel/lib/alice-carousel.css';
5460
const handleDragStart = (e) => e.preventDefault();
5561

5662
const items = [
57-
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
58-
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
59-
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
63+
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
64+
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
65+
<img src="path-to-img" onDragStart={handleDragStart} role="presentation" />,
6066
];
6167

62-
const Gallery = () => {
63-
return (
64-
<AliceCarousel mouseTracking items={items} />
65-
);
66-
}
68+
const Gallery = () => <AliceCarousel mouseTracking items={items} />;
6769
```
6870

6971
#### Options
72+
7073
- `activeIndex` : Number, default `0` - Set carousel at the specified position.
7174
- `animationDuration`: Number, default `400` - Set duration of animation.
7275
- `animationEasingFunction`: String or [Function](https://developer.mozilla.org/ru/docs/Web/CSS/animation-timing-function), default `ease` - Property sets how an animation progresses through the duration of each cycle.
@@ -78,33 +81,35 @@ const Gallery = () => {
7881
- `autoPlayDirection`: String(`ltr`, `rtl`), default `ltr` - Set autoplay direction value.
7982
- `autoPlayInterval`: Number, default `400` - Set autoplay interval value.
8083
- `autoPlayStrategy`: String(`default`, `action`, `all`, `none`) - Set a strategy for autoplay mode
81-
* `default` - pause automatic playback on the hover
82-
* `action` - stop automatic playback if user action was detected
83-
* `all` - merge `default` && `action` strategies
84-
* `none` - ignore any user actions when the `autoPlay` property was specified
84+
- `default` - pause automatic playback on the hover
85+
- `action` - stop automatic playback if user action was detected
86+
- `all` - merge `default` && `action` strategies
87+
- `none` - ignore any user actions when the `autoPlay` property was specified
8588
- `controlsStrategy`: String (`default`, `responsive`, `alternate` or combined string `"default,alternate"`) - Set a strategy for gallery controls.
86-
* `default` - use controls as is
87-
* `alternate` - show each dot for each slide
88-
* `responsive` - navigation will be hidden if the number of gallery elements is equal to the number of items in the slide.
89+
- `default` - use controls as is
90+
- `alternate` - show each dot for each slide
91+
- `responsive` - navigation will be hidden if the number of gallery elements is equal to the number of items in the slide.
8992
- `disableButtonsControls`: Boolean, default `false` - Disable buttons controls.
9093
- `disableDotsControls`: Boolean, default `false` - Disable dots controls.
9194
- `disableSlideInfo`: Boolean, default `true` - Disable information about current slide.
9295
- `infinite`: Boolean, default `false` - Set infinite mode.
9396
- `innerWidth`: Number, default `0` - Set a static value for a breakpoint(`key`) of the "responsive" property. For example, if you can't use 'window.innerWidth' during SSR.
94-
- `items`: Array, default `undefined` - Set gallery items, preferable to use this property instead of children.
95-
- `keyboardNavigation`: Boolean, default `false` - Enable keyboard navigation
96-
* `ArrowLeft` - go to the prev slide
97-
* `ArrowRight` - go to the next slide
98-
* `Space` - run/stop autoplay mode if `autoPlay` property is equal `true`
99-
- `mouseTracking`: Boolean, default `false` - Enable mouse drag animation.
100-
- `paddingLeft`: Number, default `0` - Set the gallery offset from the left.
101-
- `paddingRight`: Number, default `0` - Set the gallery offset from the right.
102-
- `renderKey`: Number, default `undefined` - Auxiliary property, allows call the render method without changing the state inside the gallery instance.
97+
- `items`: Array, default `undefined` - Set gallery items, preferable to use this property instead of children.
98+
- `keyboardNavigation`: Boolean, default `false` - Enable keyboard navigation
99+
- `ArrowLeft` - go to the prev slide
100+
- `ArrowRight` - go to the next slide
101+
- `Space` - run/stop autoplay mode if `autoPlay` property is equal `true`
102+
- `mouseTracking`: Boolean, default `false` - Enable mouse drag animation. Consider the problem with links, see the example of using the `<Link/>` component below.
103+
- `paddingLeft`: Number, default `0` - Set the gallery offset from the left.
104+
- `paddingRight`: Number, default `0` - Set the gallery offset from the right.
105+
- `renderKey`: Number, default `undefined` - Auxiliary property, allows call the render method without changing the state inside the gallery instance.
103106
- `responsive`: Object, default `undefined` - The key is the breakpoint (default is the result of: () => window.innerWidth or `innerWidth` property if the last presented).
104-
* `items` - set number of items in the slide. Default: `1`
105-
* `itemsFit`: one of (`contain | fill | undefined`) - defines, how item should fill the container according slide's width. Default: `fill`.
106-
107-
If `contain` is specified, the gallery will use the value from the `items` property to determine the width of the element for each slide and fill in the empty space as needed.
107+
108+
- `items` - set number of items in the slide. Default: `1`
109+
- `itemsFit`: one of (`contain | fill | undefined`) - defines, how item should fill the container according slide's width. Default: `fill`.
110+
111+
If `contain` is specified, the gallery will use the value from the `items` property to determine the width of the element for each slide and fill in the empty space as needed.
112+
108113
```js
109114
{
110115
0: {
@@ -115,15 +120,16 @@ const Gallery = () => {
115120
itemsFit: 'contain',
116121
}
117122
}
118-
```
119-
- `syncStateOnPropsUpdate`: Boolean, default `true` - Sync some props (like `activeIndex`) with carousel state while new props passed. This allows you to avoid resetting the carousel position while updating the props (e.g.: `children` or `items`).
120-
- `swipeDelta`: Number, default `20` - Set minimum distance to the start of the swiping (px).
121-
- `swipeExtraPadding`: Number, default `200` - Set maximum distance from initial place before swipe action will be stopped (px).
122-
- `ssrSilentMode`: Boolean, default `true` - Disable classnames modifiers for server side rendering.
123-
- `touchTracking`: Boolean, default `true` - Enable touch move animation.
124-
- `touchMoveDefaultEvents`: Boolean, default `true` - Enable touch move default events on swiping. If `false` was specified, this prevents vertical scrolling of the parent elements during the swipe.
123+
```
124+
125+
- `syncStateOnPropsUpdate`: Boolean, default `true` - Sync some props (like `activeIndex`) with carousel state while new props passed. This allows you to avoid resetting the carousel position while updating the props (e.g.: `children` or `items`).
126+
- `swipeDelta`: Number, default `20` - Set minimum distance to the start of the swiping (px).
127+
- `swipeExtraPadding`: Number, default `200` - Set maximum distance from initial place before swipe action will be stopped (px).
128+
- `ssrSilentMode`: Boolean, default `true` - Disable classnames modifiers for server side rendering.
129+
- `touchTracking`: Boolean, default `true` - Enable touch move animation.
130+
- `touchMoveDefaultEvents`: Boolean, default `true` - Enable touch move default events on swiping. If `false` was specified, this prevents vertical scrolling of the parent elements during the swipe.
125131
- `onInitialized(e: EventObject)`: Function - Fired as callback after the gallery was created.
126-
- `onResizeEvent(e: Event)`: Function, default `shouldProcessResizeEvent` method - Fired during the "resize" event to determine whether to call the event handler. Default method checks is the root element width has changed.
132+
- `onResizeEvent(e: Event)`: Function, default `shouldProcessResizeEvent` method - Fired during the "resize" event to determine whether to call the event handler. Default method checks is the root element width has changed.
127133
- `onResized(e: EventObject)`: Function - Fired as callback after the gallery was resized.
128134
- `onUpdated(e: EventObject)`: Function - Fired as callback after updating the gallery props.
129135
- `onSlideChange(e: EventObject)`: Function - Fired before the event object changes.
@@ -135,95 +141,116 @@ const Gallery = () => {
135141
- `renderPlayPauseButton({ isPlaying })`: Rendering function - create a custom component.
136142

137143
#### Methods (Refs [example](https://maxmarinich.github.io/react-alice-carousel/#custom-components-refs))
144+
138145
- `slidePrev(e: Event) => void` : Go to the prev slide.
139146
- `slideNext(e: Event) => void` : Go to the next slide.
140147
- `slideTo(activeIndex?: number) => void` : Go to the specified slide.
141148

149+
#### Components (Links [example](https://maxmarinich.github.io/react-alice-carousel/#custom-components-links))
150+
151+
- `<Link />` : allows properly handle click and drag events when mouseTracking enabled, extends base HTMLAnchorElement
152+
153+
```javascript
154+
import React from 'react';
155+
import AliceCarousel, { Link } from 'react-alice-carousel';
156+
import 'react-alice-carousel/lib/alice-carousel.css';
157+
158+
const Gallery = () => {
159+
return (
160+
<AliceCarousel mouseTracking>
161+
<Link href="#">
162+
<img src="path-to-image" />
163+
</Link>
164+
</AliceCarousel>
165+
);
166+
};
167+
```
168+
142169
#### Types
170+
143171
```typescript
144172
type EventObject = {
145-
item: number;
146-
slide: number;
147-
itemsInSlide: number;
148-
isPrevSlideDisabled: boolean;
149-
isNextSlideDisabled: boolean;
150-
type: EventType;
173+
item: number;
174+
slide: number;
175+
itemsInSlide: number;
176+
isPrevSlideDisabled: boolean;
177+
isNextSlideDisabled: boolean;
178+
type: EventType;
151179
};
152180

153181
type SlideInfo = {
154-
item: number;
155-
itemsCount: number;
182+
item: number;
183+
itemsCount: number;
156184
};
157185

158186
type DotsItem = {
159-
isActive: boolean;
160-
activeIndex: number;
187+
isActive: boolean;
188+
activeIndex: number;
161189
};
162190

163191
enum EventType {
164-
ACTION = 'action', // used if a general user action (button click or swipe)
165-
INIT = 'init', // used if the initial event was triggered
166-
RESIZE = 'resize', // used if the gallery size was changed
167-
UPDATE = 'update', // used if the gallery was updated with props
192+
ACTION = 'action', // used if a general user action (button click or swipe)
193+
INIT = 'init', // used if the initial event was triggered
194+
RESIZE = 'resize', // used if the gallery size was changed
195+
UPDATE = 'update', // used if the gallery was updated with props
168196
}
169197
```
170198

171199
#### CSS classes
200+
172201
```css
173202
.alice-carousel
174-
175-
.alice-carousel__stage
176-
.alice-carousel__stage-item
177-
178-
.alice-carousel__prev-btn
179-
.alice-carousel__prev-btn-item
180-
181-
.alice-carousel__next-btn
182-
.alice-carousel__next-btn-item
183-
184-
.alice-carousel__play-btn
185-
.alice-carousel__play-btn-item
186-
187-
.alice-carousel__dots
188-
.alice-carousel__dots-item
189-
190-
.alice-carousel__slide-info
191-
.alice-carousel__slide-info-item
203+
.alice-carousel__stage
204+
.alice-carousel__stage-item
205+
.alice-carousel__prev-btn
206+
.alice-carousel__prev-btn-item
207+
.alice-carousel__next-btn
208+
.alice-carousel__next-btn-item
209+
.alice-carousel__play-btn
210+
.alice-carousel__play-btn-item
211+
.alice-carousel__dots
212+
.alice-carousel__dots-item
213+
.alice-carousel__slide-info
214+
.alice-carousel__slide-info-item;
192215
```
193216

194217
#### CSS modifiers
218+
195219
```css
196220
.alice-carousel.__ssr
197-
198-
.alice-carousel__stage-item.__active
199-
.alice-carousel__stage-item.__cloned
200-
.alice-carousel__stage-item.__target
201-
202-
.alice-carousel__next-btn-item.__inactive
203-
.alice-carousel__prev-btn-item.__inactive
204-
205-
.alice-carousel__play-btn-item.__pause
206-
207-
.alice-carousel__dots-item.__active
208-
.alice-carousel__dots-item.__custom
209-
210-
.alice-carousel__slide-info-item.__separator
221+
.alice-carousel__stage-item.__active
222+
.alice-carousel__stage-item.__cloned
223+
.alice-carousel__stage-item.__target
224+
.alice-carousel__next-btn-item.__inactive
225+
.alice-carousel__prev-btn-item.__inactive
226+
.alice-carousel__play-btn-item.__pause
227+
.alice-carousel__dots-item.__active
228+
.alice-carousel__dots-item.__custom
229+
.alice-carousel__slide-info-item.__separator;
211230
```
212231

213232
## Build the project locally
233+
214234
#### Clone
235+
215236
```apacheconfig
216237
git clone https://github.com/maxmarinich/react-alice-carousel
217238
cd react-alice-carousel
218239
```
240+
219241
#### Run
242+
220243
```apacheconfig
221244
npm ci
222245
npm start
223246
```
247+
224248
#### Test
249+
225250
```apacheconfig
226251
npm test
227252
```
253+
228254
## License
255+
229256
MIT

src/components/pages/custom-components/index.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RenderExample from './render-components';
33
import RefsExample from './refs-components';
44
import PropsExample from './props-components';
55
import EventsExample from './event-components';
6+
import Links from './links';
67
import Anchor, { genAnchorProps } from '../../the-anchor';
78

89
const CustomComponentsPage = () => {
@@ -37,6 +38,14 @@ const CustomComponentsPage = () => {
3738
&nbsp; Refs
3839
</h2>
3940
<RefsExample />
41+
<br />
42+
<br />
43+
<br />
44+
<h2 className="title">
45+
<Anchor {...genAnchorProps('custom-components-links')} />
46+
&nbsp; Links
47+
</h2>
48+
<Links />
4049
</section>
4150
);
4251
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```javascript
2+
import React from 'react';
3+
import AliceCarousel, { Link } from 'react-alice-carousel';
4+
import 'react-alice-carousel/lib/alice-carousel.css';
5+
6+
const href = '//github.com/maxmarinich/react-alice-carousel';
7+
const src = '//github.com/maxmarinich/react-alice-carousel/raw/master/src/assets/img/1200x200.jpg';
8+
9+
const Carousel = () => (
10+
<AliceCarousel mouseTracking>
11+
<Link href={href} target="_blank" className="link">
12+
<img src={src} alt="" />
13+
</Link>
14+
<Link href={href} target="_blank" className="link">
15+
<img src={src} alt="" />
16+
</Link>
17+
<Link href={href} target="_blank" className="link">
18+
<img src={src} alt="" />
19+
</Link>
20+
</AliceCarousel>
21+
);
22+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
import markdown from './code.md';
4+
import TheCode from '../../../the-code';
5+
import AliceCarousel, { Link } from '../../../../lib/react-alice-carousel';
6+
7+
const Links = () => {
8+
const href = '//github.com/maxmarinich/react-alice-carousel';
9+
const src = '//github.com/maxmarinich/react-alice-carousel/raw/master/src/assets/img/1200x200.jpg';
10+
11+
return (
12+
<section className="p-basic">
13+
<AliceCarousel mouseTracking>
14+
<Link href={href} target="_blank" className="link">
15+
<img src={src} alt="" />
16+
</Link>
17+
<Link href={href} target="_blank" className="link">
18+
<img src={src} alt="" />
19+
</Link>
20+
<Link href={href} target="_blank" className="link">
21+
<img src={src} alt="" />
22+
</Link>
23+
</AliceCarousel>
24+
<TheCode html={markdown} />
25+
</section>
26+
);
27+
};
28+
29+
export default Links;

0 commit comments

Comments
 (0)