@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
84 lines (83 loc) • 2.61 kB
JavaScript
"use client";
import { useContext, useRef } from 'react';
import Context from "../../shared/Context.js";
import { extendPropsWithContext } from "../../shared/component-helper.js";
import { prerenderIcon, prepareIcon } from "../icon/Icon.js";
import { transition, suppressTransitions } from "../icon/IconTransition.js";
import { useSpacing } from "../space/SpacingUtils.js";
import useCombinedRef from "../../shared/helpers/useCombinedRef.js";
import { useIsomorphicLayoutEffect as useLayoutEffect } from "../../shared/helpers/useIsomorphicLayoutEffect.js";
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import * as primaryIcons from "../../icons/dnb/primary_icons.js";
import * as primaryIconsMedium from "../../icons/dnb/primary_icons_medium.js";
import { jsx as _jsx } from "react/jsx-runtime";
export * from "../icon/Icon.js";
const icons = {
...primaryIcons,
...primaryIconsMedium
};
export default function IconPrimary(localProps) {
const context = useContext(Context);
const props = extendPropsWithContext(localProps, {}, {
skeleton: context?.skeleton
}, context.Icon, context.IconPrimary);
const {
icon,
size,
wrapperParams,
iconParams,
alt,
transitionState
} = prepareIcon(props, context);
const spacingProps = useSpacing(props, {
className: wrapperParams.className,
style: wrapperParams.style
});
const IconContainer = prerenderIcon({
icon,
size,
alt,
listOfIcons: icons
});
const ref = useRef(null);
const isInitialMount = useRef(true);
const {
ref: externalRef,
...restWrapperParams
} = wrapperParams;
const combinedRef = useCombinedRef(ref, externalRef);
useLayoutEffect(() => {
if (!transitionState || !ref.current) {
return;
}
const iconFn = icon;
if (iconFn?.__iconTransitionStyle) {
for (const [key, value] of Object.entries(iconFn.__iconTransitionStyle)) {
ref.current.style.setProperty(key, value);
}
}
if (isInitialMount.current) {
isInitialMount.current = false;
suppressTransitions(ref.current, () => {
transition.activate(ref.current, transitionState);
});
} else {
transition.activate(ref.current, transitionState);
}
}, [transitionState, icon]);
if (!IconContainer) {
return null;
}
return _jsx("span", {
...restWrapperParams,
ref: combinedRef,
...spacingProps,
children: _jsx(IconContainer, {
...iconParams
})
});
}
withComponentMarkers(IconPrimary, {
_supportsSpacingProps: true
});
//# sourceMappingURL=IconPrimary.js.map