JoyTokenIcon.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import isPropValid from '@emotion/is-prop-valid'
  2. import { css } from '@emotion/react'
  3. import styled from '@emotion/styled'
  4. import { ElementType, FC, useRef } from 'react'
  5. import {
  6. SvgJoyTokenMonochrome16,
  7. SvgJoyTokenMonochrome24,
  8. SvgJoyTokenMonochrome32,
  9. SvgJoyTokenMonochrome48,
  10. SvgJoyTokenPrimary16,
  11. SvgJoyTokenPrimary24,
  12. SvgJoyTokenPrimary32,
  13. SvgJoyTokenPrimary48,
  14. SvgJoyTokenSilver16,
  15. SvgJoyTokenSilver24,
  16. SvgJoyTokenSilver32,
  17. SvgJoyTokenSilver48,
  18. } from '@/assets/icons'
  19. import { Tooltip } from '@/components/Tooltip'
  20. import { TooltipText } from '@/components/Tooltip/Tooltip.styles'
  21. import { atlasConfig } from '@/config'
  22. import { cVar } from '@/styles'
  23. import { Anchor } from '@/views/global/YppLandingView/YppAuthorizationModal/YppAuthorizationModal.styles'
  24. type JoyTokenIconVariant = 'primary' | 'silver' | 'regular' | 'gray'
  25. type JoyTokenIconSize = 16 | 24 | 32 | 48
  26. export type JoyTokenIconProps = {
  27. variant?: JoyTokenIconVariant
  28. size?: JoyTokenIconSize
  29. className?: string
  30. withoutInformationTooltip?: boolean
  31. isNegative?: boolean
  32. }
  33. const VARIANT_SIZE_COMPONENT_MAPPING: Record<JoyTokenIconVariant, Record<JoyTokenIconSize, ElementType>> = {
  34. primary: {
  35. 16: SvgJoyTokenPrimary16,
  36. 24: SvgJoyTokenPrimary24,
  37. 32: SvgJoyTokenPrimary32,
  38. 48: SvgJoyTokenPrimary48,
  39. },
  40. silver: {
  41. 16: SvgJoyTokenSilver16,
  42. 24: SvgJoyTokenSilver24,
  43. 32: SvgJoyTokenSilver32,
  44. 48: SvgJoyTokenSilver48,
  45. },
  46. regular: {
  47. 16: SvgJoyTokenMonochrome16,
  48. 24: SvgJoyTokenMonochrome24,
  49. 32: SvgJoyTokenMonochrome32,
  50. 48: SvgJoyTokenMonochrome48,
  51. },
  52. gray: {
  53. 16: SvgJoyTokenMonochrome16,
  54. 24: SvgJoyTokenMonochrome24,
  55. 32: SvgJoyTokenMonochrome32,
  56. 48: SvgJoyTokenMonochrome48,
  57. },
  58. }
  59. export const JoyTokenIcon: FC<JoyTokenIconProps> = ({
  60. variant = 'regular',
  61. size = 16,
  62. className,
  63. withoutInformationTooltip,
  64. isNegative,
  65. }) => {
  66. const ref = useRef<HTMLDivElement>(null)
  67. return (
  68. <>
  69. <Tooltip
  70. interactive
  71. hidden={withoutInformationTooltip}
  72. customContent={
  73. <TooltipText as="span" variant="t100">
  74. {atlasConfig.joystream.tokenTicker} token is a native crypto asset of Joystream blockchain. It is used for
  75. platform governance, purchasing NFTs, trading creator tokens, and covering blockchain processing fees. They
  76. are listed on{' '}
  77. <Anchor href="https://www.mexc.com/exchange/JOYSTREAM_USDT" target="__blank">
  78. MEXC
  79. </Anchor>{' '}
  80. exchange under JOYSTREAM ticker
  81. </TooltipText>
  82. }
  83. multiline
  84. reference={ref.current}
  85. delay={1000}
  86. />
  87. <JoyTokenIconWrapper
  88. ref={ref}
  89. as={VARIANT_SIZE_COMPONENT_MAPPING[variant][size]}
  90. hasShadow={!['regular', 'gray'].includes(variant)}
  91. className={className}
  92. variant={variant}
  93. isNegative={isNegative}
  94. />
  95. </>
  96. )
  97. }
  98. const shadowCss = css`
  99. filter: drop-shadow(0 6px 11px rgba(0 0 0 / 0.65)) drop-shadow(0 1.809px 3.316px rgba(0 0 0 / 0.4235))
  100. drop-shadow(0 0.7513px 1.377px rgba(0 0 0 / 0.325)) drop-shadow(0 0.2717px 0.4982px rgba(0 0 0 / 0.2265));
  101. `
  102. const fillCss = ({ variant, isNegative }: { variant: JoyTokenIconVariant; isNegative?: boolean }) => {
  103. if (isNegative) {
  104. return css`
  105. path {
  106. fill: ${cVar('colorTextError')};
  107. }
  108. `
  109. }
  110. if (variant === 'gray') {
  111. return css`
  112. path {
  113. fill: ${cVar('colorText')};
  114. }
  115. `
  116. }
  117. return css``
  118. }
  119. const JoyTokenIconWrapper = styled('div', { shouldForwardProp: isPropValid })<{
  120. hasShadow: boolean
  121. variant: JoyTokenIconVariant
  122. isNegative?: boolean
  123. }>`
  124. ${fillCss};
  125. ${({ hasShadow }) => hasShadow && shadowCss};
  126. `