|
| 1 | +import { VariantProps, cva } from "class-variance-authority"; |
| 2 | +import React, { HTMLAttributes, forwardRef } from "react"; |
| 3 | +import { cn } from "../../utilities"; |
| 4 | + |
| 5 | +export const tagVariants = cva("shrink-0 flex items-center justify-center gap-0.5 py-0.5 px-1", { |
| 6 | + variants: { |
| 7 | + rounded: { false: "rounded-md", true: "rounded-rounded" }, |
| 8 | + size: { sm: "h-6 text-text-sm", xs: "h-5 text-text-xs" }, |
| 9 | + emphasis: { |
| 10 | + bold: "", |
| 11 | + subtle: "border", |
| 12 | + minimal: "border" |
| 13 | + }, |
| 14 | + color: { |
| 15 | + grey: "", |
| 16 | + purple: "", |
| 17 | + green: "", |
| 18 | + yellow: "", |
| 19 | + red: "", |
| 20 | + blue: "", |
| 21 | + teal: "", |
| 22 | + lime: "", |
| 23 | + magenta: "", |
| 24 | + turquoise: "", |
| 25 | + orange: "" |
| 26 | + } |
| 27 | + }, |
| 28 | + compoundVariants: [ |
| 29 | + // gray |
| 30 | + { |
| 31 | + emphasis: "bold", |
| 32 | + color: "grey", |
| 33 | + class: "bg-neutral-600 text-theme-text-negative" |
| 34 | + }, |
| 35 | + { |
| 36 | + emphasis: "subtle", |
| 37 | + color: "grey", |
| 38 | + class: "border-theme-border-moderate text-theme-text-secondary" |
| 39 | + }, |
| 40 | + { |
| 41 | + emphasis: "minimal", |
| 42 | + color: "grey", |
| 43 | + class: "border-theme-border-moderate text-theme-text-secondary" |
| 44 | + }, |
| 45 | + // purple |
| 46 | + { |
| 47 | + emphasis: "bold", |
| 48 | + color: "purple", |
| 49 | + class: "bg-primary-400 text-theme-text-negative" |
| 50 | + }, |
| 51 | + { |
| 52 | + emphasis: "subtle", |
| 53 | + color: "purple", |
| 54 | + class: "border-primary-100 text-theme-text-brand bg-primary-25 " |
| 55 | + }, |
| 56 | + { |
| 57 | + emphasis: "minimal", |
| 58 | + color: "purple", |
| 59 | + class: "border-theme-border-moderate text-theme-text-brand" |
| 60 | + }, |
| 61 | + // red |
| 62 | + { |
| 63 | + emphasis: "bold", |
| 64 | + color: "red", |
| 65 | + class: "bg-error-600 text-theme-text-negative" |
| 66 | + }, |
| 67 | + { |
| 68 | + emphasis: "subtle", |
| 69 | + color: "red", |
| 70 | + class: "bg-error-50 border-error-200 text-error-800" |
| 71 | + }, |
| 72 | + { |
| 73 | + emphasis: "minimal", |
| 74 | + color: "red", |
| 75 | + class: "border-theme-border-moderate text-error-800" |
| 76 | + }, |
| 77 | + // green |
| 78 | + { |
| 79 | + emphasis: "bold", |
| 80 | + color: "green", |
| 81 | + class: "bg-success-600 text-theme-text-negative" |
| 82 | + }, |
| 83 | + { |
| 84 | + emphasis: "subtle", |
| 85 | + color: "green", |
| 86 | + class: "bg-success-50 border-success-200 text-success-800" |
| 87 | + }, |
| 88 | + { |
| 89 | + emphasis: "minimal", |
| 90 | + color: "green", |
| 91 | + class: "border-theme-border-moderate text-success-800" |
| 92 | + }, |
| 93 | + // yellow |
| 94 | + { |
| 95 | + emphasis: "bold", |
| 96 | + color: "yellow", |
| 97 | + class: "bg-warning-400 text-warning-900" |
| 98 | + }, |
| 99 | + { |
| 100 | + emphasis: "subtle", |
| 101 | + color: "yellow", |
| 102 | + class: "bg-warning-50 border-warning-200 text-warning-900" |
| 103 | + }, |
| 104 | + { |
| 105 | + emphasis: "minimal", |
| 106 | + color: "yellow", |
| 107 | + class: "border-theme-border-moderate text-warning-900" |
| 108 | + }, |
| 109 | + // blue |
| 110 | + { |
| 111 | + emphasis: "bold", |
| 112 | + color: "blue", |
| 113 | + class: "bg-blue-500 text-theme-text-negative" |
| 114 | + }, |
| 115 | + { |
| 116 | + emphasis: "subtle", |
| 117 | + color: "blue", |
| 118 | + class: "bg-blue-25 border-blue-100 text-blue-700" |
| 119 | + }, |
| 120 | + { |
| 121 | + emphasis: "minimal", |
| 122 | + color: "blue", |
| 123 | + class: "border-theme-border-moderate text-blue-700" |
| 124 | + }, |
| 125 | + // teal |
| 126 | + { |
| 127 | + emphasis: "bold", |
| 128 | + color: "teal", |
| 129 | + class: "bg-teal-600 text-theme-text-negative" |
| 130 | + }, |
| 131 | + { |
| 132 | + emphasis: "subtle", |
| 133 | + color: "teal", |
| 134 | + class: "bg-teal-25 border-teal-100 text-teal-600" |
| 135 | + }, |
| 136 | + { |
| 137 | + emphasis: "minimal", |
| 138 | + color: "teal", |
| 139 | + class: "border-theme-border-moderate text-teal-600" |
| 140 | + }, |
| 141 | + // lime |
| 142 | + { |
| 143 | + emphasis: "bold", |
| 144 | + color: "lime", |
| 145 | + class: "bg-lime-700 text-theme-text-negative" |
| 146 | + }, |
| 147 | + { |
| 148 | + emphasis: "subtle", |
| 149 | + color: "lime", |
| 150 | + class: "bg-lime-25 border-lime-100 text-lime-700" |
| 151 | + }, |
| 152 | + { |
| 153 | + emphasis: "minimal", |
| 154 | + color: "lime", |
| 155 | + class: "border-theme-border-moderate text-lime-700" |
| 156 | + }, |
| 157 | + // magenta |
| 158 | + { |
| 159 | + emphasis: "bold", |
| 160 | + color: "magenta", |
| 161 | + class: "bg-magenta-500 text-theme-text-negative" |
| 162 | + }, |
| 163 | + { |
| 164 | + emphasis: "subtle", |
| 165 | + color: "magenta", |
| 166 | + class: "bg-magenta-25 border-magenta-100 text-magenta-600" |
| 167 | + }, |
| 168 | + { |
| 169 | + emphasis: "minimal", |
| 170 | + color: "magenta", |
| 171 | + class: "border-theme-border-moderate text-magenta-600" |
| 172 | + }, |
| 173 | + // turquoise |
| 174 | + { |
| 175 | + emphasis: "bold", |
| 176 | + color: "turquoise", |
| 177 | + class: "bg-turquoise-500 text-theme-text-negative" |
| 178 | + }, |
| 179 | + { |
| 180 | + emphasis: "subtle", |
| 181 | + color: "turquoise", |
| 182 | + class: "bg-turquoise-25 border-turquoise-100 text-turquoise-600" |
| 183 | + }, |
| 184 | + { |
| 185 | + emphasis: "minimal", |
| 186 | + color: "turquoise", |
| 187 | + class: "border-theme-border-moderate text-turquoise-600" |
| 188 | + }, |
| 189 | + // orange |
| 190 | + { |
| 191 | + emphasis: "bold", |
| 192 | + color: "orange", |
| 193 | + class: "bg-orange-400 text-theme-text-negative" |
| 194 | + }, |
| 195 | + { |
| 196 | + emphasis: "subtle", |
| 197 | + color: "orange", |
| 198 | + class: "bg-orange-25 border-orange-100 text-orange-700" |
| 199 | + }, |
| 200 | + { |
| 201 | + emphasis: "minimal", |
| 202 | + color: "orange", |
| 203 | + class: "border-theme-border-moderate text-orange-600" |
| 204 | + } |
| 205 | + ], |
| 206 | + defaultVariants: { |
| 207 | + rounded: true, |
| 208 | + size: "sm" |
| 209 | + } |
| 210 | +}); |
| 211 | + |
| 212 | +export interface TagProps |
| 213 | + extends Omit<HTMLAttributes<HTMLDivElement>, "color">, |
| 214 | + VariantProps<typeof tagVariants> {} |
| 215 | + |
| 216 | +export const Tag = forwardRef<HTMLDivElement, TagProps>( |
| 217 | + ({ className, rounded, emphasis, color, size, ...rest }, ref) => { |
| 218 | + return ( |
| 219 | + <div |
| 220 | + {...rest} |
| 221 | + className={cn(tagVariants({ rounded, emphasis, color, size }), className)} |
| 222 | + ref={ref} |
| 223 | + ></div> |
| 224 | + ); |
| 225 | + } |
| 226 | +); |
| 227 | + |
| 228 | +Tag.displayName = "Tag"; |
0 commit comments