Completed menu component
This commit is contained in:
parent
80a71ff671
commit
eb9e7c02fc
|
@ -17,33 +17,24 @@
|
|||
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 {
|
||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createOrAcceptItemStore()
|
||||
let ctx = getContext("BBMD:list:context")
|
||||
|
||||
if (!_bb.getContext("BBMD:list:props")) {
|
||||
_bb.setContext("BBMD:list:props", {
|
||||
inputElement,
|
||||
variant,
|
||||
singleSelection,
|
||||
})
|
||||
}
|
||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||
|
||||
_bb.setContext("BBMD:list:props", {
|
||||
inputElement,
|
||||
variant,
|
||||
singleSelection,
|
||||
})
|
||||
|
||||
if (!!list) {
|
||||
if (!inputElement) {
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
const cb = new ClassBuilder("list-item")
|
||||
|
||||
export let onClick = item => {}
|
||||
|
||||
let _id
|
||||
let listProps = null
|
||||
|
||||
|
@ -24,6 +22,7 @@
|
|||
export let trailingIcon = ""
|
||||
export let selected = false
|
||||
export let disabled = false
|
||||
export let dividerAfter = false
|
||||
|
||||
let role = "option"
|
||||
|
||||
|
@ -110,3 +109,6 @@
|
|||
</span>
|
||||
{/if}
|
||||
</li>
|
||||
{#if dividerAfter}
|
||||
<li class="mdc-list-divider" role="separator" />
|
||||
{/if}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
export let onSelect = selectedItems => {}
|
||||
|
||||
export let singleSelection = true
|
||||
export let width = "400px"
|
||||
export let open = true
|
||||
export let useFixedPosition = false
|
||||
|
@ -17,21 +16,16 @@
|
|||
export let _bb
|
||||
|
||||
let menu = null
|
||||
let menuList = null
|
||||
let instance = null
|
||||
let selectedItemsStore
|
||||
|
||||
function createOrAcceptItemStore() {
|
||||
let store = _bb.getContext("BBMD:list:selectItemStore")
|
||||
if (!!store) {
|
||||
selectedItemsStore = store
|
||||
} else {
|
||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
createOrAcceptItemStore()
|
||||
_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)
|
||||
|
@ -43,8 +37,9 @@
|
|||
instance.setAbsolutePosition(x | 0, y | 0)
|
||||
}
|
||||
}
|
||||
setContext("BBMD:list:context", "menu")
|
||||
})
|
||||
|
||||
$: menuList && _bb.attachChildren(menuList)
|
||||
</script>
|
||||
|
||||
{#if useFixedPosition || useAbsolutePosition}
|
||||
|
@ -52,17 +47,17 @@
|
|||
bind:this={menu}
|
||||
class="mdc-menu mdc-menu-surface"
|
||||
style={`width: ${width}`}>
|
||||
<List {singleSelection} {_bb} />
|
||||
<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 {singleSelection} {_bb} />
|
||||
<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";
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
Radiobuttongroup,
|
||||
Datatable,
|
||||
CustomersIndexTable,
|
||||
List,
|
||||
Icon,
|
||||
Menu,
|
||||
List,
|
||||
} = props
|
||||
|
||||
let currentComponent
|
||||
|
@ -36,8 +36,8 @@
|
|||
Icon,
|
||||
Datatable,
|
||||
CustomersIndexTable,
|
||||
List,
|
||||
Menu,
|
||||
List,
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
@ -148,6 +148,7 @@ export const props = {
|
|||
},
|
||||
Menu: {
|
||||
_component: "@budibase/materialdesign-components/Menu",
|
||||
onSelect: items => console.log("MENU SELECT", items),
|
||||
_children: [
|
||||
{
|
||||
_component: "@budibase/materialdesign-components/ListItem",
|
||||
|
@ -168,5 +169,5 @@ export const props = {
|
|||
value: 2,
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue