Merge branch 'master' of github.com:Budibase/budibase

This commit is contained in:
Michael Shanks 2020-03-04 15:21:35 +00:00
commit c775ce9d89
15 changed files with 210 additions and 43 deletions

View File

@ -46,5 +46,8 @@
], ],
"version": "0.0.24", "version": "0.0.24",
"license": "MIT", "license": "MIT",
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072" "gitHead": "115189f72a850bfb52b65ec61d932531bf327072",
"dependencies": {
"@material/select": "4.0.0"
}
} }

View File

@ -34,10 +34,6 @@
const clicked = () => _bb.call(onClick) const clicked = () => _bb.call(onClick)
$: if (icon) {
setContext("BBMD:icon:context", "button")
}
$: renderLeadingIcon = !!icon && !trailingIcon $: renderLeadingIcon = !!icon && !trailingIcon
$: renderTrailingIcon = !!icon && trailingIcon $: renderTrailingIcon = !!icon && trailingIcon
</script> </script>
@ -54,11 +50,11 @@
{disabled} {disabled}
on:click={clicked}> on:click={clicked}>
{#if renderLeadingIcon} {#if renderLeadingIcon}
<Icon {icon} /> <Icon context="button" {icon} />
{/if} {/if}
<span class={labelClass}>{text}</span> <span class={labelClass}>{text}</span>
{#if renderTrailingIcon} {#if renderTrailingIcon}
<Icon {icon} /> <Icon context="button" {icon} />
{/if} {/if}
</button> </button>
{/if} {/if}

View File

@ -2,11 +2,9 @@
import { getContext } from "svelte" import { getContext } from "svelte"
export let icon = "" export let icon = ""
export let context = ""
let iconContext = getContext("BBMD:icon:context") let cls = !!context ? `material-icons mdc-${context}__icon` : "material-icons"
let cls = iconContext
? `material-icons mdc-${iconContext}__icon`
: "material-icons"
</script> </script>
<i class={cls}>{icon}</i> <i class={cls}>{icon}</i>

View File

@ -17,31 +17,25 @@
export let onSelect = selectedItems => {} export let onSelect = selectedItems => {}
export let singleSelection = false export let singleSelection = false
export let variant = "two-line" export let variant = "one-line"
export let inputElement = null export let inputElement = null
let selectedItemsStore let selectedItemsStore
let role = "listbox" let role = "listbox"
function createOrAcceptItemStore() { onMount(() => {
let store = _bb.getContext("BBMD:list:selectItemStore") let ctx = getContext("BBMD:list:context")
if (!!store) {
selectedItemsStore = store
} else {
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore)) selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore) _bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
}
}
onMount(() => {
createOrAcceptItemStore()
_bb.setContext("BBMD:list:props", { _bb.setContext("BBMD:list:props", {
inputElement, inputElement,
variant, variant,
singleSelection, singleSelection,
}) })
if (!!list) { if (!!list) {
if (!inputElement) { if (!inputElement) {
instance = new MDCList(list) instance = new MDCList(list)

View File

@ -2,13 +2,12 @@
import { onMount, getContext } from "svelte" import { onMount, getContext } from "svelte"
import { Radiobutton } from "../Radiobutton" import { Radiobutton } from "../Radiobutton"
import { Checkbox } from "../Checkbox" import { Checkbox } from "../Checkbox"
import Icon from "../Common/Icon.svelte"
import ClassBuilder from "../ClassBuilder.js" import ClassBuilder from "../ClassBuilder.js"
import { generate } from "shortid" import { generate } from "shortid"
const cb = new ClassBuilder("list-item") const cb = new ClassBuilder("list-item")
export let onClick = item => {}
let _id let _id
let listProps = null let listProps = null
@ -16,7 +15,7 @@
export let _bb export let _bb
export let value = null export let value = ""
export let text = "" export let text = ""
export let secondaryText = "" export let secondaryText = ""
@ -24,6 +23,7 @@
export let trailingIcon = "" export let trailingIcon = ""
export let selected = false export let selected = false
export let disabled = false export let disabled = false
export let dividerAfter = false
let role = "option" let role = "option"
@ -84,7 +84,13 @@
listProps && listProps.variant === "two-line" && !!secondaryText listProps && listProps.variant === "two-line" && !!secondaryText
</script> </script>
<li class={listItemClass} role="option" tabindex="0" on:click={handleClick}> <li
class={listItemClass}
role="option"
tabindex="0"
on:click={handleClick}
data-value={value}
aria-selected={isSelected}>
{#if leadingIcon} {#if leadingIcon}
<span class="mdc-list-item__graphic material-icons" aria-hidden="true"> <span class="mdc-list-item__graphic material-icons" aria-hidden="true">
{leadingIcon} {leadingIcon}
@ -104,9 +110,9 @@
<Checkbox checked={isSelected} {disabled} {_bb} /> <Checkbox checked={isSelected} {disabled} {_bb} />
{/if} {/if}
{:else if trailingIcon} {:else if trailingIcon}
<!-- TODO: Adapt label to accept class prop to handle this. Context is insufficient --> <Icon context="list-item__meta" icon={trailingIcon} />
<span class="mdc-list-item__meta material-icons" aria-hidden="true">
{trailingIcon}
</span>
{/if} {/if}
</li> </li>
{#if dividerAfter}
<li class="mdc-list-divider" role="separator" />
{/if}

View File

@ -2,8 +2,10 @@
import { List } from "../List" import { List } from "../List"
import { MDCMenu } from "@material/menu" import { MDCMenu } from "@material/menu"
import { onMount, setContext } from "svelte" import { onMount, setContext } from "svelte"
export let items = [] import createItemsStore from "../Common/ItemStore.js"
export let singleSelection = true
export let onSelect = selectedItems => {}
export let width = "400px" export let width = "400px"
export let open = true export let open = true
export let useFixedPosition = false export let useFixedPosition = false
@ -11,10 +13,20 @@
//{x: number, y: number} //{x: number, y: number}
export let absolutePositionCoords = null export let absolutePositionCoords = null
export let _bb
let menu = null let menu = null
let menuList = null
let instance = null let instance = null
let selectedItemsStore
onMount(() => { onMount(() => {
_bb.setContext("BBMD:list:context", "menu")
_bb.setContext("BBMD:list:props", { singleSelection: true })
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
if (!!menu) { if (!!menu) {
instance = new MDCMenu(menu) instance = new MDCMenu(menu)
instance.open = open instance.open = open
@ -25,8 +37,9 @@
instance.setAbsolutePosition(x | 0, y | 0) instance.setAbsolutePosition(x | 0, y | 0)
} }
} }
setContext("BBMD:list:context", "menu")
}) })
$: menuList && _bb.attachChildren(menuList)
</script> </script>
{#if useFixedPosition || useAbsolutePosition} {#if useFixedPosition || useAbsolutePosition}
@ -34,17 +47,17 @@
bind:this={menu} bind:this={menu}
class="mdc-menu mdc-menu-surface" class="mdc-menu mdc-menu-surface"
style={`width: ${width}`}> style={`width: ${width}`}>
<List {items} {singleSelection} /> <ul bind:this={menuList} class="mdc-list" role="menu" />
</div> </div>
{:else} {:else}
<div class="mdc-menu-surface--anchor"> <div class="mdc-menu-surface--anchor">
<!-- Will automatically anchor to slotted element --> <!--TODO: Will automatically anchor to slotted element. Not sure how this would be achieved with Budibase though -->
<slot /> <slot />
<div <div
bind:this={menu} bind:this={menu}
class="mdc-menu mdc-menu-surface" class="mdc-menu mdc-menu-surface"
style={`width: ${width}`}> style={`width: ${width}`}>
<List {items} {singleSelection} /> <ul bind:this={menuList} class="mdc-list" role="menu" />
</div> </div>
</div> </div>
{/if} {/if}

View File

@ -1,2 +1,3 @@
@import "@material/list/mdc-list.scss";
@import "@material/menu-surface/mdc-menu-surface.scss"; @import "@material/menu-surface/mdc-menu-surface.scss";
@import "@material/menu/mdc-menu.scss"; @import "@material/menu/mdc-menu.scss";

View File

@ -0,0 +1,31 @@
<script>
import "@material/select/helper-text/mdc-select-helper-text"
import { onMount } from "svelte"
import { MDCSelectHelperText } from "@material/select/helper-text"
import ClassBuilder from "../ClassBuilder.js"
const cb = new ClassBuilder("select-helper-text")
let helperText
let instance
export let id = ""
export let text = ""
export let persistent = false
onMount(() => {
if (!!helperText) {
instance = new MDCSelectHelperText(helperText)
return () => {
instance && instance.destroy()
instance = null
}
}
})
$: modifiers = { persistent }
$: props = { modifiers }
$: helperClass = cb.build({ props })
</script>
<p bind:this={helperText} {id} class={helperClass} aria-hidden="true">{text}</p>

View File

@ -0,0 +1,88 @@
<script>
import { onMount } from "svelte"
import { MDCSelect } from "@material/select"
import { generate } from "shortid"
import HelperText from "./HelperText.svelte"
import NotchedOutline from "../Common/NotchedOutline.svelte"
import FloatingLabel from "../Common/FloatingLabel.svelte"
import createItemsStore from "../Common/ItemStore.js"
import ClassBuilder from "../ClassBuilder.js"
const cb = new ClassBuilder("select", ["filled"])
let selectedItemsStore
let select
let selectList
let instance
let _helperId = ""
export let _bb
export let onSelect = items => {}
export let width = "400px"
export let variant = "filled"
export let disabled = false
export let required = false
export let label = ""
export let helperText = ""
export let persistent = false
onMount(() => {
_bb.setContext("BBMD:list:props", { singleSelection: true })
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
_helperId = generate()
if (!!select) {
instance = new MDCSelect(select)
debugger
return () => {
instance && instance.destroy()
instance = null
}
}
})
$: useNotchedOutline = variant === "outlined"
$: selectList && _bb.attachChildren(selectList)
$: modifiers = { variant, disabled, required, noLabel: !label }
$: props = { modifiers }
$: selectClass = cb.build({ props })
</script>
<div bind:this={select} id={_helperId} class={selectClass}>
<div class="mdc-select__anchor" style={`width: ${width}`}>
<i class="mdc-select__dropdown-icon" />
<div
id={_helperId}
class="mdc-select__selected-text"
aria-required={required}
aria-controls={_helperId}
aria-describedby={_helperId} />
{#if useNotchedOutline}
<NotchedOutline>
<FloatingLabel text={label} />
</NotchedOutline>
{:else}
<FloatingLabel text={label} />
<div class="mdc-line-ripple" />
{/if}
</div>
<div
class="mdc-select__menu mdc-menu mdc-menu-surface"
role="listbox"
style={`width: ${width}`}>
<ul bind:this={selectList} class="mdc-list" />
</div>
</div>
<HelperText id={_helperId} text={helperText} {persistent} />

View File

@ -0,0 +1,4 @@
@use "@material/list/mdc-list";
@use "@material/menu-surface/mdc-menu-surface";
@use "@material/menu/mdc-menu";
@use "@material/select/mdc-select";

View File

@ -0,0 +1,3 @@
import "./_style.scss"
export { default as HelperText } from "./HelperText.svelte"
export { default as Select } from "./Select.svelte";

View File

@ -14,8 +14,9 @@
Radiobuttongroup, Radiobuttongroup,
Datatable, Datatable,
CustomersIndexTable, CustomersIndexTable,
List,
Icon, Icon,
List,
Select,
} = props } = props
let currentComponent let currentComponent
@ -36,6 +37,7 @@
Datatable, Datatable,
CustomersIndexTable, CustomersIndexTable,
List, List,
Select,
], ],
}, },
} }

View File

@ -119,7 +119,7 @@ export const props = {
_component: "@budibase/materialdesign-components/List", _component: "@budibase/materialdesign-components/List",
variant: "two-line", variant: "two-line",
singleSelection: false, singleSelection: false,
onSelect: selected => console.log(selected), onSelect: selected => console.log("LIST SELECT", selected),
_children: [ _children: [
{ {
_component: "@budibase/materialdesign-components/ListItem", _component: "@budibase/materialdesign-components/ListItem",
@ -144,6 +144,33 @@ export const props = {
secondaryText: "Salmon or Cod", secondaryText: "Salmon or Cod",
value: 2, value: 2,
}, },
] ],
},
Select: {
_component: "@budibase/materialdesign-components/Select",
label: "Choose a Milkshake",
helperText: "Choose a flavour",
persistent: true,
onSelect: selectedItem => console.log("SELECT ITEM", selectedItem),
_children: [
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Orange",
value: 0,
},
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Apple",
value: 1,
},
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Berry",
value: 0,
},
],
}, },
} }

View File

@ -71,7 +71,6 @@
let useIcon = !!icon && !textarea && !fullwidth let useIcon = !!icon && !textarea && !fullwidth
if (useIcon) { if (useIcon) {
setContext("BBMD:icon:context", "text-field")
let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon" let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon"
modifiers = { ...modifiers, iconClass } modifiers = { ...modifiers, iconClass }
} }
@ -124,7 +123,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
on:change={changed} /> on:change={changed} />
{:else} {:else}
{#if renderLeadingIcon} {#if renderLeadingIcon}
<Icon {icon} /> <Icon context="text-field" {icon} />
{/if} {/if}
<input <input
{id} {id}
@ -140,7 +139,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
on:focus={focus} on:focus={focus}
on:input={changed} /> on:input={changed} />
{#if renderTrailingIcon} {#if renderTrailingIcon}
<Icon {icon} /> <Icon context="text-field" {icon} />
{/if} {/if}
{#if variant !== 'outlined'} {#if variant !== 'outlined'}
<div class="mdc-line-ripple" /> <div class="mdc-line-ripple" />

View File

@ -17,3 +17,5 @@ export {
export { default as indexDatatable } from "./Templates/indexDatatable" export { default as indexDatatable } from "./Templates/indexDatatable"
export { default as recordForm } from "./Templates/recordForm" export { default as recordForm } from "./Templates/recordForm"
export { List, ListItem } from "./List" export { List, ListItem } from "./List"
export { Menu } from "./Menu"
export { Select } from "./Select"