您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tooltip.tsx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import * as _Tooltip from '@radix-ui/react-tooltip'
  2. import React from 'react'
  3. import styled from 'styles'
  4. interface TooltipProps {
  5. children: React.ReactNode
  6. label: string
  7. kbd?: string
  8. side?: 'bottom' | 'left' | 'right' | 'top'
  9. }
  10. export default function Tooltip({
  11. children,
  12. label,
  13. kbd,
  14. side = 'top',
  15. }: TooltipProps): JSX.Element {
  16. return (
  17. <_Tooltip.Root>
  18. <_Tooltip.Trigger as="span">{children}</_Tooltip.Trigger>
  19. <StyledContent side={side} sideOffset={8}>
  20. {label}
  21. {kbd ? (
  22. <kbd>
  23. {kbd.split('').map((k, i) => (
  24. <span key={i}>{k}</span>
  25. ))}
  26. </kbd>
  27. ) : null}
  28. <StyledArrow />
  29. </StyledContent>
  30. </_Tooltip.Root>
  31. )
  32. }
  33. const StyledContent = styled(_Tooltip.Content, {
  34. borderRadius: 3,
  35. padding: '$3 $3 $3 $3',
  36. fontSize: '$1',
  37. backgroundColor: '$tooltipBg',
  38. color: '$tooltipText',
  39. boxShadow: '$3',
  40. display: 'flex',
  41. alignItems: 'center',
  42. '& kbd': {
  43. marginLeft: '$3',
  44. textShadow: '$2',
  45. textAlign: 'center',
  46. fontSize: '$1',
  47. fontFamily: '$ui',
  48. fontWeight: 400,
  49. gap: '$1',
  50. display: 'flex',
  51. alignItems: 'center',
  52. '& > span': {
  53. padding: '$0',
  54. borderRadius: '$0',
  55. background: '$overlayContrast',
  56. boxShadow: '$key',
  57. width: '20px',
  58. height: '20px',
  59. display: 'flex',
  60. alignItems: 'center',
  61. justifyContent: 'center',
  62. },
  63. },
  64. })
  65. const StyledArrow = styled(_Tooltip.Arrow, {
  66. fill: '$tooltipBg',
  67. margin: '0 8px',
  68. })