Files
Modrinth-plus/src/components/CheckboxList.svelte

47 lines
960 B
Svelte
Raw Normal View History

<script lang="ts">
2022-06-04 00:46:23 -07:00
import Checkbox from './Checkbox.svelte'
import type { Option } from './types'
2022-06-04 00:46:23 -07:00
export let value = []
export let options: Option[] = []
2022-06-04 00:46:23 -07:00
/** Wrap the options horizontally */
export let wrap = false
const handleChange = (event: any, key: string | number) => {
if (event.target.checked) {
2022-06-04 00:46:23 -07:00
if (!value) value = []
value = [key, ...value]
} else {
value = value.filter((it) => key !== it)
}
}
</script>
<div class="checkbox-list" class:wrap>
2022-06-04 00:46:23 -07:00
{#each options as option}
<Checkbox on:change={(e) => handleChange(e, option.value)}>
{#if option.icon && typeof option.icon === 'string'}
{@html option.icon}
{:else if option.icon}
<svelte:component this={option.icon} />
{/if}
{option.label}
</Checkbox>
{/each}
</div>
<style lang="postcss">
2022-06-04 00:46:23 -07:00
.checkbox-list {
display: flex;
flex-direction: column;
gap: 2px;
2022-06-04 00:46:23 -07:00
&.wrap {
flex-direction: row;
flex-wrap: wrap;
2022-06-07 14:00:53 -07:00
gap: 2rem;
2022-06-04 00:46:23 -07:00
}
}
</style>