From adfec3b85d04430469ebc4b53ec65353898a2dfd Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Mon, 2 Mar 2020 11:17:04 +0000 Subject: [PATCH 1/3] Starting menu refactor --- .../src/List/List.svelte | 10 +++++++ .../src/Menu/Menu.svelte | 26 ++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/materialdesign-components/src/List/List.svelte b/packages/materialdesign-components/src/List/List.svelte index ac375da4f3..3ba864e355 100644 --- a/packages/materialdesign-components/src/List/List.svelte +++ b/packages/materialdesign-components/src/List/List.svelte @@ -17,11 +17,21 @@ //items: [{text: string | {primary: string, secondary: string}, value: any, selected: bool}...n] export let items = [] export let singleSelection = false + export let inputElement = null let role = "listbox" onMount(() => { + createOrAcceptItemStore() + + if (!_bb.getContext("BBMD:list:props")) { + _bb.setContext("BBMD:list:props", { + inputElement, + variant, + singleSelection, + }) + } if (!!list) { instance = new MDCList(list) instance.singleSelection = singleSelection diff --git a/packages/materialdesign-components/src/Menu/Menu.svelte b/packages/materialdesign-components/src/Menu/Menu.svelte index 89c2404f4c..4121f41340 100644 --- a/packages/materialdesign-components/src/Menu/Menu.svelte +++ b/packages/materialdesign-components/src/Menu/Menu.svelte @@ -2,7 +2,10 @@ import { List } from "../List" import { MDCMenu } from "@material/menu" import { onMount, setContext } from "svelte" - export let items = [] + import createItemsStore from "../Common/ItemStore.js" + + export let onSelect = selectedItems => {} + export let singleSelection = true export let width = "400px" export let open = true @@ -11,10 +14,25 @@ //{x: number, y: number} export let absolutePositionCoords = null + export let _bb + let menu = 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() + if (!!menu) { instance = new MDCMenu(menu) instance.open = open @@ -27,6 +45,8 @@ } setContext("BBMD:list:context", "menu") }) + + $: menu && _bb.attachChildren(menu) {#if useFixedPosition || useAbsolutePosition} @@ -34,7 +54,7 @@ bind:this={menu} class="mdc-menu mdc-menu-surface" style={`width: ${width}`}> - + {:else}
@@ -44,7 +64,7 @@ bind:this={menu} class="mdc-menu mdc-menu-surface" style={`width: ${width}`}> - +
{/if} From cb72266c81c1eb0590d9afb1d25e40ba3b00fcff Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Mon, 2 Mar 2020 11:40:16 +0000 Subject: [PATCH 2/3] Commit before pull --- .../src/Menu/Menu.svelte | 2 -- .../src/Test/TestApp.svelte | 2 ++ .../src/Test/props.js | 23 +++++++++++++++++++ .../materialdesign-components/src/index.js | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/materialdesign-components/src/Menu/Menu.svelte b/packages/materialdesign-components/src/Menu/Menu.svelte index 4121f41340..b601d38f3e 100644 --- a/packages/materialdesign-components/src/Menu/Menu.svelte +++ b/packages/materialdesign-components/src/Menu/Menu.svelte @@ -45,8 +45,6 @@ } setContext("BBMD:list:context", "menu") }) - - $: menu && _bb.attachChildren(menu) {#if useFixedPosition || useAbsolutePosition} diff --git a/packages/materialdesign-components/src/Test/TestApp.svelte b/packages/materialdesign-components/src/Test/TestApp.svelte index b6c40fa895..63fec32977 100644 --- a/packages/materialdesign-components/src/Test/TestApp.svelte +++ b/packages/materialdesign-components/src/Test/TestApp.svelte @@ -16,6 +16,7 @@ CustomersIndexTable, List, Icon, + Menu, } = props let currentComponent @@ -40,6 +41,7 @@ Datatable, CustomersIndexTable, List, + Menu, ], }, } diff --git a/packages/materialdesign-components/src/Test/props.js b/packages/materialdesign-components/src/Test/props.js index c10cce0161..3503631a86 100644 --- a/packages/materialdesign-components/src/Test/props.js +++ b/packages/materialdesign-components/src/Test/props.js @@ -152,4 +152,27 @@ export const props = { singleSelection: true, onSelect: selected => console.log(selected), }, + Menu: { + _component: "@budibase/materialdesign-components/Menu", + _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, + }, + ], + } } diff --git a/packages/materialdesign-components/src/index.js b/packages/materialdesign-components/src/index.js index 5dac37d7b6..3517b2ed7e 100644 --- a/packages/materialdesign-components/src/index.js +++ b/packages/materialdesign-components/src/index.js @@ -17,3 +17,4 @@ export { export { default as indexDatatable } from "./Templates/indexDatatable" export { default as recordForm } from "./Templates/recordForm" export { List, ListItem } from "./List" +export {Menu} from "./Menu" From eb9e7c02fc30b1b396c2dc07a34f700f8a4b4039 Mon Sep 17 00:00:00 2001 From: Conor Mack Date: Mon, 2 Mar 2020 14:43:06 +0000 Subject: [PATCH 3/3] Completed menu component --- .../src/List/List.svelte | 29 +++++++------------ .../src/List/ListItem.svelte | 6 ++-- .../src/Menu/Menu.svelte | 27 +++++++---------- .../src/Menu/_styles.scss | 1 + .../src/Test/TestApp.svelte | 4 +-- .../src/Test/props.js | 5 ++-- 6 files changed, 31 insertions(+), 41 deletions(-) diff --git a/packages/materialdesign-components/src/List/List.svelte b/packages/materialdesign-components/src/List/List.svelte index f1686c43ee..eae7018d1b 100644 --- a/packages/materialdesign-components/src/List/List.svelte +++ b/packages/materialdesign-components/src/List/List.svelte @@ -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) { diff --git a/packages/materialdesign-components/src/List/ListItem.svelte b/packages/materialdesign-components/src/List/ListItem.svelte index 775d73d2e2..979ea3e8b3 100644 --- a/packages/materialdesign-components/src/List/ListItem.svelte +++ b/packages/materialdesign-components/src/List/ListItem.svelte @@ -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 @@ {/if} +{#if dividerAfter} +