use-props.mjs 867 B

123456789101112131415161718192021222324
  1. import { useMemo } from 'react';
  2. import { copyRawValuesOnly } from '../html/use-props.mjs';
  3. import { buildSVGAttrs } from './utils/build-attrs.mjs';
  4. import { createSvgRenderState } from './utils/create-render-state.mjs';
  5. import { isSVGTag } from './utils/is-svg-tag.mjs';
  6. function useSVGProps(props, visualState, _isStatic, Component) {
  7. const visualProps = useMemo(() => {
  8. const state = createSvgRenderState();
  9. buildSVGAttrs(state, visualState, isSVGTag(Component), props.transformTemplate);
  10. return {
  11. ...state.attrs,
  12. style: { ...state.style },
  13. };
  14. }, [visualState]);
  15. if (props.style) {
  16. const rawStyles = {};
  17. copyRawValuesOnly(rawStyles, props.style, props);
  18. visualProps.style = { ...rawStyles, ...visualProps.style };
  19. }
  20. return visualProps;
  21. }
  22. export { useSVGProps };