1
0
Fork 0
mirror of synced 2024-09-02 18:51:36 +12:00
budibase/packages/standard-components/src/helpers.js

33 lines
723 B
JavaScript

/**
* Capitalises a string.
*
* @param string
* @returns {string}
*/
export const capitalise = string => {
return string.substring(0, 1).toUpperCase() + string.substring(1)
}
/**
* Svelte action to set CSS variables on a DOM node.
*
* @param node
* @param props
*/
export const cssVars = (node, props) => {
Object.entries(props).forEach(([key, value]) => {
node.style.setProperty(`--${key}`, value)
})
return {
update(new_props) {
Object.entries(new_props).forEach(([key, value]) => {
node.style.setProperty(`--${key}`, value)
delete props[key]
})
Object.keys(props).forEach(name => node.style.removeProperty(`--${name}`))
props = new_props
},
}
}