mdb-ui-kit/docs/assets/js/src/style.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Dynamically display style properties i.e. font
*/
2016-01-29 19:24:23 +03:00
const Style = class {
2016-01-29 19:24:23 +03:00
constructor() {
2016-01-29 19:24:23 +03:00
}
2016-01-29 19:24:23 +03:00
static rgbToHex(rgba) {
rgba = rgba.match(/\d+/g)
let hex = `#${String(`0${Number(rgba[0]).toString(16)}`).slice(-2)}${String(`0${Number(rgba[1]).toString(16)}`).slice(-2)}${String(`0${Number(rgba[2]).toString(16)}`).slice(-2)}`
return hex
}
2016-01-29 19:24:23 +03:00
// Function to display font properties dynamically discovered
static displayFontSizeWeightColor($elements, writeFn, bg = false, wrapWithCode = false) {
return $elements.each((index, element) => {
let $element = $(element)
2016-01-29 19:24:23 +03:00
let rgbaBgColor = $element.css('background-color')
// let hexBgColor = Style.rgbToHex(rgbaBgColor)
2016-01-29 19:24:23 +03:00
let rgbaColor = $element.css('color')
// let hexColor = Style.rgbToHex(rgbaColor)
2016-01-29 19:24:23 +03:00
let text = ''
2016-01-29 19:24:23 +03:00
if (wrapWithCode) {
text += `<code style='font-size: 10px; font-weight: 500; letter-spacing: normal'>`
}
2016-01-29 19:24:23 +03:00
// text += `${$element.css('font-size')} ${$element.css('font-weight')} ${hexColor}`
text += `<span>${$element.css('font-size')} ${$element.css('font-weight')} <span style='white-space: nowrap'>${rgbaColor}</span></span>`
if (bg) {
// text += ` bg: ${hexBgColor} `
text += ` bg: ${rgbaBgColor} `
}
2016-01-29 19:24:23 +03:00
if (wrapWithCode) {
text += `</code>`
}
2016-01-29 19:24:23 +03:00
writeFn($element, $(text))
})
}
2016-01-29 19:24:23 +03:00
}
export default Style