-
+
{#if arrows}
@@ -57,6 +77,12 @@
.content-container {
flex: 1;
display: flex;
+ overflow: hidden;
+ }
+ .content-container > div {
+ display: flex;
+ transition: transform 1s ease-in-out;
+ background-color: chocolate;
}
.side-container {
background-color: cornflowerblue;
diff --git a/src/store.js b/src/store.js
index fe22800..44e3f4d 100644
--- a/src/store.js
+++ b/src/store.js
@@ -1,16 +1,21 @@
import { writable } from 'svelte/store';
+import { v4 as uuid } from 'uuid'
import { getNextItemIndexFn, getPrevItemIndexFn } from './utils/item-index'
+
function createStore() {
const { subscribe, set, update } = writable({
items: [],
- currentItemId: null
+ currentItemId: null,
+ currentItemIndex: null,
+ action: 'next'
});
- function setItem(id) {
+ function setItem(id = uuid()) {
update(store => ({
...store,
currentItemId: id,
+ currentItemIndex: 0, // store.items.length - 1, TODO: use as a param
items: [
...store.items,
id
@@ -27,22 +32,26 @@ function createStore() {
function next({ infinite }) {
update(store => {
- const currentItemIndex = store.items.findIndex(item => item === store.currentItemId)
+ const currentItemIndex = store.currentItemIndex // store.items.findIndex(item => item === store.currentItemId)
const newCurrentItemIndex = getNextItemIndexFn(infinite)(currentItemIndex, store.items)
return {
...store,
- currentItemId: store.items[newCurrentItemIndex]
+ currentItemId: store.items[newCurrentItemIndex],
+ currentItemIndex: newCurrentItemIndex,
+ action: 'next'
}
})
}
function prev({ infinite }) {
update(store => {
- const currentItemIndex = store.items.findIndex(item => item === store.currentItemId)
+ const currentItemIndex = store.currentItemIndex // store.items.findIndex(item => item === store.currentItemId)
const newCurrentItemIndex = getPrevItemIndexFn(infinite)(currentItemIndex, store.items)
return {
...store,
- currentItemId: store.items[newCurrentItemIndex]
+ currentItemId: store.items[newCurrentItemIndex],
+ currentItemIndex: newCurrentItemIndex,
+ action: 'prev'
}
})
}
diff --git a/src/stories/ImageCarouselView.svelte b/src/stories/ImageCarouselView.svelte
index 3d7b131..913f49b 100644
--- a/src/stories/ImageCarouselView.svelte
+++ b/src/stories/ImageCarouselView.svelte
@@ -18,16 +18,28 @@
{arrows}
{infinite}
>
-
-
+
+
Element 1
-
-
-
+
+
Element 2
-
+
+
+
Element 3
+
+
@@ -37,8 +49,8 @@
width: 100%;
}
.child-content-container {
- width: 100%;
- display: flex;
+ width: 500px;
+ height: 100px;
align-items: center;
justify-content: center;
}
diff --git a/src/transition.js b/src/transition.js
new file mode 100644
index 0000000..861b4f5
--- /dev/null
+++ b/src/transition.js
@@ -0,0 +1,16 @@
+import { cubicIn } from 'svelte/easing';
+
+export function custom(node, { duration, offset }) {
+ console.log(node.style.left)
+ return {
+ duration,
+ css: t => {
+ const eased = cubicIn(t);
+ // console.log(Math.round(offset/t))
+ // transform: translate(${Math.round(offset/t)}px);
+ return `
+ transform: translate(${Math.round(offset/t)}px);
+ `
+ }
+ };
+}