Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
feat: added new actions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheComputerM committed Sep 9, 2020
1 parent 9cee4d1 commit be8e6c3
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/svelte-materialify/src/internal/BackgroundColor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable no-param-reassign */

const themeColors = ['primary', 'secondary', 'success', 'info', 'warning', 'error'];

/**
* @param node {Element}
* @param text {string|boolean}
*/
export default (node, text) => {
let klass;
if (text) {
if (/^#([0-9A-F]{3}){1,2}$/i.test(text)) {
// This is a CSS hex.
node.style.color = text;
klass = false;
} else if (themeColors.includes(text)) {
klass = `${text}-color`;
node.classList.add(klass);
} else if (text.startsWith('--')) {
// This is a CSS variable.
node.style.color = `var(${text})`;
klass = false;
} else {
klass = text;
node.classList.add(klass);
}
}

return {
update(newText) {
if (klass) {
node.classList.remove(klass);
} else {
node.style.color = null;
}

if (newText) {
if (/^#([0-9A-F]{3}){1,2}$/i.test(newText)) {
// This is a CSS hex.
node.style.color = newText;
klass = false;
} else if (themeColors.includes(newText)) {
klass = `${newText}-color`;
node.classList.add(klass);
} else if (text.startsWith('--')) {
// This is a CSS variable.
node.style.color = `var(${newText})`;
klass = false;
} else {
klass = `${newText}-text`;
node.classList.add(klass);
}
}
},
};
};
48 changes: 48 additions & 0 deletions packages/svelte-materialify/src/internal/TextColor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-param-reassign */

/**
* @param node {Element}
* @param text {string|boolean}
*/
export default (node, text) => {
let klass;
if (text) {
if (/^#([0-9A-F]{3}){1,2}$/i.test(text)) {
// This is a CSS hex.
node.style.color = text;
klass = false;
} else if (text.startsWith('--')) {
// This is a CSS variable.
node.style.color = `var(${text})`;
klass = false;
} else {
klass = `${text}-text`;
node.classList.add(klass);
}
}

return {
update(newText) {
if (klass) {
node.classList.remove(klass);
} else {
node.style.color = null;
}

if (newText) {
if (/^#([0-9A-F]{3}){1,2}$/i.test(newText)) {
// This is a CSS hex.
node.style.color = newText;
klass = false;
} else if (text.startsWith('--')) {
// This is a CSS variable.
node.style.color = `var(${newText})`;
klass = false;
} else {
klass = `${newText}-text`;
node.classList.add(klass);
}
}
},
};
};

0 comments on commit be8e6c3

Please sign in to comment.