@present-day/scroll-area 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/base-ui.d.mts +23 -0
- package/dist/base-ui.d.ts +23 -0
- package/dist/base-ui.js +319 -0
- package/dist/base-ui.js.map +1 -0
- package/dist/base-ui.mjs +179 -0
- package/dist/base-ui.mjs.map +1 -0
- package/dist/chunk-GSHKDU53.mjs +117 -0
- package/dist/chunk-GSHKDU53.mjs.map +1 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +284 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +145 -0
- package/dist/index.mjs.map +1 -0
- package/dist/props-CCrZyXhY.d.mts +83 -0
- package/dist/props-CCrZyXhY.d.ts +83 -0
- package/dist/styles.css +157 -0
- package/dist/styles.css.map +1 -0
- package/package.json +118 -0
package/dist/base-ui.mjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
import {
|
|
4
|
+
EDGE_SIDES,
|
|
5
|
+
SCROLL_AREA_AXIS,
|
|
6
|
+
SCROLL_AREA_EDGE_EFFECT,
|
|
7
|
+
SCROLL_AREA_SCROLLBARS,
|
|
8
|
+
axesFor,
|
|
9
|
+
measureEdges,
|
|
10
|
+
mergeRefs,
|
|
11
|
+
rootStyle,
|
|
12
|
+
useScrollEdges
|
|
13
|
+
} from "./chunk-GSHKDU53.mjs";
|
|
14
|
+
|
|
15
|
+
// src/base-ui/parts.tsx
|
|
16
|
+
import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area";
|
|
17
|
+
import clsx from "clsx";
|
|
18
|
+
import * as React from "react";
|
|
19
|
+
import { jsx } from "react/jsx-runtime";
|
|
20
|
+
function withBase(base, className) {
|
|
21
|
+
return typeof className === "function" ? (state) => clsx(base, className(state)) : clsx(base, className);
|
|
22
|
+
}
|
|
23
|
+
var Root = React.forwardRef(function Root2({ className, ...props }, ref) {
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
ScrollAreaPrimitive.Root,
|
|
26
|
+
{
|
|
27
|
+
ref,
|
|
28
|
+
"data-primitive": "base-ui",
|
|
29
|
+
className: withBase("sa-root", className),
|
|
30
|
+
...props
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
var Viewport = React.forwardRef(function Viewport2({ className, ...props }, ref) {
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
ScrollAreaPrimitive.Viewport,
|
|
37
|
+
{
|
|
38
|
+
ref,
|
|
39
|
+
className: withBase("sa-viewport", className),
|
|
40
|
+
...props
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
var Content = React.forwardRef(function Content2({ className, ...props }, ref) {
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
ScrollAreaPrimitive.Content,
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
className: withBase("sa-content", className),
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
var Scrollbar = React.forwardRef(function Scrollbar2({ className, ...props }, ref) {
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
ScrollAreaPrimitive.Scrollbar,
|
|
57
|
+
{
|
|
58
|
+
ref,
|
|
59
|
+
className: withBase("sa-scrollbar", className),
|
|
60
|
+
...props
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
var Thumb = React.forwardRef(function Thumb2({ className, ...props }, ref) {
|
|
65
|
+
return /* @__PURE__ */ jsx(
|
|
66
|
+
ScrollAreaPrimitive.Thumb,
|
|
67
|
+
{
|
|
68
|
+
ref,
|
|
69
|
+
className: withBase("sa-thumb", className),
|
|
70
|
+
...props
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
var Corner = React.forwardRef(function Corner2({ className, ...props }, ref) {
|
|
75
|
+
return /* @__PURE__ */ jsx(
|
|
76
|
+
ScrollAreaPrimitive.Corner,
|
|
77
|
+
{
|
|
78
|
+
ref,
|
|
79
|
+
className: withBase("sa-corner", className),
|
|
80
|
+
...props
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// src/base-ui/ScrollArea.tsx
|
|
86
|
+
import { DirectionProvider } from "@base-ui/react/direction-provider";
|
|
87
|
+
import clsx2 from "clsx";
|
|
88
|
+
import * as React2 from "react";
|
|
89
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
90
|
+
var ScrollArea = React2.forwardRef(
|
|
91
|
+
function ScrollArea2({
|
|
92
|
+
children,
|
|
93
|
+
axis = "vertical",
|
|
94
|
+
edgeEffect = "fade",
|
|
95
|
+
edgeSize,
|
|
96
|
+
scrollbars = "hover",
|
|
97
|
+
dir,
|
|
98
|
+
classNames = {},
|
|
99
|
+
className,
|
|
100
|
+
style,
|
|
101
|
+
viewportRef,
|
|
102
|
+
onScroll,
|
|
103
|
+
...rootProps
|
|
104
|
+
}, ref) {
|
|
105
|
+
const rootRef = React2.useRef(null);
|
|
106
|
+
const { horizontal, vertical } = axesFor(axis);
|
|
107
|
+
const edgesRef = useScrollEdges(rootRef, {
|
|
108
|
+
horizontal,
|
|
109
|
+
vertical
|
|
110
|
+
});
|
|
111
|
+
const mergedRootRef = React2.useMemo(() => mergeRefs(ref, rootRef), [ref]);
|
|
112
|
+
const mergedViewportRef = React2.useMemo(
|
|
113
|
+
() => mergeRefs(viewportRef, edgesRef),
|
|
114
|
+
[viewportRef, edgesRef]
|
|
115
|
+
);
|
|
116
|
+
const keepMounted = scrollbars === "always";
|
|
117
|
+
const area = /* @__PURE__ */ jsxs(
|
|
118
|
+
Root,
|
|
119
|
+
{
|
|
120
|
+
...rootProps,
|
|
121
|
+
ref: mergedRootRef,
|
|
122
|
+
dir,
|
|
123
|
+
"data-edge-effect": edgeEffect,
|
|
124
|
+
"data-scrollbars": scrollbars,
|
|
125
|
+
className: clsx2(className, classNames.root),
|
|
126
|
+
style: rootStyle(style, edgeSize),
|
|
127
|
+
children: [
|
|
128
|
+
/* @__PURE__ */ jsx2(
|
|
129
|
+
Viewport,
|
|
130
|
+
{
|
|
131
|
+
ref: mergedViewportRef,
|
|
132
|
+
className: classNames.viewport,
|
|
133
|
+
onScroll,
|
|
134
|
+
children: /* @__PURE__ */ jsx2(Content, { className: classNames.content, children })
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
edgeEffect === "shadow" ? /* @__PURE__ */ jsx2("div", { className: "sa-edge-shadow", "aria-hidden": "true" }) : null,
|
|
138
|
+
vertical ? /* @__PURE__ */ jsx2(
|
|
139
|
+
Scrollbar,
|
|
140
|
+
{
|
|
141
|
+
orientation: "vertical",
|
|
142
|
+
keepMounted,
|
|
143
|
+
className: classNames.scrollbar,
|
|
144
|
+
children: /* @__PURE__ */ jsx2(Thumb, { className: classNames.thumb })
|
|
145
|
+
}
|
|
146
|
+
) : null,
|
|
147
|
+
horizontal ? /* @__PURE__ */ jsx2(
|
|
148
|
+
Scrollbar,
|
|
149
|
+
{
|
|
150
|
+
orientation: "horizontal",
|
|
151
|
+
keepMounted,
|
|
152
|
+
className: classNames.scrollbar,
|
|
153
|
+
children: /* @__PURE__ */ jsx2(Thumb, { className: classNames.thumb })
|
|
154
|
+
}
|
|
155
|
+
) : null,
|
|
156
|
+
vertical && horizontal ? /* @__PURE__ */ jsx2(Corner, {}) : null
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
return dir ? /* @__PURE__ */ jsx2(DirectionProvider, { direction: dir, children: area }) : area;
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
export {
|
|
164
|
+
Content,
|
|
165
|
+
Corner,
|
|
166
|
+
EDGE_SIDES,
|
|
167
|
+
Root,
|
|
168
|
+
SCROLL_AREA_AXIS,
|
|
169
|
+
SCROLL_AREA_EDGE_EFFECT,
|
|
170
|
+
SCROLL_AREA_SCROLLBARS,
|
|
171
|
+
ScrollArea,
|
|
172
|
+
Scrollbar,
|
|
173
|
+
Thumb,
|
|
174
|
+
Viewport,
|
|
175
|
+
measureEdges,
|
|
176
|
+
mergeRefs,
|
|
177
|
+
useScrollEdges
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=base-ui.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base-ui/parts.tsx","../src/base-ui/ScrollArea.tsx"],"sourcesContent":["import { ScrollArea as ScrollAreaPrimitive } from '@base-ui/react/scroll-area'\nimport clsx from 'clsx'\nimport * as React from 'react'\n\ntype ClassName<State> =\n | string\n | ((state: State) => string | undefined)\n | undefined\n\n/** Prepends a base class, preserving Base UI's state-callback form. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n return typeof className === 'function'\n ? (state: State) => clsx(base, className(state))\n : clsx(base, className)\n}\n\nexport const Root = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Root.Props\n>(function Root({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Root\n ref={ref}\n data-primitive=\"base-ui\"\n className={withBase('sa-root', className)}\n {...props}\n />\n )\n})\n\nexport const Viewport = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Viewport.Props\n>(function Viewport({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Viewport\n ref={ref}\n className={withBase('sa-viewport', className)}\n {...props}\n />\n )\n})\n\nexport const Content = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Content.Props\n>(function Content({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Content\n ref={ref}\n className={withBase('sa-content', className)}\n {...props}\n />\n )\n})\n\nexport const Scrollbar = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Scrollbar.Props\n>(function Scrollbar({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Scrollbar\n ref={ref}\n className={withBase('sa-scrollbar', className)}\n {...props}\n />\n )\n})\n\nexport const Thumb = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Thumb.Props\n>(function Thumb({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Thumb\n ref={ref}\n className={withBase('sa-thumb', className)}\n {...props}\n />\n )\n})\n\nexport const Corner = React.forwardRef<\n HTMLDivElement,\n ScrollAreaPrimitive.Corner.Props\n>(function Corner({ className, ...props }, ref) {\n return (\n <ScrollAreaPrimitive.Corner\n ref={ref}\n className={withBase('sa-corner', className)}\n {...props}\n />\n )\n})\n","import { DirectionProvider } from '@base-ui/react/direction-provider'\nimport type { ScrollArea as ScrollAreaPrimitive } from '@base-ui/react/scroll-area'\nimport clsx from 'clsx'\nimport * as React from 'react'\n\nimport { mergeRefs } from '../core/mergeRefs'\nimport {\n axesFor,\n rootStyle,\n type ScrollAreaClassNames,\n type ScrollAreaSharedProps,\n} from '../core/props'\nimport { useScrollEdges } from '../core/useScrollEdges'\nimport { Content, Corner, Root, Scrollbar, Thumb, Viewport } from './parts'\n\nexport type BaseUIScrollAreaClassNames = ScrollAreaClassNames & {\n /** The Content part that wraps `children` inside the viewport. */\n content?: string\n}\n\nexport interface ScrollAreaProps\n extends Omit<ScrollAreaSharedProps, 'classNames'>,\n Omit<ScrollAreaPrimitive.Root.Props, keyof ScrollAreaSharedProps> {\n classNames?: BaseUIScrollAreaClassNames\n}\n\nexport const ScrollArea = React.forwardRef<HTMLDivElement, ScrollAreaProps>(\n function ScrollArea(\n {\n children,\n axis = 'vertical',\n edgeEffect = 'fade',\n edgeSize,\n scrollbars = 'hover',\n dir,\n classNames = {},\n className,\n style,\n viewportRef,\n onScroll,\n ...rootProps\n },\n ref,\n ) {\n const rootRef = React.useRef<HTMLDivElement>(null)\n const { horizontal, vertical } = axesFor(axis)\n // Base UI sets its own logical `data-overflow-x-start` etc. The shared hook\n // adds the physical `data-overflow-*` attributes the stylesheet keys off.\n const edgesRef = useScrollEdges<HTMLDivElement>(rootRef, {\n horizontal,\n vertical,\n })\n // Memoized so React doesn't detach and reattach the refs on every render.\n const mergedRootRef = React.useMemo(() => mergeRefs(ref, rootRef), [ref])\n const mergedViewportRef = React.useMemo(\n () => mergeRefs(viewportRef, edgesRef),\n [viewportRef, edgesRef],\n )\n\n // Base UI mounts scrollbars only while content overflows (\"auto\"), and\n // exposes hover/scroll state that the stylesheet uses for the other modes.\n const keepMounted = scrollbars === 'always'\n\n const area = (\n <Root\n {...rootProps}\n ref={mergedRootRef}\n dir={dir}\n data-edge-effect={edgeEffect}\n data-scrollbars={scrollbars}\n className={clsx(className, classNames.root)}\n style={rootStyle(style, edgeSize)}\n >\n <Viewport\n ref={mergedViewportRef}\n className={classNames.viewport}\n onScroll={onScroll}\n >\n <Content className={classNames.content}>{children}</Content>\n </Viewport>\n {edgeEffect === 'shadow' ? (\n <div className=\"sa-edge-shadow\" aria-hidden=\"true\" />\n ) : null}\n {vertical ? (\n <Scrollbar\n orientation=\"vertical\"\n keepMounted={keepMounted}\n className={classNames.scrollbar}\n >\n <Thumb className={classNames.thumb} />\n </Scrollbar>\n ) : null}\n {horizontal ? (\n <Scrollbar\n orientation=\"horizontal\"\n keepMounted={keepMounted}\n className={classNames.scrollbar}\n >\n <Thumb className={classNames.thumb} />\n </Scrollbar>\n ) : null}\n {vertical && horizontal ? <Corner /> : null}\n </Root>\n )\n\n // Base UI reads direction from context, not the `dir` attribute. Only\n // provide it when set, so an app-level DirectionProvider still applies.\n return dir ? (\n <DirectionProvider direction={dir}>{area}</DirectionProvider>\n ) : (\n area\n )\n },\n)\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,cAAc,2BAA2B;AAClD,OAAO,UAAU;AACjB,YAAY,WAAW;AAmBnB;AAXJ,SAAS,SAAgB,MAAc,WAA6B;AAClE,SAAO,OAAO,cAAc,aACxB,CAAC,UAAiB,KAA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,kBAAiB,eAAY,QAAO,IACjD;AAAA,UACH,WACC,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,aAAY;AAAA,cACZ;AAAA,cACA,WAAW,WAAW;AAAA,cAEtB,0BAAAA,KAAC,SAAM,WAAW,WAAW,OAAO;AAAA;AAAA,UACtC,IACE;AAAA,UACH,aACC,gBAAAA;AAAA,YAAC;AAAA;AAAA,cACC,aAAY;AAAA,cACZ;AAAA,cACA,WAAW,WAAW;AAAA,cAEtB,0BAAAA,KAAC,SAAM,WAAW,WAAW,OAAO;AAAA;AAAA,UACtC,IACE;AAAA,UACH,YAAY,aAAa,gBAAAA,KAAC,UAAO,IAAK;AAAA;AAAA;AAAA,IACzC;AAKF,WAAO,MACL,gBAAAA,KAAC,qBAAkB,WAAW,KAAM,gBAAK,IAEzC;AAAA,EAEJ;AACF;","names":["Root","Viewport","Content","Scrollbar","Thumb","Corner","clsx","React","jsx","ScrollArea","clsx"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
|
|
4
|
+
// src/core/mergeRefs.ts
|
|
5
|
+
function mergeRefs(...refs) {
|
|
6
|
+
return (node) => {
|
|
7
|
+
for (const ref of refs) {
|
|
8
|
+
if (typeof ref === "function") ref(node);
|
|
9
|
+
else if (ref) ref.current = node;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/core/props.ts
|
|
15
|
+
var SCROLL_AREA_AXIS = {
|
|
16
|
+
VERTICAL: "vertical",
|
|
17
|
+
HORIZONTAL: "horizontal",
|
|
18
|
+
BOTH: "both"
|
|
19
|
+
};
|
|
20
|
+
var SCROLL_AREA_EDGE_EFFECT = {
|
|
21
|
+
/** Fades the content itself toward the edge (color-independent). */
|
|
22
|
+
FADE: "fade",
|
|
23
|
+
/** Draws `--scroll-area-shadow-color` over the edge. */
|
|
24
|
+
SHADOW: "shadow",
|
|
25
|
+
/** Draws nothing; `data-overflow-*` attributes are still set. */
|
|
26
|
+
NONE: "none"
|
|
27
|
+
};
|
|
28
|
+
var SCROLL_AREA_SCROLLBARS = {
|
|
29
|
+
/** While scrolling or hovering the area. */
|
|
30
|
+
HOVER: "hover",
|
|
31
|
+
/** While scrolling. */
|
|
32
|
+
SCROLL: "scroll",
|
|
33
|
+
/** While the content overflows. */
|
|
34
|
+
AUTO: "auto",
|
|
35
|
+
/** Even when the content doesn't overflow. */
|
|
36
|
+
ALWAYS: "always",
|
|
37
|
+
/** Never; the area still scrolls by wheel, touch, and keyboard. */
|
|
38
|
+
HIDDEN: "hidden"
|
|
39
|
+
};
|
|
40
|
+
function axesFor(axis) {
|
|
41
|
+
return {
|
|
42
|
+
horizontal: axis !== "vertical",
|
|
43
|
+
vertical: axis !== "horizontal"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function rootStyle(style, edgeSize) {
|
|
47
|
+
const result = { ...style };
|
|
48
|
+
if (edgeSize !== void 0) {
|
|
49
|
+
result["--scroll-area-edge-size"] = typeof edgeSize === "number" ? `${edgeSize}px` : edgeSize;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/core/useScrollEdges.ts
|
|
55
|
+
import { useLayoutEffect, useState } from "react";
|
|
56
|
+
var EDGE_SIDES = [
|
|
57
|
+
"top",
|
|
58
|
+
"right",
|
|
59
|
+
"bottom",
|
|
60
|
+
"left"
|
|
61
|
+
];
|
|
62
|
+
var TOLERANCE = 1;
|
|
63
|
+
function measureEdges(el, axes) {
|
|
64
|
+
const { scrollTop, scrollHeight, clientHeight, scrollWidth, clientWidth } = el;
|
|
65
|
+
const maxLeft = scrollWidth - clientWidth;
|
|
66
|
+
const rtl = getComputedStyle(el).direction === "rtl";
|
|
67
|
+
const fromLeft = rtl ? maxLeft + el.scrollLeft : el.scrollLeft;
|
|
68
|
+
return {
|
|
69
|
+
top: axes.vertical && scrollTop > TOLERANCE,
|
|
70
|
+
right: axes.horizontal && maxLeft - fromLeft > TOLERANCE,
|
|
71
|
+
bottom: axes.vertical && scrollHeight - clientHeight - scrollTop > TOLERANCE,
|
|
72
|
+
left: axes.horizontal && fromLeft > TOLERANCE
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function useScrollEdges(targetRef, { horizontal, vertical }) {
|
|
76
|
+
const [viewport, setViewport] = useState(null);
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
if (!viewport) return;
|
|
79
|
+
let frame = 0;
|
|
80
|
+
const apply = () => {
|
|
81
|
+
frame = 0;
|
|
82
|
+
const target = targetRef.current;
|
|
83
|
+
if (!target) return;
|
|
84
|
+
const edges = measureEdges(viewport, { horizontal, vertical });
|
|
85
|
+
for (const side of EDGE_SIDES) {
|
|
86
|
+
target.toggleAttribute(`data-overflow-${side}`, edges[side]);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const schedule = () => {
|
|
90
|
+
if (!frame) frame = requestAnimationFrame(apply);
|
|
91
|
+
};
|
|
92
|
+
apply();
|
|
93
|
+
viewport.addEventListener("scroll", schedule, { passive: true });
|
|
94
|
+
const observer = new ResizeObserver(schedule);
|
|
95
|
+
observer.observe(viewport);
|
|
96
|
+
if (viewport.firstElementChild) observer.observe(viewport.firstElementChild);
|
|
97
|
+
return () => {
|
|
98
|
+
cancelAnimationFrame(frame);
|
|
99
|
+
viewport.removeEventListener("scroll", schedule);
|
|
100
|
+
observer.disconnect();
|
|
101
|
+
};
|
|
102
|
+
}, [viewport, targetRef, horizontal, vertical]);
|
|
103
|
+
return setViewport;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
mergeRefs,
|
|
108
|
+
SCROLL_AREA_AXIS,
|
|
109
|
+
SCROLL_AREA_EDGE_EFFECT,
|
|
110
|
+
SCROLL_AREA_SCROLLBARS,
|
|
111
|
+
axesFor,
|
|
112
|
+
rootStyle,
|
|
113
|
+
EDGE_SIDES,
|
|
114
|
+
measureEdges,
|
|
115
|
+
useScrollEdges
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=chunk-GSHKDU53.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/mergeRefs.ts","../src/core/props.ts","../src/core/useScrollEdges.ts"],"sourcesContent":["import type { Ref, RefCallback } from 'react'\n\n/** Combines several refs into one callback ref. */\nexport function mergeRefs<T>(\n ...refs: Array<Ref<T> | undefined>\n): RefCallback<T> {\n return (node) => {\n for (const ref of refs) {\n if (typeof ref === 'function') ref(node)\n else if (ref) (ref as { current: T | null }).current = node\n }\n }\n}\n","import type { CSSProperties, ReactNode, Ref, UIEventHandler } from 'react'\n\nimport type { ScrollAxes } from './useScrollEdges'\n\n/*\n * Each option set is an `as const` object in SCREAMING_SNAKE_CASE plus a\n * PascalCase union type derived from it, so `axis={SCROLL_AREA_AXIS.BOTH}` and\n * `axis=\"both\"` are equivalent.\n */\n\n/** Which directions scroll. */\nexport const SCROLL_AREA_AXIS = {\n VERTICAL: 'vertical',\n HORIZONTAL: 'horizontal',\n BOTH: 'both',\n} as const\nexport type ScrollAreaAxis =\n (typeof SCROLL_AREA_AXIS)[keyof typeof SCROLL_AREA_AXIS]\n\n/** How edges with more content beyond them are signaled. */\nexport const SCROLL_AREA_EDGE_EFFECT = {\n /** Fades the content itself toward the edge (color-independent). */\n FADE: 'fade',\n /** Draws `--scroll-area-shadow-color` over the edge. */\n SHADOW: 'shadow',\n /** Draws nothing; `data-overflow-*` attributes are still set. */\n NONE: 'none',\n} as const\nexport type ScrollAreaEdgeEffect =\n (typeof SCROLL_AREA_EDGE_EFFECT)[keyof typeof SCROLL_AREA_EDGE_EFFECT]\n\n/** When scrollbars are visible. */\nexport const SCROLL_AREA_SCROLLBARS = {\n /** While scrolling or hovering the area. */\n HOVER: 'hover',\n /** While scrolling. */\n SCROLL: 'scroll',\n /** While the content overflows. */\n AUTO: 'auto',\n /** Even when the content doesn't overflow. */\n ALWAYS: 'always',\n /** Never; the area still scrolls by wheel, touch, and keyboard. */\n HIDDEN: 'hidden',\n} as const\nexport type ScrollAreaScrollbars =\n (typeof SCROLL_AREA_SCROLLBARS)[keyof typeof SCROLL_AREA_SCROLLBARS]\n\nexport type ScrollAreaClassNames = {\n root?: string\n viewport?: string\n scrollbar?: string\n thumb?: string\n}\n\n/** Props every adapter's `ScrollArea` accepts, with the same meaning. */\nexport interface ScrollAreaSharedProps {\n children?: ReactNode\n /** Which directions scroll. Defaults to `\"vertical\"`. */\n axis?: ScrollAreaAxis\n /** How edges with more content beyond them are signaled. Defaults to `\"fade\"`. */\n edgeEffect?: ScrollAreaEdgeEffect\n /** Depth of the edge effect: a number of pixels or any CSS length. */\n edgeSize?: number | string\n /** When scrollbars are visible. Defaults to `\"hover\"`. */\n scrollbars?: ScrollAreaScrollbars\n /** Reading direction; flips horizontal scrolling and the scrollbar side. */\n dir?: 'ltr' | 'rtl'\n className?: string\n style?: CSSProperties\n /** Classes for the internal parts. */\n classNames?: ScrollAreaClassNames\n /** Ref to the scrolling viewport element. */\n viewportRef?: Ref<HTMLDivElement>\n onScroll?: UIEventHandler<HTMLDivElement>\n}\n\ntype StyleWithVars = CSSProperties & Record<`--${string}`, string>\n\nexport function axesFor(axis: ScrollAreaAxis): ScrollAxes {\n return {\n horizontal: axis !== 'vertical',\n vertical: axis !== 'horizontal',\n }\n}\n\n/** The root's inline style, with `edgeSize` applied as the size token. */\nexport function rootStyle(\n style: CSSProperties | undefined,\n edgeSize: number | string | undefined,\n): StyleWithVars {\n const result: StyleWithVars = { ...style }\n if (edgeSize !== undefined) {\n result['--scroll-area-edge-size'] =\n typeof edgeSize === 'number' ? `${edgeSize}px` : edgeSize\n }\n return result\n}\n","import { type RefObject, useLayoutEffect, useState } from 'react'\n\nexport type ScrollAxes = { horizontal: boolean; vertical: boolean }\nexport type EdgeSide = 'top' | 'right' | 'bottom' | 'left'\nexport type Edges = Record<EdgeSide, boolean>\n\nexport const EDGE_SIDES: readonly EdgeSide[] = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n]\n\n/** Absorbs fractional scroll positions from zoom and high-DPI displays. */\nconst TOLERANCE = 1\n\n/** Which physical edges of `el` have more content beyond them. */\nexport function measureEdges(el: HTMLElement, axes: ScrollAxes): Edges {\n const { scrollTop, scrollHeight, clientHeight, scrollWidth, clientWidth } = el\n const maxLeft = scrollWidth - clientWidth\n // In RTL, scrollLeft is 0 at the right edge and goes negative toward the left.\n const rtl = getComputedStyle(el).direction === 'rtl'\n const fromLeft = rtl ? maxLeft + el.scrollLeft : el.scrollLeft\n\n return {\n top: axes.vertical && scrollTop > TOLERANCE,\n right: axes.horizontal && maxLeft - fromLeft > TOLERANCE,\n bottom:\n axes.vertical && scrollHeight - clientHeight - scrollTop > TOLERANCE,\n left: axes.horizontal && fromLeft > TOLERANCE,\n }\n}\n\n/**\n * Tracks which edges of a scrolling element have hidden content and mirrors\n * them as `data-overflow-{side}` attributes on `targetRef`. Writes go straight\n * to the DOM, so scrolling never re-renders React.\n *\n * Returns a callback ref for the scrolling element.\n */\nexport function useScrollEdges<T extends HTMLElement = HTMLDivElement>(\n targetRef: RefObject<HTMLElement | null>,\n { horizontal, vertical }: ScrollAxes,\n): (node: T | null) => void {\n const [viewport, setViewport] = useState<T | null>(null)\n\n useLayoutEffect(() => {\n if (!viewport) return\n\n let frame = 0\n const apply = () => {\n frame = 0\n const target = targetRef.current\n if (!target) return\n const edges = measureEdges(viewport, { horizontal, vertical })\n for (const side of EDGE_SIDES) {\n target.toggleAttribute(`data-overflow-${side}`, edges[side])\n }\n }\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(apply)\n }\n\n apply()\n viewport.addEventListener('scroll', schedule, { passive: true })\n const observer = new ResizeObserver(schedule)\n observer.observe(viewport)\n if (viewport.firstElementChild) observer.observe(viewport.firstElementChild)\n\n return () => {\n cancelAnimationFrame(frame)\n viewport.removeEventListener('scroll', schedule)\n observer.disconnect()\n }\n }, [viewport, targetRef,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AAc,UAAU,WAAW;AAAA,IAC/C,QACE,KAAK,YAAY,eAAe,eAAe,YAAY;AAAA,IAC7D,MAAM,KAAK,cAAc,WAAW;AAAA,EACtC;AACF;AASO,SAAS,eACd,WACA,EAAE,YAAY,SAAS,GACG;AAC1B,QAAM,CAAC,UAAU,WAAW,IAAI,SAAmB,IAAI;AAEvD,kBAAgB,MAAM;AACpB,QAAI,CAAC,SAAU;AAEf,QAAI,QAAQ;AACZ,UAAM,QAAQ,MAAM;AAClB,cAAQ;AACR,YAAM,SAAS,UAAU;AACzB,UAAI,CAAC,OAAQ;AACb,YAAM,QAAQ,aAAa,UAAU,EAAE,YAAY,SAAS,CAAC;AAC7D,iBAAW,QAAQ,YAAY;AAC7B,eAAO,gBAAgB,iBAAiB,IAAI,IAAI,MAAM,IAAI,CAAC;AAAA,MAC7D;AAAA,IACF;AACA,UAAM,WAAW,MAAM;AACrB,UAAI,CAAC,MAAO,SAAQ,sBAAsB,KAAK;AAAA,IACjD;AAEA,UAAM;AACN,aAAS,iBAAiB,UAAU,UAAU,EAAE,SAAS,KAAK,CAAC;AAC/D,UAAM,WAAW,IAAI,eAAe,QAAQ;AAC5C,aAAS,QAAQ,QAAQ;AACzB,QAAI,SAAS,kBAAmB,UAAS,QAAQ,SAAS,iBAAiB;AAE3E,WAAO,MAAM;AACX,2BAAqB,KAAK;AAC1B,eAAS,oBAAoB,UAAU,QAAQ;AAC/C,eAAS,WAAW;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,UAAU,WAAW,YAAY,QAAQ,CAAC;AAE9C,SAAO;AACT;","names":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as ScrollAreaSharedProps } from './props-CCrZyXhY.mjs';
|
|
2
|
+
export { E as EDGE_SIDES, b as EdgeSide, c as Edges, d as SCROLL_AREA_AXIS, e as SCROLL_AREA_EDGE_EFFECT, f as SCROLL_AREA_SCROLLBARS, g as ScrollAreaAxis, S as ScrollAreaClassNames, h as ScrollAreaEdgeEffect, i as ScrollAreaScrollbars, j as ScrollAxes, m as measureEdges, k as mergeRefs, u as useScrollEdges } from './props-CCrZyXhY.mjs';
|
|
3
|
+
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
declare const Root: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaProps & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
declare const Viewport: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaViewportProps & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
declare const Scrollbar: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaScrollbarProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const Thumb: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaThumbProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const Corner: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaCornerProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
|
|
12
|
+
interface ScrollAreaProps extends ScrollAreaSharedProps, Omit<ScrollAreaPrimitive.ScrollAreaProps, keyof ScrollAreaSharedProps | 'type'> {
|
|
13
|
+
}
|
|
14
|
+
declare const ScrollArea: React.ForwardRefExoticComponent<ScrollAreaProps & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
|
|
16
|
+
export { Corner, Root, ScrollArea, type ScrollAreaProps, ScrollAreaSharedProps, Scrollbar, Thumb, Viewport };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as ScrollAreaSharedProps } from './props-CCrZyXhY.js';
|
|
2
|
+
export { E as EDGE_SIDES, b as EdgeSide, c as Edges, d as SCROLL_AREA_AXIS, e as SCROLL_AREA_EDGE_EFFECT, f as SCROLL_AREA_SCROLLBARS, g as ScrollAreaAxis, S as ScrollAreaClassNames, h as ScrollAreaEdgeEffect, i as ScrollAreaScrollbars, j as ScrollAxes, m as measureEdges, k as mergeRefs, u as useScrollEdges } from './props-CCrZyXhY.js';
|
|
3
|
+
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
declare const Root: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaProps & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
declare const Viewport: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaViewportProps & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
declare const Scrollbar: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaScrollbarProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const Thumb: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaThumbProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
declare const Corner: React.ForwardRefExoticComponent<ScrollAreaPrimitive.ScrollAreaCornerProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
|
|
12
|
+
interface ScrollAreaProps extends ScrollAreaSharedProps, Omit<ScrollAreaPrimitive.ScrollAreaProps, keyof ScrollAreaSharedProps | 'type'> {
|
|
13
|
+
}
|
|
14
|
+
declare const ScrollArea: React.ForwardRefExoticComponent<ScrollAreaProps & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
|
|
16
|
+
export { Corner, Root, ScrollArea, type ScrollAreaProps, ScrollAreaSharedProps, Scrollbar, Thumb, Viewport };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
require("./styles.css");
|
|
3
|
+
"use strict";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var src_exports = {};
|
|
34
|
+
__export(src_exports, {
|
|
35
|
+
Corner: () => Corner2,
|
|
36
|
+
EDGE_SIDES: () => EDGE_SIDES,
|
|
37
|
+
Root: () => Root2,
|
|
38
|
+
SCROLL_AREA_AXIS: () => SCROLL_AREA_AXIS,
|
|
39
|
+
SCROLL_AREA_EDGE_EFFECT: () => SCROLL_AREA_EDGE_EFFECT,
|
|
40
|
+
SCROLL_AREA_SCROLLBARS: () => SCROLL_AREA_SCROLLBARS,
|
|
41
|
+
ScrollArea: () => ScrollArea,
|
|
42
|
+
Scrollbar: () => Scrollbar2,
|
|
43
|
+
Thumb: () => Thumb2,
|
|
44
|
+
Viewport: () => Viewport2,
|
|
45
|
+
measureEdges: () => measureEdges,
|
|
46
|
+
mergeRefs: () => mergeRefs,
|
|
47
|
+
useScrollEdges: () => useScrollEdges
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(src_exports);
|
|
50
|
+
|
|
51
|
+
// src/core/mergeRefs.ts
|
|
52
|
+
function mergeRefs(...refs) {
|
|
53
|
+
return (node) => {
|
|
54
|
+
for (const ref of refs) {
|
|
55
|
+
if (typeof ref === "function") ref(node);
|
|
56
|
+
else if (ref) ref.current = node;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/core/props.ts
|
|
62
|
+
var SCROLL_AREA_AXIS = {
|
|
63
|
+
VERTICAL: "vertical",
|
|
64
|
+
HORIZONTAL: "horizontal",
|
|
65
|
+
BOTH: "both"
|
|
66
|
+
};
|
|
67
|
+
var SCROLL_AREA_EDGE_EFFECT = {
|
|
68
|
+
/** Fades the content itself toward the edge (color-independent). */
|
|
69
|
+
FADE: "fade",
|
|
70
|
+
/** Draws `--scroll-area-shadow-color` over the edge. */
|
|
71
|
+
SHADOW: "shadow",
|
|
72
|
+
/** Draws nothing; `data-overflow-*` attributes are still set. */
|
|
73
|
+
NONE: "none"
|
|
74
|
+
};
|
|
75
|
+
var SCROLL_AREA_SCROLLBARS = {
|
|
76
|
+
/** While scrolling or hovering the area. */
|
|
77
|
+
HOVER: "hover",
|
|
78
|
+
/** While scrolling. */
|
|
79
|
+
SCROLL: "scroll",
|
|
80
|
+
/** While the content overflows. */
|
|
81
|
+
AUTO: "auto",
|
|
82
|
+
/** Even when the content doesn't overflow. */
|
|
83
|
+
ALWAYS: "always",
|
|
84
|
+
/** Never; the area still scrolls by wheel, touch, and keyboard. */
|
|
85
|
+
HIDDEN: "hidden"
|
|
86
|
+
};
|
|
87
|
+
function axesFor(axis) {
|
|
88
|
+
return {
|
|
89
|
+
horizontal: axis !== "vertical",
|
|
90
|
+
vertical: axis !== "horizontal"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function rootStyle(style, edgeSize) {
|
|
94
|
+
const result = { ...style };
|
|
95
|
+
if (edgeSize !== void 0) {
|
|
96
|
+
result["--scroll-area-edge-size"] = typeof edgeSize === "number" ? `${edgeSize}px` : edgeSize;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/core/useScrollEdges.ts
|
|
102
|
+
var import_react = require("react");
|
|
103
|
+
var EDGE_SIDES = [
|
|
104
|
+
"top",
|
|
105
|
+
"right",
|
|
106
|
+
"bottom",
|
|
107
|
+
"left"
|
|
108
|
+
];
|
|
109
|
+
var TOLERANCE = 1;
|
|
110
|
+
function measureEdges(el, axes) {
|
|
111
|
+
const { scrollTop, scrollHeight, clientHeight, scrollWidth, clientWidth } = el;
|
|
112
|
+
const maxLeft = scrollWidth - clientWidth;
|
|
113
|
+
const rtl = getComputedStyle(el).direction === "rtl";
|
|
114
|
+
const fromLeft = rtl ? maxLeft + el.scrollLeft : el.scrollLeft;
|
|
115
|
+
return {
|
|
116
|
+
top: axes.vertical && scrollTop > TOLERANCE,
|
|
117
|
+
right: axes.horizontal && maxLeft - fromLeft > TOLERANCE,
|
|
118
|
+
bottom: axes.vertical && scrollHeight - clientHeight - scrollTop > TOLERANCE,
|
|
119
|
+
left: axes.horizontal && fromLeft > TOLERANCE
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function useScrollEdges(targetRef, { horizontal, vertical }) {
|
|
123
|
+
const [viewport, setViewport] = (0, import_react.useState)(null);
|
|
124
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
125
|
+
if (!viewport) return;
|
|
126
|
+
let frame = 0;
|
|
127
|
+
const apply = () => {
|
|
128
|
+
frame = 0;
|
|
129
|
+
const target = targetRef.current;
|
|
130
|
+
if (!target) return;
|
|
131
|
+
const edges = measureEdges(viewport, { horizontal, vertical });
|
|
132
|
+
for (const side of EDGE_SIDES) {
|
|
133
|
+
target.toggleAttribute(`data-overflow-${side}`, edges[side]);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const schedule = () => {
|
|
137
|
+
if (!frame) frame = requestAnimationFrame(apply);
|
|
138
|
+
};
|
|
139
|
+
apply();
|
|
140
|
+
viewport.addEventListener("scroll", schedule, { passive: true });
|
|
141
|
+
const observer = new ResizeObserver(schedule);
|
|
142
|
+
observer.observe(viewport);
|
|
143
|
+
if (viewport.firstElementChild) observer.observe(viewport.firstElementChild);
|
|
144
|
+
return () => {
|
|
145
|
+
cancelAnimationFrame(frame);
|
|
146
|
+
viewport.removeEventListener("scroll", schedule);
|
|
147
|
+
observer.disconnect();
|
|
148
|
+
};
|
|
149
|
+
}, [viewport, targetRef, horizontal, vertical]);
|
|
150
|
+
return setViewport;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/radix/parts.tsx
|
|
154
|
+
var ScrollAreaPrimitive = __toESM(require("@radix-ui/react-scroll-area"));
|
|
155
|
+
var import_clsx = __toESM(require("clsx"));
|
|
156
|
+
var React = __toESM(require("react"));
|
|
157
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
158
|
+
var Root2 = React.forwardRef(function Root3({ className, ...props }, ref) {
|
|
159
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
160
|
+
ScrollAreaPrimitive.Root,
|
|
161
|
+
{
|
|
162
|
+
ref,
|
|
163
|
+
"data-primitive": "radix",
|
|
164
|
+
className: (0, import_clsx.default)("sa-root", className),
|
|
165
|
+
...props
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
var Viewport2 = React.forwardRef(function Viewport3({ className, ...props }, ref) {
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
171
|
+
ScrollAreaPrimitive.Viewport,
|
|
172
|
+
{
|
|
173
|
+
ref,
|
|
174
|
+
className: (0, import_clsx.default)("sa-viewport", className),
|
|
175
|
+
...props
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
var Scrollbar2 = React.forwardRef(function Scrollbar3({ className, ...props }, ref) {
|
|
180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
+
ScrollAreaPrimitive.Scrollbar,
|
|
182
|
+
{
|
|
183
|
+
ref,
|
|
184
|
+
className: (0, import_clsx.default)("sa-scrollbar", className),
|
|
185
|
+
...props
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
var Thumb2 = React.forwardRef(function Thumb3({ className, ...props }, ref) {
|
|
190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
191
|
+
ScrollAreaPrimitive.Thumb,
|
|
192
|
+
{
|
|
193
|
+
ref,
|
|
194
|
+
className: (0, import_clsx.default)("sa-thumb", className),
|
|
195
|
+
...props
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
var Corner2 = React.forwardRef(function Corner3({ className, ...props }, ref) {
|
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
201
|
+
ScrollAreaPrimitive.Corner,
|
|
202
|
+
{
|
|
203
|
+
ref,
|
|
204
|
+
className: (0, import_clsx.default)("sa-corner", className),
|
|
205
|
+
...props
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// src/radix/ScrollArea.tsx
|
|
211
|
+
var import_clsx2 = __toESM(require("clsx"));
|
|
212
|
+
var React2 = __toESM(require("react"));
|
|
213
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
214
|
+
var ScrollArea = React2.forwardRef(
|
|
215
|
+
function ScrollArea2({
|
|
216
|
+
children,
|
|
217
|
+
axis = "vertical",
|
|
218
|
+
edgeEffect = "fade",
|
|
219
|
+
edgeSize,
|
|
220
|
+
scrollbars = "hover",
|
|
221
|
+
classNames = {},
|
|
222
|
+
className,
|
|
223
|
+
style,
|
|
224
|
+
viewportRef,
|
|
225
|
+
onScroll,
|
|
226
|
+
...rootProps
|
|
227
|
+
}, ref) {
|
|
228
|
+
const rootRef = React2.useRef(null);
|
|
229
|
+
const { horizontal, vertical } = axesFor(axis);
|
|
230
|
+
const edgesRef = useScrollEdges(rootRef, {
|
|
231
|
+
horizontal,
|
|
232
|
+
vertical
|
|
233
|
+
});
|
|
234
|
+
const mergedRootRef = React2.useMemo(() => mergeRefs(ref, rootRef), [ref]);
|
|
235
|
+
const mergedViewportRef = React2.useMemo(
|
|
236
|
+
() => mergeRefs(viewportRef, edgesRef),
|
|
237
|
+
[viewportRef, edgesRef]
|
|
238
|
+
);
|
|
239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
240
|
+
Root2,
|
|
241
|
+
{
|
|
242
|
+
...rootProps,
|
|
243
|
+
ref: mergedRootRef,
|
|
244
|
+
type: scrollbars === "hidden" ? "scroll" : scrollbars,
|
|
245
|
+
"data-edge-effect": edgeEffect,
|
|
246
|
+
"data-scrollbars": scrollbars,
|
|
247
|
+
className: (0, import_clsx2.default)(className, classNames.root),
|
|
248
|
+
style: rootStyle(style, edgeSize),
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
251
|
+
Viewport2,
|
|
252
|
+
{
|
|
253
|
+
ref: mergedViewportRef,
|
|
254
|
+
className: classNames.viewport,
|
|
255
|
+
onScroll,
|
|
256
|
+
children
|
|
257
|
+
}
|
|
258
|
+
),
|
|
259
|
+
edgeEffect === "shadow" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "sa-edge-shadow", "aria-hidden": "true" }) : null,
|
|
260
|
+
vertical ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Scrollbar2, { orientation: "vertical", className: classNames.scrollbar, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Thumb2, { className: classNames.thumb }) }) : null,
|
|
261
|
+
horizontal ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Scrollbar2, { orientation: "horizontal", className: classNames.scrollbar, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Thumb2, { className: classNames.thumb }) }) : null,
|
|
262
|
+
vertical && horizontal ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Corner2, {}) : null
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
Corner,
|
|
271
|
+
EDGE_SIDES,
|
|
272
|
+
Root,
|
|
273
|
+
SCROLL_AREA_AXIS,
|
|
274
|
+
SCROLL_AREA_EDGE_EFFECT,
|
|
275
|
+
SCROLL_AREA_SCROLLBARS,
|
|
276
|
+
ScrollArea,
|
|
277
|
+
Scrollbar,
|
|
278
|
+
Thumb,
|
|
279
|
+
Viewport,
|
|
280
|
+
measureEdges,
|
|
281
|
+
mergeRefs,
|
|
282
|
+
useScrollEdges
|
|
283
|
+
});
|
|
284
|
+
//# sourceMappingURL=index.js.map
|