Skip to content

Commit

Permalink
feat: expose scrollSnaps selectedIndex scrollTo (#1052)
Browse files Browse the repository at this point in the history
Co-authored-by: Davis SHYAKA <[email protected]>
  • Loading branch information
shyakadavis and shyakadavis authored Apr 27, 2024
1 parent a56d026 commit 9125246
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/www/src/lib/registry/default/ui/carousel/carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
const canScrollNext = writable(false);
const optionsStore = writable(opts);
const pluginStore = writable(plugins);
const scrollSnapsStore = writable<number[]>([]);
const selectedIndexStore = writable(0);
$: orientationStore.set(orientation);
$: pluginStore.set(plugins);
Expand All @@ -31,6 +33,9 @@
function scrollNext() {
api?.scrollNext();
}
function scrollTo(index: number, jump?: boolean) {
api?.scrollTo(index, jump);
}
function onSelect(api: CarouselAPI) {
if (!api) return;
Expand Down Expand Up @@ -65,6 +70,9 @@
options: optionsStore,
plugins: pluginStore,
onInit,
scrollSnaps: scrollSnapsStore,
selectedIndex: selectedIndexStore,
scrollTo,
});
function onInit(event: CustomEvent<CarouselAPI>) {
Expand Down
3 changes: 3 additions & 0 deletions apps/www/src/lib/registry/default/ui/carousel/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type EmblaContext = {
options: Writable<CarouselOptions>;
plugins: Writable<CarouselPlugins>;
onInit: (e: CustomEvent<CarouselAPI>) => void;
scrollTo: (index: number, jump?: boolean) => void;
scrollSnaps: Readable<number[]>;
selectedIndex: Readable<number>;
};

export function setEmblaContext(config: EmblaContext): EmblaContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
const canScrollNext = writable(false);
const optionsStore = writable(opts);
const pluginStore = writable(plugins);
const scrollSnapsStore = writable<number[]>([]);
const selectedIndexStore = writable(0);
$: orientationStore.set(orientation);
$: pluginStore.set(plugins);
Expand All @@ -31,6 +33,9 @@
function scrollNext() {
api?.scrollNext();
}
function scrollTo(index: number, jump?: boolean) {
api?.scrollTo(index, jump);
}
function onSelect(api: CarouselAPI) {
if (!api) return;
Expand Down Expand Up @@ -65,6 +70,9 @@
options: optionsStore,
plugins: pluginStore,
onInit,
scrollSnaps: scrollSnapsStore,
selectedIndex: selectedIndexStore,
scrollTo,
});
function onInit(event: CustomEvent<CarouselAPI>) {
Expand Down
3 changes: 3 additions & 0 deletions apps/www/src/lib/registry/new-york/ui/carousel/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type EmblaContext = {
options: Writable<CarouselOptions>;
plugins: Writable<CarouselPlugins>;
onInit: (e: CustomEvent<CarouselAPI>) => void;
scrollTo: (index: number, jump?: boolean) => void;
scrollSnaps: Readable<number[]>;
selectedIndex: Readable<number>;
};

export function setEmblaContext(config: EmblaContext): EmblaContext {
Expand Down

0 comments on commit 9125246

Please sign in to comment.