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"