Skip to content

Commit

Permalink
[PBNTR-833] Advanced Table: Hide Actions Bar Till Rows are Selected (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nidaqg authored Feb 5, 2025
1 parent 7e80bab commit 4ba0f44
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ export const TableHeaderCell = ({
sortIcon,
table
}: TableHeaderCellProps) => {
const { sortControl, responsive, selectableRows, hasAnySubRows, showActionsBar, inlineRowLoading } =
useContext(AdvancedTableContext);
const {
sortControl,
responsive,
selectableRows,
hasAnySubRows,
showActionsBar,
inlineRowLoading,
isActionBarVisible,
} = useContext(AdvancedTableContext);

type justifyTypes = "none" | "center" | "start" | "end" | "between" | "around" | "evenly"

Expand All @@ -65,7 +72,7 @@ export const TableHeaderCell = ({

const cellClassName = classnames(
"table-header-cells",
`${showActionsBar && "header-cells-with-actions"}`,
`${showActionsBar && isActionBarVisible && "header-cells-with-actions"}`,
`${isChrome() ? "chrome-styles" : ""}`,
`${enableSorting ? "table-header-cells-active" : ""}`,
{ "pinned-left": responsive === "scroll" && isPinnedLeft },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const showActionBar = (elem: HTMLElement) => {
elem.style.display = "block";
const height = elem.scrollHeight + "px";
elem.style.height = height;
elem.classList.add("is-visible");
elem.style.overflow = "hidden";

window.setTimeout(() => {
if (elem.classList.contains("is-visible")) {
elem.style.height = "";
elem.style.overflow = "visible";
}
}, 300);
};

export const hideActionBar = (elem: HTMLElement) => {
elem.style.height = elem.scrollHeight + "px";
elem.offsetHeight;
window.setTimeout(() => {
elem.style.height = "0";
elem.style.overflow = "hidden";
}, 10);
window.setTimeout(() => {
elem.classList.remove("is-visible");
}, 300);
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
width: 100%;
}

.row-selection-actions-card {
border-bottom-right-radius: 0px !important;
border-bottom-left-radius: 0px !important;
border-bottom-color: transparent;
}

.row-selection-actions-card {
border-bottom-right-radius: 0px !important;
border-bottom-left-radius: 0px !important;
border-bottom-color: transparent;
transition: height 300ms ease;
}
.table-header-cells:first-child {
min-width: 180px;
}
Expand Down
55 changes: 34 additions & 21 deletions playbook/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback } from "react"
import React, { useState, useEffect, useCallback, useRef } from "react"
import classnames from "classnames"

import { GenericObject } from "../types"
Expand Down Expand Up @@ -27,6 +27,7 @@ import FlexItem from "../pb_flex/_flex_item"
import AdvancedTableContext from "./Context/AdvancedTableContext"

import { updateExpandAndCollapseState } from "./Utilities/ExpansionControlHelpers"
import { showActionBar, hideActionBar } from "./Utilities/ActionBarAnimationHelper"

import { CustomCell } from "./Components/CustomCell"
import { TableHeader } from "./SubKits/TableHeader"
Expand Down Expand Up @@ -295,6 +296,20 @@ const AdvancedTable = (props: AdvancedTableProps) => {
const onPageChange = (page: number) => {
table.setPageIndex(page - 1)
}
//When to show the actions bar as a whole
const isActionBarVisible = selectableRows && showActionsBar && selectedRowsLength > 0

//Ref and useEffect for animating the actions bar
const cardRef = useRef(null);
useEffect(() => {
if (cardRef.current) {
if (isActionBarVisible) {
showActionBar(cardRef.current);
} else {
hideActionBar(cardRef.current);
}
}
}, [isActionBarVisible]);

return (
<div {...ariaProps}
Expand All @@ -311,6 +326,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
expandedControl,
handleExpandOrCollapse,
inlineRowLoading,
isActionBarVisible,
loading,
responsive,
setExpanded,
Expand All @@ -333,27 +349,24 @@ const AdvancedTable = (props: AdvancedTableProps) => {
total={table.getPageCount()}
/>
}
{
selectableRows && showActionsBar && (
<Card className="row-selection-actions-card"
padding="xs"
<Card
borderNone={!isActionBarVisible}
className={`${isActionBarVisible && "show-action-card row-selection-actions-card"}`}
htmlOptions={{ ref: cardRef as any }}
padding={`${isActionBarVisible ? "xs" : "none"}`}
>
<Flex alignItems="center"
justify="between"
>
<Caption color="light"
paddingLeft="xs"
size="xs"
>
<Flex alignItems="center"
justify="between"
>
<Caption color="light"
paddingLeft="xs"
size="xs"
>
{selectedRowsLength} Selected
</Caption>
<FlexItem>
{actions}
</FlexItem>
</Flex>
</Card>
)
}
{selectedRowsLength} Selected
</Caption>
<FlexItem>{actions}</FlexItem>
</Flex>
</Card>
<Table
className={`${loading ? "content-loading" : ""}`}
dark={dark}
Expand Down

0 comments on commit 4ba0f44

Please sign in to comment.