2020-02-12 13:32:46 +01:00
|
|
|
<script>
|
2020-02-21 14:39:18 +01:00
|
|
|
import { onMount, onDestroy, getContext } from "svelte"
|
|
|
|
import Formfield from "../Common/Formfield.svelte"
|
|
|
|
import { fieldStore } from "../Common/FormfieldStore.js"
|
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
|
|
|
import { MDCCheckbox } from "@material/checkbox"
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
export let onClick = item => {}
|
2020-02-14 11:32:19 +01:00
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
export let id = ""
|
|
|
|
export let label = ""
|
|
|
|
export let disabled = false
|
|
|
|
export let alignEnd = false
|
|
|
|
export let indeterminate = false
|
|
|
|
export let checked = false
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
let instance = null
|
|
|
|
let checkbox = null
|
|
|
|
|
|
|
|
let context = getContext("BBMD:input:context")
|
2020-02-12 13:32:46 +01:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
if (!!checkbox) {
|
2020-02-21 14:39:18 +01:00
|
|
|
instance = new MDCCheckbox(checkbox)
|
|
|
|
instance.indeterminate = indeterminate
|
|
|
|
if (context !== "list-item") {
|
|
|
|
let fieldStore = getContext("BBMD:field-element")
|
|
|
|
fieldStore.setInput(instance)
|
|
|
|
}
|
2020-02-12 13:32:46 +01:00
|
|
|
}
|
2020-02-21 14:39:18 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
let extras = null
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
if (context === "list-item") {
|
|
|
|
extras = ["mdc-list-item__meta"]
|
|
|
|
}
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
const cb = new ClassBuilder("checkbox")
|
|
|
|
let modifiers = { disabled }
|
|
|
|
let props = { modifiers, extras }
|
|
|
|
|
|
|
|
const blockClass = cb.build({ props })
|
2020-02-12 13:32:46 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- TODO: Customizing Colour and Density - What level of customization for these things does Budibase need here? -->
|
|
|
|
|
2020-02-21 14:39:18 +01:00
|
|
|
{#if context !== 'list-item'}
|
|
|
|
<Formfield {label} {id} {alignEnd}>
|
|
|
|
<div bind:this={checkbox} class={blockClass}>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class={cb.elem`native-control`}
|
|
|
|
{id}
|
|
|
|
{disabled}
|
|
|
|
{checked}
|
|
|
|
on:click={onClick} />
|
|
|
|
<div class={cb.elem`background`}>
|
|
|
|
<svg class={cb.elem`checkmark`} viewBox="0 0 24 24">
|
|
|
|
<path
|
|
|
|
class={cb.elem`checkmark-path`}
|
|
|
|
fill="none"
|
|
|
|
d="M1.73,12.91 8.1,19.28 22.79,4.59" />
|
|
|
|
</svg>
|
|
|
|
<div class={cb.elem`mixedmark`} />
|
|
|
|
</div>
|
|
|
|
<div class={cb.elem`ripple`} />
|
|
|
|
</div>
|
|
|
|
</Formfield>
|
|
|
|
{:else}
|
2020-02-12 13:32:46 +01:00
|
|
|
<div bind:this={checkbox} class={blockClass}>
|
2020-02-14 11:32:19 +01:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class={cb.elem`native-control`}
|
|
|
|
{id}
|
|
|
|
{disabled}
|
|
|
|
{checked}
|
|
|
|
on:click={onClick} />
|
2020-02-12 13:32:46 +01:00
|
|
|
<div class={cb.elem`background`}>
|
|
|
|
<svg class={cb.elem`checkmark`} viewBox="0 0 24 24">
|
|
|
|
<path
|
|
|
|
class={cb.elem`checkmark-path`}
|
|
|
|
fill="none"
|
|
|
|
d="M1.73,12.91 8.1,19.28 22.79,4.59" />
|
|
|
|
</svg>
|
|
|
|
<div class={cb.elem`mixedmark`} />
|
|
|
|
</div>
|
|
|
|
<div class={cb.elem`ripple`} />
|
|
|
|
</div>
|
2020-02-21 14:39:18 +01:00
|
|
|
{/if}
|