Completed menu component
This commit is contained in:
parent
80a71ff671
commit
eb9e7c02fc
|
@ -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() {
|
|
||||||
let store = _bb.getContext("BBMD:list:selectItemStore")
|
|
||||||
if (!!store) {
|
|
||||||
selectedItemsStore = store
|
|
||||||
} else {
|
|
||||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
|
||||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
createOrAcceptItemStore()
|
let ctx = getContext("BBMD:list:context")
|
||||||
|
|
||||||
if (!_bb.getContext("BBMD:list:props")) {
|
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
||||||
_bb.setContext("BBMD:list:props", {
|
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
||||||
inputElement,
|
|
||||||
variant,
|
_bb.setContext("BBMD:list:props", {
|
||||||
singleSelection,
|
inputElement,
|
||||||
})
|
variant,
|
||||||
}
|
singleSelection,
|
||||||
|
})
|
||||||
|
|
||||||
if (!!list) {
|
if (!!list) {
|
||||||
if (!inputElement) {
|
if (!inputElement) {
|
||||||
|
|
|
@ -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}
|
||||||
|
|
|
@ -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() {
|
|
||||||
let store = _bb.getContext("BBMD:list:selectItemStore")
|
|
||||||
if (!!store) {
|
|
||||||
selectedItemsStore = store
|
|
||||||
} else {
|
|
||||||
selectedItemsStore = createItemsStore(() => onSelect($selectedItemsStore))
|
|
||||||
_bb.setContext("BBMD:list:selectItemStore", selectedItemsStore)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
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) {
|
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}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -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,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue