|
|
|
@ -3,23 +3,29 @@ |
|
|
|
import Formfield from "../Common/Formfield.svelte" |
|
|
|
import ClassBuilder from "../ClassBuilder.js" |
|
|
|
import { MDCRadio } from "@material/radio" |
|
|
|
import { generate } from "shortid" |
|
|
|
|
|
|
|
export let onClick = item => {} |
|
|
|
export let _bb |
|
|
|
|
|
|
|
export let id = "" |
|
|
|
export let label = "" |
|
|
|
export let value = "" |
|
|
|
export let name = "radios" |
|
|
|
export let checked = false |
|
|
|
export let disabled = false |
|
|
|
export let alignEnd = false |
|
|
|
|
|
|
|
let _id |
|
|
|
let instance = null |
|
|
|
let radiobtn = null |
|
|
|
let selectedItems |
|
|
|
|
|
|
|
let context = _bb.getContext("BBMD:input:context") |
|
|
|
|
|
|
|
onMount(() => { |
|
|
|
_id = generate() |
|
|
|
|
|
|
|
if (!!radiobtn) { |
|
|
|
instance = new MDCRadio(radiobtn) |
|
|
|
if (context !== "list-item") { |
|
|
|
@ -27,8 +33,23 @@ |
|
|
|
fieldStore.setInput(instance) |
|
|
|
} |
|
|
|
} |
|
|
|
if (context === "radiobuttongroup") { |
|
|
|
selectedItems = _bb.getContext("BBMD:radiobutton:selectedItemsStore") |
|
|
|
let props = _bb.getContext("BBMD:radiobutton:props") |
|
|
|
name = props.name |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
function handleOnClick() { |
|
|
|
let item = { _id, label, value } |
|
|
|
if (context === "radiobuttongroup") { |
|
|
|
selectedItems.addSingleItem(item) |
|
|
|
} else { |
|
|
|
debugger |
|
|
|
onClick(item) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let extras = null |
|
|
|
|
|
|
|
if (context === "list-item") { |
|
|
|
@ -40,6 +61,11 @@ |
|
|
|
let props = { modifiers, extras } |
|
|
|
|
|
|
|
const blockClass = cb.build({ props }) |
|
|
|
|
|
|
|
$: isChecked = |
|
|
|
context === "radiobuttongroup" |
|
|
|
? $selectedItems && $selectedItems.findIndex(i => i._id === _id) > -1 |
|
|
|
: checked |
|
|
|
</script> |
|
|
|
|
|
|
|
{#if context !== 'list-item'} |
|
|
|
@ -52,7 +78,7 @@ |
|
|
|
{name} |
|
|
|
{checked} |
|
|
|
{disabled} |
|
|
|
on:click={onClick} /> |
|
|
|
on:click={handleOnClick} /> |
|
|
|
<div class={cb.elem`background`}> |
|
|
|
<div class={cb.elem`outer-circle`} /> |
|
|
|
<div class={cb.elem`inner-circle`} /> |
|
|
|
|