OHIF with Cornerstone3D 2.0 (#4347)

This commit is contained in:
Alireza authored and GitHub committed 2024-11-06 07:15:27 -05:00
1 parent 8981a61b8c
commit 7ce7127d7c
803 files changed
+32760 -15893

No files matched your search

@@ -2,25 +2,101 @@ import * as React from 'react';
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
import { cn } from '../../lib/utils';
import { Icons } from '../Icons';
/**
* Props interface for the ScrollArea component.
* Extends Radix UI ScrollArea root props.
*/
interface ScrollAreaProps extends React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> {
/** Flag to show/hide scroll indicator arrows at top and bottom */
showArrows?: boolean;
}
/**
* A custom scroll area component built on top of Radix UI's ScrollArea.
* Provides a scrollable container with custom styling and optional scroll indicators.
*
* @param props - The component props
* @param props.className - Additional CSS classes to apply
* @param props.children - The content to be scrolled
* @param props.showArrows - Whether to show scroll indicator arrows
* @param ref - Forward ref for the root element
*
* @example
* ```tsx
* <ScrollArea showArrows>
* <div>Scrollable content</div>
* </ScrollArea>
* ```
*/
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn('relative overflow-hidden', className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
));
ScrollAreaProps
>(({ className, children, showArrows = false, ...props }, ref) => {
const [showBottomArrow, setShowBottomArrow] = React.useState(false);
const [showTopArrow, setShowTopArrow] = React.useState(false);
const viewportRef = React.useRef<HTMLDivElement>(null);
const checkScroll = React.useCallback(() => {
if (viewportRef.current) {
const { scrollHeight, clientHeight, scrollTop } = viewportRef.current;
setShowBottomArrow(scrollHeight > clientHeight && scrollTop < scrollHeight - clientHeight);
setShowTopArrow(scrollTop > 0);
}
}, []);
React.useEffect(() => {
checkScroll();
window.addEventListener('resize', checkScroll);
return () => window.removeEventListener('resize', checkScroll);
}, [checkScroll]);
return (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn('relative h-full overflow-hidden', className)}
{...props}
>
<ScrollAreaPrimitive.Viewport
ref={viewportRef}
className="h-full w-full rounded-[inherit]"
onScroll={checkScroll}
>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
{showArrows && showTopArrow && (
<div className="from-background via-background/80 pointer-events-none absolute -top-1 left-0 right-0 flex h-8 items-center justify-center bg-gradient-to-b to-transparent">
<Icons.ChevronOpen className="text-foreground/50 h-8 w-8 rotate-180" />
</div>
)}
{showArrows && showBottomArrow && (
<div className="from-background via-background/80 pointer-events-none absolute -bottom-1 left-0 right-0 flex h-8 items-center justify-center bg-gradient-to-t to-transparent">
<Icons.ChevronOpen className="text-foreground/50 h-8 w-8" />
</div>
)}
</ScrollAreaPrimitive.Root>
);
});
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
/**
* Custom scrollbar component for the ScrollArea.
* Provides styled scrollbars that can be either vertical or horizontal.
*
* @param props - The component props
* @param props.className - Additional CSS classes to apply
* @param props.orientation - The scrollbar orientation ('vertical' | 'horizontal')
* @param ref - Forward ref for the scrollbar element
*
* @example
* ```tsx
* <ScrollBar orientation="vertical" />
* ```
*/
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>