From 4e4470f240af2fbf81616520820b5732c73766e6 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 21 Feb 2020 13:39:18 +0000 Subject: [PATCH] Completed List Component and related changes to Radio and Check Components --- .../materialdesign-components/package.json | 1 + .../src/Checkbox/Checkbox.svelte | 82 +++++++++++++------ .../src/List/List.svelte | 67 +++++++++++++++ .../src/List/ListItem.svelte | 59 +++++++++++++ .../src/List/_style.scss | 1 + .../src/List/index.js | 2 + .../src/Radiobutton/Radiobutton.svelte | 38 +++++++-- .../src/Radiobutton/RadiobuttonGroup.svelte | 2 +- .../src/Test/TestApp.svelte | 4 +- .../src/Test/props.js | 19 +++++ .../materialdesign-components/src/index.js | 1 + 11 files changed, 244 insertions(+), 32 deletions(-) create mode 100644 packages/materialdesign-components/src/List/List.svelte create mode 100644 packages/materialdesign-components/src/List/ListItem.svelte create mode 100644 packages/materialdesign-components/src/List/_style.scss create mode 100644 packages/materialdesign-components/src/List/index.js diff --git a/packages/materialdesign-components/package.json b/packages/materialdesign-components/package.json index 22a172766f..02997ee31e 100644 --- a/packages/materialdesign-components/package.json +++ b/packages/materialdesign-components/package.json @@ -44,6 +44,7 @@ "@material/checkbox": "^4.0.0", "@material/data-table": "4.0.0", "@material/form-field": "^4.0.0", + "@material/list": "4.0.0", "@material/radio": "^4.0.0", "@material/textfield": "^4.0.0" } diff --git a/packages/materialdesign-components/src/Checkbox/Checkbox.svelte b/packages/materialdesign-components/src/Checkbox/Checkbox.svelte index 7466e84be2..bfe861f373 100644 --- a/packages/materialdesign-components/src/Checkbox/Checkbox.svelte +++ b/packages/materialdesign-components/src/Checkbox/Checkbox.svelte @@ -1,41 +1,73 @@ - +{#if context !== 'list-item'} + +
+ +
+ + + +
+
+
+
+ +{:else}
- +{/if} diff --git a/packages/materialdesign-components/src/List/List.svelte b/packages/materialdesign-components/src/List/List.svelte new file mode 100644 index 0000000000..ddfb208119 --- /dev/null +++ b/packages/materialdesign-components/src/List/List.svelte @@ -0,0 +1,67 @@ + + +
+ {#each items as item, i} + handleSelectedItem(item)} /> + {/each} +
diff --git a/packages/materialdesign-components/src/List/ListItem.svelte b/packages/materialdesign-components/src/List/ListItem.svelte new file mode 100644 index 0000000000..d2b72b1166 --- /dev/null +++ b/packages/materialdesign-components/src/List/ListItem.svelte @@ -0,0 +1,59 @@ + + +
  • + {#if item.leadingIcon} + + {/if} + + {#if useDoubleLine} + {item.text.primary} + {#if useSecondaryText} + {item.text.secondary} + {/if} + {:else}{item.text}{/if} + + + {#if inputElement} + {#if inputElement === 'radiobutton'} + + {:else if inputElement === 'checkbox'} + + {/if} + {:else if item.trailingIcon} + + + {/if} +
  • diff --git a/packages/materialdesign-components/src/List/_style.scss b/packages/materialdesign-components/src/List/_style.scss new file mode 100644 index 0000000000..7ebce7254c --- /dev/null +++ b/packages/materialdesign-components/src/List/_style.scss @@ -0,0 +1 @@ +@import "@material/list/mdc-list.scss"; diff --git a/packages/materialdesign-components/src/List/index.js b/packages/materialdesign-components/src/List/index.js new file mode 100644 index 0000000000..1db72f9273 --- /dev/null +++ b/packages/materialdesign-components/src/List/index.js @@ -0,0 +1,2 @@ +import "./_style.scss"; +export { default as List } from "./List.svelte"; diff --git a/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte b/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte index 9ebc5bb7f2..9b4c475241 100644 --- a/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte +++ b/packages/materialdesign-components/src/Radiobutton/Radiobutton.svelte @@ -16,22 +16,50 @@ let instance = null let radiobtn = null + let context = getContext("BBMD:input:context") + onMount(() => { if (!!radiobtn) { instance = new MDCRadio(radiobtn) - let fieldStore = getContext("BBMD:field-element") - fieldStore.setInput(instance) + if (context !== "list-item") { + let fieldStore = getContext("BBMD:field-element") + fieldStore.setInput(instance) + } } }) + let extras = null + + if (context === "list-item") { + extras = ["mdc-list-item__meta"] + } + const cb = new ClassBuilder("radio") let modifiers = { disabled } - let props = { modifiers } + let props = { modifiers, extras } const blockClass = cb.build({ props }) - +{#if context !== 'list-item'} + +
    + +
    +
    +
    +
    +
    +
    + +{:else}
    - +{/if} diff --git a/packages/materialdesign-components/src/Radiobutton/RadiobuttonGroup.svelte b/packages/materialdesign-components/src/Radiobutton/RadiobuttonGroup.svelte index 350251549f..c0b083db3c 100644 --- a/packages/materialdesign-components/src/Radiobutton/RadiobuttonGroup.svelte +++ b/packages/materialdesign-components/src/Radiobutton/RadiobuttonGroup.svelte @@ -37,7 +37,7 @@ {name} {alignEnd} label={item.label} - checked={item.checked} + checked={item.checked || false} onClick={() => handleOnClick(item)} />
    {/each} diff --git a/packages/materialdesign-components/src/Test/TestApp.svelte b/packages/materialdesign-components/src/Test/TestApp.svelte index 229f5293e9..6fce993281 100644 --- a/packages/materialdesign-components/src/Test/TestApp.svelte +++ b/packages/materialdesign-components/src/Test/TestApp.svelte @@ -13,6 +13,7 @@ Radiobuttongroup, Datatable, CustomersIndexTable, + List, } = props let currentComponent @@ -33,7 +34,8 @@ Radiobutton, Radiobuttongroup, Datatable, - CustomersIndexTable + CustomersIndexTable, + List, ], }, } diff --git a/packages/materialdesign-components/src/Test/props.js b/packages/materialdesign-components/src/Test/props.js index 43da839f65..d199d7ff67 100644 --- a/packages/materialdesign-components/src/Test/props.js +++ b/packages/materialdesign-components/src/Test/props.js @@ -103,4 +103,23 @@ export const props = { }, CustomersIndexTable: indexDatatable(templateOptions)[0].props, + List: { + _component: "@budibase/materialdesign-components/List", + _children: [], + variant: "two-line", + singleSelection: true, + items: [ + { + text: { primary: "Curry", secondary: "Chicken or Beef" }, + value: 0, + }, + { + text: { primary: "Pastie", secondary: "Bap with Mayo" }, + value: 1, + selected: true, + }, + { text: { primary: "Fish", secondary: "Salmon or Cod" }, value: 2 }, + ], + onSelect: selected => console.log(selected), + }, } diff --git a/packages/materialdesign-components/src/index.js b/packages/materialdesign-components/src/index.js index 92bdf2ca8e..88ca8190c4 100644 --- a/packages/materialdesign-components/src/index.js +++ b/packages/materialdesign-components/src/index.js @@ -15,3 +15,4 @@ export { DatatableRow, } from "./Datatable" export { default as indexDatatable } from "./Templates/indexDatatable" +export { List } from "./List"