Merge pull request #175 from Conor-Mack/bugfix/md-reference-bb-apis

MD Components to Reference Budibase API's
This commit is contained in:
Conor_Mack 2020-03-30 13:12:22 +01:00 committed by GitHub
commit 2ec5c20198
17 changed files with 113 additions and 112 deletions

View File

@ -6,6 +6,7 @@
const cb = new ClassBuilder("button", ["primary", "medium", "text"]) const cb = new ClassBuilder("button", ["primary", "medium", "text"])
export let _bb
export let onClick export let onClick
export let variant = "text" export let variant = "text"
@ -20,8 +21,6 @@
export let text = "" export let text = ""
export let disabled = false export let disabled = false
export let _bb
onMount(() => { onMount(() => {
let ctx = _bb.getContext("BBMD:button:context") let ctx = _bb.getContext("BBMD:button:context")
extras = [ctx] extras = [ctx]

View File

@ -2,9 +2,11 @@
export let _bb export let _bb
export let onClick = () => {} export let onClick = () => {}
export let clicked = () => _bb.call(onClick)
let cardBody let cardBody
$: cardBody && _bb.attachChildren(cardBody) $: cardBody && _bb.attachChildren(cardBody)
</script> </script>
<div bind:this={cardBody} class="mdc-card__primary-action" on:click={onClick} /> <div bind:this={cardBody} class="mdc-card__primary-action" on:click={clicked} />

View File

@ -6,7 +6,7 @@
import { MDCCheckbox } from "@material/checkbox" import { MDCCheckbox } from "@material/checkbox"
import { generate } from "shortid" import { generate } from "shortid"
export let onClick = item => {} export let onChange = item => {}
export let _bb export let _bb
@ -59,13 +59,16 @@
function changed(e) { function changed(e) {
const val = e.target.checked const val = e.target.checked
checked = val checked = val
handleOnClick()
if (_bb.isBound(_bb.props.checked)) { if (_bb.isBound(_bb.props.checked)) {
_bb.setStateFromBinding(_bb.props.checked, val) _bb.setStateFromBinding(_bb.props.checked, val)
} }
} }
function handleOnClick() { function handleOnClick() {
let item = { _id, label, value } let item = { _id, checked, label, value }
debugger
if (context === "checkboxgroup") { if (context === "checkboxgroup") {
let idx = selectedItems.getItemIdx($selectedItems, _id) let idx = selectedItems.getItemIdx($selectedItems, _id)
if (idx > -1) { if (idx > -1) {
@ -73,9 +76,8 @@
} else { } else {
selectedItems.addItem(item) selectedItems.addItem(item)
} }
} else {
onClick(item)
} }
_bb.call(onChange, item)
} }
$: isChecked = $: isChecked =
@ -101,7 +103,6 @@
{id} {id}
disabled={isDisabled} disabled={isDisabled}
{isChecked} {isChecked}
on:click={handleOnClick}
on:change={changed} /> on:change={changed} />
<div class={cb.elem`background`}> <div class={cb.elem`background`}>
<svg class={cb.elem`checkmark`} viewBox="0 0 24 24"> <svg class={cb.elem`checkmark`} viewBox="0 0 24 24">
@ -123,8 +124,7 @@
{id} {id}
disabled={isDisabled} disabled={isDisabled}
{isChecked} {isChecked}
on:change={changed} on:change={changed} />
on:click={handleOnClick} />
<div class={cb.elem`background`}> <div class={cb.elem`background`}>
<svg class={cb.elem`checkmark`} viewBox="0 0 24 24"> <svg class={cb.elem`checkmark`} viewBox="0 0 24 24">
<path <path

View File

@ -15,10 +15,18 @@
export let disabled = false export let disabled = false
export let alignEnd = false export let alignEnd = false
export let value = []
onMount(() => { onMount(() => {
_bb.setContext("BBMD:input:context", "checkboxgroup") _bb.setContext("BBMD:input:context", "checkboxgroup")
selectedItemsStore = createItemsStore(() => onChange($selectedItemsStore)) selectedItemsStore = createItemsStore(() => {
value = $selectedItemsStore
if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, value)
}
debugger
_bb.call(onChange, value)
}, value)
_bb.setContext("BBMD:checkbox:selectedItemsStore", selectedItemsStore) _bb.setContext("BBMD:checkbox:selectedItemsStore", selectedItemsStore)
_bb.setContext("BBMD:checkbox:props", { alignEnd, disabled }) _bb.setContext("BBMD:checkbox:props", { alignEnd, disabled })
}) })

View File

@ -1,16 +1,17 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
function createItemsStore(componentOnSelect) { function createItemsStore(componentOnSelect, initialState = []) {
const { subscribe, set, update } = writable([]) const { subscribe, set, update } = writable(initialState)
function addItem(item) {
update(items => {
return [...items, item]
})
if (componentOnSelect) {
componentOnSelect()
}
function addItem(item) {
update(items => {
return [...items, item]
})
if (componentOnSelect) {
componentOnSelect()
} }
}
function addSingleItem(item) { function addSingleItem(item) {
set([item]) set([item])

View File

@ -38,11 +38,31 @@
} }
}) })
function handleSelect(date) {
if (_bb.isBound(_bb.props.date)) {
_bb.setStateFromBinding(_bb.props.date, date)
}
_bb.call(onSelect, date)
}
function selectDate(dayOfMonth) { function selectDate(dayOfMonth) {
let month = getMonth(navDate) let month = getMonth(navDate)
let year = getYear(navDate) let year = getYear(navDate)
date = new Date(year, month, dayOfMonth) date = new Date(year, month, dayOfMonth)
onSelect(date) handleSelect(date)
}
function dateFieldChange(value) {
const isDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/
if (isDate.test(value)) {
const [year, month, day] = value.split("/").reverse()
if (month > 0 && month <= 12 && (day > 0 && day <= 31)) {
date = new Date(year, month - 1, day)
navDate = date
openCalendar(true)
handleSelect(date)
}
}
} }
function addMonth() { function addMonth() {
@ -57,19 +77,6 @@
instance.open = isOpen === undefined ? !instance.open : isOpen instance.open = isOpen === undefined ? !instance.open : isOpen
} }
function textFieldChange(value) {
const isDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/
if (isDate.test(value)) {
const [year, month, day] = value.split("/").reverse()
if (month > 0 && month <= 12 && day > 0 && day <= 31) {
date = new Date(year, month - 1, day)
navDate = date
openCalendar(true)
onSelect(date)
}
}
}
$: dateMonthEnds = endOfMonth(navDate).getDate() $: dateMonthEnds = endOfMonth(navDate).getDate()
$: dateMonthBegins = startOfMonth(navDate).getDay() $: dateMonthBegins = startOfMonth(navDate).getDay()
$: dayStart = dateMonthBegins + 1 //1 = sunday $: dayStart = dateMonthBegins + 1 //1 = sunday
@ -92,7 +99,7 @@
<div class="mdc-menu-surface--anchor"> <div class="mdc-menu-surface--anchor">
<Textfield <Textfield
{label} {label}
onChange={textFieldChange} onChange={dateFieldChange}
value={selectedDate} value={selectedDate}
trailingIcon={true} trailingIcon={true}
useIconButton={true} useIconButton={true}

View File

@ -26,7 +26,7 @@
function onButtonClick() { function onButtonClick() {
open = !open open = !open
onClick() _bb.call(onClick)
} }
$: isToggleButton = !!icon && !!onIcon $: isToggleButton = !!icon && !!onIcon

View File

@ -17,6 +17,7 @@
export let singleSelection = false export let singleSelection = false
export let variant = "one-line" export let variant = "one-line"
export let inputElement = null export let inputElement = null
export let value = []
let selectedItemsStore let selectedItemsStore
@ -25,7 +26,13 @@
onMount(() => { onMount(() => {
let ctx = getContext("BBMD:list:context") let ctx = getContext("BBMD:list:context")
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore)) selectedItemsStore = createItemsStore(() => {
value = $selectedItemsStore
if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, value)
}
_bb.call(onSelect, value)
}, value)
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore) _bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
_bb.setContext("BBMD:list:props", { _bb.setContext("BBMD:list:props", {

View File

@ -24,7 +24,14 @@
_bb.setContext("BBMD:list:context", "menu") _bb.setContext("BBMD:list:context", "menu")
_bb.setContext("BBMD:list:props", { singleSelection: true }) _bb.setContext("BBMD:list:props", { singleSelection: true })
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore)) selectedItemsStore = createItemsStore(() => {
let value =
$selectedItemsStore && $selectedItemsStore.length > 0
? $selectedItemsStore[0]
: ""
_bb.call(onSelect, value)
})
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore) _bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
if (!!menu) { if (!!menu) {

View File

@ -46,7 +46,7 @@
if (context === "radiobuttongroup") { if (context === "radiobuttongroup") {
selectedItems.addSingleItem(item) selectedItems.addSingleItem(item)
} else { } else {
onClick(item) _bb.call(onClick, item)
} }
} }
@ -106,7 +106,7 @@
{name} {name}
{checked} {checked}
disabled={isDisabled} disabled={isDisabled}
on:click={onClick} /> 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`} />
<div class={cb.elem`inner-circle`} /> <div class={cb.elem`inner-circle`} />

View File

@ -13,6 +13,9 @@
export let fullwidth = false export let fullwidth = false
export let alignEnd = false export let alignEnd = false
export let disabled = false export let disabled = false
export let value = []
$: safeValue = Array.isArray(value) ? value : [value]
let selectedItemsStore let selectedItemsStore
let selected = null let selected = null
@ -20,7 +23,13 @@
onMount(() => { onMount(() => {
_bb.setContext("BBMD:input:context", "radiobuttongroup") _bb.setContext("BBMD:input:context", "radiobuttongroup")
selectedItemsStore = createItemStore(() => onChange($selectedItemsStore)) selectedItemsStore = createItemStore(() => {
value = $selectedItemsStore[0]
if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, value)
}
_bb.call(onChange, value)
}, safeValue)
_bb.setContext("BBMD:radiobutton:props", { name, disabled, alignEnd }) _bb.setContext("BBMD:radiobutton:props", { name, disabled, alignEnd })
_bb.setContext("BBMD:radiobutton:selectedItemsStore", selectedItemsStore) _bb.setContext("BBMD:radiobutton:selectedItemsStore", selectedItemsStore)
}) })

View File

@ -30,6 +30,8 @@
export let persistent = false export let persistent = false
export let value = "" export let value = ""
$: safeValue = Array.isArray(value) ? value : [value]
onMount(() => { onMount(() => {
_bb.setContext("BBMD:list:props", { singleSelection: true }) _bb.setContext("BBMD:list:props", { singleSelection: true })
_bb.setContext("BBMD:list:addItem", i => (listItems = [...listItems, i])) _bb.setContext("BBMD:list:addItem", i => (listItems = [...listItems, i]))
@ -43,7 +45,8 @@
value = v value = v
_bb.setStateFromBinding(_bb.props.value, v) _bb.setStateFromBinding(_bb.props.value, v)
_bb.call(onSelect, v) _bb.call(onSelect, v)
}) }, safeValue)
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore) _bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
_helperId = generate() _helperId = generate()

View File

@ -8,6 +8,8 @@
let slider let slider
let instance let instance
export let _bb
export let onChange = value => {}
export let variant = "continuous" //or discrete export let variant = "continuous" //or discrete
export let showTicks = false export let showTicks = false
export let min = 0 export let min = 0
@ -17,6 +19,14 @@
export let label = "" export let label = ""
export let disabled = false export let disabled = false
function handleChange(val) {
value = val
if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, value)
}
_bb.call(onChange, val)
}
onMount(() => { onMount(() => {
let s = MDCSlider.attachTo(slider) let s = MDCSlider.attachTo(slider)
return () => instance.destroy() return () => instance.destroy()
@ -28,16 +38,12 @@
} }
} }
$: instance && console.log("instance dot value: ", instance.value)
$: isDiscrete = variant === "discrete" $: isDiscrete = variant === "discrete"
$: displayMarkers = isDiscrete && showTicks $: displayMarkers = isDiscrete && showTicks
$: modifiers = { variant, displayMarkers } $: modifiers = { variant, displayMarkers }
$: props = { modifiers } $: props = { modifiers }
$: sliderCls = cb.build({ props }) $: sliderCls = cb.build({ props })
$: console.log("VALUE", value)
</script> </script>
<div <div
@ -49,7 +55,8 @@
aria-valuemax="100" aria-valuemax="100"
aria-valuenow="0" aria-valuenow="0"
aria-label="Select Value" aria-label="Select Value"
on:MDCSlider:change={e => console.log('SLIDER VAL', e.detail.value)}> on:MDCSlider:input={e => handleChange(e.detail.value)}
on:MDCSlider:change={e => handleChange(e.detail.value)}>
<div class="mdc-slider__track-container"> <div class="mdc-slider__track-container">
<div class="mdc-slider__track" /> <div class="mdc-slider__track" />
</div> </div>
@ -63,57 +70,3 @@
<div class="mdc-slider__focus-ring" /> <div class="mdc-slider__focus-ring" />
</div> </div>
</div> </div>
<!--
<div
bind:this={slider}
class={sliderCls}
tabindex="0"
role="slider"
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
data-step={step}
aria-label={label}
on:MDCSlider:input={e => console.log('INPUT', e.detail.value)}
on:MDCSlider:change={e => console.log('CHANGE', e.detail.value)}
aria-disabled={disabled}>
<div class="mdc-slider__track-container">
{#if displayMarkers}
<div class="mdc-slider__track-container">
<div class="mdc-slider__track" />
<div class="mdc-slider__track-marker-container" />
</div>
{:else}
<div class="mdc-slider__track" />
{/if}
</div>
<div class="mdc-slider__thumb-container">
{#if isDiscrete}
<div class="mdc-slider__pin">
<span class="mdc-slider__pin-value-marker" />
</div>
{/if}
<svg class="mdc-slider__thumb" width="21" height="21">
<circle cx="10.5" cy="10.5" r="7.875" />
</svg>
<div class="mdc-slider__focus-ring" />
</div>
</div> -->
<!-- <div class="mdc-slider mdc-slider--discrete" tabindex="0" role="slider"
aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"
aria-label="Select Value">
<div class="mdc-slider__track-container">
<div class="mdc-slider__track"></div>
</div>
<div class="mdc-slider__thumb-container">
<div class="mdc-slider__pin">
<span class="mdc-slider__pin-value-marker"></span>
</div>
<svg class="mdc-slider__thumb" width="21" height="21">
<circle cx="10.5" cy="10.5" r="7.875"></circle>
</svg>
<div class="mdc-slider__focus-ring"></div>
</div>
</div> -->

View File

@ -15,7 +15,10 @@
function handleChange() { function handleChange() {
checked = !checked checked = !checked
onChange(checked) if (_bb.isBound(_bb.props.checked)) {
_bb.setStateFromBinding(_bb.props.checked, checked)
}
_bb.call(onChange, checked)
} }
$: modifiers = { disabled, checked } $: modifiers = { disabled, checked }

View File

@ -34,13 +34,18 @@
props: { props: {
_component: "testcomponents/rootComponent", _component: "testcomponents/rootComponent",
_children: [ _children: [
BodyBoundToStore,
Textfield, Textfield,
Select, Checkboxgroup,
Radiobutton, Radiobutton,
Radiobuttongroup, Radiobuttongroup,
Datatable,
CustomersIndexTable,
Icon,
List,
Select,
DatePicker, DatePicker,
IconButton, IconButton,
Card,
Switch, Switch,
Slider, Slider,
], ],

View File

@ -79,12 +79,11 @@ export const props = {
id: "test-check", id: "test-check",
alignEnd: true, alignEnd: true,
label: "Check Yo Self", label: "Check Yo Self",
onClick: () => alert`Before ya reck yo'self`, onChange: item => console.log(item),
}, },
Checkboxgroup: { Checkboxgroup: {
_component: "@budibase/materialdesign-components/Checkboxgroup", _component: "@budibase/materialdesign-components/Checkboxgroup",
label: "Whats your favourite?", label: "Whats your favourite?",
disabled: true,
alignEnd: true, alignEnd: true,
onChange: selectedItems => console.log(selectedItems), onChange: selectedItems => console.log(selectedItems),
_children: [ _children: [
@ -117,7 +116,6 @@ 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, alignEnd: true,
onChange: selected => console.log("Radiobutton Group", selected), onChange: selected => console.log("Radiobutton Group", selected),
_children: [ _children: [

View File

@ -97,11 +97,10 @@
function changed(e) { function changed(e) {
const val = e.target.value const val = e.target.value
value = val value = val
onChange(value) if (_bb.isBound(_bb.props.value)) {
// if (_bb.isBound(_bb.props.value)) { _bb.setStateFromBinding(_bb.props.value, val)
// _bb.setStateFromBinding(_bb.props.value, val) }
// } _bb.call(onChange, val)
// _bb.call(onChange, val)
} }
</script> </script>