Mislav Lukach 764077ef3d
Feat/create UI dir (#9462)
Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
2025-07-03 13:26:19 +00:00

51 lines
1.2 KiB
TypeScript

import type { PropsWithChildren } from "react";
import type { HTMLProps } from "../../shared/types";
import { cn } from "../../shared/utils/cn";
export type ScrollableMode = "auto" | "scroll";
export type ScrollableType = "horizontal" | "vertical";
export type ScrollableProps = HTMLProps<"div"> & {
mode?: ScrollableMode;
type?: ScrollableType;
};
const scrollableStyles: Record<
ScrollableType,
Record<ScrollableMode, string>
> = {
horizontal: {
auto: "overflow-x-auto overflow-y-hidden whitespace-nowrap",
scroll: "overflow-x-scroll overflow-y-hidden whitespace-nowrap",
},
vertical: {
auto: "overflow-y-auto overflow-x-hidden",
scroll: "overflow-y-scroll overflow-x-hidden",
},
};
export const Scrollable = ({
className,
children,
tabIndex,
mode = "auto",
type = "vertical",
...props
}: PropsWithChildren<ScrollableProps>) => {
const style = scrollableStyles[type][mode];
return (
<div
tabIndex={tabIndex ?? 0}
{...props}
className={cn(
"scrollbar-thin scrollbar-thumb-light-neutral-700 scrollbar-track-grey-985",
"scrollbar-thumb-rounded-md scrollbar-track-rounded-md",
style,
className
)}
>
{children}
</div>
);
};