Skip to content
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

Migrate ChevronScroll Component from SCSS to Tailwind CSS #602

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions frontend/src/components/Scroll/ChevronScroll.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets revert all the changes to the original ChevronScroll.tsx file. I'd like for it to remain untouched so we have something to compare to, and other pages might still be using this component.

Edit:
On second thought, after reviewing, I see how difficult this instruction realistically is. I didn't realize there would be so much Component functionality to migrate. Sorry about that. I am going to change the instructions so that we just modify the CSS classes directly in the original Component files.

For this PR, lets remove the ChevronScrollTailwind.tsx file and keep the changes within ChevronScroll.tsx.

Thank you for going with the original instruction anyway even though it was silly 😅

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function ChevronScroll(props: React.PropsWithChildren<{}>) {
(e: React.UIEvent<HTMLDivElement>) => {
const { scrollLeft, scrollWidth, clientWidth } = e.currentTarget;
const maxScroll = scrollWidth - clientWidth - 1;
// show left chevron if not at start of scrollable area
// Show left chevron if not at the start of the scrollable area
setShowLeftChevron(scrollLeft !== 0);
//show right chevron if not at end of scrollable area
// Show right chevron if not at the end of the scrollable area
setShowRightChevron(scrollLeft < maxScroll);
},
[]
Expand All @@ -32,7 +32,7 @@ function ChevronScroll(props: React.PropsWithChildren<{}>) {
});
setChildIndex(childIndex + 1);
} else if (direction === "left") {
// if at end of scrollable area, don't want to skip over partially cut element
// If at the end of the scrollable area, don't skip over a partially cut element
if (!showRightChevron) {
scrollRef.current.scrollBy({
left: -1,
Expand All @@ -50,13 +50,10 @@ function ChevronScroll(props: React.PropsWithChildren<{}>) {
};

return (
<div className="chevron-scroll-outer-container">
<div className="whitespace-nowrap flex w-[1088px] h-[47px]">
<button
className={combineClasses(
"chevron-scroll-left-btn",
"align-center",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should convert this align-center class to tailwind. It can be found in the _alignment.scss file.

CSS:
align-items: center

"justify-center",
"row",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also convert this row class. Its definition is in _layout.scss

"bg-white px-[32px] py-0 cursor-pointer border-none justify-center",
showLeftChevron ? undefined : "hidden"
)}
onClick={() => scrollMove("left")}
Expand All @@ -67,23 +64,21 @@ function ChevronScroll(props: React.PropsWithChildren<{}>) {
<div
ref={scrollRef}
onScroll={handleChevronVisibility}
className="chevron-scroll-child-container"
className="scroll-snap-x mandatory overflow-auto flex items-center gap-4 scrollbar-none"
>
{props.children}
</div>
<button
className={combineClasses(
"chevron-scroll-right-btn",
"align-center",
"row",
"bg-white px-[32px] py-0 cursor-pointer border-none justify-center",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

px-[32px]

The chevron-scroll-right-btn class has a left padding of 15px and a right padding of 32px.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also keep the CSS for the above "align-center" and "row" classes.

showRightChevron ? undefined : "hidden"
)}
onClick={() => scrollMove("right")}
aria-label="Scroll right"
>
<IconChevronRight />
</button>
<button className="chevron-scroll-clear-btn">Clear all</button>
<button className="flex items-center underline font-bold text-lg text-gray-700 ml-4 bg-transparent p-0 border-none cursor-pointer">Clear all</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is perfect, very nice 👌

</div>
);
}
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/tw-components/ChevronScrollTailwind.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";

const ChevronScroll = () => {
return (
<div className="whitespace-nowrap flex w-[1088px] h-[47px]">
<div className="scroll-snap-x mandatory overflow-auto flex items-center gap-4 scrollbar-none">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • scroll-snap-x
  • mandatory
  • scrollbar-none

I don't think these are valid tailwind classes

{/* Chevron Scroll Left Button */}
<button
className="bg-white px-8 py-0 cursor-pointer border-none"
aria-label="Scroll Left"
>
{/* Insert left chevron icon here */}
</button>

{/* Scrollable Content */}
<div className="flex-1">Scrollable content goes here</div>

{/* Chevron Scroll Right Button */}
<button
className="bg-white px-8 py-0 cursor-pointer border-none"
aria-label="Scroll Right"
>
{/* Insert right chevron icon here */}
</button>
</div>

{/* Clear Button */}
<button className="flex items-center underline font-bold text-lg text-gray-700 ml-4 bg-transparent p-0 border-none cursor-pointer">
Clear
</button>
</div>
);
};

export default ChevronScroll;