budibase/packages/materialdesign-components/src/Checkbox/CheckboxGroup.svelte

78 lines
1.5 KiB
Svelte
Raw Normal View History

<script>
2020-02-25 16:21:23 +01:00
import Checkbox from "./Checkbox.svelte"
import Label from "../Common/Label.svelte"
2020-02-25 16:21:23 +01:00
export let label = ""
export let orientation = "row"
export let fullwidth = false
export let onChange = selectedItems => {}
2020-02-25 16:21:23 +01:00
export let items = []
2020-02-25 16:21:23 +01:00
export let disabled = false
export let alignEnd = false
let selectedItems = []
function handleonChange(item) {
if (!!item.checked) {
2020-02-25 16:21:23 +01:00
item.checked = !item.checked
} else {
2020-02-25 16:21:23 +01:00
item.checked = true
}
2020-02-25 16:21:23 +01:00
onChange(items.filter(i => i.checked))
}
</script>
2020-02-25 16:21:23 +01:00
<div class="checkbox-group">
<div class="checkbox-group__label">
<Label text={label} bold />
</div>
<div class={`checkbox-group__boxes ${orientation}`}>
{#each items as item, i}
<div class:fullwidth>
<Checkbox
id={`${item.label}-${i}`}
{disabled}
{alignEnd}
indeterminate={item.indeterminate || false}
label={item.label}
checked={item.checked || false}
onClick={() => handleonChange(item)} />
</div>
{/each}
</div>
</div>
<style>
.checkbox-group {
display: flex;
flex-direction: column;
}
.checkbox-group__boxes.row > div:not(:first-child) {
padding-left: 10px;
}
.checkbox-group > div {
text-align: left;
flex: 1;
}
.row {
display: flex;
flex-flow: row wrap;
align-items: flex-start;
}
.column {
display: flex;
flex-flow: column wrap;
align-items: flex-start;
}
.fullwidth {
flex: 1;
text-align: left;
}
</style>