UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

68 lines (67 loc) 2.39 kB
"use strict"; 'use client'; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScrollAreaThumb = void 0; var React = _interopRequireWildcard(require("react")); var _ScrollAreaRootContext = require("../root/ScrollAreaRootContext"); var _ScrollAreaScrollbarContext = require("../scrollbar/ScrollAreaScrollbarContext"); var _ScrollAreaScrollbarCssVars = require("../scrollbar/ScrollAreaScrollbarCssVars"); var _useRenderElement = require("../../utils/useRenderElement"); /** * The draggable part of the the scrollbar that indicates the current scroll position. * Renders a `<div>` element. * * Documentation: [Base UI Scroll Area](https://base-ui.com/react/components/scroll-area) */ const ScrollAreaThumb = exports.ScrollAreaThumb = /*#__PURE__*/React.forwardRef(function ScrollAreaThumb(componentProps, forwardedRef) { const { render, className, ...elementProps } = componentProps; const { thumbYRef, thumbXRef, handlePointerDown, handlePointerMove, handlePointerUp, setScrollingX, setScrollingY } = (0, _ScrollAreaRootContext.useScrollAreaRootContext)(); const { orientation } = (0, _ScrollAreaScrollbarContext.useScrollAreaScrollbarContext)(); const state = React.useMemo(() => ({ orientation }), [orientation]); const element = (0, _useRenderElement.useRenderElement)('div', componentProps, { ref: [forwardedRef, orientation === 'vertical' ? thumbYRef : thumbXRef], state, props: [{ onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp(event) { if (orientation === 'vertical') { setScrollingY(false); } if (orientation === 'horizontal') { setScrollingX(false); } handlePointerUp(event); }, style: { ...(orientation === 'vertical' && { height: `var(${_ScrollAreaScrollbarCssVars.ScrollAreaScrollbarCssVars.scrollAreaThumbHeight})` }), ...(orientation === 'horizontal' && { width: `var(${_ScrollAreaScrollbarCssVars.ScrollAreaScrollbarCssVars.scrollAreaThumbWidth})` }) } }, elementProps] }); return element; }); if (process.env.NODE_ENV !== "production") ScrollAreaThumb.displayName = "ScrollAreaThumb";