-
Notifications
You must be signed in to change notification settings - Fork 158
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
feat:show table in mobile with hscroll #1273
Merged
DonKoko
merged 15 commits into
Shelf-nu:main
from
rajeshj11:feat-969-show-table-with-hscroll
Aug 22, 2024
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ebb97eb
feat:show table in mobile with hscroll
rajeshj11 80b5625
Merge branch 'main' into feat-969-show-table-with-hscroll
rajeshj11 0f634f3
fix: handle the broken manage assets and bookings and other feedback …
rajeshj11 d0232ec
chore:formatted
rajeshj11 47c2ebd
Merge branch 'feat-969-show-table-with-hscroll' of github.com:rajeshj…
rajeshj11 c132c9a
chore:chnage the fade effect width to 35px
rajeshj11 974b87c
fix:fixed the fade z-index issue
rajeshj11 b5ddc8f
fix:gradient issue and add lin breaker to description
rajeshj11 e95edc3
fix: description issue
rajeshj11 708b0b1
fix:added linbreak for kit also and formatted
rajeshj11 df28816
chore:cleanup the commented code
rajeshj11 8583a72
chore:formatted
rajeshj11 b3fcd66
refactore:moved the fade effect changes to new hook
rajeshj11 3575da6
chore:formatted
rajeshj11 42bfa77
chore:renamed the hook
rajeshj11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { TdHTMLAttributes } from "react"; | ||
import React from "react"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { tw } from "~/utils/tw"; | ||
|
||
export function Table({ | ||
|
@@ -9,10 +9,49 @@ export function Table({ | |
children: React.ReactNode; | ||
className?: string; | ||
}) { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const [isOverflowing, setIsOverflowing] = useState(false); | ||
|
||
useEffect(() => { | ||
const checkOverflow = () => { | ||
const container = containerRef.current; | ||
if (container) { | ||
const hasOverflow = container.scrollWidth > container.clientWidth; | ||
const hasReachedEnd = | ||
container.scrollLeft + container.clientWidth >= container.scrollWidth; | ||
setIsOverflowing(hasOverflow && !hasReachedEnd); | ||
} | ||
}; | ||
|
||
checkOverflow(); // Initial check | ||
window.addEventListener("resize", checkOverflow); // Check on resize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to do this, inside the useEffect you should have a |
||
|
||
// Ensure the scroll event listener is added correctly | ||
const container = containerRef.current; | ||
if (container) { | ||
container.addEventListener("scroll", checkOverflow); | ||
} | ||
|
||
return () => { | ||
window.removeEventListener("resize", checkOverflow); | ||
if (container) { | ||
container.removeEventListener("scroll", checkOverflow); | ||
} | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<table className={tw("w-full table-auto border-collapse", className)}> | ||
{children} | ||
</table> | ||
<div className={`relative ${isOverflowing ? "overflowing" : ""}`}> | ||
<div className="fixed-gradient"></div> | ||
<div | ||
ref={containerRef} | ||
className="scrollbar-top scrollbar-always-visible" | ||
> | ||
<table className={tw("w-full table-auto border-collapse", className)}> | ||
{children} | ||
</table> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
|
@@ -56,7 +95,10 @@ interface TdProps extends TdHTMLAttributes<HTMLTableCellElement> { | |
export function Td({ children, className, ...props }: TdProps) { | ||
return ( | ||
<td | ||
className={tw("whitespace-nowrap border-b p-4 md:px-6", className)} | ||
className={tw( | ||
"max-w-[200px] truncate whitespace-nowrap border-b p-4 md:px-6", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please abstract this into its own hook called
useTableIsOverflowing
which returns the value?