diff --git a/packages/materialdesign-components/src/Common/ItemStore.js b/packages/materialdesign-components/src/Common/ItemStore.js index c523405dad..cf0b7de24e 100644 --- a/packages/materialdesign-components/src/Common/ItemStore.js +++ b/packages/materialdesign-components/src/Common/ItemStore.js @@ -1,14 +1,14 @@ -import { writable } from "svelte/store"; +import { writable } from "svelte/store" function createItemsStore(componentOnSelect) { - const { subscribe, set, update } = writable([]); + const { subscribe, set, update } = writable([]) function addItem(item) { update(items => { - return [...items, item] + return [...items, item] }) if (componentOnSelect) { - componentOnSelect(); + componentOnSelect() } } diff --git a/packages/materialdesign-components/src/List/List.svelte b/packages/materialdesign-components/src/List/List.svelte index eae7018d1b..d83ae15053 100644 --- a/packages/materialdesign-components/src/List/List.svelte +++ b/packages/materialdesign-components/src/List/List.svelte @@ -6,8 +6,6 @@ import ListItem from "./ListItem.svelte" import ClassBuilder from "../ClassBuilder.js" - let selectedItems - export let _bb const cb = new ClassBuilder("list", ["one-line"]) diff --git a/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte b/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte index cb83f88d40..9916b0f0f1 100644 --- a/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte +++ b/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte @@ -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 {#if context !== 'list-item'} @@ -52,7 +78,7 @@ {name} {checked} {disabled} - on:click={onClick} /> + on:click={handleOnClick} />