You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-121
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,14 @@
2
2
3
3
This npm package provides react components to display a carousel. The components can be loaded through a `useCarousel` hook. The carousel is quite simple but still supports a wide set of requirements and is easy to use.
4
4
5
-
## Should I use a carousel?
6
-
Short answer, no. See [shouldiuseacarousel.com](https://shouldiuseacarousel.com) for more information on this topic. If you want or have to use a carousel anyway you're more than welcome to use this one. :-)
7
-
8
-
9
-
10
5
## Key features
11
6
12
-
- Load **multiple carousels on one page** without conflicts
13
-
- Easy to use `Carousel`, `Slides`, `Control` and `Pagination` components
14
-
-**Lightweight** and **zero dependencies** (besides react)
15
-
- Supports **multiple slides per view** without any custom configurations
16
-
- Realized with vanilla JavaScript and [CSS Scroll Snap](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap)
17
-
-**Accessible** and automatically applied aria attributes
7
+
-🫱🏾🫲🏼 Load **multiple carousels on one page** without conflicts
8
+
-⚡️ Easy to use `Carousel`, `Slides`, `Control` and `Pagination` components
9
+
-📦 **Lightweight** and **zero dependencies** (besides react)
10
+
-𝌕 Supports **multiple slides per view** without any custom configurations
11
+
-⚛️ Realized with vanilla JavaScript and [CSS Scroll Snap](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap) for React apps
12
+
-🦮 **Accessible** and automatically applied aria attributes
With `react-use-carousel-hook` you can easily display a carousel by importing the hook and use the returned components. There are four available components.
30
-
The first one is the `Carousel` component which is needed to support the aria attributes.
31
-
The second one is the `Slides` component which is used to wrap your slides.
32
-
The third one is the `Control` component which can be used to display previous / next slide buttons.
33
-
The last one is the `Pagination` component which can be used to display a pagination representing the carousel slides.
25
+
-The first one is the `Carousel` component which is needed to support the aria attributes.
26
+
-The second one is the `Slides` component which is used to wrap your slides.
27
+
-The third one is the `Control` component which can be used to display previous / next slide buttons.
28
+
-The last one is the `Pagination` component which can be used to display a pagination representing the carousel slides.
<!-- The example from above renders the following HTML:
68
-
69
-
```html
70
-
TODO
71
-
``` -->
72
-
73
-
## Hook
74
-
75
-
### Usage
76
-
77
-
The `useCarousel` hook returns four components and accpets some options as function parameter.
78
-
79
-
```tsx
80
-
const { Slides } =useCarousel({ loop: false });
81
-
```
82
-
83
-
### Options
84
-
85
-
| Option | Type | Default | Description |
86
-
| --- | --- | --- | --- |
87
-
|`loop`|`boolean`|`false`| If set to false the `Control` prev/next button will be disabled when start/end of carousel is reached. If set to true buttons can always be clicked and carousel jumps to start if at end and vice versa. |
88
-
89
-
## Components
90
-
91
-
There are four components that can be used via the `useCarousel` hook. Those components are `Carousel`, `Slides`, `Control` and `Pagination`. Each of them supports or even requires a number of props.
92
-
93
-
### `Carousel`
94
-
95
-
This component is needed to support the aria attributes. Its only purpose is to make the carousel accessible. You can pass anything as children.
| children\*|`ReactElement[]`|`undefined`| The slides of the carousel. |
128
-
||||_All props that are supported by the `<div/>` element._|
129
-
130
-
_\* required_
131
-
132
-
### `Control`
133
-
134
-
This component can be used to display a previous or next slide button. To style a disabled control button use the [`:disabled`](https://developer.mozilla.org/en-US/docs/Web/CSS/:disabled) pseudo-class in CSS.
135
-
136
-
```tsx
137
-
<Controldirection="prev"/>
138
-
<Controldirection="next"/>
139
-
```
140
-
141
-
| Prop | Type | Default | Description |
142
-
| --- | --- | --- | --- |
143
-
| direction\*|`"prev" \| "next"`|`undefined`| The direction in which the carousel should scroll/slide when clicked. |
144
-
||||_All props that are supported by the `<button/>` element._|
145
-
146
-
_\* required_
147
-
148
-
### `Pagination`
149
-
150
-
This component can be used to display a pagination to control the carousel slides.
151
-
To style the active pagination button use the `&[aria-selected=“true”]`[attribute selector](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Attribute_selectors) in CSS.
If you need more control and want to display a numbered pagination you can implement it like this:
160
-
161
-
```tsx
162
-
<Pagination>
163
-
{(index) => (
164
-
<buttonclassName="bg-gray aria-selected:bg-black">Slide number {index}</button>
165
-
)}
166
-
</Pagination>
167
-
```
62
+
See [the docs](https://react-use-carousel-hook.vercel.app/) for API reference, examples and more.
168
63
169
-
| Prop | Type | Default | Description |
170
-
| --- | --- | --- | --- |
171
-
| buttonClassName |`string`|`undefined`| Can be used to set classNames to the pagination buttons. |
172
-
| children |`(index: number) => HTMLButtonElement`|`undefined`| Will return basic button as pagination point if undefined. Button can be customized by returning a function returning a button. |
173
-
||||_All props that are supported by the `<div/>` element._|
64
+
## Should I use a carousel?
65
+
Short answer, no. See [shouldiuseacarousel.com](https://shouldiuseacarousel.com) for more information on this topic. If you want or have to use a carousel anyway you're more than welcome to use this one. :-)
0 commit comments