diff --git a/src/TriStateCheckbox.svelte b/src/TriStateCheckbox.svelte index 7e2c979..90ea55b 100644 --- a/src/TriStateCheckbox.svelte +++ b/src/TriStateCheckbox.svelte @@ -8,45 +8,31 @@ import { UNCHECKED, CHECKED, WEIRD } from './stores'; import { createEventDispatcher } from 'svelte'; + const icons = new Map() + .set(UNCHECKED, 'square') + .set(CHECKED, 'check-square-fill') + .set(WEIRD, 'square-half'); + const dispatch = createEventDispatcher(); - function handleClick() { - if (state === CHECKED) { - state = UNCHECKED; - } else { - state = CHECKED; - } + const handleClick = () => { + state = state === CHECKED ? UNCHECKED : CHECKED; dispatch('change', { value: state }); - } - - function handleCollapse(evt) { - collapsed = !collapsed; - } - - $: icon = () => { - switch (state) { - case UNCHECKED: - return 'square'; - case WEIRD: - return 'square-half'; - case CHECKED: - return 'check-square-fill'; - } }; - $: colIcon = () => { - return collapsed ? 'chevron-expand' : 'chevron-contract'; - }; + $: icon = icons.get(state); + + $: chevron = collapsed ? 'chevron-expand' : 'chevron-contract'; - + {value} {#if collapsed !== undefined} - - + (collapsed = !collapsed)}> + {/if}