Completed menu component

This commit is contained in:
Conor Mack 2020-03-02 14:43:06 +00:00
parent 80a71ff671
commit eb9e7c02fc
6 changed files with 31 additions and 41 deletions

View File

@ -17,33 +17,24 @@
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()
if (!_bb.getContext("BBMD:list:props")) {
_bb.setContext("BBMD:list:props", { _bb.setContext("BBMD:list:props", {
inputElement, inputElement,
variant, variant,
singleSelection, singleSelection,
}) })
}
if (!!list) { if (!!list) {
if (!inputElement) { if (!inputElement) {

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

@ -6,7 +6,6 @@
export let onSelect = selectedItems => {} export let onSelect = selectedItems => {}
export let singleSelection = true
export let width = "400px" export let width = "400px"
export let open = true export let open = true
export let useFixedPosition = false export let useFixedPosition = false
@ -17,21 +16,16 @@
export let _bb export let _bb
let menu = null let menu = null
let menuList = null
let instance = null let instance = null
let selectedItemsStore let selectedItemsStore
function createOrAcceptItemStore() { onMount(() => {
let store = _bb.getContext("BBMD:list:selectItemStore") _bb.setContext("BBMD:list:context", "menu")
if (!!store) { _bb.setContext("BBMD:list:props", { singleSelection: true })
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()
if (!!menu) { if (!!menu) {
instance = new MDCMenu(menu) instance = new MDCMenu(menu)
@ -43,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}
@ -52,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 {singleSelection} {_bb} /> <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 {singleSelection} {_bb} /> <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,9 +14,9 @@
Radiobuttongroup, Radiobuttongroup,
Datatable, Datatable,
CustomersIndexTable, CustomersIndexTable,
List,
Icon, Icon,
Menu, Menu,
List,
} = props } = props
let currentComponent let currentComponent
@ -36,8 +36,8 @@
Icon, Icon,
Datatable, Datatable,
CustomersIndexTable, CustomersIndexTable,
List,
Menu, Menu,
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",
@ -148,6 +148,7 @@ export const props = {
}, },
Menu: { Menu: {
_component: "@budibase/materialdesign-components/Menu", _component: "@budibase/materialdesign-components/Menu",
onSelect: items => console.log("MENU SELECT", items),
_children: [ _children: [
{ {
_component: "@budibase/materialdesign-components/ListItem", _component: "@budibase/materialdesign-components/ListItem",
@ -168,5 +169,5 @@ export const props = {
value: 2, value: 2,
}, },
], ],
} },
} }