2020-02-14 11:32:19 +01:00
|
|
|
<script>
|
2020-03-05 12:56:23 +01:00
|
|
|
import { onMount } from "svelte"
|
2020-02-25 16:21:23 +01:00
|
|
|
import Checkbox from "./Checkbox.svelte"
|
|
|
|
import Label from "../Common/Label.svelte"
|
2020-03-05 12:56:23 +01:00
|
|
|
import createItemsStore from "../Common/ItemStore.js"
|
2020-02-14 11:32:19 +01:00
|
|
|
|
2020-03-05 12:56:23 +01:00
|
|
|
let selectedItemsStore
|
|
|
|
let checkItems
|
|
|
|
|
|
|
|
export let _bb
|
2020-02-25 16:21:23 +01:00
|
|
|
export let label = ""
|
|
|
|
export let orientation = "row"
|
|
|
|
export let onChange = selectedItems => {}
|
2020-02-14 11:32:19 +01:00
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
export let disabled = false
|
|
|
|
export let alignEnd = false
|
2020-03-30 12:20:55 +02:00
|
|
|
export let value = []
|
2020-02-14 11:32:19 +01:00
|
|
|
|
2020-03-05 12:56:23 +01:00
|
|
|
onMount(() => {
|
|
|
|
_bb.setContext("BBMD:input:context", "checkboxgroup")
|
2020-03-30 12:20:55 +02:00
|
|
|
selectedItemsStore = createItemsStore(() => {
|
|
|
|
value = $selectedItemsStore
|
|
|
|
if (_bb.isBound(_bb.props.value)) {
|
|
|
|
_bb.setStateFromBinding(_bb.props.value, value)
|
|
|
|
}
|
|
|
|
_bb.call(onChange, value)
|
|
|
|
}, value)
|
2020-03-05 12:56:23 +01:00
|
|
|
_bb.setContext("BBMD:checkbox:selectedItemsStore", selectedItemsStore)
|
2020-03-05 15:59:08 +01:00
|
|
|
_bb.setContext("BBMD:checkbox:props", { alignEnd, disabled })
|
2020-03-05 12:56:23 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
$: checkItems && _bb.attachChildren(checkItems)
|
2020-02-14 11:32:19 +01:00
|
|
|
</script>
|
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
<div class="checkbox-group">
|
|
|
|
<div class="checkbox-group__label">
|
|
|
|
<Label text={label} bold />
|
|
|
|
</div>
|
2020-04-14 15:15:32 +02:00
|
|
|
<div bind:this={checkItems} class={`checkbox-group__boxes ${orientation}`} />
|
2020-02-25 16:21:23 +01:00
|
|
|
</div>
|
|
|
|
|
2020-02-14 11:32:19 +01:00
|
|
|
<style>
|
|
|
|
.checkbox-group {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-04-14 15:15:32 +02:00
|
|
|
width: fit-content;
|
2020-02-14 11:32:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
</style>
|