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.

index.tsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 right-1/2 top-0 translate-x-[20%] opacity-50 transition-all duration-100 ease-out hover:translate-x-[30%] hover:opacity-80',
  62. size === 's' ? 'h-[18px] w-12' : 'h-6 w-12',
  63. )}
  64. />
  65. </div>
  66. )
  67. }
  68. PremiumBadge.displayName = 'PremiumBadge'
  69. export default PremiumBadge
  70. export { PremiumBadge, PremiumBadgeVariants }