tag.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import classNames from '@/utils/classnames'
  3. const variantStyles = {
  4. medium: 'rounded-lg px-1.5 ring-1 ring-inset',
  5. } as { [key: string]: string }
  6. const colorStyles = {
  7. emerald: {
  8. small: 'text-emerald-500 dark:text-emerald-400',
  9. medium:
  10. 'ring-emerald-300 dark:ring-emerald-400/30 bg-emerald-400/10 text-emerald-500 dark:text-emerald-400',
  11. },
  12. sky: {
  13. small: 'text-sky-500',
  14. medium:
  15. 'ring-sky-300 bg-sky-400/10 text-sky-500 dark:ring-sky-400/30 dark:bg-sky-400/10 dark:text-sky-400',
  16. },
  17. amber: {
  18. small: 'text-amber-500',
  19. medium:
  20. 'ring-amber-300 bg-amber-400/10 text-amber-500 dark:ring-amber-400/30 dark:bg-amber-400/10 dark:text-amber-400',
  21. },
  22. rose: {
  23. small: 'text-red-500 dark:text-rose-500',
  24. medium:
  25. 'ring-rose-200 bg-rose-50 text-red-500 dark:ring-rose-500/20 dark:bg-rose-400/10 dark:text-rose-400',
  26. },
  27. zinc: {
  28. small: 'text-zinc-400 dark:text-zinc-500',
  29. medium:
  30. 'ring-zinc-200 bg-zinc-50 text-zinc-500 dark:ring-zinc-500/20 dark:bg-zinc-400/10 dark:text-zinc-400',
  31. },
  32. } as { [key: string]: { [key: string]: string } }
  33. const valueColorMap = {
  34. get: 'emerald',
  35. post: 'sky',
  36. put: 'amber',
  37. delete: 'rose',
  38. } as { [key: string]: string }
  39. type ITagProps = {
  40. children: string
  41. color?: string
  42. variant?: string
  43. }
  44. export function Tag({
  45. children,
  46. variant = 'medium',
  47. color = valueColorMap[children.toLowerCase()] ?? 'emerald',
  48. }: ITagProps) {
  49. return (
  50. <span
  51. className={classNames(
  52. 'font-mono text-[0.625rem] font-semibold leading-6',
  53. variantStyles[variant],
  54. colorStyles[color][variant],
  55. )}
  56. >
  57. {children}
  58. </span>
  59. )
  60. }