Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@solidjs/start": "0.6.1",
"@tanstack/solid-virtual": "3.0.0-beta.6",
"clsx": "2.0.0",
"embla-carousel-autoplay": "^8.3.1",
"minisearch": "7.1.0",
"solid-js": "1.8.15",
"undici": "5.23.0",
Expand Down
142 changes: 142 additions & 0 deletions apps/docs/src/examples/carousel.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
.item {
width: 400px;
height: 200px;
background-color: hsl(0 0% 98%);
margin: 8px;
flex: 0 0 100%;
min-width: 0;
display: flex;
justify-content: center;
align-items: center;
border-radius: 8px;
border: 2px solid hsl(240 5% 84%);
transition: border-color 250ms;
}

.button {
appearance: none;
display: inline-flex;
justify-content: center;
align-items: center;
height: 40px;
padding: 0 16px;
margin-inline: 20px;
border-radius: 6px;
background-color: hsl(200 98% 39%);
color: white;
transition: background-color 250ms;
}

.button:hover {
background-color: hsl(201 96% 32%);
}

.button:focus-visible {
outline: 2px solid hsl(200 98% 39%);
outline-offset: 2px;
}

.button:disabled {
opacity: 0.5;
cursor: not-allowed;
}

.horizontal {
.root {
max-width: 500px;
overflow: hidden;
margin: auto;
}
.viewport {
display: flex;
max-height: 400px;
gap: 16px;
margin: 16px;
}

.indicators {
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
margin-top: 16px;
}

.indicator {
width: 8px;
height: 8px;
border-radius: 50%;
background: hsl(240 5% 84%);
border: none;
cursor: pointer;
padding: 0;
transition: background-color 250ms;
}

.indicator[data-selected] {
background: hsl(200 98% 39%);
}
}

/* Dark theme styles */
[data-kb-theme="dark"] .horizontal, .autoplay {
.item {
background-color: hsl(240 4% 16%);
border-color: hsl(240 5% 26%);
}

.button {
background-color: hsl(201 96% 32%);
color: hsla(0 100% 100% / 0.9);
}

.button:hover {
background-color: hsl(200 98% 39%);
}

.button:active {
background-color: hsl(199 89% 48%);
}

.indicator {
background: hsl(240 5% 26%);
}

.indicator[data-selected] {
background: hsl(201 96% 32%);
}
}

.vertical {
.root {
margin: 32px auto;
overflow: hidden;
margin: auto;
}
.viewport {
max-height: 250px;
margin: 16px;
}

.indicators {
display: flex;
justify-content: center;
gap: 8px;
margin-top: 16px;
}

.indicator {
width: 8px;
height: 8px;
border-radius: 50%;
background: rgba(0, 0, 0, 0.3);
border: none;
cursor: pointer;
padding: 0;
}

.indicator[data-selected] {
background: rgba(0, 0, 0, 0.8);
}
}

127 changes: 127 additions & 0 deletions apps/docs/src/examples/carousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import styles from "./carousel.module.css";
import { Carousel } from "@kobalte/core/carousel";
import { Index } from "solid-js";
import Autoplay from "embla-carousel-autoplay"

const slides = Array.from({ length: 5 }).map((_, i) => i + 1);

export function HorrizontalExample() {
return (
<div class={styles.horizontal}>
<Carousel
orientation="horizontal"
class={styles.root}
options={{
align: "start",
loop: false,
}}
>
<Carousel.Viewport class={styles.viewport}>
<Index each={slides}>
{(_, index) => (
<Carousel.Item class={styles.item} index={index}>
Slide {index}
</Carousel.Item>
)}
</Index>
</Carousel.Viewport>

<div class={styles.indicators}>
<Carousel.Previous class={styles.button}>Prev</Carousel.Previous>
<Index each={slides}>
{(_, index) => (
<Carousel.Indicator
class={styles.indicator}
index={index}
aria-label={`Go to slide ${index + 1}`}
/>
)}
</Index>
<Carousel.Next class={styles.button}>Next</Carousel.Next>
</div>
</Carousel>
</div>
);
}

export function VerticalExample() {
return (
<div class={styles.vertical}>
<Carousel
orientation="vertical"
class={styles.root}
options={{
align: "start",
loop: false,
}}
>
<Carousel.Viewport class={styles.viewport}>
<Index each={slides}>
{(_, index) => (
<Carousel.Item class={styles.item} index={index}>
Slide {index}
</Carousel.Item>
)}
</Index>
</Carousel.Viewport>

{
<div class={styles.indicators}>
<Index each={slides}>
{(_, index) => (
<Carousel.Indicator
class={styles.indicator}
index={index}
aria-label={`Go to slide ${index + 1}`}
/>
)}
</Index>
</div>
}
</Carousel>
</div>
);
}

export function AutoPlayExample() {
const autoPlayPlugin = Autoplay({ delay: 1800, stopOnInteraction: true });
return (
<div class={styles.horizontal}>
<Carousel
orientation="horizontal"
plugins={[autoPlayPlugin]}
onMouseEnter={autoPlayPlugin.stop}
onMouseLeave={() => autoPlayPlugin.play(false)}
class={styles.root}
options={{
align: "start",
loop: false,
}}
>
<Carousel.Viewport class={styles.viewport}>
<Index each={slides}>
{(_, index) => (
<Carousel.Item class={styles.item} index={index}>
Slide {index}
</Carousel.Item>
)}
</Index>
</Carousel.Viewport>

<div class={styles.indicators}>
<Carousel.Previous class={styles.button}>Prev</Carousel.Previous>
<Index each={slides}>
{(_, index) => (
<Carousel.Indicator
class={styles.indicator}
index={index}
aria-label={`Go to slide ${index + 1}`}
/>
)}
</Index>
<Carousel.Next class={styles.button}>Next</Carousel.Next>
</div>
</Carousel>
</div>
);
}
5 changes: 5 additions & 0 deletions apps/docs/src/routes/docs/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const CORE_NAV_SECTIONS: NavSection[] = [
title: "Button",
href: "/docs/core/components/button",
},
{
title: "Carousel",
href: "/docs/core/components/carousel",
status: "new"
},
{
title: "Checkbox",
href: "/docs/core/components/checkbox",
Expand Down
Loading