-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1573 from openmsupply/1569-Header-labels-for-mobi…
…le-tables #1569 Header labels for mobile tables
- Loading branch information
Showing
6 changed files
with
103 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { useViewport } from '../../contexts/ViewportState' | ||
import { HideOnMobileTestMethod } from '../types' | ||
|
||
/** | ||
* When displayed on mobile devices, table rows become "stacked", in that each | ||
* cell is stacked vertically within a box. This removes any ability to see the | ||
* field names (column headers), so this components provides a simple wrapper | ||
* around table cells to inject a header back in as a label. When not in | ||
* "mobile" view, the table cells will be rendered unchanged | ||
* | ||
* It also has a few options so that this behaviour can be suppressed (in cases | ||
* where the context clearly implies the label), or hidden completely in mobile | ||
* view. | ||
*/ | ||
|
||
interface MobileLabelWrapperProps { | ||
label: string | ||
rowData: Record<string, unknown> | ||
hideLabel?: boolean | ||
hideCell?: boolean | HideOnMobileTestMethod | ||
} | ||
|
||
export const TableCellMobileLabelWrapper: React.FC<MobileLabelWrapperProps> = ({ | ||
children, | ||
rowData, | ||
label, | ||
hideCell, | ||
hideLabel = false, | ||
}) => { | ||
const { isMobile } = useViewport() | ||
|
||
if (isMobile && ((typeof hideCell === 'function' && hideCell(rowData)) || hideCell === true)) | ||
return null | ||
|
||
if (!isMobile || hideLabel) return <>{children}</> | ||
|
||
return ( | ||
<div className="flex-row" style={{ gap: 5, alignItems: 'flex-end' }}> | ||
<strong className="slightly-smaller-text">{label}:</strong> {children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters