|
|
|
@ -1,16 +1,17 @@ |
|
|
|
/** |
|
|
|
* Helper to build a CSS string from a style object |
|
|
|
*/ |
|
|
|
const buildStyleString = (styles, selected) => { |
|
|
|
const buildStyleString = (styleObject, customStyles, selected) => { |
|
|
|
let str = "" |
|
|
|
if (selected) { |
|
|
|
styles.border = "2px solid #0055ff !important" |
|
|
|
} |
|
|
|
Object.entries(styles).forEach(([style, value]) => { |
|
|
|
Object.entries(styleObject).forEach(([style, value]) => { |
|
|
|
if (style && value != null) { |
|
|
|
str += `${style}: ${value}; ` |
|
|
|
} |
|
|
|
}) |
|
|
|
str += customStyles || "" |
|
|
|
if (selected) { |
|
|
|
str += ";border: 2px solid #0055ff !important;" |
|
|
|
} |
|
|
|
return str |
|
|
|
} |
|
|
|
|
|
|
|
@ -24,6 +25,7 @@ export const styleable = (node, styles = {}) => { |
|
|
|
// Creates event listeners and applies initial styles
|
|
|
|
const setupStyles = newStyles => { |
|
|
|
const selected = newStyles.selected |
|
|
|
const customStyles = newStyles.custom |
|
|
|
const normalStyles = newStyles.normal || {} |
|
|
|
const hoverStyles = { |
|
|
|
...normalStyles, |
|
|
|
@ -31,11 +33,11 @@ export const styleable = (node, styles = {}) => { |
|
|
|
} |
|
|
|
|
|
|
|
applyNormalStyles = () => { |
|
|
|
node.style = buildStyleString(normalStyles, selected) |
|
|
|
node.style = buildStyleString(normalStyles, customStyles, selected) |
|
|
|
} |
|
|
|
|
|
|
|
applyHoverStyles = () => { |
|
|
|
node.style = buildStyleString(hoverStyles, selected) |
|
|
|
node.style = buildStyleString(hoverStyles, customStyles, selected) |
|
|
|
} |
|
|
|
|
|
|
|
// Add listeners to toggle hover styles
|
|
|
|
|