Starting menu refactor
This commit is contained in:
parent
e862675956
commit
adfec3b85d
|
@ -17,11 +17,21 @@
|
||||||
//items: [{text: string | {primary: string, secondary: string}, value: any, selected: bool}...n]
|
//items: [{text: string | {primary: string, secondary: string}, value: any, selected: bool}...n]
|
||||||
export let items = []
|
export let items = []
|
||||||
export let singleSelection = false
|
export let singleSelection = false
|
||||||
|
|
||||||
export let inputElement = null
|
export let inputElement = null
|
||||||
|
|
||||||
let role = "listbox"
|
let role = "listbox"
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
createOrAcceptItemStore()
|
||||||
|
|
||||||
|
if (!_bb.getContext("BBMD:list:props")) {
|
||||||
|
_bb.setContext("BBMD:list:props", {
|
||||||
|
inputElement,
|
||||||
|
variant,
|
||||||
|
singleSelection,
|
||||||
|
})
|
||||||
|
}
|
||||||
if (!!list) {
|
if (!!list) {
|
||||||
instance = new MDCList(list)
|
instance = new MDCList(list)
|
||||||
instance.singleSelection = singleSelection
|
instance.singleSelection = singleSelection
|
||||||
|
|
|
@ -2,7 +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 onSelect = selectedItems => {}
|
||||||
|
|
||||||
export let singleSelection = true
|
export let singleSelection = true
|
||||||
export let width = "400px"
|
export let width = "400px"
|
||||||
export let open = true
|
export let open = true
|
||||||
|
@ -11,10 +14,25 @@
|
||||||
//{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 instance = 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(() => {
|
onMount(() => {
|
||||||
|
createOrAcceptItemStore()
|
||||||
|
|
||||||
if (!!menu) {
|
if (!!menu) {
|
||||||
instance = new MDCMenu(menu)
|
instance = new MDCMenu(menu)
|
||||||
instance.open = open
|
instance.open = open
|
||||||
|
@ -27,6 +45,8 @@
|
||||||
}
|
}
|
||||||
setContext("BBMD:list:context", "menu")
|
setContext("BBMD:list:context", "menu")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$: menu && _bb.attachChildren(menu)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if useFixedPosition || useAbsolutePosition}
|
{#if useFixedPosition || useAbsolutePosition}
|
||||||
|
@ -34,7 +54,7 @@
|
||||||
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} />
|
<List {singleSelection} {_bb} />
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="mdc-menu-surface--anchor">
|
<div class="mdc-menu-surface--anchor">
|
||||||
|
@ -44,7 +64,7 @@
|
||||||
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} />
|
<List {singleSelection} {_bb} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in New Issue