Merge branch 'master' of github.com:Budibase/budibase
This commit is contained in:
commit
910251e167
|
@ -46,5 +46,8 @@
|
|||
],
|
||||
"version": "0.0.24",
|
||||
"license": "MIT",
|
||||
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072"
|
||||
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072",
|
||||
"dependencies": {
|
||||
"@material/select": "4.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@
|
|||
|
||||
const clicked = () => _bb.call(onClick)
|
||||
|
||||
$: if (icon) {
|
||||
setContext("BBMD:icon:context", "button")
|
||||
}
|
||||
|
||||
$: renderLeadingIcon = !!icon && !trailingIcon
|
||||
$: renderTrailingIcon = !!icon && trailingIcon
|
||||
</script>
|
||||
|
@ -54,11 +50,11 @@
|
|||
{disabled}
|
||||
on:click={clicked}>
|
||||
{#if renderLeadingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="button" {icon} />
|
||||
{/if}
|
||||
<span class={labelClass}>{text}</span>
|
||||
{#if renderTrailingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="button" {icon} />
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
import { getContext } from "svelte"
|
||||
|
||||
export let icon = ""
|
||||
export let context = ""
|
||||
|
||||
let iconContext = getContext("BBMD:icon:context")
|
||||
let cls = iconContext
|
||||
? `material-icons mdc-${iconContext}__icon`
|
||||
: "material-icons"
|
||||
let cls = !!context ? `material-icons mdc-${context}__icon` : "material-icons"
|
||||
</script>
|
||||
|
||||
<i class={cls}>{icon}</i>
|
||||
|
|
|
@ -17,31 +17,25 @@
|
|||
export let onSelect = selectedItems => {}
|
||||
|
||||
export let singleSelection = false
|
||||
export let variant = "two-line"
|
||||
export let variant = "one-line"
|
||||
export let inputElement = null
|
||||
|
||||
let selectedItemsStore
|
||||
|
||||
let role = "listbox"
|
||||
|
||||
function createOrAcceptItemStore() {
|
||||
let store = _bb.getContext("BBMD:list:selectItemStore")
|
||||
if (!!store) {
|
||||
selectedItemsStore = store
|
||||
} else {
|
||||
onMount(() => {
|
||||
let ctx = getContext("BBMD:list:context")
|
||||
|
||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createOrAcceptItemStore()
|
||||
|
||||
_bb.setContext("BBMD:list:props", {
|
||||
inputElement,
|
||||
variant,
|
||||
singleSelection,
|
||||
})
|
||||
|
||||
if (!!list) {
|
||||
if (!inputElement) {
|
||||
instance = new MDCList(list)
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
import { onMount, getContext } from "svelte"
|
||||
import { Radiobutton } from "../Radiobutton"
|
||||
import { Checkbox } from "../Checkbox"
|
||||
import Icon from "../Common/Icon.svelte"
|
||||
import ClassBuilder from "../ClassBuilder.js"
|
||||
import { generate } from "shortid"
|
||||
|
||||
const cb = new ClassBuilder("list-item")
|
||||
|
||||
export let onClick = item => {}
|
||||
|
||||
let _id
|
||||
let listProps = null
|
||||
|
||||
|
@ -16,7 +15,7 @@
|
|||
|
||||
export let _bb
|
||||
|
||||
export let value = null
|
||||
export let value = ""
|
||||
export let text = ""
|
||||
export let secondaryText = ""
|
||||
|
||||
|
@ -24,6 +23,7 @@
|
|||
export let trailingIcon = ""
|
||||
export let selected = false
|
||||
export let disabled = false
|
||||
export let dividerAfter = false
|
||||
|
||||
let role = "option"
|
||||
|
||||
|
@ -84,7 +84,13 @@
|
|||
listProps && listProps.variant === "two-line" && !!secondaryText
|
||||
</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}
|
||||
<span class="mdc-list-item__graphic material-icons" aria-hidden="true">
|
||||
{leadingIcon}
|
||||
|
@ -104,9 +110,9 @@
|
|||
<Checkbox checked={isSelected} {disabled} {_bb} />
|
||||
{/if}
|
||||
{:else if trailingIcon}
|
||||
<!-- TODO: Adapt label to accept class prop to handle this. Context is insufficient -->
|
||||
<span class="mdc-list-item__meta material-icons" aria-hidden="true">
|
||||
{trailingIcon}
|
||||
</span>
|
||||
<Icon context="list-item__meta" icon={trailingIcon} />
|
||||
{/if}
|
||||
</li>
|
||||
{#if dividerAfter}
|
||||
<li class="mdc-list-divider" role="separator" />
|
||||
{/if}
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
import { List } from "../List"
|
||||
import { MDCMenu } from "@material/menu"
|
||||
import { onMount, setContext } from "svelte"
|
||||
export let items = []
|
||||
export let singleSelection = true
|
||||
import createItemsStore from "../Common/ItemStore.js"
|
||||
|
||||
export let onSelect = selectedItems => {}
|
||||
|
||||
export let width = "400px"
|
||||
export let open = true
|
||||
export let useFixedPosition = false
|
||||
|
@ -11,10 +13,20 @@
|
|||
//{x: number, y: number}
|
||||
export let absolutePositionCoords = null
|
||||
|
||||
export let _bb
|
||||
|
||||
let menu = null
|
||||
let menuList = null
|
||||
let instance = null
|
||||
let selectedItemsStore
|
||||
|
||||
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) {
|
||||
instance = new MDCMenu(menu)
|
||||
instance.open = open
|
||||
|
@ -25,8 +37,9 @@
|
|||
instance.setAbsolutePosition(x | 0, y | 0)
|
||||
}
|
||||
}
|
||||
setContext("BBMD:list:context", "menu")
|
||||
})
|
||||
|
||||
$: menuList && _bb.attachChildren(menuList)
|
||||
</script>
|
||||
|
||||
{#if useFixedPosition || useAbsolutePosition}
|
||||
|
@ -34,17 +47,17 @@
|
|||
bind:this={menu}
|
||||
class="mdc-menu mdc-menu-surface"
|
||||
style={`width: ${width}`}>
|
||||
<List {items} {singleSelection} />
|
||||
<ul bind:this={menuList} class="mdc-list" role="menu" />
|
||||
</div>
|
||||
{:else}
|
||||
<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 />
|
||||
<div
|
||||
bind:this={menu}
|
||||
class="mdc-menu mdc-menu-surface"
|
||||
style={`width: ${width}`}>
|
||||
<List {items} {singleSelection} />
|
||||
<ul bind:this={menuList} class="mdc-list" role="menu" />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
@import "@material/list/mdc-list.scss";
|
||||
@import "@material/menu-surface/mdc-menu-surface.scss";
|
||||
@import "@material/menu/mdc-menu.scss";
|
||||
|
|
|
@ -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>
|
|
@ -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} />
|
|
@ -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";
|
|
@ -0,0 +1,3 @@
|
|||
import "./_style.scss"
|
||||
export { default as HelperText } from "./HelperText.svelte"
|
||||
export { default as Select } from "./Select.svelte";
|
|
@ -14,8 +14,9 @@
|
|||
Radiobuttongroup,
|
||||
Datatable,
|
||||
CustomersIndexTable,
|
||||
List,
|
||||
Icon,
|
||||
List,
|
||||
Select,
|
||||
} = props
|
||||
|
||||
let currentComponent
|
||||
|
@ -36,6 +37,7 @@
|
|||
Datatable,
|
||||
CustomersIndexTable,
|
||||
List,
|
||||
Select,
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ export const props = {
|
|||
_component: "@budibase/materialdesign-components/List",
|
||||
variant: "two-line",
|
||||
singleSelection: false,
|
||||
onSelect: selected => console.log(selected),
|
||||
onSelect: selected => console.log("LIST SELECT", selected),
|
||||
_children: [
|
||||
{
|
||||
_component: "@budibase/materialdesign-components/ListItem",
|
||||
|
@ -144,6 +144,33 @@ export const props = {
|
|||
secondaryText: "Salmon or Cod",
|
||||
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,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@
|
|||
let useIcon = !!icon && !textarea && !fullwidth
|
||||
|
||||
if (useIcon) {
|
||||
setContext("BBMD:icon:context", "text-field")
|
||||
let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon"
|
||||
modifiers = { ...modifiers, iconClass }
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
|||
on:change={changed} />
|
||||
{:else}
|
||||
{#if renderLeadingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="text-field" {icon} />
|
||||
{/if}
|
||||
<input
|
||||
{id}
|
||||
|
@ -140,7 +139,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
|||
on:focus={focus}
|
||||
on:input={changed} />
|
||||
{#if renderTrailingIcon}
|
||||
<Icon {icon} />
|
||||
<Icon context="text-field" {icon} />
|
||||
{/if}
|
||||
{#if variant !== 'outlined'}
|
||||
<div class="mdc-line-ripple" />
|
||||
|
|
|
@ -17,3 +17,5 @@ export {
|
|||
export { default as indexDatatable } from "./Templates/indexDatatable"
|
||||
export { default as recordForm } from "./Templates/recordForm"
|
||||
export { List, ListItem } from "./List"
|
||||
export { Menu } from "./Menu"
|
||||
export { Select } from "./Select"
|
||||
|
|
Loading…
Reference in New Issue