@visx/text
Version:
visx text
56 lines (55 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Text;
var _useText = _interopRequireDefault(require("./hooks/useText"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const SVG_STYLE = {
overflow: 'visible'
};
function Text(props) {
const {
dx = 0,
dy = 0,
textAnchor = 'start',
innerRef,
innerTextRef,
verticalAnchor,
angle,
lineHeight = '1em',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
scaleToFit = false,
capHeight,
width,
...textProps
} = props;
const {
x = 0,
fontSize
} = textProps;
const {
wordsByLines,
startDy,
transform
} = (0, _useText.default)(props);
return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
ref: innerRef,
x: dx,
y: dy,
fontSize: fontSize,
style: SVG_STYLE,
children: wordsByLines.length > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {
ref: innerTextRef,
transform: transform,
...textProps,
textAnchor: textAnchor,
children: wordsByLines.map((line, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)("tspan", {
x: x,
dy: index === 0 ? startDy : lineHeight,
children: line.words.join(' ')
}, index))
}) : null
});
}