opendash
Version:
open.DASH data visualization framework
36 lines • 1.38 kB
JavaScript
import * as React from "react";
var BASE = 1000;
var FACTOR = 0.8;
var INITIAL_STATE = {
visibility: "hidden",
position: "absolute",
fontSize: BASE + "px",
lineHeight: BASE + "px",
height: "auto",
width: "auto",
textAlign: "center",
whiteSpace: "nowrap",
};
export var FitText = function (_a) {
var width = _a.width, height = _a.height, style = _a.style, children = _a.children;
var element = React.useRef(null);
React.useEffect(function () {
if (element.current && width > 0 && height > 0) {
Object.assign(element.current.style, INITIAL_STATE);
var factor = Math.max(element.current.offsetWidth / width, element.current.offsetHeight / height);
var fontSize = Math.floor((BASE / factor) * FACTOR);
Object.assign(element.current.style, {
visibility: "visible",
position: "static",
fontSize: fontSize + "px",
lineHeight: height + "px",
height: height + "px",
width: width + "px",
textAlign: "center",
whiteSpace: "nowrap",
});
}
}, [element.current, width, height, children]);
return (React.createElement("div", { ref: element, style: style }, children));
};
//# sourceMappingURL=FitText.js.map