Skip to content

Commit

Permalink
Row Selection, background color
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesoroka committed Mar 12, 2024
1 parent e559d9f commit 336c024
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
51 changes: 24 additions & 27 deletions src/DataTable/TemplateTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,30 @@ import { RowsIcon } from "lucide-react";
import { Checkbox } from "@/components/ui/checkbox";

const columns = [
{
accessorKey: "uuid",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => {
row.toggleSelected(!!value);
}}
aria-label="Select row"
/>
),
},
// {
// accessorKey: "uuid",
// header: ({ table }) => <>#</>,
// cell: ({ row }) => (
// <Checkbox
// checked={row.getIsSelected()}
// onCheckedChange={(value) => {
// row.toggleSelected(!!value);
// }}
// aria-label="Select row"
// />
// ),
// },

{
accessorKey: "template_name",
header: "Template Name",
cell: (props) => <p>{props.getValue()}</p>,
},
{
accessorKey: "template_author",
header: "Template Author",
cell: (props) => <p>{props.getValue()}</p>,
},
{
accessorKey: "METHOD",
header: "Method",
Expand All @@ -58,6 +55,8 @@ const columns = [
export default function TemplateTable({ data }) {
const [rowSelection, setRowSelection] = useState({});

console.log(rowSelection);

const table = useReactTable({
data,
columns,
Expand All @@ -71,11 +70,7 @@ export default function TemplateTable({ data }) {

const setIdShosen = useSetIsShosen();
useEffect(() => {
setIdShosen(
data && Object.keys(rowSelection)[0]
? data[Object.keys(rowSelection)[0]].uuid
: null
);
setIdShosen(data && rowSelection ? data[rowSelection]?.uuid : null);
}, [rowSelection]);

return (
Expand All @@ -96,6 +91,8 @@ export default function TemplateTable({ data }) {
<tr
key={RowsIcon.id}
data-state={row.getIsSelected() && "selected"}
onClick={() => setRowSelection(row.id)}
className={row.id == rowSelection ? "selected" : "nonSelected"}
>
{row.getVisibleCells().map((cell) => (
<td key={cell.id}>
Expand Down
8 changes: 8 additions & 0 deletions src/StartScreenComp/StartScreenComp.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,11 @@ tr.choosen {
iframe {
border: none;
}

.selected {
background-color: #dee0ff;
}
.nonSelected {
background-color: #fff;
cursor: pointer;
}
14 changes: 7 additions & 7 deletions src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"
import * as React from "react";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";

import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
Expand All @@ -22,7 +22,7 @@ const Checkbox = React.forwardRef<
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;

export { Checkbox }
export { Checkbox };

0 comments on commit 336c024

Please sign in to comment.