forked from antfu-collective/vitesse-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheCounter.tsx
43 lines (37 loc) · 898 Bytes
/
TheCounter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* ## The Counter
*/
export default defineComponent(({
initial = undefined as undefined | number,
}) => {
const { count, inc, dec } = useCounter(initial)
const color = computed(() => (index: number) => (
index
? count.value >= index
: count.value <= index)
? 'green'
: 'red',
)
const styles = defineStyle(`
.inc, .dec {
@apply px3 b-(2 solid rounded [${color.value(1)}]);
}
.dec {
@apply b-[${color.value(0)}];
}
`)
const slots = defineSlots({
default: ({ value }: { value: number }) => <div class={styles.inc}>{value}</div>,
})
return () => (
<div gap3 mb3 flex="~ justify-center">
<slots.default value={count.value} />
<button class={styles.inc} onClick={() => inc()}>
+
</button>
<button class={styles.dec} onClick={() => dec()}>
-
</button>
</div>
)
})