From 6785198c62de538d7f860039470e411c2440a4f1 Mon Sep 17 00:00:00 2001 From: Conor Mack Date: Tue, 3 Mar 2020 15:23:03 +0000 Subject: [PATCH 1/2] Completed MD Select --- .../materialdesign-components/package.json | 5 +- .../src/Button/Button.svelte | 8 +- .../src/Common/Icon.svelte | 6 +- .../src/List/ListItem.svelte | 16 ++-- .../src/Select/HelperText.svelte | 31 +++++++ .../src/Select/Select.svelte | 87 +++++++++++++++++++ .../src/Select/_style.scss | 4 + .../src/Select/index.js | 2 + .../src/Test/TestApp.svelte | 4 +- .../src/Test/props.js | 18 ++-- .../src/Textfield/Textfield.svelte | 5 +- .../materialdesign-components/src/index.js | 3 +- 12 files changed, 158 insertions(+), 31 deletions(-) create mode 100644 packages/materialdesign-components/src/Select/HelperText.svelte create mode 100644 packages/materialdesign-components/src/Select/Select.svelte create mode 100644 packages/materialdesign-components/src/Select/_style.scss create mode 100644 packages/materialdesign-components/src/Select/index.js diff --git a/packages/materialdesign-components/package.json b/packages/materialdesign-components/package.json index ba2e4dc891..1629b78963 100644 --- a/packages/materialdesign-components/package.json +++ b/packages/materialdesign-components/package.json @@ -46,5 +46,8 @@ ], "version": "0.0.24", "license": "MIT", - "gitHead": "115189f72a850bfb52b65ec61d932531bf327072" + "gitHead": "115189f72a850bfb52b65ec61d932531bf327072", + "dependencies": { + "@material/select": "4.0.0" + } } diff --git a/packages/materialdesign-components/src/Button/Button.svelte b/packages/materialdesign-components/src/Button/Button.svelte index 84e3395987..7c8821547a 100644 --- a/packages/materialdesign-components/src/Button/Button.svelte +++ b/packages/materialdesign-components/src/Button/Button.svelte @@ -34,10 +34,6 @@ const clicked = () => _bb.call(onClick) - $: if (icon) { - setContext("BBMD:icon:context", "button") - } - $: renderLeadingIcon = !!icon && !trailingIcon $: renderTrailingIcon = !!icon && trailingIcon @@ -54,11 +50,11 @@ {disabled} on:click={clicked}> {#if renderLeadingIcon} - + {/if} {text} {#if renderTrailingIcon} - + {/if} {/if} diff --git a/packages/materialdesign-components/src/Common/Icon.svelte b/packages/materialdesign-components/src/Common/Icon.svelte index e2c309f73e..d4820fcf6c 100644 --- a/packages/materialdesign-components/src/Common/Icon.svelte +++ b/packages/materialdesign-components/src/Common/Icon.svelte @@ -2,11 +2,9 @@ import { getContext } from "svelte" export let icon = "" + export let context = "" - let iconContext = getContext("BBMD:icon:context") - let cls = iconContext - ? `material-icons mdc-${iconContext}__icon` - : "material-icons" + let cls = !!context ? `material-icons mdc-${context}__icon` : "material-icons" {icon} diff --git a/packages/materialdesign-components/src/List/ListItem.svelte b/packages/materialdesign-components/src/List/ListItem.svelte index 979ea3e8b3..f60396ae4d 100644 --- a/packages/materialdesign-components/src/List/ListItem.svelte +++ b/packages/materialdesign-components/src/List/ListItem.svelte @@ -2,6 +2,7 @@ import { onMount, getContext } from "svelte" import { Radiobutton } from "../Radiobutton" import { Checkbox } from "../Checkbox" + import Icon from "../Common/Icon.svelte" import ClassBuilder from "../ClassBuilder.js" import { generate } from "shortid" @@ -14,7 +15,7 @@ export let _bb - export let value = null + export let value = "" export let text = "" export let secondaryText = "" @@ -83,7 +84,13 @@ listProps && listProps.variant === "two-line" && !!secondaryText -
  • +
  • {#if leadingIcon}
  • {#if dividerAfter} diff --git a/packages/materialdesign-components/src/Select/HelperText.svelte b/packages/materialdesign-components/src/Select/HelperText.svelte new file mode 100644 index 0000000000..0e0016f3df --- /dev/null +++ b/packages/materialdesign-components/src/Select/HelperText.svelte @@ -0,0 +1,31 @@ + + +

    {text}

    diff --git a/packages/materialdesign-components/src/Select/Select.svelte b/packages/materialdesign-components/src/Select/Select.svelte new file mode 100644 index 0000000000..d146f4b001 --- /dev/null +++ b/packages/materialdesign-components/src/Select/Select.svelte @@ -0,0 +1,87 @@ + + +
    +
    + +
    + + {#if useNotchedOutline} + + + + {:else} + +
    + {/if} + +
    + +
    + +
      + +
    +
    + diff --git a/packages/materialdesign-components/src/Select/_style.scss b/packages/materialdesign-components/src/Select/_style.scss new file mode 100644 index 0000000000..e58101303e --- /dev/null +++ b/packages/materialdesign-components/src/Select/_style.scss @@ -0,0 +1,4 @@ +@use "@material/list/mdc-list"; +@use "@material/menu-surface/mdc-menu-surface"; +@use "@material/menu/mdc-menu"; +@use "@material/select/mdc-select"; \ No newline at end of file diff --git a/packages/materialdesign-components/src/Select/index.js b/packages/materialdesign-components/src/Select/index.js new file mode 100644 index 0000000000..fbfce001c1 --- /dev/null +++ b/packages/materialdesign-components/src/Select/index.js @@ -0,0 +1,2 @@ +import "./_style.scss" +export { default as Select } from "./Select.svelte"; \ No newline at end of file diff --git a/packages/materialdesign-components/src/Test/TestApp.svelte b/packages/materialdesign-components/src/Test/TestApp.svelte index e4320e94e9..bdea8413ed 100644 --- a/packages/materialdesign-components/src/Test/TestApp.svelte +++ b/packages/materialdesign-components/src/Test/TestApp.svelte @@ -15,8 +15,8 @@ Datatable, CustomersIndexTable, Icon, - Menu, List, + Select, } = props let currentComponent @@ -36,8 +36,8 @@ Icon, Datatable, CustomersIndexTable, - Menu, List, + Select, ], }, } diff --git a/packages/materialdesign-components/src/Test/props.js b/packages/materialdesign-components/src/Test/props.js index 039f056365..4e69766e12 100644 --- a/packages/materialdesign-components/src/Test/props.js +++ b/packages/materialdesign-components/src/Test/props.js @@ -144,29 +144,31 @@ export const props = { secondaryText: "Salmon or Cod", value: 2, }, - ] + ], }, - Menu: { - _component: "@budibase/materialdesign-components/Menu", - onSelect: items => console.log("MENU SELECT", items), + Select: { + _component: "@budibase/materialdesign-components/Select", + label: "Choose a Milkshake", + helperText: "Choose a flavour", + onSelect: selectedItem => console.log("SELECT ITEM", selectedItem), _children: [ { _component: "@budibase/materialdesign-components/ListItem", _children: [], - text: "Settings", + text: "Orange", value: 0, }, { _component: "@budibase/materialdesign-components/ListItem", _children: [], - text: "Account", + text: "Apple", value: 1, }, { _component: "@budibase/materialdesign-components/ListItem", _children: [], - text: "Profile", - value: 2, + text: "Berry", + value: 0, }, ], }, diff --git a/packages/materialdesign-components/src/Textfield/Textfield.svelte b/packages/materialdesign-components/src/Textfield/Textfield.svelte index a5d5517df0..7de3141e54 100644 --- a/packages/materialdesign-components/src/Textfield/Textfield.svelte +++ b/packages/materialdesign-components/src/Textfield/Textfield.svelte @@ -71,7 +71,6 @@ let useIcon = !!icon && !textarea && !fullwidth if (useIcon) { - setContext("BBMD:icon:context", "text-field") let iconClass = trailingIcon ? "with-trailing-icon" : "with-leading-icon" modifiers = { ...modifiers, iconClass } } @@ -124,7 +123,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors on:change={changed} /> {:else} {#if renderLeadingIcon} - + {/if} {#if renderTrailingIcon} - + {/if} {#if variant !== 'outlined'}
    diff --git a/packages/materialdesign-components/src/index.js b/packages/materialdesign-components/src/index.js index 3517b2ed7e..5e1df0081e 100644 --- a/packages/materialdesign-components/src/index.js +++ b/packages/materialdesign-components/src/index.js @@ -17,4 +17,5 @@ export { export { default as indexDatatable } from "./Templates/indexDatatable" export { default as recordForm } from "./Templates/recordForm" export { List, ListItem } from "./List" -export {Menu} from "./Menu" +export { Menu } from "./Menu" +export { Select } from "./Select" From cc2c6764ee06c8d836ef690583f7599838e13e0a Mon Sep 17 00:00:00 2001 From: Conor Mack Date: Wed, 4 Mar 2020 11:02:17 +0000 Subject: [PATCH 2/2] Completed MD Select --- .../materialdesign-components/src/Select/HelperText.svelte | 2 +- packages/materialdesign-components/src/Select/Select.svelte | 3 ++- packages/materialdesign-components/src/Select/index.js | 1 + packages/materialdesign-components/src/Test/props.js | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/materialdesign-components/src/Select/HelperText.svelte b/packages/materialdesign-components/src/Select/HelperText.svelte index 0e0016f3df..888f6e5267 100644 --- a/packages/materialdesign-components/src/Select/HelperText.svelte +++ b/packages/materialdesign-components/src/Select/HelperText.svelte @@ -28,4 +28,4 @@ $: helperClass = cb.build({ props }) -

    {text}

    + diff --git a/packages/materialdesign-components/src/Select/Select.svelte b/packages/materialdesign-components/src/Select/Select.svelte index d146f4b001..28cf58697f 100644 --- a/packages/materialdesign-components/src/Select/Select.svelte +++ b/packages/materialdesign-components/src/Select/Select.svelte @@ -27,6 +27,7 @@ export let required = false export let label = "" export let helperText = "" + export let persistent = false onMount(() => { _bb.setContext("BBMD:list:props", { singleSelection: true }) @@ -84,4 +85,4 @@
    - + diff --git a/packages/materialdesign-components/src/Select/index.js b/packages/materialdesign-components/src/Select/index.js index fbfce001c1..ee0c361c69 100644 --- a/packages/materialdesign-components/src/Select/index.js +++ b/packages/materialdesign-components/src/Select/index.js @@ -1,2 +1,3 @@ import "./_style.scss" +export { default as HelperText } from "./HelperText.svelte" export { default as Select } from "./Select.svelte"; \ No newline at end of file diff --git a/packages/materialdesign-components/src/Test/props.js b/packages/materialdesign-components/src/Test/props.js index 4e69766e12..942b031117 100644 --- a/packages/materialdesign-components/src/Test/props.js +++ b/packages/materialdesign-components/src/Test/props.js @@ -150,6 +150,7 @@ export const props = { _component: "@budibase/materialdesign-components/Select", label: "Choose a Milkshake", helperText: "Choose a flavour", + persistent: true, onSelect: selectedItem => console.log("SELECT ITEM", selectedItem), _children: [ {