Merge pull request #134 from Conor-Mack/feature/menu-refactor

Feature/menu refactor
This commit is contained in:
Conor_Mack 2020-03-02 14:44:00 +00:00 committed by GitHub
commit 82187ef66c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 22 deletions

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

@ -7,8 +7,6 @@
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
@ -24,6 +22,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"
@ -110,3 +109,6 @@
</span> </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

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

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",
@ -146,4 +146,28 @@ export const props = {
}, },
] ]
}, },
Menu: {
_component: "@budibase/materialdesign-components/Menu",
onSelect: items => console.log("MENU SELECT", items),
_children: [
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Settings",
value: 0,
},
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Account",
value: 1,
},
{
_component: "@budibase/materialdesign-components/ListItem",
_children: [],
text: "Profile",
value: 2,
},
],
},
} }

View File

@ -17,3 +17,4 @@ 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"