Skip to content

Commit

Permalink
Add documentation page for AutoScroll.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjerleke committed Jan 13, 2024
1 parent b21dc52 commit 490fa5e
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ function AutoScroll(userOptions: AutoScrollOptionsType = {}): AutoScrollType {
return self
}

function play(delayOverride?: number): void {
if (typeof delayOverride !== 'undefined') startDelay = delayOverride
function play(startDelayOverride?: number): void {
if (typeof startDelayOverride !== 'undefined') {
startDelay = startDelayOverride
}
resume = true
startScroll()
}
Expand Down
4 changes: 2 additions & 2 deletions packages/embla-carousel-docs/src/content/pages/api/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ The `EmblaEventType` is obtained directly from the **core package** `embla-carou
</TabsItem>
</Tabs>

---

## Reference

Below follows an exhaustive **list of all** Embla Carousel **events** together with information about how they work.
Expand Down Expand Up @@ -357,3 +355,5 @@ Runs when the user has a pointer down on the carousel. It's triggered by a `touc
Once: <BrandPrimaryText>`no`</BrandPrimaryText>

Runs when the user has released the pointer from the carousel. It's triggered by a `touchend` or a `mouseup` event.

---
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ The `EmblaCarouselType` is obtained directly from the **core package** `embla-ca
</TabsItem>
</Tabs>

---

## Reference

Below follows an exhaustive **list of all** Embla Carousel **methods** with their respective parameters and return values.
Expand Down Expand Up @@ -363,3 +361,5 @@ Parameters: <BrandPrimaryText>`event: EmblaEventType`</BrandPrimaryText>
Returns: <BrandSecondaryText>`void`</BrandSecondaryText>

Emits an embla [event](/api/events/). This doesn't trigger any internal Embla functionality.

---
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ The `EmblaOptionsType` is obtained directly from the **core package** `embla-car
</TabsItem>
</Tabs>

---

## Reference

Below follows an exhaustive **list of all** Embla Carousel **options** and their default values.
Expand Down Expand Up @@ -422,3 +420,5 @@ Embla automatically watches the [container](/api/methods/#containernode/) for **
run its default mutation behaviour after your callback, or return `false` if
you want to disable it.
</Admonition>

---
126 changes: 67 additions & 59 deletions packages/embla-carousel-docs/src/content/pages/api/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,37 @@ It's possible to **extend** Embla carousel with additional features using **plug

---

## Installation

All **official plugins** are separate **NPM packages**. They're all **prefixed** with `embla-carousel` followed by its **unique** plugin **name**. For example, the `Autoplay` plugin is installed like so:

<Tabs groupId="package-manager">
<TabsItem label="CDN" value="cdn">

```html
<script src="https://unpkg.com/embla-carousel-autoplay/embla-carousel-autoplay.umd.js"></script>
```

</TabsItem>
<TabsItem label="npm" value="npm">

```shell
npm install embla-carousel-autoplay --save
```

</TabsItem>
<TabsItem label="yarn" value="yarn">

```shell
yarn add embla-carousel-autoplay
```

</TabsItem>
</Tabs>

## Usage

The Embla Carousel **constructor** accepts an **array of plugins**. Each plugin has its own [options](/api/plugins/#constructor-options) and [methods](/api/plugins/#calling-methods).
The Embla Carousel **constructor** accepts an **array of plugins**. Each plugin might have its own [options](/api/plugins/#constructor-options), [methods](/api/plugins/#calling-methods) and [events](/api/plugins/#adding-event-listeners).

### Adding a plugin

Expand All @@ -25,7 +53,7 @@ The constructor plugin array is the default way of providing plugins to Embla Ca
<Tabs groupId="library">
<TabsItem label="Vanilla" value="vanilla">

```js highlight={4}
```js highlight={2,4}
import EmblaCarousel from 'embla-carousel'
import Autoplay from 'embla-carousel-autoplay'

Expand All @@ -35,7 +63,7 @@ The constructor plugin array is the default way of providing plugins to Embla Ca
</TabsItem>
<TabsItem label="React" value="react">

```jsx highlight={5}
```jsx highlight={2,5}
import useEmblaCarousel from 'embla-carousel-react'
import Autoplay from 'embla-carousel-autoplay'

Expand All @@ -48,17 +76,13 @@ The constructor plugin array is the default way of providing plugins to Embla Ca
</TabsItem>
<TabsItem label="Vue" value="vue">

```html highlight={7}
<script>
```html highlight={3,5}
<script setup>
import emblaCarouselVue from 'embla-carousel-vue'
import Autoplay from 'embla-carousel-autoplay'
export default {
setup() {
const [emblaNode] = emblaCarouselVue({ loop: true }, [Autoplay()])
// ...
}
}
const [emblaNode] = emblaCarouselVue({ loop: true }, [Autoplay()])
// ...
</script>
```

Expand Down Expand Up @@ -105,19 +129,15 @@ Plugins have their own specific **options** which is the first argument of the p
</TabsItem>
<TabsItem label="Vue" value="vue">

```html highlight={8}
<script>
```html highlight={6}
<script setup>
import emblaCarouselVue from 'embla-carousel-vue'
import Autoplay from 'embla-carousel-autoplay'
export default {
setup() {
const [emblaNode] = emblaCarouselVue({ loop: true }, [
Autoplay({ delay: 4000 })
])
// ...
}
}
const [emblaNode] = emblaCarouselVue({ loop: true }, [
Autoplay({ delay: 4000 })
])
// ...
</script>
```

Expand Down Expand Up @@ -159,18 +179,14 @@ All [official plugins](/plugins/) allows you to set **global options** that will
<TabsItem label="Vue" value="vue">

```html highlight={5}
<script>
<script setup>
import emblaCarouselVue from 'embla-carousel-vue'
import Autoplay from 'embla-carousel-autoplay'
Autoplay.globalOptions = { delay: 4000 }
export default {
setup() {
const [emblaNode] = emblaCarouselVue({ loop: true }, [Autoplay()])
// ...
}
}
const [emblaNode] = emblaCarouselVue({ loop: true }, [Autoplay()])
// ...
</script>
```

Expand Down Expand Up @@ -221,25 +237,21 @@ Additionally, some plugins expose their own **API methods**. You can access plug
</TabsItem>
<TabsItem label="Vue" value="vue">

```html highlight={13}
<script>
```html highlight={11}
<script setup>
import { watchEffect } from 'vue'
import emblaCarouselVue from 'embla-carousel-vue'
import Autoplay from 'embla-carousel-autoplay'
export default {
setup() {
const [emblaNode, emblaApi] = emblaCarouselVue({ loop: true }, [
Autoplay()
])
const [emblaNode, emblaApi] = emblaCarouselVue({ loop: true }, [
Autoplay()
])
watchEffect(() => {
if (emblaApi.value) emblaApi.value.plugins().autoplay.stop()
})
watchEffect(() => {
if (emblaApi.value) emblaApi.value.plugins().autoplay.stop()
})
// ...
}
}
// ...
</script>
```

Expand Down Expand Up @@ -294,31 +306,27 @@ Some plugins fire their own **events**. Plugin events are structured as follows
</TabsItem>
<TabsItem label="Vue" value="vue">

```html highlight={18}
<script>
```html highlight={16}
<script setup>
import { watchEffect, onBeforeUnmount } from 'vue'
import emblaCarouselVue from 'embla-carousel-vue'
import Autoplay from 'embla-carousel-autoplay'
export default {
setup() {
const [emblaNode, emblaApi] = emblaCarouselVue({ loop: true }, [
Autoplay()
])
function logAutoplayStopEvent() {
console.log('Autoplay plugin stopped playing!')
}
const [emblaNode, emblaApi] = emblaCarouselVue({ loop: true }, [
Autoplay()
])
watchEffect(() => {
if (emblaApi.value) {
emblaApi.value.on('autoplay:stop', logAutoplayStopEvent) // add
}
})
function logAutoplayStopEvent() {
console.log('Autoplay plugin stopped playing!')
}
// ...
watchEffect(() => {
if (emblaApi.value) {
emblaApi.value.on('autoplay:stop', logAutoplayStopEvent) // add
}
}
})
// ...
</script>
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Auto Height
description: Learn how to add this Auto Height plugin to Embla Carousel
order: 1
description: Learn how to use the Auto Height plugin for Embla Carousel
order: 2
date: 2022-01-14
---

Expand All @@ -23,6 +23,13 @@ This plugin is used to extend Embla Carousel with **auto height** functionality.
First you need to install the **npm package** and save it to your dependencies:

<Tabs groupId="package-manager">
<TabsItem label="CDN" value="cdn">

```html
<script src="https://unpkg.com/embla-carousel-auto-height/embla-carousel-auto-height.umd.js"></script>
```

</TabsItem>
<TabsItem label="npm" value="npm">

```shell
Expand All @@ -39,32 +46,29 @@ First you need to install the **npm package** and save it to your dependencies:
</TabsItem>
</Tabs>

Alternatively, you can use a **CDN** to include it in your project:

```html
<script src="https://unpkg.com/embla-carousel-auto-height/embla-carousel-auto-height.umd.js"></script>
```

## Usage

This plugin accepts a single **optional** parameter, which is its [options](/plugins/auto-height/#options) object that allows you to configure it.
Please read the [plugins](/api/plugins/#usage) page to learn **how to work with plugins**.

```js
import EmblaCarousel from 'embla-carousel'
import AutoHeight from 'embla-carousel-auto-height'

const embla = EmblaCarousel(emblaRoot, { loop: false }, [AutoHeight()]) // Add plugin
```
<Admonition type="note">

You can make use of CSS transitions to **transition height** changes. But beware: Transitioning height triggers reflow and may cause a performance hit.

<br />

```css
.embla__container {
transition: height 0.2s;
}
```

If you've been following along with any of the guides in the [Get Started](/get-started/) section, you will probably want to make sure that each **slide height** is **determined** by the **content** it holds. Amend your CSS with the following to achieve this:
</Admonition>

<Admonition type="warning">

If you've been following along with any of the guides in the [get started](/get-started/) section, you want to make sure that each **slide height** is **determined** by the **content** it holds. Add the following to your CSS to achieve this:

<br />

```css highlight={3}
.embla__container {
Expand All @@ -73,20 +77,11 @@ If you've been following along with any of the guides in the [Get Started](/get-
}
```

## Options

The Auto Height plugin accepts an optional **options** object as the first argument. Here's an example of how to make use of it:
</Admonition>

```js
import EmblaCarousel from 'embla-carousel'
import AutoHeight from 'embla-carousel-auto-height'

const autoHeightOptions = { destroyHeight: 'auto' } // Options
## Options

const embla = EmblaCarousel(emblaRoot, { loop: false }, [
AutoHeight(autoHeightOptions) // Add plugin with options
])
```
Below follows an exhaustive **list of all** `Auto Height` **options** and their default values.

---

Expand All @@ -96,3 +91,5 @@ Type: <BrandPrimaryText>`CSSStyleDeclaration.height`</BrandPrimaryText>
Default: <BrandSecondaryText>`auto`</BrandSecondaryText>

Choose CSS height declaration that will be applied to the carousel container when the plugin is destroyed.

---
Loading

0 comments on commit 490fa5e

Please # to comment.