From 45bca81d1c296b0e4a22a2513371e5ae58fb46b6 Mon Sep 17 00:00:00 2001 From: Jesse Bofill Date: Tue, 9 Jan 2024 13:34:47 -0700 Subject: [PATCH] chore: finish profile add/overwrite modal styling --- src/components/generic/ScrollableWindow.tsx | 63 ++++++++++++++------- src/components/modals/TabProfileModals.tsx | 61 +++++++++++++------- src/hooks/useIsOverflowing.tsx | 19 +++++++ 3 files changed, 101 insertions(+), 42 deletions(-) create mode 100644 src/hooks/useIsOverflowing.tsx diff --git a/src/components/generic/ScrollableWindow.tsx b/src/components/generic/ScrollableWindow.tsx index 838ffb2..87981c4 100644 --- a/src/components/generic/ScrollableWindow.tsx +++ b/src/components/generic/ScrollableWindow.tsx @@ -1,19 +1,47 @@ -import { GamepadButton } from 'decky-frontend-lib'; -import { FC, Fragment } from 'react'; +import { GamepadButton, gamepadDialogClasses, scrollPanelClasses } from 'decky-frontend-lib'; +import { FC, Fragment, useRef } from 'react'; import { ModalPosition, Panel, ScrollPanelGroup } from '../docs/Scrollable'; +import { useIsOverflowing } from '../../hooks/useIsOverflowing'; export interface ScrollableWindowProps { height: string; - fadePercent: number; + fadeAmount: string; + scrollBarWidth?: string; } -export const ScrollableWindow: FC = ({ height, fadePercent, children }) => { +export const ScrollableWindow: FC = ({ height, fadeAmount, scrollBarWidth, children }) => { + const barWidth = scrollBarWidth === undefined || scrollBarWidth === '' ? '4px' : scrollBarWidth; + + const scrollPanelRef = useRef(); + const isOverflowing = useIsOverflowing(scrollPanelRef); + + const panel = ( + + + {children} + + + ); + return ( <>
= ({ height, fadePercen style={{ position: 'relative', height: height, - WebkitMaskImage: `linear-gradient(to bottom, transparent, black ${fadePercent}%, black ${100 - fadePercent}%, transparent 100%)` + WebkitMask: `linear-gradient(to right , transparent, transparent calc(100% - ${barWidth}), white calc(100% - ${barWidth})), linear-gradient(to bottom, transparent, black ${fadeAmount}, black calc(100% - ${fadeAmount}), transparent 100%)` }}> - - - - - {children} - - - + {isOverflowing ? ( + + {panel} + + ) : ( +
+ {panel} +
+ )}
); diff --git a/src/components/modals/TabProfileModals.tsx b/src/components/modals/TabProfileModals.tsx index 00e183c..d6031e7 100644 --- a/src/components/modals/TabProfileModals.tsx +++ b/src/components/modals/TabProfileModals.tsx @@ -4,6 +4,7 @@ import { TabMasterManager } from '../../state/TabMasterManager'; import { TabMasterContextProvider } from "../../state/TabMasterContext"; import { TabProfileModalStyles } from "../styles/TabProfileModalStyles"; import { TabListLabel } from '../TabListLabel'; +import { ScrollableWindow } from '../generic/ScrollableWindow'; export interface CreateTabProfileModalProps { tabMasterManager: TabMasterManager, @@ -40,17 +41,17 @@ export const CreateTabProfileModal: VFC = ({ tabMast } /> - {/* */} -
- {visibleTabs.map(tabContainer => { - return ( +
+ +
+ {visibleTabs.map(tabContainer => - ); - })} -
- {/*
*/} + )} +
+ +
@@ -77,14 +78,35 @@ export const OverwriteTabProfileModal: VFC = ({ p }} onCancel={() => closeModal!()} > -
-
- New Tabs: - {visibleTabsList.map(tabContainer =>
{tabContainer.title}
)} +
+
+
+ New Tabs +
+
+ Existing Tabs +
-
- Existing Tabs: - {existingTabs.map(tabContainer =>
{tabContainer?.title}
)} +
+
+ +
+
+ {visibleTabsList.map(tabContainer => + + + + )} +
+
+ {existingTabs.map(tabContainer => + + + + )} +
+
+
@@ -94,18 +116,13 @@ export const OverwriteTabProfileModal: VFC = ({ p }; const TabItem: FC<{}> = ({ children }) => { + return ( <>
{children}
-
+
); }; diff --git a/src/hooks/useIsOverflowing.tsx b/src/hooks/useIsOverflowing.tsx new file mode 100644 index 0000000..aba924e --- /dev/null +++ b/src/hooks/useIsOverflowing.tsx @@ -0,0 +1,19 @@ +import { MutableRefObject, useLayoutEffect, useState } from 'react'; + +export const useIsOverflowing = (ref: MutableRefObject) => { + const [isOverflow, setIsOverflow] = useState(false); + + useLayoutEffect(() => { + const { current } = ref; + const trigger = () => { + const hasOverflow = current!.scrollHeight > current!.clientHeight; + setIsOverflow(hasOverflow); + }; + + if (current) { + trigger(); + } + }, [ref]); + + return isOverflow; +};