diff --git a/packages/materialdesign-components/package.json b/packages/materialdesign-components/package.json
index 15d80d9e50..f279bbc908 100644
--- a/packages/materialdesign-components/package.json
+++ b/packages/materialdesign-components/package.json
@@ -40,6 +40,8 @@
"license": "MIT",
"gitHead": "115189f72a850bfb52b65ec61d932531bf327072",
"dependencies": {
+ "@material/checkbox": "^4.0.0",
+ "@material/form-field": "^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
new file mode 100644
index 0000000000..3a48c444df
--- /dev/null
+++ b/packages/materialdesign-components/src/Checkbox/Checkbox.svelte
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
diff --git a/packages/materialdesign-components/src/Checkbox/_style.scss b/packages/materialdesign-components/src/Checkbox/_style.scss
new file mode 100644
index 0000000000..666f84c426
--- /dev/null
+++ b/packages/materialdesign-components/src/Checkbox/_style.scss
@@ -0,0 +1,2 @@
+@import "@material/form-field/mdc-form-field";
+@import "@material/checkbox/mdc-checkbox.scss";
diff --git a/packages/materialdesign-components/src/Checkbox/index.js b/packages/materialdesign-components/src/Checkbox/index.js
new file mode 100644
index 0000000000..3954d4062a
--- /dev/null
+++ b/packages/materialdesign-components/src/Checkbox/index.js
@@ -0,0 +1,2 @@
+import "./_style.scss";
+export { default as checkbox } from "./Checkbox.svelte";
diff --git a/packages/materialdesign-components/src/ClassBuilder.js b/packages/materialdesign-components/src/ClassBuilder.js
index 1e152ca1c6..cebed61f4f 100644
--- a/packages/materialdesign-components/src/ClassBuilder.js
+++ b/packages/materialdesign-components/src/ClassBuilder.js
@@ -1,38 +1,74 @@
export default class ClassBuilder {
- constructor(block, customDefaults) {
- this.block = `mdc-${block}`
- this.customDefaults = customDefaults //will be ignored when building custom classes
+ constructor(block, defaultIgnoreList) {
+ this.block = `mdc-${block}`;
+ this.defaultIgnoreList = defaultIgnoreList; //will be ignored when building custom classes
}
- // classParams: {modifiers:[] (mdc), custom:[] (bbmd), extra:[] (any)}
- blocks(classParams) {
- let base = this.block
- if (classParams == undefined) return base
- return this.buildClass(base, classParams)
+ /*
+ handles both blocks and elementss (BEM MD Notation)
+ params = {elementName: string, props: {modifiers{}, customs:{}, extras: []}}
+ All are optional
+ */
+ build(params) {
+ if (!params) return this.block; //return block if nothing passed
+ const { props, elementName } = params;
+ let base = !!elementName ? `${this.block}__${elementName}` : this.block;
+ if (!props) return base;
+ return this._handleProps(base, props);
}
- //elementName: string, classParams: {}
- elements(elementName, classParams) {
- let base = `${this.block}__${elementName}`
- if (classParams == undefined) return base
- return this.buildClass(base, classParams)
+ //Easily grab a simple element class
+ elem(elementName) {
+ return this.build({ elementName });
}
- buildClass(base, classParams) {
- let cls = base
- const { modifiers, customs, extras } = classParams
- if (modifiers) cls += modifiers.map(m => ` ${base}--${m}`).join(" ")
- if (customs)
- cls += Object.entries(customs)
- .map(([property, value]) => {
- //disregard falsy and values set by customDefaults constructor param
- if (!!value && !this.customDefaults.includes(value)) {
- //custom scss name convention = bbmd-[block | element]--[property]-[value]
- return ` bbmd-${base}--${property}-${value}`
+ //use if a different base is needed than whats defined by this.block
+ debase(base, elementProps) {
+ if (!elementProps) return base;
+ return this._handleProps(base, elementProps);
+ }
+
+ //proxies bindProps and checks for which elementProps exist before binding
+ _handleProps(base, elementProps) {
+ let cls = base;
+ const { modifiers, customs, extras } = elementProps;
+ if (!!modifiers) cls += this._bindProps(modifiers, base);
+ if (!!customs) cls += this._bindProps(customs, base, true);
+ if (!!extras) cls += ` ${extras.join(" ")}`;
+ return cls.trim();
+ }
+
+ /*
+ Handles both modifiers and customs. Use property, value or both depending
+ on whether it is passsed props for custom or modifiers
+ if custom uses the following convention for scss mixins:
+ bbmd-{this.block}--{property}-{value}
+ bbmd-mdc-button--size-large
+ */
+ _bindProps(elementProps, base, isCustom = false) {
+ return Object.entries(elementProps)
+ .map(([property, value]) => {
+ //disregard falsy and values set by defaultIgnoreList constructor param
+ if (
+ !!value &&
+ (!this.defaultIgnoreList || !this.defaultIgnoreList.includes(value))
+ ) {
+ let classBase = isCustom ? `bbmd-${base}` : `${base}`;
+ let valueType = typeof value;
+
+ if (valueType == "string" || valueType == "number") {
+ return isCustom
+ ? ` ${classBase}--${this._convertCamel(property)}-${value}`
+ : ` ${classBase}--${value}`;
+ } else if (valueType == "boolean") {
+ return ` ${classBase}--${this._convertCamel(property)}`;
}
- })
- .join("")
- if (extras) cls += ` ${extras.join(" ")}`
- return cls.trim()
+ }
+ })
+ .join("");
+ }
+
+ _convertCamel(str) {
+ return str.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
}
}
diff --git a/packages/materialdesign-components/src/Common/Formfield.svelte b/packages/materialdesign-components/src/Common/Formfield.svelte
new file mode 100644
index 0000000000..ec71ff2380
--- /dev/null
+++ b/packages/materialdesign-components/src/Common/Formfield.svelte
@@ -0,0 +1,35 @@
+
+
+
+
+
+
diff --git a/packages/materialdesign-components/src/Common/FormfieldStore.js b/packages/materialdesign-components/src/Common/FormfieldStore.js
new file mode 100644
index 0000000000..082b120ff5
--- /dev/null
+++ b/packages/materialdesign-components/src/Common/FormfieldStore.js
@@ -0,0 +1,19 @@
+import { writable } from "svelte/store";
+
+function store() {
+ const { set, update, subscribe } = writable({});
+
+ function setInput(inp) {
+ update(n => {
+ n.input = inp;
+ });
+ }
+
+ return {
+ subscribe,
+ set,
+ setInput
+ };
+}
+
+export const fieldStore = store();
diff --git a/packages/materialdesign-components/src/Test/TestApp.svelte b/packages/materialdesign-components/src/Test/TestApp.svelte
index 306ccb1169..bac1c09bb7 100644
--- a/packages/materialdesign-components/src/Test/TestApp.svelte
+++ b/packages/materialdesign-components/src/Test/TestApp.svelte
@@ -1,19 +1,22 @@
@@ -21,9 +24,7 @@
{#await _appPromise}
loading
{:then _bb}
-
-
{/await}