Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sparkle] - feature: enhance DataTable with interactive row elements #6617

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sparkle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sparkle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dust-tt/sparkle",
"version": "0.2.197",
"version": "0.2.198",
"scripts": {
"build": "rm -rf dist && rollup -c",
"build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
Expand Down
18 changes: 11 additions & 7 deletions sparkle/src/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function DataTable<TData, TValue>({
: ArrowDownIcon
}
className={classNames(
"s-h-4 s-w-3 s-font-extralight",
"s-ml-1 s-w-2.5 s-font-extralight",
header.column.getIsSorted()
? "s-opacity-100"
: "s-opacity-0"
Expand All @@ -97,8 +97,8 @@ export function DataTable<TData, TValue>({
{table.getRowModel().rows.map((row) => (
<DataTable.Row
key={row.id}
clickable={row.original.clickable}
onClick={row.original.onClick}
onMoreClick={row.original.onMoreClick}
>
{row.getVisibleCells().map((cell) => (
<DataTable.Cell key={cell.id}>
Expand Down Expand Up @@ -182,38 +182,42 @@ DataTable.Body = function Body({

interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
children: ReactNode;
clickable?: boolean;
onClick?: () => void;
onMoreClick?: () => void;
}

DataTable.Row = function Row({
children,
className,
clickable = false,
onClick,
onMoreClick,
...props
}: RowProps) {
return (
<tr
className={classNames(
"s-border-b s-border-structure-200 s-text-sm",
onMoreClick ? "s-cursor-pointer" : "",
className || ""
)}
onClick={onClick ? onClick : undefined}
{...props}
>
{children}
{clickable && (
{onMoreClick && (
<td
className="s-w-1 s-cursor-pointer s-pl-1 s-text-element-600"
onClick={clickable ? onClick : undefined}
onClick={(e) => {
e.stopPropagation(); // Prevent row click event
onMoreClick?.();
}}
>
<Icon visual={MoreIcon} size="sm" />
</td>
)}
</tr>
);
};

interface CellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
avatarUrl?: string;
icon?: React.ComponentType<{ className?: string }>;
Expand Down
5 changes: 3 additions & 2 deletions sparkle/src/stories/DataTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Data = {
icon?: React.ComponentType<{ className?: string }>;
clickable?: boolean;
onClick?: () => void;
showMore?: boolean;
onMoreClick?: () => void;
};

const DataTableExample = () => {
Expand All @@ -35,8 +37,8 @@ const DataTableExample = () => {
lastUpdated: "July 8, 2023",
size: "32kb",
avatarUrl: "https://dust.tt/static/droidavatar/Droid_Lime_3.jpg",
clickable: true,
onClick: () => console.log("hehe"),
onMoreClick: () => console.log("show more"),
},
{
name: "Design",
Expand All @@ -45,7 +47,6 @@ const DataTableExample = () => {
lastUpdated: "2023-07-09",
size: "64kb",
icon: FolderIcon,
clickable: false,
},
{
name: "Development",
Expand Down
Loading