@react-three/uikit
Version:
Build performant 3D user interfaces with react-three-fiber and yoga.
24 lines (23 loc) • 1.56 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { createIconState, setupIcon } from '@pmndrs/uikit/internals';
import { forwardRef, useEffect, useMemo, useRef } from 'react';
import { AddHandlers, usePropertySignals } from './utils.js';
import { useParent } from './context.js';
import { useComponentInternals } from './ref.js';
export const Icon = forwardRef((properties, ref) => {
const parent = useParent();
const outerRef = useRef(null);
const propertySignals = usePropertySignals(properties);
const internals = useMemo(() => createIconState(parent, properties.text, properties.svgWidth, properties.svgHeight, propertySignals.style, propertySignals.properties, propertySignals.default), [parent, properties.svgHeight, properties.svgWidth, properties.text, propertySignals]);
internals.interactionPanel.name = properties.name ?? '';
useEffect(() => {
if (outerRef.current == null) {
return;
}
const abortController = new AbortController();
setupIcon(internals, parent, propertySignals.style, propertySignals.properties, outerRef.current, abortController.signal);
return () => abortController.abort();
}, [parent, propertySignals, internals]);
useComponentInternals(ref, parent.root, propertySignals.style, internals, internals.interactionPanel);
return (_jsxs(AddHandlers, { ref: outerRef, handlers: internals.handlers, children: [_jsx("primitive", { object: internals.interactionPanel }), _jsx("primitive", { object: internals.iconGroup })] }));
});