2020-02-12 13:32:46 +01:00
|
|
|
<script>
|
2020-02-25 16:21:23 +01:00
|
|
|
import "@material/form-field/mdc-form-field.scss"
|
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
|
|
|
import { fieldStore } from "./FormfieldStore.js"
|
|
|
|
import { MDCFormField } from "@material/form-field"
|
2020-02-27 11:03:49 +01:00
|
|
|
import { onMount, onDestroy } from "svelte"
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
const cb = new ClassBuilder("form-field")
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
let store
|
|
|
|
const unsubscribe = fieldStore.subscribe(s => (store = s))
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-27 11:03:49 +01:00
|
|
|
export let _bb
|
2020-02-25 16:21:23 +01:00
|
|
|
export let id = ""
|
|
|
|
export let label = ""
|
|
|
|
export let alignEnd = false
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
let formField = null
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-03-05 15:59:08 +01:00
|
|
|
$: modifiers = { alignEnd }
|
|
|
|
$: props = { modifiers }
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-03-05 15:59:08 +01:00
|
|
|
$: blockClasses = cb.build({ props })
|
2020-02-12 13:32:46 +01:00
|
|
|
|
|
|
|
onMount(() => {
|
2020-02-25 16:21:23 +01:00
|
|
|
if (!!formField) fieldStore.set(new MDCFormField(formField))
|
2020-03-05 15:59:08 +01:00
|
|
|
_bb.setContext("BBMD:field-element", fieldStore)
|
2020-02-25 16:21:23 +01:00
|
|
|
})
|
2020-02-12 13:32:46 +01:00
|
|
|
|
2020-02-25 16:21:23 +01:00
|
|
|
onDestroy(unsubscribe)
|
2020-02-12 13:32:46 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div bind:this={formField} class={blockClasses}>
|
|
|
|
<slot />
|
|
|
|
<label for={id}>{label}</label>
|
|
|
|
</div>
|