@grafana/ui
Version:
Grafana Components Library
99 lines (92 loc) • 2.66 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var css = require('@emotion/css');
var React = require('react');
var ThemeContext = require('../../themes/ThemeContext.cjs');
var TruncatedText = require('./TruncatedText.cjs');
var utils = require('./utils.cjs');
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
;
const Text = React__namespace.forwardRef(
({ element = "span", variant, weight, color, truncate, italic, textAlignment, children, tabular, ...restProps }, ref) => {
const styles = ThemeContext.useStyles2(getTextStyles, element, variant, color, weight, truncate, italic, textAlignment, tabular);
const childElement = (ref2) => {
return React.createElement(
element,
{
...restProps,
style: void 0,
// Remove the style prop to avoid overriding the styles
className: styles,
// When overflowing, the internalRef is passed to the tooltip, which forwards it to the child element
ref: ref2
},
children
);
};
if (!truncate || element === "span") {
return childElement(void 0);
}
return /* @__PURE__ */ jsxRuntime.jsx(
TruncatedText.TruncatedText,
{
childElement,
children,
ref
}
);
}
);
Text.displayName = "Text";
const getTextStyles = (theme, element, variant, color, weight, truncate, italic, textAlignment, tabular) => {
return css.css([
{
margin: 0,
padding: 0,
...utils.customVariant(theme, element, variant)
},
variant && {
...theme.typography[variant]
},
color && {
color: utils.customColor(color, theme)
},
weight && {
fontWeight: utils.customWeight(weight, theme)
},
truncate && {
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap"
},
italic && {
fontStyle: "italic"
},
textAlignment && {
textAlign: textAlignment
},
tabular && {
fontFeatureSettings: '"tnum"'
}
]);
};
exports.Text = Text;
//# sourceMappingURL=Text.cjs.map