From 4e4470f240af2fbf81616520820b5732c73766e6 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 21 Feb 2020 13:39:18 +0000 Subject: [PATCH 1/3] 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" From 705ffacd337c0cbac6f45f1e5932e8fc5912e471 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 21 Feb 2020 14:00:20 +0000 Subject: [PATCH 2/3] Adding List divider --- .../src/List/List.svelte | 63 ++++++++++--------- .../src/Test/props.js | 2 +- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/packages/materialdesign-components/src/List/List.svelte b/packages/materialdesign-components/src/List/List.svelte index ddfb208119..61e19b030c 100644 --- a/packages/materialdesign-components/src/List/List.svelte +++ b/packages/materialdesign-components/src/List/List.svelte @@ -1,59 +1,59 @@
    @@ -63,5 +63,8 @@ {useDoubleLine} {inputElement} onClick={() => handleSelectedItem(item)} /> + {#if item.divider} +
    diff --git a/packages/materialdesign-components/src/Test/props.js b/packages/materialdesign-components/src/Test/props.js index d199d7ff67..852a845ad6 100644 --- a/packages/materialdesign-components/src/Test/props.js +++ b/packages/materialdesign-components/src/Test/props.js @@ -112,11 +112,11 @@ export const props = { { text: { primary: "Curry", secondary: "Chicken or Beef" }, value: 0, + divider: true, }, { text: { primary: "Pastie", secondary: "Bap with Mayo" }, value: 1, - selected: true, }, { text: { primary: "Fish", secondary: "Salmon or Cod" }, value: 2 }, ], From 43355bf2d320c1871e52a5eb6c7a4ab3c6e787fc Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 21 Feb 2020 15:00:42 +0000 Subject: [PATCH 3/3] Component JSON options update and related changes --- .../materialdesign-components/components.json | 45 +++++++++++++++---- .../src/Button/Button.svelte | 4 +- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/materialdesign-components/components.json b/packages/materialdesign-components/components.json index e62d30f5ef..a97c2a0267 100644 --- a/packages/materialdesign-components/components.json +++ b/packages/materialdesign-components/components.json @@ -28,9 +28,21 @@ "description": "A Material Design button with different variations. It renders as an anchor if href is passed to it.", "props": { "onClick": "event", - "variant": "string", - "colour": "string", - "size": "string", + "variant": { + "type": "options", + "options": ["text", "raised", "unelevated", "outlined"], + "default": "text" + }, + "colour": { + "type": "options", + "options": ["primary", "secondary"], + "default": "primary" + }, + "size": { + "type": "options", + "options": ["small", "medium", "large"], + "default": "medium" + }, "href": "string", "icon": "string", "trailingIcon": "bool", @@ -158,8 +170,7 @@ "props": { "onClick": "event", "id": "string", - "label": "string", - "names": "string", + "label": "string", "name": "string", "checked": "bool", "disabled": "bool", @@ -189,12 +200,28 @@ "props": { "onChange": "event", "label": "string", - "variant": "string", + "variant": { + "type": "options", + "options": ["standard", "outlined", "filled"], + "default": "standard" + }, "disabled": "bool", "fullwidth": "bool", - "colour":"string", - "size":"string", - "type": "string", + "colour": { + "type": "options", + "options": ["primary", "secondary"], + "default": "primary" + }, + "size":{ + "type": "options", + "options": ["small", "medium", "large"], + "default": "medium" + }, + "type": { + "type": "options", + "options": ["text", "password"], + "default": "text" + }, "required": "bool", "minLength": "number", "maxLength": "number", diff --git a/packages/materialdesign-components/src/Button/Button.svelte b/packages/materialdesign-components/src/Button/Button.svelte index e4157ea95b..411b99c394 100644 --- a/packages/materialdesign-components/src/Button/Button.svelte +++ b/packages/materialdesign-components/src/Button/Button.svelte @@ -4,11 +4,11 @@ import ripple from "../Common/Ripple.js" import ClassBuilder from "../ClassBuilder.js" - const cb = new ClassBuilder("button", ["primary", "medium"]) + const cb = new ClassBuilder("button", ["primary", "medium", "text"]) export let onClick = () => {} - export let variant = "raised" + export let variant = "text" export let colour = "primary" export let size = "medium"