You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import type { ButtonProps, TooltipProps } from 'antd'
  2. import { Button, Tooltip } from 'antd'
  3. import { CSSProperties, FC, memo } from 'react'
  4. import { ConfigProvider } from '@/components/config-provider'
  5. import { useStyles } from './style'
  6. /**
  7. * @title
  8. * @description `Button` `title`, `type` `size`
  9. */
  10. export interface ActionIconProps extends Omit<ButtonProps, 'title' | 'size'> {
  11. /**
  12. * @title
  13. */
  14. cursor?: CSSProperties['cursor'];
  15. /**
  16. * @title
  17. */
  18. title?: TooltipProps['title'];
  19. /**
  20. * @title
  21. */
  22. placement?: TooltipProps['placement'];
  23. /**
  24. * @title
  25. */
  26. icon: ButtonProps['icon'];
  27. /**
  28. * @title
  29. */
  30. onClick?: ButtonProps['onClick'];
  31. /**
  32. * @title
  33. */
  34. size?: 'default' | 'large' | number;
  35. /**
  36. * @description tooltip时间 0.5
  37. * @default 0.5
  38. */
  39. tooltipDelay?: number;
  40. /**
  41. * @description
  42. * @default false
  43. */
  44. arrow?: boolean;
  45. bordered?: boolean;
  46. }
  47. const BaseActionIcon: FC<ActionIconProps> = memo(({
  48. placement,
  49. title,
  50. icon,
  51. cursor,
  52. onClick,
  53. className,
  54. bordered = false,
  55. arrow = false,
  56. size = 'default',
  57. tooltipDelay = 0.5,
  58. ...restProps
  59. }) => {
  60. const { styles, cx } = useStyles({ size, bordered, className })
  61. const Icon = (
  62. <Button
  63. icon={icon}
  64. className={cx(styles.container, className)}
  65. type={'text'}
  66. style={{ cursor }}
  67. size={typeof size === 'number' || size === 'default' ? 'middle' : size}
  68. {...restProps}
  69. onClick={onClick}
  70. />
  71. )
  72. return (
  73. <>
  74. {!title ? (
  75. Icon
  76. ) : (
  77. <Tooltip
  78. arrow={arrow}
  79. overlayClassName={styles.tooltip}
  80. title={title}
  81. mouseEnterDelay={tooltipDelay}
  82. placement={placement}
  83. >
  84. {Icon}
  85. </Tooltip>
  86. )}
  87. </>
  88. )
  89. })
  90. const ActionIcon = memo((props: ActionIconProps) => {
  91. const { size } = props || {}
  92. const { theme: token } = useStyles({ size })
  93. return (
  94. <ConfigProvider
  95. componentToken={{
  96. Button: {
  97. colorText: token.colorTextTertiary,
  98. colorBgTextHover: token.colorFillSecondary,
  99. colorBgTextActive: token.colorFill,
  100. },
  101. }}
  102. >
  103. <BaseActionIcon {...props} />
  104. </ConfigProvider>
  105. )
  106. })
  107. export default ActionIcon