Merge pull request #142 from Conor-Mack/feature/check-group-refactor
Tidyup and bugfixes
This commit is contained in:
commit
a544c13bab
|
@ -22,6 +22,7 @@
|
||||||
let instance = null
|
let instance = null
|
||||||
let checkbox = null
|
let checkbox = null
|
||||||
let selectedItems
|
let selectedItems
|
||||||
|
let checkProps
|
||||||
|
|
||||||
let context = _bb.getContext("BBMD:input:context")
|
let context = _bb.getContext("BBMD:input:context")
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
|
|
||||||
if (context === "checkboxgroup") {
|
if (context === "checkboxgroup") {
|
||||||
selectedItems = _bb.getContext("BBMD:checkbox:selectedItemsStore")
|
selectedItems = _bb.getContext("BBMD:checkbox:selectedItemsStore")
|
||||||
|
checkProps = _bb.getContext("BBMD:checkbox:props")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -80,18 +82,24 @@
|
||||||
context === "checkboxgroup"
|
context === "checkboxgroup"
|
||||||
? $selectedItems && $selectedItems.findIndex(i => i._id === _id) > -1
|
? $selectedItems && $selectedItems.findIndex(i => i._id === _id) > -1
|
||||||
: checked
|
: checked
|
||||||
|
|
||||||
|
$: isAlignedEnd =
|
||||||
|
context === "checkboxgroup" && !!checkProps ? checkProps.alignEnd : alignEnd
|
||||||
|
|
||||||
|
$: isDisabled =
|
||||||
|
context === "checkboxgroup" && !!checkProps ? checkProps.disabled : disabled
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- TODO: Customizing Colour and Density - What level of customization for these things does Budibase need here? -->
|
<!-- TODO: Customizing Colour and Density - What level of customization for these things does Budibase need here? -->
|
||||||
|
|
||||||
{#if context !== 'list-item'}
|
{#if context !== 'list-item'}
|
||||||
<Formfield {label} {id} {alignEnd}>
|
<Formfield {label} {_bb} {id} alignEnd={isAlignedEnd}>
|
||||||
<div bind:this={checkbox} class={blockClass}>
|
<div bind:this={checkbox} class={blockClass}>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class={cb.elem`native-control`}
|
class={cb.elem`native-control`}
|
||||||
{id}
|
{id}
|
||||||
{disabled}
|
disabled={isDisabled}
|
||||||
{isChecked}
|
{isChecked}
|
||||||
on:click={handleOnClick}
|
on:click={handleOnClick}
|
||||||
on:change={changed} />
|
on:change={changed} />
|
||||||
|
@ -113,7 +121,7 @@
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class={cb.elem`native-control`}
|
class={cb.elem`native-control`}
|
||||||
{id}
|
{id}
|
||||||
{disabled}
|
disabled={isDisabled}
|
||||||
{isChecked}
|
{isChecked}
|
||||||
on:change={changed}
|
on:change={changed}
|
||||||
on:click={handleOnClick} />
|
on:click={handleOnClick} />
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
|
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
export let alignEnd = false
|
export let alignEnd = false
|
||||||
let selectedItems = []
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
_bb.setContext("BBMD:input:context", "checkboxgroup")
|
_bb.setContext("BBMD:input:context", "checkboxgroup")
|
||||||
selectedItemsStore = createItemsStore(() => onChange($selectedItemsStore))
|
selectedItemsStore = createItemsStore(() => onChange($selectedItemsStore))
|
||||||
_bb.setContext("BBMD:checkbox:selectedItemsStore", selectedItemsStore)
|
_bb.setContext("BBMD:checkbox:selectedItemsStore", selectedItemsStore)
|
||||||
|
_bb.setContext("BBMD:checkbox:props", { alignEnd, disabled })
|
||||||
})
|
})
|
||||||
|
|
||||||
$: checkItems && _bb.attachChildren(checkItems)
|
$: checkItems && _bb.attachChildren(checkItems)
|
||||||
|
|
|
@ -17,15 +17,14 @@
|
||||||
|
|
||||||
let formField = null
|
let formField = null
|
||||||
|
|
||||||
let modifiers = { alignEnd }
|
$: modifiers = { alignEnd }
|
||||||
let props = { modifiers }
|
$: props = { modifiers }
|
||||||
|
|
||||||
let blockClasses = cb.build({ props })
|
$: blockClasses = cb.build({ props })
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!!formField) fieldStore.set(new MDCFormField(formField))
|
if (!!formField) fieldStore.set(new MDCFormField(formField))
|
||||||
//TODO: Fix this, _bb is coming back undefined
|
_bb.setContext("BBMD:field-element", fieldStore)
|
||||||
// _bb.setContext("BBMD:field-element", fieldStore)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onDestroy(unsubscribe)
|
onDestroy(unsubscribe)
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
let instance = null
|
let instance = null
|
||||||
let radiobtn = null
|
let radiobtn = null
|
||||||
let selectedItems
|
let selectedItems
|
||||||
|
let radioProps
|
||||||
|
|
||||||
let context = _bb.getContext("BBMD:input:context")
|
let context = _bb.getContext("BBMD:input:context")
|
||||||
|
|
||||||
|
@ -35,8 +36,8 @@
|
||||||
}
|
}
|
||||||
if (context === "radiobuttongroup") {
|
if (context === "radiobuttongroup") {
|
||||||
selectedItems = _bb.getContext("BBMD:radiobutton:selectedItemsStore")
|
selectedItems = _bb.getContext("BBMD:radiobutton:selectedItemsStore")
|
||||||
let props = _bb.getContext("BBMD:radiobutton:props")
|
radioProps = _bb.getContext("BBMD:radiobutton:props")
|
||||||
name = props.name
|
name = radioProps.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -56,19 +57,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const cb = new ClassBuilder("radio")
|
const cb = new ClassBuilder("radio")
|
||||||
let modifiers = { disabled }
|
|
||||||
let props = { modifiers, extras }
|
|
||||||
|
|
||||||
const blockClass = cb.build({ props })
|
|
||||||
|
|
||||||
$: isChecked =
|
$: isChecked =
|
||||||
context === "radiobuttongroup"
|
context === "radiobuttongroup"
|
||||||
? $selectedItems && $selectedItems.findIndex(i => i._id === _id) > -1
|
? $selectedItems && $selectedItems.findIndex(i => i._id === _id) > -1
|
||||||
: checked
|
: checked
|
||||||
|
|
||||||
|
$: isAlignedEnd =
|
||||||
|
context === "radiobuttongroup" && !!radioProps
|
||||||
|
? radioProps.alignEnd
|
||||||
|
: alignEnd
|
||||||
|
|
||||||
|
$: isDisabled =
|
||||||
|
context === "radiobuttongroup" && !!radioProps
|
||||||
|
? radioProps.disabled
|
||||||
|
: disabled
|
||||||
|
|
||||||
|
$: modifiers = { disabled: isDisabled }
|
||||||
|
$: props = { modifiers, extras }
|
||||||
|
|
||||||
|
$: blockClass = cb.build({ props })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if context !== 'list-item'}
|
{#if context !== 'list-item'}
|
||||||
<Formfield {id} {label} {alignEnd}>
|
<Formfield {id} {_bb} {label} alignEnd={isAlignedEnd}>
|
||||||
<div class={blockClass}>
|
<div class={blockClass}>
|
||||||
<input
|
<input
|
||||||
{id}
|
{id}
|
||||||
|
@ -76,7 +88,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
{name}
|
{name}
|
||||||
{checked}
|
{checked}
|
||||||
{disabled}
|
disabled={isDisabled}
|
||||||
on:click={handleOnClick} />
|
on:click={handleOnClick} />
|
||||||
<div class={cb.elem`background`}>
|
<div class={cb.elem`background`}>
|
||||||
<div class={cb.elem`outer-circle`} />
|
<div class={cb.elem`outer-circle`} />
|
||||||
|
@ -93,7 +105,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
{name}
|
{name}
|
||||||
{checked}
|
{checked}
|
||||||
{disabled}
|
disabled={isDisabled}
|
||||||
on:click={onClick} />
|
on:click={onClick} />
|
||||||
<div class={cb.elem`background`}>
|
<div class={cb.elem`background`}>
|
||||||
<div class={cb.elem`outer-circle`} />
|
<div class={cb.elem`outer-circle`} />
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
export let orientation = "row"
|
export let orientation = "row"
|
||||||
export let fullwidth = false
|
export let fullwidth = false
|
||||||
export let alignEnd = false
|
export let alignEnd = false
|
||||||
|
export let disabled = false
|
||||||
|
|
||||||
let selectedItemsStore
|
let selectedItemsStore
|
||||||
let selected = null
|
let selected = null
|
||||||
|
@ -20,18 +21,10 @@
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
_bb.setContext("BBMD:input:context", "radiobuttongroup")
|
_bb.setContext("BBMD:input:context", "radiobuttongroup")
|
||||||
selectedItemsStore = createItemStore(() => onChange($selectedItemsStore))
|
selectedItemsStore = createItemStore(() => onChange($selectedItemsStore))
|
||||||
_bb.setContext("BBMD:radiobutton:props", { name })
|
_bb.setContext("BBMD:radiobutton:props", { name, disabled, alignEnd })
|
||||||
_bb.setContext("BBMD:radiobutton:selectedItemsStore", selectedItemsStore)
|
_bb.setContext("BBMD:radiobutton:selectedItemsStore", selectedItemsStore)
|
||||||
})
|
})
|
||||||
|
|
||||||
// function handleOnClick(item) {
|
|
||||||
// if (!!selected) selected.checked = false
|
|
||||||
// item.checked = true
|
|
||||||
// selected = item
|
|
||||||
// items = items
|
|
||||||
// onChange(selected)w
|
|
||||||
// }
|
|
||||||
|
|
||||||
$: alignRight = orientation === "column" && alignEnd
|
$: alignRight = orientation === "column" && alignEnd
|
||||||
$: radioItems && _bb.attachChildren(radioItems)
|
$: radioItems && _bb.attachChildren(radioItems)
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -28,20 +28,12 @@
|
||||||
props: {
|
props: {
|
||||||
_component: "testcomponents/rootComponent",
|
_component: "testcomponents/rootComponent",
|
||||||
_children: [
|
_children: [
|
||||||
H1,
|
|
||||||
Overline,
|
|
||||||
Button,
|
Button,
|
||||||
BodyBoundToStore,
|
BodyBoundToStore,
|
||||||
Textfield,
|
Textfield,
|
||||||
Icon,
|
|
||||||
Datatable,
|
|
||||||
CustomersIndexTable,
|
|
||||||
List,
|
|
||||||
Select,
|
Select,
|
||||||
Radiobutton,
|
Radiobutton,
|
||||||
Radiobuttongroup,
|
Radiobuttongroup,
|
||||||
Checkbox,
|
|
||||||
Checkboxgroup,
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,12 +77,15 @@ export const props = {
|
||||||
_component: "@budibase/materialdesign-components/Checkbox",
|
_component: "@budibase/materialdesign-components/Checkbox",
|
||||||
_children: [],
|
_children: [],
|
||||||
id: "test-check",
|
id: "test-check",
|
||||||
|
alignEnd: true,
|
||||||
label: "Check Yo Self",
|
label: "Check Yo Self",
|
||||||
onClick: () => alert`Before ya reck yo'self`,
|
onClick: () => alert`Before ya reck yo'self`,
|
||||||
},
|
},
|
||||||
Checkboxgroup: {
|
Checkboxgroup: {
|
||||||
_component: "@budibase/materialdesign-components/Checkboxgroup",
|
_component: "@budibase/materialdesign-components/Checkboxgroup",
|
||||||
label: "Whats your favourite?",
|
label: "Whats your favourite?",
|
||||||
|
disabled: true,
|
||||||
|
alignEnd: true,
|
||||||
onChange: selectedItems => console.log(selectedItems),
|
onChange: selectedItems => console.log(selectedItems),
|
||||||
_children: [
|
_children: [
|
||||||
{
|
{
|
||||||
|
@ -114,6 +117,8 @@ export const props = {
|
||||||
_component: "@budibase/materialdesign-components/Radiobuttongroup",
|
_component: "@budibase/materialdesign-components/Radiobuttongroup",
|
||||||
label: "Preferred method of contact: ",
|
label: "Preferred method of contact: ",
|
||||||
orientation: "column",
|
orientation: "column",
|
||||||
|
disabled: true,
|
||||||
|
alignEnd: true,
|
||||||
onChange: selected => console.log("Radiobutton Group", selected),
|
onChange: selected => console.log("Radiobutton Group", selected),
|
||||||
_children: [
|
_children: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue