Skip to content

Commit 18d1156

Browse files
authored
Merge pull request #13972 from ethereum/shadcn-tag
Shadcn migration - tags
2 parents 66100fb + f39c7ee commit 18d1156

File tree

5 files changed

+177
-6
lines changed

5 files changed

+177
-6
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Meta, StoryObj } from "@storybook/react"
2+
3+
import { HStack, VStack } from "../flex"
4+
import { Tag } from "../tag"
5+
6+
const meta = {
7+
title: "Molecules / Display Content / New Tags",
8+
component: Tag,
9+
} satisfies Meta<typeof Tag>
10+
11+
export default meta
12+
13+
type Story = StoryObj<typeof meta>
14+
15+
// "normal" is default status
16+
const statusArray = ["normal", "tag", "success", "error", "warning"] as const
17+
18+
// "subtle" is default variant
19+
const variantArray = ["subtle", "highContrast", "solid", "outline"] as const
20+
21+
const StyleVariantList = () => (
22+
<HStack>
23+
{statusArray.map((status) => (
24+
<VStack key={status}>
25+
{variantArray.map((variant) => (
26+
<Tag key={variant} status={status} variant={variant}>
27+
Tag Name
28+
</Tag>
29+
))}
30+
</VStack>
31+
))}
32+
</HStack>
33+
)
34+
35+
export const StyleVariantsBasic: Story = {
36+
render: (args) => <StyleVariantList {...args} />,
37+
}

src/components/ui/tag.tsx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { cva, VariantProps } from "class-variance-authority"
2+
import { Slot } from "@radix-ui/react-slot"
3+
4+
import { cn } from "@/lib/utils/cn"
5+
6+
const tagVariants = cva(
7+
"inline-flex items-center rounded-full border px-2 py-0.5 min-h-8 text-xs uppercase transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
8+
{
9+
variants: {
10+
status: {
11+
normal: "bg-background-highlight text-body-medium border-body-medium",
12+
tag: "bg-primary-low-contrast text-primary-high-contrast border-primary",
13+
success: "bg-success-light text-success border-success-border",
14+
error: "bg-error-light text-error border-error-border",
15+
warning: "bg-warning-light text-warning-dark border-warning-border",
16+
},
17+
variant: {
18+
subtle: "border-transparent",
19+
highContrast: "border-transparent",
20+
solid: "border-transparent text-body-inverse",
21+
outline: "bg-transparent",
22+
},
23+
},
24+
compoundVariants: [
25+
{
26+
variant: "solid",
27+
status: "normal",
28+
className: "bg-body-medium",
29+
},
30+
{
31+
variant: "solid",
32+
status: "tag",
33+
className: "bg-primary",
34+
},
35+
{
36+
variant: "solid",
37+
status: "success",
38+
className: "bg-success text-success-light",
39+
},
40+
{
41+
variant: "solid",
42+
status: "error",
43+
className: "bg-error text-error-light",
44+
},
45+
{
46+
variant: "solid",
47+
status: "warning",
48+
className: "bg-warning text-warning-dark",
49+
},
50+
{
51+
variant: "highContrast",
52+
status: "normal",
53+
className: "bg-body-light text-body",
54+
},
55+
{
56+
variant: "highContrast",
57+
status: "tag",
58+
className: "bg-background-highlight",
59+
},
60+
{
61+
variant: "highContrast",
62+
status: "success",
63+
className: "text-success-dark",
64+
},
65+
{
66+
variant: "highContrast",
67+
status: "error",
68+
className: "text-error-dark",
69+
},
70+
{
71+
variant: "outline",
72+
status: "success",
73+
className: "text-success-border",
74+
},
75+
{
76+
variant: "outline",
77+
status: "error",
78+
className: "text-error-border",
79+
},
80+
{
81+
variant: "outline",
82+
status: "warning",
83+
className: "text-warning-border",
84+
},
85+
],
86+
defaultVariants: {
87+
variant: "subtle",
88+
status: "normal",
89+
},
90+
}
91+
)
92+
93+
export interface TagProps
94+
extends React.HTMLAttributes<HTMLDivElement>,
95+
VariantProps<typeof tagVariants> {
96+
asChild?: boolean
97+
}
98+
99+
function Tag({ className, asChild, variant, status, ...props }: TagProps) {
100+
const Comp = asChild ? Slot : "div"
101+
return (
102+
<Comp
103+
className={cn(tagVariants({ variant, status }), className)}
104+
{...props}
105+
/>
106+
)
107+
}
108+
109+
export { Tag }

src/styles/colors.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
--yellow-500: 38, 92%, 50%; /* #F59E0B */
7373
--yellow-600: 32, 95%, 44%; /* #D97706 */
7474
--yellow-700: 26, 90%, 37%; /* #B45309 */
75-
--yellow-800: 23, 83%, 31%; /* #92400E */
76-
--yellow-900: 22, 78%, 26%; /* #78350F */
75+
--yellow-800: 23, 88%, 22%; /* #6B2D07 */
76+
--yellow-900: 22, 84%, 15%; /* #471E06 */
7777

7878
--red-50: 0, 86%, 97%; /* #fef2f2 */
7979
--red-100: 0, 93%, 94%; /* #fee2e2 */
@@ -84,7 +84,7 @@
8484
--red-600: 0, 72%, 51%; /* #dc2626 */
8585
--red-700: 0, 74%, 42%; /* #b91c1c */
8686
--red-800: 0, 70%, 35%; /* #991b1b */
87-
--red-900: 0, 63%, 31%; /* #7f1d1d */
87+
--red-900: 0, 82%, 19%; /* #5A0909 */
8888

8989
--green-50: 138, 76%, 97%; /* #F0FDF4 */
9090
--green-100: 141, 84%, 93%; /* #DCFCE7 */
@@ -94,8 +94,8 @@
9494
--green-500: 142, 71%, 45%; /* #22C55E */
9595
--green-600: 142, 76%, 36%; /* #16A34A */
9696
--green-700: 142, 72%, 29%; /* #15803D */
97-
--green-800: 143, 64%, 24%; /* #166534 */
98-
--green-900: 144, 61%, 20%; /* #14532D */
97+
--green-800: 143, 74%, 19%; /* #0D5629 */
98+
--green-900: 143, 79%, 11%; /* #063418 */
9999

100100
--orange-100: 30, 100%, 94%; /* #FFF0DB */
101101
--orange-800: 10, 76%, 28%; /* #7D2711 */

src/styles/semantic-tokens.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@
4747

4848
--success: var(--green-600);
4949
--success-light: var(--green-100);
50+
--success-dark: var(--green-900);
51+
--success-border: var(--green-700);
5052

5153
--error: var(--red-700);
5254
--error-light: var(--red-100);
55+
--error-dark: var(--red-900);
56+
--error-border: var(--red-800);
5357

54-
--warning: var(--yellow-400);
58+
--warning: var(--yellow-300);
5559
--warning-light: var(--yellow-100);
60+
--warning-dark: var(--yellow-900);
61+
--warning-border: var(--yellow-700);
5662

5763
/**
5864
/* Gradients (radial, conic, or linear over 3 stops)
@@ -152,7 +158,20 @@
152158
--accent-c: var(--teal-400);
153159
--accent-c-hover: var(--teal-300);
154160

161+
--success: var(--green-600);
162+
--success-light: var(--green-100);
163+
--success-dark: var(--green-900);
164+
--success-border: var(--green-400);
165+
166+
--error: var(--red-700);
167+
--error-light: var(--red-100);
168+
--error-dark: var(--red-900);
169+
--error-border: var(--red-300);
170+
155171
--warning: var(--yellow-300);
172+
--warning-light: var(--yellow-100);
173+
--warning-dark: var(--yellow-900);
174+
--warning-border: var(--yellow-200);
156175

157176
/* Gradients (dark mode adjustments) */
158177
--radial-a-opacity-1: 0.16;

tailwind.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,22 @@ const config = {
189189
success: {
190190
DEFAULT: "hsla(var(--success))",
191191
light: "hsla(var(--success-light))",
192+
dark: "hsla(var(--success-dark))",
193+
border: "hsla(var(--success-border))",
192194
},
193195

194196
error: {
195197
DEFAULT: "hsla(var(--error))",
196198
light: "hsla(var(--error-light))",
199+
dark: "hsla(var(--error-dark))",
200+
border: "hsla(var(--error-border))",
197201
},
198202

199203
warning: {
200204
DEFAULT: "hsla(var(--warning))",
201205
light: "hsla(var(--warning-light))",
206+
dark: "hsla(var(--warning-dark))",
207+
border: "hsla(var(--warning-border))",
202208
},
203209

204210
/** @deprecated */

0 commit comments

Comments
 (0)