Skip to content

Commit 735f096

Browse files
committed
Add tweened example
1 parent 213ee41 commit 735f096

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"svelte": "^3.0.0"
1818
},
1919
"dependencies": {
20+
"d3-interpolate": "^2.0.1",
2021
"sirv-cli": "^1.0.0",
2122
"uuid": "^8.3.2"
2223
}

src/App.svelte

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,35 @@
1313
}
1414
</script>
1515

16-
<AddTodoItem
17-
title='Please type todo here:'
18-
buttonTitle={`Add (${$todoStats.doneCount}/${$todoStats.totalCount})`}
19-
on:add={handleAddTodoItem}
20-
/>
16+
<div class="add-todo-item-container">
17+
<AddTodoItem
18+
title='Please type todo here:'
19+
buttonTitle={`Add (${$todoStats.doneCount}/${$todoStats.totalCount})`}
20+
on:add={handleAddTodoItem}
21+
/>
22+
</div>
2123

2224
{#if $todoStats.totalCount === 0}
2325
No items yet
2426
{:else}
25-
<div>
27+
<div class="todo-items-container">
2628
{#each $todoItems as { id, text, checked }, index (id)}
27-
<TodoItem
28-
text={`${index + 1}: ${text}`}
29-
{checked}
30-
on:checked={event => handleItemChecked(id, event.detail)}
31-
/>
29+
<div class="todo-item-container">
30+
<TodoItem
31+
text={`${index + 1}: ${text}`}
32+
{checked}
33+
on:checked={event => handleItemChecked(id, event.detail)}
34+
/>
35+
</div>
3236
{/each}
3337
</div>
3438
{/if}
39+
40+
<style>
41+
.add-todo-item-container {
42+
margin-bottom: 5px;
43+
}
44+
.todo-items-container:not(:last-child) > .todo-item-container {
45+
margin-bottom: 5px;
46+
}
47+
</style>

src/TodoItem.svelte

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
<script>
22
import { createEventDispatcher } from 'svelte'
3+
import { tweened } from 'svelte/motion';
4+
import { cubicOut } from 'svelte/easing';
5+
import { interpolateLab } from 'd3-interpolate';
6+
37
const dispatch = createEventDispatcher()
48
59
export let text
610
export let checked
711
12+
const checkedMotion = tweened('#faf792', {
13+
delay: 0,
14+
duration: 250,
15+
easing: cubicOut,
16+
interpolate: (from, to) => (t) => {
17+
// return t < 0.5 ? from : to
18+
// interpolate and interpolateLab function signatures are the same
19+
return interpolateLab(from, to)(t)
20+
}
21+
});
22+
823
$: {
924
dispatch('checked', checked)
25+
checkedMotion.set(checked ? '#64ad80' : '#faf792')
1026
}
1127
</script>
1228

13-
<div class="main-container">
29+
<div class="main-container" style="background-color: {$checkedMotion}">
1430
<input
1531
type="checkbox"
1632
bind:checked={checked}

0 commit comments

Comments
 (0)