-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Jerleke <[email protected]> Co-authored-by: Liam Martens <[email protected]>
- Loading branch information
1 parent
354b2ee
commit 1d0ba4b
Showing
30 changed files
with
1,941 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion
2
packages/embla-carousel-docs/src/content/pages/get-started/cdn.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
packages/embla-carousel-docs/src/content/pages/get-started/solid.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
--- | ||
title: Solid | ||
description: Learn how to setup Embla Carousel using Solid. | ||
order: 4 | ||
date: 2023-12-31 | ||
--- | ||
|
||
import { Tabs } from 'components/Tabs/Tabs' | ||
import { TabsItem } from 'components/Tabs/TabsItem' | ||
|
||
# Solid | ||
|
||
Start by installing the Embla Carousel **npm package** and add it to your dependencies. | ||
|
||
<Tabs groupId="package-manager"> | ||
<TabsItem label="npm" value="npm"> | ||
|
||
```shell | ||
npm install embla-carousel-solid --save | ||
``` | ||
|
||
</TabsItem> | ||
<TabsItem label="yarn" value="yarn"> | ||
|
||
```shell | ||
yarn add embla-carousel-solid | ||
``` | ||
|
||
</TabsItem> | ||
</Tabs> | ||
|
||
--- | ||
|
||
## The component structure | ||
|
||
Embla Carousel provides the handy `createEmblaCarousel` method for seamless integration with Solid. A minimal setup requires an **overflow wrapper** and a **scroll container**. Start by adding the following structure to your carousel: | ||
|
||
```jsx | ||
import createEmblaCarousel from 'embla-carousel-solid' | ||
|
||
export const EmblaCarousel = () => { | ||
const [emblaRef] = createEmblaCarousel() | ||
|
||
return ( | ||
<div class="embla" ref={emblaRef}> | ||
<div class="embla__container"> | ||
<div class="embla__slide">Slide 1</div> | ||
<div class="embla__slide">Slide 2</div> | ||
<div class="embla__slide">Slide 3</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
## Styling the carousel | ||
|
||
The method gives us a **ref** to attach to our wrapping element with the classname `embla`, which is needed to cover the scroll overflow. The element with the `container` classname is the scroll body that scrolls the slides. Continue by adding the following **CSS** to these elements: | ||
|
||
```css | ||
.embla { | ||
overflow: hidden; | ||
} | ||
.embla__container { | ||
display: flex; | ||
} | ||
.embla__slide { | ||
flex: 0 0 100%; | ||
min-width: 0; | ||
} | ||
``` | ||
|
||
## Accessing the carousel API | ||
|
||
The `createEmblaCarousel` method takes the Embla Carousel [options](/api/options/) as the first argument, which is a Solid accessor. Additionally, you can access the [API](/api/) with a `createEffect` like demonstrated below: | ||
|
||
```jsx{5,7-12} | ||
import { createEffect } from 'solid-js' | ||
import createEmblaCarousel from 'embla-carousel-solid' | ||
export const EmblaCarousel = () => { | ||
const [emblaRef, emblaApi] = createEmblaCarousel(() => ({ loop: true })) | ||
createEffect(() => { | ||
const api = emblaApi() | ||
if (api) { | ||
console.log(api.slideNodes()) // Access API | ||
} | ||
}) | ||
return ( | ||
<div class="embla" ref={emblaRef}> | ||
<div class="embla__container"> | ||
<div class="embla__slide">Slide 1</div> | ||
<div class="embla__slide">Slide 2</div> | ||
<div class="embla__slide">Slide 3</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
## Adding plugins | ||
|
||
Start by installing the plugin you want to use. In this example, we're going to install the [Autoplay](/plugins/autoplay/) plugin: | ||
|
||
<Tabs groupId="package-manager"> | ||
<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> | ||
|
||
The `createEmblaCarousel` method accepts [plugins](/plugins/) as the second argument, which is a Solid accessor. Note that plugins need to be passed in an **array** like so: | ||
|
||
The config getter can also return a list of plugins, like so: | ||
|
||
```jsx{2,7} | ||
import createEmblaCarousel from 'embla-carousel-solid' | ||
import Autoplay from 'embla-carousel-autoplay' | ||
export const EmblaCarousel = () => { | ||
const [emblaRef] = createEmblaCarousel( | ||
() => ({ loop: true }), | ||
() => [AutoPlay()] | ||
) | ||
return ( | ||
<div class="embla" ref={emblaRef}> | ||
<div class="embla__container"> | ||
<div class="embla__slide">Slide 1</div> | ||
<div class="embla__slide">Slide 2</div> | ||
<div class="embla__slide">Slide 3</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
Congratulations! You just created your first Embla Carousel component. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
docs | ||
package.json | ||
package-lock.json | ||
yarn.lock | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
ecmaFeatures: { jsx: true } | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:prettier/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended' | ||
], | ||
rules: { | ||
'no-debugger': 2, | ||
'no-console': 2, | ||
'@typescript-eslint/no-inferrable-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../.prettierrc.js') |
Oops, something went wrong.