Skip to content

Commit 3cdb260

Browse files
Shrinks99claude
andauthored
Add closable prop to resourcebadge, document and fix table data-state selector (#85)
Co-authored-by: Claude <claude@users.noreply.github.com>
1 parent 8794be9 commit 3cdb260

6 files changed

Lines changed: 88 additions & 30 deletions

File tree

packages/demo/src/components/demo/table.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TableHeader,
1212
TableRow,
1313
} from "@eqtylab/equality";
14+
import { useState } from "react";
1415

1516
interface TableDemoProps {
1617
variant?:
@@ -33,6 +34,9 @@ export const TableDemo = ({
3334
variant = "default",
3435
elevation,
3536
}: TableDemoProps) => {
37+
const [selectedRow, setSelectedRow] = useState<number | null>(null);
38+
const toggleRow = (row: number) =>
39+
setSelectedRow((current) => (current === row ? null : row));
3640
if (variant === "column-sizing") {
3741
return (
3842
<TableContainer elevation={elevation} columns="3fr 3fr 100px 100px 60px">
@@ -451,11 +455,8 @@ export const TableDemo = ({
451455
<TableBody>
452456
<TableRow
453457
clickable={variant === "clickable"}
454-
onClick={
455-
variant === "clickable"
456-
? () => console.log("Clicked row 1")
457-
: undefined
458-
}
458+
data-state={selectedRow === 0 ? "selected" : undefined}
459+
onClick={variant === "clickable" ? () => toggleRow(0) : undefined}
459460
>
460461
<TableCell>Alice Cooper</TableCell>
461462
<TableCell>alice@example.com</TableCell>
@@ -469,11 +470,8 @@ export const TableDemo = ({
469470
</TableRow>
470471
<TableRow
471472
clickable={variant === "clickable"}
472-
onClick={
473-
variant === "clickable"
474-
? () => console.log("Clicked row 2")
475-
: undefined
476-
}
473+
data-state={selectedRow === 1 ? "selected" : undefined}
474+
onClick={variant === "clickable" ? () => toggleRow(1) : undefined}
477475
>
478476
<TableCell>Bob Smith</TableCell>
479477
<TableCell>bob@example.com</TableCell>
@@ -487,11 +485,8 @@ export const TableDemo = ({
487485
</TableRow>
488486
<TableRow
489487
clickable={variant === "clickable"}
490-
onClick={
491-
variant === "clickable"
492-
? () => console.log("Clicked row 3")
493-
: undefined
494-
}
488+
data-state={selectedRow === 2 ? "selected" : undefined}
489+
onClick={variant === "clickable" ? () => toggleRow(2) : undefined}
495490
>
496491
<TableCell>Charlie Brown</TableCell>
497492
<TableCell>charlie@example.com</TableCell>

packages/demo/src/content/components/resource-badge.mdx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,46 @@ Show only the text by setting `display` to `"text-only"`:
130130
<ResourceBadge type="document" display="text-only" />
131131
```
132132

133+
## Custom Content
134+
135+
By default, Resource Badge displays the label associated with the `type`. You can pass `children` to override that label.
136+
137+
This _may_ be used to display the name of a resource on the badge, though displaying names separately is generally preferred.
138+
139+
<div className="flex items-center gap-3">
140+
<ResourceBadge type="model">claude-opus-4-7</ResourceBadge>
141+
<ResourceBadge type="dataset">Dataset Group</ResourceBadge>
142+
<ResourceBadge type="credential">aws-prod-key</ResourceBadge>
143+
</div>
144+
145+
### Usage
146+
147+
```tsx
148+
<ResourceBadge type="model">claude-opus-4-7</ResourceBadge>
149+
```
150+
151+
## Closable
152+
153+
Set `closeable` and provide a `handleClosable` callback to render a close button on the badge. This is useful for representing active filters or selections that the user can dismiss.
154+
155+
### Usage
156+
157+
```tsx
158+
<ResourceBadge
159+
type="dataset"
160+
closeable
161+
handleClosable={() => removeFilter("dataset")}
162+
>
163+
customer-events-2026
164+
</ResourceBadge>
165+
```
166+
133167
## Props
134168

135-
| Name | Description | Type | Default | Required |
136-
| --------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- |
137-
| `type` | The resource type that determines the badge variant, icon, and label. | `"agent"`, `"benchmark"`, `"benchmark-result"`, `"binary"`, `"certificate"`, `"code"`, `"compute"`, `"config"`, `"credential"`, `"database"`, `"dataset"`, `"document"`, `"guardrail"`, `"media"`, `"model"`, `"prompt"`, `"reasoning"`, `"skill"`, `"system-prompt"`, `"token"`, `"tool"`, `"unknown"` | ||
138-
| `display` | Controls what elements are displayed: icon, text, or both. | `"both"`, `"text-only"`, `"icon-only"` | `"both"` ||
169+
| Name | Description | Type | Default | Required |
170+
| ---------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- |
171+
| `type` | The resource type that determines the badge variant, icon, and label. | `"agent"`, `"benchmark"`, `"benchmark-result"`, `"binary"`, `"certificate"`, `"code"`, `"compute"`, `"config"`, `"credential"`, `"database"`, `"dataset"`, `"document"`, `"guardrail"`, `"media"`, `"model"`, `"prompt"`, `"reasoning"`, `"skill"`, `"system-prompt"`, `"token"`, `"tool"`, `"unknown"` | ||
172+
| `display` | Controls what elements are displayed: icon, text, or both. | `"both"`, `"text-only"`, `"icon-only"` | `"both"` ||
173+
| `children` | Custom content to display in place of the default type label. | `ReactNode` | ||
174+
| `closeable` | When true, displays a close button on the badge. | `boolean` | `false` ||
175+
| `handleClosable` | Callback called when the close button is clicked. | `() => void` | ||

packages/demo/src/content/components/table.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ Basic usage:
6969

7070
### Clickable Rows
7171

72-
Rows accept an `onClick` handler, which enables hover interactions.
72+
Rows accept an `onClick` handler, which enables hover interactions. Use `data-state="selected"` to mark a row as selected.
73+
74+
Try clicking a row below to toggle its selected state!
7375

7476
<TableDemo client:only="react" variant="clickable" />
7577

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@eqtylab/equality",
33
"description": "EQTYLab's component and token-based design system",
44
"homepage": "https://equality.eqtylab.io/",
5-
"version": "1.7.3",
5+
"version": "1.8.0",
66
"license": "Apache-2.0",
77
"keywords": [
88
"component library",

packages/ui/src/components/resource-badge/resource-badge.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as React from 'react';
2+
13
import { Badge, type BadgeDisplayMode } from '@/components/badge/badge';
24
import styles from '@/components/resource-badge/resource-badge.module.css';
35

@@ -33,14 +35,30 @@ export type ResourceDisplayMode = BadgeDisplayMode;
3335
interface ResourceBadgeProps {
3436
type: ResourceType;
3537
display?: ResourceDisplayMode;
38+
closeable?: boolean;
39+
handleClosable?: () => void;
40+
children?: React.ReactNode;
3641
}
3742

38-
const ResourceBadge = ({ type, display = 'both' }: ResourceBadgeProps) => {
43+
const ResourceBadge = ({
44+
type,
45+
display = 'both',
46+
closeable,
47+
handleClosable,
48+
children,
49+
}: ResourceBadgeProps) => {
3950
const config = getTypeConfig(type);
4051

4152
return (
42-
<Badge icon={config.icon} display={display} className={config.className} variant={null}>
43-
{config.label}
53+
<Badge
54+
icon={config.icon}
55+
display={display}
56+
className={config.className}
57+
variant={null}
58+
closeable={closeable}
59+
handleClosable={handleClosable}
60+
>
61+
{children ?? config.label}
4462
</Badge>
4563
);
4664
};

packages/ui/src/components/table/table-components.module.css

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,25 @@
5353
grid-column: 1 / -1;
5454
}
5555

56+
.table-body .table-row:nth-child(even) {
57+
background-color: var(--table-stripe-bg);
58+
}
59+
5660
/* Clickable Variant */
5761

58-
.table-row--clickable {
62+
.table-row--clickable:not([data-state='selected']) {
5963
--mix-color: var(--color-brand-primary);
6064
--hover-darken: 50%;
6165
--hover-lighten: 50%;
6266
@apply cursor-pointer;
6367
@apply hover:bg-mixed-light! dark:hover:bg-mixed-dark!;
64-
@apply data-[state=selected]:bg-mixed-light dark:data-[state=selected]:bg-mixed-dark;
68+
}
69+
70+
.table-body .table-row--clickable[data-state='selected'] {
71+
background-color: light-dark(
72+
color-mix(in oklch, var(--color-brand-primary), white 40%),
73+
color-mix(in oklch, var(--color-brand-primary), black 40%)
74+
);
6575
}
6676

6777
.table-caption {
@@ -137,7 +147,3 @@
137147
.table--overlay.table-border {
138148
@apply border-border-overlay;
139149
}
140-
141-
.table-body .table-row:nth-child(even) {
142-
background-color: var(--table-stripe-bg);
143-
}

0 commit comments

Comments
 (0)