index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import type { CSSProperties, ReactNode } from 'react'
  2. import React from 'react'
  3. import { type VariantProps, cva } from 'class-variance-authority'
  4. import { Highlight } from '@/app/components/base/icons/src/public/common'
  5. import classNames from '@/utils/classnames'
  6. import './index.css'
  7. const PremiumBadgeVariants = cva(
  8. 'premium-badge',
  9. {
  10. variants: {
  11. size: {
  12. s: 'premium-badge-s',
  13. m: 'premium-badge-m',
  14. },
  15. color: {
  16. blue: 'premium-badge-blue',
  17. indigo: 'premium-badge-indigo',
  18. gray: 'premium-badge-gray',
  19. orange: 'premium-badge-orange',
  20. },
  21. allowHover: {
  22. true: 'allowHover',
  23. false: '',
  24. },
  25. },
  26. defaultVariants: {
  27. size: 'm',
  28. color: 'blue',
  29. allowHover: false,
  30. },
  31. },
  32. )
  33. type PremiumBadgeProps = {
  34. size?: 's' | 'm'
  35. color?: 'blue' | 'indigo' | 'gray' | 'orange'
  36. allowHover?: boolean
  37. styleCss?: CSSProperties
  38. children?: ReactNode
  39. } & React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof PremiumBadgeVariants>
  40. const PremiumBadge: React.FC<PremiumBadgeProps> = ({
  41. className,
  42. size,
  43. color,
  44. allowHover,
  45. styleCss,
  46. children,
  47. ...props
  48. }) => {
  49. return (
  50. <div
  51. className={classNames(
  52. PremiumBadgeVariants({ size, color, allowHover, className }),
  53. 'relative text-nowrap',
  54. )}
  55. style={styleCss}
  56. {...props}
  57. >
  58. {children}
  59. <Highlight
  60. className={classNames(
  61. 'absolute top-0 opacity-50 hover:opacity-80',
  62. size === 's' ? 'h-4.5 w-12' : 'h-6 w-12',
  63. )}
  64. style={{
  65. right: '50%',
  66. transform: 'translateX(10%)',
  67. }}
  68. />
  69. </div>
  70. )
  71. }
  72. PremiumBadge.displayName = 'PremiumBadge'
  73. export default PremiumBadge
  74. export { PremiumBadge, PremiumBadgeVariants }