Skip to content

Commit 85fc526

Browse files
committed
docs(#2): improve docs
1 parent e33161f commit 85fc526

File tree

3 files changed

+28
-137
lines changed

3 files changed

+28
-137
lines changed

README.md

+13-121
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22

33
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.
44

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-
105
## Key features
116

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
1813

1914
## Installation
2015

@@ -27,10 +22,10 @@ yarn add react-use-carousel-hook
2722
## Usage
2823

2924
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.
3429

3530
```tsx
3631
import { useCarousel } from 'react-use-carousel-hook';
@@ -64,113 +59,10 @@ const YourComponent = ({ items = [] }) => {
6459
};
6560
```
6661

67-
<!-- 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.
96-
97-
```tsx
98-
<Carousel>
99-
<h2>FooBar</h2>
100-
<Slides>
101-
<div>1</div>
102-
<div>2</div>
103-
<div>3</div>
104-
</Slides>
105-
</Carousel>
106-
```
107-
108-
| Prop | Type | Default | Description |
109-
| ---------- | ----------- | ----------- | --------------------------- |
110-
| children | `ReactNode` | `undefined` | Any elements. Used as wrapper for `Slides`, `Control`, `Pagination`. |
111-
| | | | _All props that are supported by the `<div/>` element._ |
112-
113-
### `Slides`
114-
115-
Wrapper component for the slides. It will add styles to make the slides look and feel like a carousel.
116-
117-
```tsx
118-
<Slides>
119-
{[1, 2, 3, 4].map((item) => (
120-
<div key={item}>Slide {item}</div>
121-
))}
122-
</Slides>
123-
```
124-
125-
| Prop | Type | Default | Description |
126-
| ---------- | ---------------- | ----------- | --------------------------- |
127-
| 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-
<Control direction="prev"/>
138-
<Control direction="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.
152-
153-
Usage of basic pagination with bullets:
154-
155-
```tsx
156-
<Pagination buttonClassName="bg-gray aria-selected:bg-black" />
157-
```
158-
159-
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-
<button className="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.
16863

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. :-)
17466

17567
## Contributors
17668

docs/src/content/docs/examples.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@ title: 'Examples'
33
description: 'Demonstration of different carousel use cases.'
44
---
55

6-
## All features in action
6+
## Images
77

8-
Example of a useCarousel implementation that fully exploits the package's potential.
8+
A carousel with images as slides.
99

10-
<iframe src="https://codesandbox.io/embed/styles-one-slide-per-view-bw4xst?fontsize=14&hidenavigation=1&theme=dark"
11-
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
12-
title="styles-one-slide-per-view"
13-
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
10+
<iframe src="https://codesandbox.io/embed/images-1ydq92?codemirror=1&hidedevtools=1&hidenavigation=1&module=/src/App.tsx,/src/App.css"
11+
style="width:100%; height:600px; border:0; border-radius: 4px; overflow:hidden;"
12+
title="styles-one-slide"
13+
allow="accelerometer; ambient-light-sensor;"
1414
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
1515
></iframe>
1616
17-
## Styles
18-
17+
## Controlling slides per view
1918
### One slide per view
2019

2120
Example of a useCarousel implementation that has one slide per view.
2221

23-
<iframe src="https://codesandbox.io/embed/styles-one-slide-bw4xst?fontsize=14&hidenavigation=1&theme=dark"
24-
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
22+
<iframe src="https://codesandbox.io/embed/one-slide-per-view-7ivi1m?codemirror=1&hidedevtools=1&hidenavigation=1&module=/src/App.tsx,/src/App.css"
23+
style="width:100%; height:400px; border:0; border-radius: 4px; overflow:hidden;"
2524
title="styles-one-slide"
26-
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
25+
allow="accelerometer; ambient-light-sensor;"
2726
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
2827
></iframe>
2928
3029
### Multiple slides per view
3130

3231
Example of a useCarousel implementation that has multiple slides per view.
3332

34-
<iframe src="https://codesandbox.io/embed/tender-albattani-qn2rbp?fontsize=14&hidenavigation=1&theme=dark"
35-
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
36-
title="styles-multiple-slides-per-view"
37-
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
33+
<iframe src="https://codesandbox.io/embed/multiple-slides-per-view-dgsn67?codemirror=1&hidedevtools=1&hidenavigation=1&module=/src/App.tsx,/src/App.css"
34+
style="width:100%; height:400px; border:0; border-radius: 4px; overflow:hidden;"
35+
title="styles-one-slide"
36+
allow="accelerometer; ambient-light-sensor;"
3837
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
3938
></iframe>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"author": "faessler",
1515
"license": "MIT",
16-
"homepage": "https://github.com/faessler/react-use-carousel-hook#readme",
16+
"homepage": "https://react-use-carousel-hook.vercel.app",
1717
"bugs": {
1818
"url": "https://github.com/faessler/react-use-carousel-hook/issues"
1919
},

0 commit comments

Comments
 (0)