Add global toggle
This commit is contained in:
parent
ccfa22c277
commit
93f7c7895d
2 changed files with 39 additions and 6 deletions
|
@ -1,14 +1,19 @@
|
||||||
<script>
|
<script>
|
||||||
import { Button, Offcanvas, Icon } from 'sveltestrap';
|
import { Button, Offcanvas, Icon } from 'sveltestrap';
|
||||||
import FilterItem from './FilterItem.svelte';
|
import FilterItem from './FilterItem.svelte';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
export let calendarTree = [];
|
export let calendarTree = [];
|
||||||
export let selected = null;
|
export let selected = null;
|
||||||
|
|
||||||
|
let open = true;
|
||||||
|
let generalToggle = writable(true);
|
||||||
|
const toggle = () => (open = !open);
|
||||||
|
|
||||||
|
$: icon = () => ($generalToggle ? 'toggle-on' : 'toggle-off');
|
||||||
|
|
||||||
let subSelections = Array.from({ length: Object.keys(calendarTree).length }, _ => []);
|
let subSelections = Array.from({ length: Object.keys(calendarTree).length }, _ => []);
|
||||||
$: selected = subSelections.flat();
|
$: selected = subSelections.flat();
|
||||||
|
|
||||||
let open = false;
|
|
||||||
const toggle = () => (open = !open);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Button on:click={toggle} class="mb-3 col-6 mx-auto">
|
<Button on:click={toggle} class="mb-3 col-6 mx-auto">
|
||||||
|
@ -23,7 +28,27 @@
|
||||||
placement="start"
|
placement="start"
|
||||||
header="Sélection des calendriers"
|
header="Sélection des calendriers"
|
||||||
>
|
>
|
||||||
|
<span class="fs-5 toggle" on:click={() => ($generalToggle = !$generalToggle)}>
|
||||||
|
<Icon name={icon()} />
|
||||||
|
<span class="ms-2">Tous les calendriers</span>
|
||||||
|
</span>
|
||||||
|
<hr class="my-3" />
|
||||||
|
|
||||||
{#each Object.entries(calendarTree) as [toplevel, subtrees], i}
|
{#each Object.entries(calendarTree) as [toplevel, subtrees], i}
|
||||||
<FilterItem item={toplevel} children={subtrees} bind:selected={subSelections[i]} />
|
<FilterItem
|
||||||
|
item={toplevel}
|
||||||
|
children={subtrees}
|
||||||
|
bind:selected={subSelections[i]}
|
||||||
|
bind:generalToggle
|
||||||
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</Offcanvas>
|
</Offcanvas>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.toggle {
|
||||||
|
display: block;
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
|
|
||||||
export let item = null;
|
export let item = null;
|
||||||
export let level = 1;
|
export let level = 1;
|
||||||
|
export let generalToggle = undefined;
|
||||||
|
|
||||||
export let children = [];
|
export let children = [];
|
||||||
export let selected = [];
|
export let selected = [];
|
||||||
export let filtering = createTriState(CHECKED);
|
export let filtering = createTriState(UNCHECKED);
|
||||||
let subfiltering = createTriStates(CHECKED, Object.entries(children).length);
|
let subfiltering = createTriStates(UNCHECKED, Object.entries(children).length);
|
||||||
let subselected = Array.from({ length: Object.entries(children).length }, _ => []);
|
let subselected = Array.from({ length: Object.entries(children).length }, _ => []);
|
||||||
|
|
||||||
function isVal(val) {
|
function isVal(val) {
|
||||||
|
@ -68,6 +69,13 @@
|
||||||
dispatch('change', { value: evt.detail.value });
|
dispatch('change', { value: evt.detail.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (generalToggle) {
|
||||||
|
generalToggle.subscribe(value => {
|
||||||
|
setTimeout(() => (value ? filtering.setChecked() : filtering.setUnchecked()), 0);
|
||||||
|
dispatch('change', { value: $filtering });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$: selected =
|
$: selected =
|
||||||
$filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
|
$filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue