icon.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from 'react';
  2. import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
  3. import semiGlobal from '../_utils/semi-global';
  4. import { get } from 'lodash';
  5. import cls from 'classnames';
  6. let _id = -1;
  7. export interface IconProps {
  8. id?: number;
  9. component?: React.ReactNode;
  10. size?: number;
  11. className?: string;
  12. type?: string;
  13. customIconCls?: string;
  14. }
  15. function Icon(props: IconProps = {}) {
  16. const { id: propsId, className, customIconCls, ...rest } = props;
  17. const globalIndicator = get(semiGlobal, 'config.overrideDefaultProps.Spin.indicator');
  18. if (globalIndicator && React.isValidElement(globalIndicator)) {
  19. return React.cloneElement(globalIndicator, { className: cls({ [customIconCls]: customIconCls, [className]: className }) } as any);
  20. }
  21. let _propsId = propsId;
  22. if (isNullOrUndefined(_propsId)) {
  23. _id++;
  24. _propsId = _id;
  25. }
  26. const id = `linearGradient-${_propsId}`;
  27. return (
  28. <svg
  29. {...rest}
  30. className={className}
  31. width="48"
  32. height="48"
  33. viewBox="0 0 36 36"
  34. version="1.1"
  35. xmlns="http://www.w3.org/2000/svg"
  36. aria-hidden
  37. data-icon="spin"
  38. >
  39. <defs>
  40. <linearGradient x1="0%" y1="100%" x2="100%" y2="100%" id={id}>
  41. <stop stopColor="currentColor" stopOpacity="0" offset="0%" />
  42. <stop stopColor="currentColor" stopOpacity="0.50" offset="39.9430698%" />
  43. <stop stopColor="currentColor" offset="100%" />
  44. </linearGradient>
  45. </defs>
  46. <g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
  47. <rect fillOpacity="0.01" fill="none" x="0" y="0" width="36" height="36" />
  48. <path
  49. d="M34,18 C34,9.163444 26.836556,2 18,2 C11.6597233,2 6.18078805,5.68784135 3.59122325,11.0354951"
  50. stroke={`url(#${id})`}
  51. strokeWidth="4"
  52. strokeLinecap="round"
  53. />
  54. </g>
  55. </svg>
  56. );
  57. }
  58. export default Icon;