import { forwardRef, type HTMLAttributes, type ReactNode } from "react";
import { useHorizontalWheelScroll, type UseHorizontalWheelScrollOptions } from "@/hooks/useHorizontalWheelScroll";
import { mergeRefs } from "@/utils/mergeRefs";
export type HorizontalWheelScrollProps = HTMLAttributes & UseHorizontalWheelScrollOptions;
/** 横向滚动容器:滚轮垂直滑动转为左右滚动 */
export const HorizontalWheelScroll = forwardRef(function HorizontalWheelScroll(
{ enabled, ignoreWithin, className, children, ...rest },
forwardedRef,
) {
const wheelRef = useHorizontalWheelScroll({ enabled, ignoreWithin });
return (
{children}
);
});
export type HorizontalWheelScrollRowProps = Omit, "children"> &
UseHorizontalWheelScrollOptions & {
leading?: ReactNode;
scrollClassName?: string;
scrollProps?: HTMLAttributes;
children?: ReactNode;
};
/** 左侧固定 + 右侧横向滚动(滚轮可左右滑) */
export const HorizontalWheelScrollRow = forwardRef(function HorizontalWheelScrollRow(
{ leading, scrollClassName, scrollProps, className, children, enabled, ignoreWithin, ...rest },
forwardedRef,
) {
const wheelRef = useHorizontalWheelScroll({ enabled, ignoreWithin });
const { className: scrollExtraClassName, ...scrollRest } = scrollProps ?? {};
return (
);
});