This repository has been archived by the owner on Sep 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cee4d1
commit be8e6c3
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
packages/svelte-materialify/src/internal/BackgroundColor/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
packages/svelte-materialify/src/internal/TextColor/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}, | ||
}; | ||
}; |