Skip to content

Commit

Permalink
[PBNTR-834] Advanced Table kit: Address scss changes and add maxHeigh…
Browse files Browse the repository at this point in the history
…t prop (#4191)

**What does this PR do?** A clear and concise description with your
runway ticket url.
[PBNTR-834](https://runway.powerhrg.com/backlog_items/PBNTR-834) enacts
the plan set forward from the investigation in
[PBNTR-769](https://runway.powerhrg.com/backlog_items/PBNTR-769). There
were some unforeseen issues getting the overflow/appearance to work as
expected for all possible table variants, and so doc examples have
explicit usage/prop instructions.

The existing "Table Props" doc example which has a sticky header already
has been updated to showcase a sticky header on a nonresponsive table
(whose functionality is unchanged with this PR); a new "Table Props
Sticky Header" doc example showcases sticky header + responsiveness 1st
column sticky working side by side in a smaller screen like the previous
investigation desired. The header in large screen mode is sticky within
the container - not sticky to the page but if rows are expanded past the
given max height it will get an overflow-y scroll bar.

**Screenshots:** Screenshots to visualize your addition/change
<img width="1326" alt="for PR both doc ex"
src="https://github.com/user-attachments/assets/5c16951e-34e3-40ed-9e6d-2ee671886211"
/>
<img width="1302" alt="nonresponsive table props doc ex"
src="https://github.com/user-attachments/assets/980775c3-adaa-4224-9777-d89d6c16c34f"
/>
<img width="534" alt="responsive small screen doc ex"
src="https://github.com/user-attachments/assets/d42f9e38-39a1-4f1f-b07b-1b3bb2b5822d"
/>
<img width="1313" alt="responsive large screen doc ex"
src="https://github.com/user-attachments/assets/acf0754a-f613-4dbc-a4d0-b8594b84deb1"
/>


**How to test?** Steps to confirm the desired behavior:
1. Go to the [Table Props doc
example](https://pr4191.playbook.beta.px.powerapp.cloud/kits/advanced_table/react#table-props)
and scroll down the page to see the sticky header in action for a
nonresponsive table. Do this on a large window and a smaller one.
2. Go to the [Table Props Sticky Header doc
example(https://pr4191.playbook.beta.px.powerapp.cloud/kits/advanced_table/react#table-props-sticky-header).
Expand at least 3 rows to activate the overflow-y based on the max
height given to the table. On a large window, scroll up and down and see
the sticky header for the container in action. Make the window smaller
and see the sticky header and responsiveness first sticky column both
work within the container of the table.


#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
~~- [ ] **TESTS** I have added test coverage to my code.~~
  • Loading branch information
ElisaShapiro authored Feb 7, 2025
1 parent e087920 commit 40bdc6b
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,43 @@
color: $primary !important;
}

// Sticky Header
.sticky-header {
thead {
z-index: 3 !important;
}
}

// Max height overflow - the below prevents expansion from overflowing container at full screen for responsive and nonresponsive tables
&.advanced-table-max-height-xs {
max-height: 320px;
overflow-y: auto;
}
&.advanced-table-max-height-sm {
max-height: 480px;
overflow-y: auto;
}
&.advanced-table-max-height-md {
max-height: 768px;
overflow-y: auto;
}
&.advanced-table-max-height-lg {
max-height: 1024px;
overflow-y: auto;
}
&.advanced-table-max-height-xl {
max-height: 1280px;
overflow-y: auto;
}
&.advanced-table-max-height-xxl {
max-height: 1440px;
overflow-y: auto;
}
&.advanced-table-max-height-xxxl {
max-height: 1920px;
overflow-y: auto;
}

// Icons
.button-icon {
display: flex;
Expand Down Expand Up @@ -214,7 +251,13 @@
.bg-white td:first-child {
background-color: $white;
}

.sticky-header {
thead {
th:first-child {
box-shadow: 1px 0 10px -2px $border_light !important;
}
}
}
}
}
@media only screen and (min-width: $screen-xl-min) {
Expand Down Expand Up @@ -302,6 +345,14 @@
.bg-white td:first-child {
background-color: $bg_dark_card;
}
.sticky-header {
thead {
th:first-child {
background: $bg_dark;
box-shadow: 1px 0 10px -2px $border_dark !important;
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type AdvancedTableProps = {
initialLoadingRowsCount?: number
inlineRowLoading?: boolean
loading?: boolean | string
maxHeight?: "auto" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl"
onRowToggleClick?: (arg: Row<GenericObject>) => void
onToggleExpansionClick?: (arg: Row<GenericObject>) => void
pagination?: boolean,
Expand Down Expand Up @@ -80,6 +81,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
initialLoadingRowsCount = 10,
inlineRowLoading = false,
loading,
maxHeight,
onRowToggleClick,
onToggleExpansionClick,
pagination = false,
Expand Down Expand Up @@ -289,6 +291,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
const classes = classnames(
buildCss("pb_advanced_table"),
`advanced-table-responsive-${responsive}`,
maxHeight ? `advanced-table-max-height-${maxHeight}` : '', // max height as kit prop not global prop to control overflow-y
globalProps(props),
className
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const AdvancedTableTableProps = (props) => {
<div>
<AdvancedTable
columnDefinitions={columnDefinitions}
responsive="none"
tableData={MOCK_DATA}
tableProps={tableProps}
{...props}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
This kit uses the [Table kit](https://playbook.powerapp.cloud/kits/table/react) under the hood which comes with it's own set of props. If you want to apply certain Table props to that underlying kit, you can do so by using the optional `tableProps` prop. This prop must be an object that contains valid Table props. For a full list of Table props, see [here](https://playbook.powerapp.cloud/kits/table/react).
This kit uses the [Table kit](https://playbook.powerapp.cloud/kits/table/react) under the hood which comes with it's own set of props. If you want to apply certain Table props to that underlying kit, you can do so by using the optional `tableProps` prop. This prop must be an object that contains valid Table props. For a full list of Table props, see [here](https://playbook.powerapp.cloud/kits/table/react).

This doc example showcases how to set a sticky header for a nonresponsive table. To achieve sticky header AND responsive functionality, see the ["Table Props Sticky Header"](https://playbook.powerapp.cloud/kits/advanced_table/react#table-props-sticky-header) doc example below.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from "react"
import { AdvancedTable } from "playbook-ui"
import MOCK_DATA from "./advanced_table_mock_data.json"

const AdvancedTableTablePropsStickyHeader = (props) => {
const columnDefinitions = [
{
accessor: "year",
label: "Year",
cellAccessors: ["quarter", "month", "day"],
},
{
accessor: "newEnrollments",
label: "New Enrollments",
},
{
accessor: "scheduledMeetings",
label: "Scheduled Meetings",
},
{
accessor: "attendanceRate",
label: "Attendance Rate",
},
{
accessor: "completedClasses",
label: "Completed Classes",
},
{
accessor: "classCompletionRate",
label: "Class Completion Rate",
},
{
accessor: "graduatedStudents",
label: "Graduated Students",
},
]

const tableProps = {
sticky: true
}

return (
<div>
<AdvancedTable
columnDefinitions={columnDefinitions}
maxHeight="xs"
tableData={MOCK_DATA}
tableProps={tableProps}
{...props}
/>
</div>
)
}

export default AdvancedTableTablePropsStickyHeader
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Create a sticky header that works for responsive Advanced Tables by setting `sticky: true` via `tableProps` and giving the AdvancedTable a `maxHeight` using our [Max Height](https://playbook.powerapp.cloud/visual_guidelines/max_height) global prop. This behavior requires a `maxHeight` to work. The header is sticky within the table container, allowing for it to work along with the first column stickiness of a responsive table on smaller screen sizes.

A sticky header on a nonresponsive table is demonstrated in the ["Table Props"](https://playbook.powerapp.cloud/kits/advanced_table/react#table-props) doc example above.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ examples:
- advanced_table_collapsible_trail: Collapsible Trail
- advanced_table_table_options: Table Options
- advanced_table_table_props: Table Props
- advanced_table_table_props_sticky_header: Table Props Sticky Header
- advanced_table_inline_row_loading: Inline Row Loading
- advanced_table_responsive: Responsive Tables
- advanced_table_custom_cell: Custom Components for Cells
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export { default as AdvancedTableSelectableRows } from './_advanced_table_select
export { default as AdvancedTableSelectableRowsNoSubrows } from './_advanced_table_selectable_rows_no_subrows.jsx'
export { default as AdvancedTableNoSubrows } from './_advanced_table_no_subrows.jsx'
export { default as AdvancedTableSelectableRowsHeader } from './_advanced_table_selectable_rows_header.jsx'
export { default as AdvancedTableSelectableRowsActions } from './_advanced_table_selectable_rows_actions.jsx'
export { default as AdvancedTableSelectableRowsActions } from './_advanced_table_selectable_rows_actions.jsx'
export { default as AdvancedTableTablePropsStickyHeader } from './_advanced_table_table_props_sticky_header.jsx'

0 comments on commit 40bdc6b

Please sign in to comment.