@bioturing/components 0.33.1 → 0.34.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/dist/components/code-block/component.d.ts +1 -1
- package/dist/components/code-block/component.d.ts.map +1 -1
- package/dist/components/code-block/component.js +80 -71
- package/dist/components/code-block/component.js.map +1 -1
- package/dist/components/code-block/types.d.ts +17 -0
- package/dist/components/code-block/types.d.ts.map +1 -1
- package/dist/components/scroll-area/component.d.ts +1 -1
- package/dist/components/scroll-area/component.d.ts.map +1 -1
- package/dist/components/scroll-area/component.js +74 -58
- package/dist/components/scroll-area/component.js.map +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { CodeBlockProps } from './types';
|
|
2
|
-
export declare const CodeBlock: ({ code, children, lang: defaultLang, className, options, activeOption: controlledActiveOption, defaultActiveOption, onActiveOptionChange, copyText, copySuccessText, classNames, maxHeight, onCopy, ...rest }: CodeBlockProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const CodeBlock: ({ code, children, lang: defaultLang, className, options, activeOption: controlledActiveOption, defaultActiveOption, onActiveOptionChange, copyText, copySuccessText, classNames, maxHeight, onCopy, theme, themeProviderProps, scrollAreaProps, ...rest }: CodeBlockProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
//# sourceMappingURL=component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/code-block/component.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/code-block/component.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,OAAO,aAAa,CAAC;AAQrB,eAAO,MAAM,SAAS,GAAI,2PAmBvB,cAAc,4CAqIhB,CAAC"}
|
|
@@ -1,127 +1,136 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { CheckIcon as
|
|
4
|
-
import { Highlight as
|
|
5
|
-
import { useState as
|
|
6
|
-
import { ThemeProvider as
|
|
2
|
+
import { jsxs as R, jsx as e } from "react/jsx-runtime";
|
|
3
|
+
import { CheckIcon as U, CopyIcon as V } from "@bioturing/assets";
|
|
4
|
+
import { Highlight as W, themes as T } from "prism-react-renderer";
|
|
5
|
+
import { useState as i, useEffect as X, useCallback as I } from "react";
|
|
6
|
+
import { ThemeProvider as Y } from "../theme-provider/component.js";
|
|
7
7
|
import './style.css';/* empty css */
|
|
8
|
-
import { Segmented as
|
|
9
|
-
import { useControlledState as
|
|
10
|
-
import { reactNodeToString as
|
|
11
|
-
import { useCls as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
import { Segmented as Z } from "../segmented/component.js";
|
|
9
|
+
import { useControlledState as ee } from "../hooks/useControlledState.js";
|
|
10
|
+
import { reactNodeToString as oe } from "../utils/reactToString.js";
|
|
11
|
+
import { useCls as te } from "../utils/antdUtils.js";
|
|
12
|
+
import { useTheme as re } from "../theme-provider/context/themeStore.js";
|
|
13
|
+
import { clsx as ne } from "../utils/cn.js";
|
|
14
|
+
import { IconButton as ce } from "../icon-button/component.js";
|
|
15
|
+
import { ScrollArea as se } from "../scroll-area/component.js";
|
|
16
|
+
const M = {
|
|
17
|
+
dark: T.vsDark,
|
|
18
|
+
light: T.vsLight
|
|
19
|
+
}, ye = ({
|
|
20
|
+
code: v,
|
|
21
|
+
children: m,
|
|
18
22
|
// initial,
|
|
19
|
-
lang:
|
|
20
|
-
className:
|
|
23
|
+
lang: d = "tsx",
|
|
24
|
+
className: w,
|
|
21
25
|
options: t,
|
|
22
|
-
activeOption:
|
|
23
|
-
defaultActiveOption:
|
|
24
|
-
onActiveOptionChange:
|
|
25
|
-
copyText:
|
|
26
|
+
activeOption: x,
|
|
27
|
+
defaultActiveOption: g = 0,
|
|
28
|
+
onActiveOptionChange: E,
|
|
29
|
+
copyText: p = "Copy",
|
|
26
30
|
copySuccessText: b = "Copied",
|
|
27
|
-
classNames:
|
|
31
|
+
classNames: h,
|
|
28
32
|
maxHeight: c,
|
|
29
|
-
onCopy:
|
|
30
|
-
|
|
33
|
+
onCopy: u,
|
|
34
|
+
theme: s = "auto",
|
|
35
|
+
themeProviderProps: L,
|
|
36
|
+
scrollAreaProps: O,
|
|
37
|
+
...j
|
|
31
38
|
}) => {
|
|
32
|
-
const [l,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
), [n,
|
|
37
|
-
|
|
39
|
+
const [l, k] = ee(
|
|
40
|
+
x,
|
|
41
|
+
E,
|
|
42
|
+
g
|
|
43
|
+
), [n, A] = i(v || ""), [B, F] = i(d), C = t && t.length > 0;
|
|
44
|
+
X(() => {
|
|
38
45
|
if (C) {
|
|
39
|
-
const o = t[l]?.code || "", r = t[l]?.lang ||
|
|
40
|
-
|
|
46
|
+
const o = t[l]?.code || "", r = t[l]?.lang || d;
|
|
47
|
+
A(o), F(r);
|
|
41
48
|
}
|
|
42
49
|
}, [
|
|
43
|
-
f,
|
|
44
|
-
l,
|
|
45
50
|
v,
|
|
51
|
+
l,
|
|
52
|
+
g,
|
|
46
53
|
t,
|
|
47
|
-
|
|
54
|
+
d,
|
|
48
55
|
C,
|
|
49
|
-
|
|
56
|
+
k
|
|
50
57
|
]);
|
|
51
|
-
const [
|
|
52
|
-
const o = n ||
|
|
58
|
+
const [P, f] = i(p), [_, y] = i(!1), D = I(() => {
|
|
59
|
+
const o = n || oe(m);
|
|
53
60
|
try {
|
|
54
61
|
navigator.clipboard.writeText(o).then(() => {
|
|
55
|
-
|
|
62
|
+
f(b), y(!0), u && u(o);
|
|
56
63
|
});
|
|
57
64
|
} catch {
|
|
58
|
-
|
|
65
|
+
f("Failed to copy");
|
|
59
66
|
}
|
|
60
|
-
}, [n,
|
|
61
|
-
|
|
62
|
-
}, [
|
|
63
|
-
return /* @__PURE__ */ e(R, { theme: "dark", appendClassesToChildren: !0, children: /* @__PURE__ */ q(
|
|
67
|
+
}, [n, m, b, u]), $ = I(() => {
|
|
68
|
+
f(p), y(!1);
|
|
69
|
+
}, [p]), a = te(), { theme: q } = re(), S = () => /* @__PURE__ */ R(
|
|
64
70
|
"div",
|
|
65
71
|
{
|
|
66
|
-
className:
|
|
67
|
-
...
|
|
72
|
+
className: ne(a("code-block"), w, h?.root),
|
|
73
|
+
...j,
|
|
68
74
|
children: [
|
|
69
|
-
C && /* @__PURE__ */ e("div", { className:
|
|
70
|
-
|
|
75
|
+
C && /* @__PURE__ */ e("div", { className: a("code-block-header", h?.header), children: /* @__PURE__ */ e(
|
|
76
|
+
Z,
|
|
71
77
|
{
|
|
72
78
|
value: l,
|
|
73
|
-
onChange:
|
|
79
|
+
onChange: k,
|
|
74
80
|
options: t.map((o, r) => ({
|
|
75
81
|
label: o.label,
|
|
76
82
|
value: r
|
|
77
83
|
}))
|
|
78
84
|
}
|
|
79
85
|
) }),
|
|
80
|
-
/* @__PURE__ */ e("div", { className:
|
|
81
|
-
|
|
86
|
+
/* @__PURE__ */ e("div", { className: a("code-block-copy"), children: /* @__PURE__ */ e(
|
|
87
|
+
ce,
|
|
82
88
|
{
|
|
83
|
-
onClick:
|
|
84
|
-
label:
|
|
85
|
-
onMouseLeave:
|
|
86
|
-
children:
|
|
89
|
+
onClick: D,
|
|
90
|
+
label: P,
|
|
91
|
+
onMouseLeave: $,
|
|
92
|
+
children: _ ? /* @__PURE__ */ e(U, {}) : /* @__PURE__ */ e(V, {})
|
|
87
93
|
}
|
|
88
94
|
) }),
|
|
89
95
|
/* @__PURE__ */ e(
|
|
90
96
|
"div",
|
|
91
97
|
{
|
|
92
|
-
className:
|
|
98
|
+
className: a("code-block-content", h?.content),
|
|
93
99
|
style: {
|
|
94
100
|
maxHeight: c && (typeof c == "number" ? `${c}px` : c)
|
|
95
101
|
},
|
|
96
|
-
children: /* @__PURE__ */ e(
|
|
97
|
-
|
|
102
|
+
children: /* @__PURE__ */ e(se, { orientation: "both", ...O, children: n ? /* @__PURE__ */ e(
|
|
103
|
+
W,
|
|
98
104
|
{
|
|
99
|
-
language:
|
|
105
|
+
language: B,
|
|
100
106
|
code: n,
|
|
101
|
-
theme:
|
|
102
|
-
children: ({
|
|
103
|
-
className: o,
|
|
104
|
-
style: r,
|
|
105
|
-
tokens: D,
|
|
106
|
-
getLineProps: E,
|
|
107
|
-
getTokenProps: F
|
|
108
|
-
}) => /* @__PURE__ */ e(
|
|
107
|
+
theme: s == "auto" ? M[q] : M[s],
|
|
108
|
+
children: ({ className: o, style: r, tokens: z, getLineProps: G, getTokenProps: H }) => /* @__PURE__ */ e(
|
|
109
109
|
"pre",
|
|
110
110
|
{
|
|
111
111
|
style: { ...r, backgroundColor: "transparent" },
|
|
112
112
|
className: o,
|
|
113
|
-
children:
|
|
113
|
+
children: z.map((N, J) => /* @__PURE__ */ e("div", { ...G({ line: N }), children: N.map((K, Q) => /* @__PURE__ */ e("span", { ...H({ token: K }) }, Q)) }, J))
|
|
114
114
|
}
|
|
115
115
|
)
|
|
116
116
|
}
|
|
117
|
-
) :
|
|
117
|
+
) : m })
|
|
118
118
|
}
|
|
119
119
|
)
|
|
120
120
|
]
|
|
121
121
|
}
|
|
122
|
-
)
|
|
122
|
+
);
|
|
123
|
+
return s == "auto" ? S() : /* @__PURE__ */ e(
|
|
124
|
+
Y,
|
|
125
|
+
{
|
|
126
|
+
theme: s,
|
|
127
|
+
appendClassesToChildren: !0,
|
|
128
|
+
...L,
|
|
129
|
+
children: S()
|
|
130
|
+
}
|
|
131
|
+
);
|
|
123
132
|
};
|
|
124
133
|
export {
|
|
125
|
-
|
|
134
|
+
ye as CodeBlock
|
|
126
135
|
};
|
|
127
136
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/code-block/component.tsx"],"sourcesContent":["\"use client\";\nimport { CheckIcon, CopyIcon } from \"@bioturing/assets\";\nimport { Highlight, themes } from \"prism-react-renderer\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useControlledState } from \"../hooks\";\nimport { IconButton } from \"../icon-button\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { Segmented } from \"../segmented\";\nimport { ThemeProvider } from \"../theme-provider/component\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\nimport type { CodeBlockProps } from \"./types\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useTheme } from \"../theme-provider\";\n\nexport const CodeBlock = ({\n code,\n children,\n // initial,\n lang: defaultLang = \"tsx\",\n className,\n options,\n activeOption: controlledActiveOption,\n defaultActiveOption = 0,\n onActiveOptionChange,\n copyText = \"Copy\",\n copySuccessText = \"Copied\",\n classNames,\n maxHeight,\n onCopy,\n ...rest\n}: CodeBlockProps) => {\n const [activeOption, setActiveOption] = useControlledState(\n controlledActiveOption,\n onActiveOptionChange,\n defaultActiveOption\n );\n\n const [currentCode, setCurrentCode] = useState(code || \"\");\n\n const [lang, setLang] = useState(defaultLang);\n\n const hasOptions = options && options.length > 0;\n\n useEffect(() => {\n if (hasOptions) {\n const newCode = options[activeOption]?.code || \"\";\n const newLang = options[activeOption]?.lang || defaultLang;\n setCurrentCode(newCode);\n setLang(newLang);\n }\n }, [\n code,\n activeOption,\n defaultActiveOption,\n options,\n defaultLang,\n hasOptions,\n setActiveOption,\n ]);\n\n const [tooltipContent, setTooltipContent] = useState(copyText);\n const [copySuccess, setCopySuccess] = useState(false);\n\n const handleCopy = useCallback(() => {\n const codeContent = currentCode ? currentCode : reactNodeToString(children);\n try {\n navigator.clipboard.writeText(codeContent).then(() => {\n setTooltipContent(copySuccessText);\n setCopySuccess(true);\n if (onCopy) onCopy(codeContent);\n });\n } catch (_) {\n setTooltipContent(\"Failed to copy\");\n }\n }, [currentCode, children, copySuccessText, onCopy]);\n\n const handleMouseLeave = useCallback(() => {\n setTooltipContent(copyText);\n setCopySuccess(false);\n }, [copyText]);\n\n const cls = useCls();\n
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/code-block/component.tsx"],"sourcesContent":["\"use client\";\nimport { CheckIcon, CopyIcon } from \"@bioturing/assets\";\nimport { Highlight, themes } from \"prism-react-renderer\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useControlledState } from \"../hooks\";\nimport { IconButton } from \"../icon-button\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { Segmented } from \"../segmented\";\nimport { ThemeProvider } from \"../theme-provider/component\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\nimport type { CodeBlockProps } from \"./types\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useTheme } from \"../theme-provider\";\n\nconst THEME_MAP = {\n dark: themes.vsDark,\n light: themes.vsLight,\n};\n\nexport const CodeBlock = ({\n code,\n children,\n // initial,\n lang: defaultLang = \"tsx\",\n className,\n options,\n activeOption: controlledActiveOption,\n defaultActiveOption = 0,\n onActiveOptionChange,\n copyText = \"Copy\",\n copySuccessText = \"Copied\",\n classNames,\n maxHeight,\n onCopy,\n theme = \"auto\",\n themeProviderProps,\n scrollAreaProps,\n ...rest\n}: CodeBlockProps) => {\n const [activeOption, setActiveOption] = useControlledState(\n controlledActiveOption,\n onActiveOptionChange,\n defaultActiveOption\n );\n\n const [currentCode, setCurrentCode] = useState(code || \"\");\n\n const [lang, setLang] = useState(defaultLang);\n\n const hasOptions = options && options.length > 0;\n\n useEffect(() => {\n if (hasOptions) {\n const newCode = options[activeOption]?.code || \"\";\n const newLang = options[activeOption]?.lang || defaultLang;\n setCurrentCode(newCode);\n setLang(newLang);\n }\n }, [\n code,\n activeOption,\n defaultActiveOption,\n options,\n defaultLang,\n hasOptions,\n setActiveOption,\n ]);\n\n const [tooltipContent, setTooltipContent] = useState(copyText);\n const [copySuccess, setCopySuccess] = useState(false);\n\n const handleCopy = useCallback(() => {\n const codeContent = currentCode ? currentCode : reactNodeToString(children);\n try {\n navigator.clipboard.writeText(codeContent).then(() => {\n setTooltipContent(copySuccessText);\n setCopySuccess(true);\n if (onCopy) onCopy(codeContent);\n });\n } catch (_) {\n setTooltipContent(\"Failed to copy\");\n }\n }, [currentCode, children, copySuccessText, onCopy]);\n\n const handleMouseLeave = useCallback(() => {\n setTooltipContent(copyText);\n setCopySuccess(false);\n }, [copyText]);\n\n const cls = useCls();\n const { theme: currentThemeFromContext } = useTheme();\n\n const renderInner = () => (\n <div\n className={clsx(cls(\"code-block\"), className, classNames?.root)}\n {...rest}\n >\n {hasOptions && (\n <div className={cls(\"code-block-header\", classNames?.header)}>\n <Segmented\n value={activeOption}\n onChange={setActiveOption}\n options={options.map((opt, index) => ({\n label: opt.label,\n value: index,\n }))}\n />\n </div>\n )}\n <div className={cls(\"code-block-copy\")}>\n <IconButton\n onClick={handleCopy}\n label={tooltipContent}\n onMouseLeave={handleMouseLeave}\n >\n {copySuccess ? <CheckIcon /> : <CopyIcon />}\n </IconButton>\n </div>\n <div\n className={cls(\"code-block-content\", classNames?.content)}\n style={{\n maxHeight:\n maxHeight &&\n (typeof maxHeight === \"number\" ? `${maxHeight}px` : maxHeight),\n }}\n >\n <ScrollArea orientation=\"both\" {...scrollAreaProps}>\n {currentCode ? (\n <Highlight\n language={lang}\n code={currentCode}\n theme={\n theme == \"auto\"\n ? THEME_MAP[currentThemeFromContext]\n : THEME_MAP[theme]\n }\n >\n {({ className, style, tokens, getLineProps, getTokenProps }) => (\n <pre\n style={{ ...style, backgroundColor: \"transparent\" }}\n className={className}\n >\n {tokens.map((line, i) => (\n <div key={i} {...getLineProps({ line })}>\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </pre>\n )}\n </Highlight>\n ) : (\n children\n )}\n </ScrollArea>\n </div>\n </div>\n );\n\n return theme == \"auto\" ? (\n renderInner()\n ) : (\n <ThemeProvider\n theme={theme}\n appendClassesToChildren\n {...themeProviderProps}\n >\n {renderInner()}\n </ThemeProvider>\n );\n};\n"],"names":["THEME_MAP","themes","CodeBlock","code","children","defaultLang","className","options","controlledActiveOption","defaultActiveOption","onActiveOptionChange","copyText","copySuccessText","classNames","maxHeight","onCopy","theme","themeProviderProps","scrollAreaProps","rest","activeOption","setActiveOption","useControlledState","currentCode","setCurrentCode","useState","lang","setLang","hasOptions","useEffect","newCode","newLang","tooltipContent","setTooltipContent","copySuccess","setCopySuccess","handleCopy","useCallback","codeContent","reactNodeToString","handleMouseLeave","cls","useCls","currentThemeFromContext","useTheme","renderInner","jsxs","clsx","jsx","Segmented","opt","index","IconButton","CheckIcon","CopyIcon","ScrollArea","Highlight","style","tokens","getLineProps","getTokenProps","line","i","token","key","ThemeProvider"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAMA,IAAY;AAAA,EAChB,MAAMC,EAAO;AAAA,EACb,OAAOA,EAAO;AAChB,GAEaC,KAAY,CAAC;AAAA,EACxB,MAAAC;AAAA,EACA,UAAAC;AAAA;AAAA,EAEA,MAAMC,IAAc;AAAA,EACpB,WAAAC;AAAA,EACA,SAAAC;AAAA,EACA,cAAcC;AAAA,EACd,qBAAAC,IAAsB;AAAA,EACtB,sBAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,oBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,GAAGC;AACL,MAAsB;AACpB,QAAM,CAACC,GAAcC,CAAe,IAAIC;AAAA,IACtCd;AAAA,IACAE;AAAA,IACAD;AAAA,EAAA,GAGI,CAACc,GAAaC,CAAc,IAAIC,EAAStB,KAAQ,EAAE,GAEnD,CAACuB,GAAMC,CAAO,IAAIF,EAASpB,CAAW,GAEtCuB,IA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BAAAhB,EAAC,QAAA,EAAgB,GAAGY,EAAc,EAAE,OAAAG,EAAA,CAAO,EAAA,GAAhCC,CAAmC,CAC/C,EAAA,GAHOF,CAIV,CACD;AAAA,kBAAA;AAAA,gBAAA;AAAA,cACH;AAAA,YAAA,IAIJ1D,EAAA,CAEJ;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAIJ,SAAOY,KAAS,SACd6B,EAAA,IAEA,gBAAAG;AAAA,IAACiB;AAAA,IAAA;AAAA,MACC,OAAAjD;AAAA,MACA,yBAAuB;AAAA,MACtB,GAAGC;AAAA,MAEH,UAAA4B,EAAA;AAAA,IAAY;AAAA,EAAA;AAGnB;"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { HighlightProps } from 'prism-react-renderer';
|
|
2
|
+
import { Theme } from '../../tokens';
|
|
3
|
+
import { ThemeProviderProps } from '../theme-provider';
|
|
4
|
+
import { ScrollAreaProps } from '../scroll-area';
|
|
2
5
|
export interface CodeOption {
|
|
3
6
|
label: string;
|
|
4
7
|
code: string;
|
|
@@ -60,5 +63,19 @@ export interface CodeBlockProps extends Omit<React.ComponentPropsWithRef<"div">,
|
|
|
60
63
|
* Copy callback function
|
|
61
64
|
*/
|
|
62
65
|
onCopy?: (code?: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Theme of the code block
|
|
68
|
+
* @default "dark"
|
|
69
|
+
*/
|
|
70
|
+
theme?: Theme | "auto";
|
|
71
|
+
/**
|
|
72
|
+
* Props to pass to the ThemeProvider
|
|
73
|
+
* Only works when theme is not "auto"
|
|
74
|
+
*/
|
|
75
|
+
themeProviderProps?: ThemeProviderProps;
|
|
76
|
+
/**
|
|
77
|
+
* Props to pass to the ScrollArea
|
|
78
|
+
*/
|
|
79
|
+
scrollAreaProps?: ScrollAreaProps;
|
|
63
80
|
}
|
|
64
81
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/code-block/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/code-block/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;IAC1D;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC"}
|
|
@@ -52,7 +52,7 @@ export interface ScrollAreaProps extends Omit<BaseScrollArea.Root.Props, "onScro
|
|
|
52
52
|
* Orientation of the scrollbar
|
|
53
53
|
* @default "vertical"
|
|
54
54
|
*/
|
|
55
|
-
orientation?: "vertical" | "horizontal";
|
|
55
|
+
orientation?: "vertical" | "horizontal" | "both";
|
|
56
56
|
/**
|
|
57
57
|
* Enable fade-out effect at scrollable edges
|
|
58
58
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/scroll-area/component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIzE,OAAO,aAAa,CAAC;AAErB,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;WAEG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF;;OAEG;IACH,MAAM,CAAC,EAAE;QACP;;WAEG;QACH,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC/B;;WAEG;QACH,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC9B;;WAEG;QACH,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAChC;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;KAC7B,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/components/scroll-area/component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIzE,OAAO,aAAa,CAAC;AAErB,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;WAEG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF;;OAEG;IACH,MAAM,CAAC,EAAE;QACP;;WAEG;QACH,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC/B;;WAEG;QACH,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC9B;;WAEG;QACH,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAChC;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;KAC7B,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,MAAM,CAAC;IACjD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACnC;AAED,eAAO,MAAM,UAAU,GAAI,wFASxB,eAAe,4CAmJjB,CAAC"}
|
|
@@ -1,97 +1,113 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { useRef as
|
|
4
|
-
import { ScrollArea as
|
|
2
|
+
import { jsxs as x, jsx as i } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as R, useState as E, useEffect as L } from "react";
|
|
4
|
+
import { ScrollArea as e } from "@base-ui-components/react";
|
|
5
5
|
import './style.css';/* empty css */
|
|
6
6
|
import { useCls as j } from "../utils/antdUtils.js";
|
|
7
|
-
import { clsx as
|
|
7
|
+
import { clsx as c } from "../utils/cn.js";
|
|
8
8
|
const V = ({
|
|
9
|
-
children:
|
|
10
|
-
className:
|
|
11
|
-
classNames:
|
|
9
|
+
children: A,
|
|
10
|
+
className: w,
|
|
11
|
+
classNames: a = {},
|
|
12
12
|
orientation: r = "vertical",
|
|
13
|
-
fadeEdges:
|
|
13
|
+
fadeEdges: o = !1,
|
|
14
14
|
onScroll: u,
|
|
15
|
-
styles:
|
|
15
|
+
styles: s = {},
|
|
16
16
|
...y
|
|
17
17
|
}) => {
|
|
18
|
-
const t = j(),
|
|
18
|
+
const t = j(), v = R(null), [l, p] = E({
|
|
19
19
|
isAtStart: !0,
|
|
20
20
|
isAtEnd: !1,
|
|
21
21
|
isScrollable: !1
|
|
22
22
|
});
|
|
23
23
|
return L(() => {
|
|
24
|
-
if (!
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
24
|
+
if (!v.current) return;
|
|
25
|
+
const n = v.current, b = (z) => {
|
|
26
|
+
if (z && u && u(z), o)
|
|
27
27
|
if (r === "vertical") {
|
|
28
|
-
const { scrollTop:
|
|
28
|
+
const { scrollTop: h, scrollHeight: m, clientHeight: S } = n, f = m > S;
|
|
29
29
|
p({
|
|
30
|
-
isAtStart:
|
|
31
|
-
isAtEnd:
|
|
32
|
-
isScrollable:
|
|
30
|
+
isAtStart: h <= 1,
|
|
31
|
+
isAtEnd: h >= m - S - 1,
|
|
32
|
+
isScrollable: f
|
|
33
33
|
});
|
|
34
34
|
} else {
|
|
35
|
-
const { scrollLeft:
|
|
35
|
+
const { scrollLeft: h, scrollWidth: m, clientWidth: S } = n, f = m > S + 2;
|
|
36
36
|
p({
|
|
37
|
-
isAtStart:
|
|
38
|
-
isAtEnd:
|
|
39
|
-
isScrollable:
|
|
37
|
+
isAtStart: h <= 1,
|
|
38
|
+
isAtEnd: h >= m - S - 1,
|
|
39
|
+
isScrollable: f
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
43
|
+
b();
|
|
44
|
+
const T = setTimeout(b, 0);
|
|
45
|
+
n.addEventListener("scroll", b);
|
|
46
46
|
const d = new ResizeObserver(() => {
|
|
47
|
-
|
|
47
|
+
b();
|
|
48
48
|
});
|
|
49
|
-
return d.observe(
|
|
50
|
-
clearTimeout(
|
|
49
|
+
return d.observe(n), () => {
|
|
50
|
+
clearTimeout(T), n.removeEventListener("scroll", b), d.disconnect();
|
|
51
51
|
};
|
|
52
|
-
}, [
|
|
53
|
-
|
|
52
|
+
}, [o, r, u]), /* @__PURE__ */ x(
|
|
53
|
+
e.Root,
|
|
54
54
|
{
|
|
55
|
-
className:
|
|
55
|
+
className: c(t("scroll-area"), w),
|
|
56
56
|
...y,
|
|
57
57
|
children: [
|
|
58
|
-
/* @__PURE__ */
|
|
59
|
-
|
|
58
|
+
/* @__PURE__ */ i(
|
|
59
|
+
e.Viewport,
|
|
60
60
|
{
|
|
61
|
-
ref:
|
|
62
|
-
className:
|
|
61
|
+
ref: v,
|
|
62
|
+
className: c(
|
|
63
63
|
t("scroll-area-viewport"),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
o && l.isScrollable && r === "vertical" && l.isAtStart && t("scroll-area-fade-bottom-only"),
|
|
65
|
+
o && l.isScrollable && r === "vertical" && l.isAtEnd && t("scroll-area-fade-top-only"),
|
|
66
|
+
o && l.isScrollable && r === "vertical" && !l.isAtStart && !l.isAtEnd && t("scroll-area-fade-both-vertical"),
|
|
67
|
+
o && l.isScrollable && r === "horizontal" && l.isAtStart && t("scroll-area-fade-right-only"),
|
|
68
|
+
o && l.isScrollable && r === "horizontal" && l.isAtEnd && t("scroll-area-fade-left-only"),
|
|
69
|
+
o && l.isScrollable && r === "horizontal" && !l.isAtStart && !l.isAtEnd && t("scroll-area-fade-both-horizontal"),
|
|
70
|
+
a?.viewport
|
|
71
71
|
),
|
|
72
|
-
style:
|
|
73
|
-
children: r == "horizontal" ? /* @__PURE__ */
|
|
74
|
-
|
|
72
|
+
style: s?.viewport,
|
|
73
|
+
children: r == "horizontal" ? /* @__PURE__ */ i(
|
|
74
|
+
e.Content,
|
|
75
75
|
{
|
|
76
|
-
className:
|
|
77
|
-
style:
|
|
78
|
-
children:
|
|
76
|
+
className: c(t("scroll-area-content"), a?.content),
|
|
77
|
+
style: s?.content,
|
|
78
|
+
children: A
|
|
79
79
|
}
|
|
80
|
-
) :
|
|
80
|
+
) : A
|
|
81
81
|
}
|
|
82
82
|
),
|
|
83
|
-
/* @__PURE__ */
|
|
84
|
-
|
|
83
|
+
(r == "horizontal" || r == "both") && /* @__PURE__ */ i(
|
|
84
|
+
e.Scrollbar,
|
|
85
85
|
{
|
|
86
|
-
className:
|
|
87
|
-
orientation:
|
|
88
|
-
"data-orientation":
|
|
89
|
-
style:
|
|
90
|
-
children: /* @__PURE__ */
|
|
91
|
-
|
|
86
|
+
className: c(t("scroll-area-scrollbar"), a?.scrollbar),
|
|
87
|
+
orientation: "horizontal",
|
|
88
|
+
"data-orientation": "horizontal",
|
|
89
|
+
style: s?.scrollbar,
|
|
90
|
+
children: /* @__PURE__ */ i(
|
|
91
|
+
e.Thumb,
|
|
92
92
|
{
|
|
93
|
-
className:
|
|
94
|
-
style:
|
|
93
|
+
className: c(t("scroll-area-thumb"), a?.thumb),
|
|
94
|
+
style: s?.thumb
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
(r == "vertical" || r == "both") && /* @__PURE__ */ i(
|
|
100
|
+
e.Scrollbar,
|
|
101
|
+
{
|
|
102
|
+
className: c(t("scroll-area-scrollbar"), a?.scrollbar),
|
|
103
|
+
orientation: "vertical",
|
|
104
|
+
"data-orientation": "vertical",
|
|
105
|
+
style: s?.scrollbar,
|
|
106
|
+
children: /* @__PURE__ */ i(
|
|
107
|
+
e.Thumb,
|
|
108
|
+
{
|
|
109
|
+
className: c(t("scroll-area-thumb"), a?.thumb),
|
|
110
|
+
style: s?.thumb
|
|
95
111
|
}
|
|
96
112
|
)
|
|
97
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/scroll-area/component.tsx"],"sourcesContent":["\"use client\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { ScrollArea as BaseScrollArea } from \"@base-ui-components/react\";\nimport { clsx, useCls } from \"../utils\";\n\n// Import component-specific styles\nimport \"./style.css\";\n\nexport interface ScrollAreaProps\n extends Omit<BaseScrollArea.Root.Props, \"onScroll\"> {\n children: ReactNode;\n /**\n * Additional class name for the root component\n */\n className?: string;\n /**\n * Custom class names for each part of the scroll area\n */\n classNames?: {\n /**\n * Class name for the viewport element\n */\n viewport?: string;\n /**\n * Class name for the content element\n */\n content?: string;\n /**\n * Class name for the scrollbar element\n */\n scrollbar?: string;\n /**\n * Class name for the thumb element\n */\n thumb?: string;\n };\n /**\n * Custom styles for each part of the scroll area\n */\n styles?: {\n /**\n * Styles for the viewport element\n */\n viewport?: React.CSSProperties;\n /**\n * Styles for the content element\n */\n content?: React.CSSProperties;\n /**\n * Styles for the scrollbar element\n */\n scrollbar?: React.CSSProperties;\n /**\n * Styles for the thumb element\n */\n thumb?: React.CSSProperties;\n };\n /**\n * Orientation of the scrollbar\n * @default \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\";\n /**\n * Enable fade-out effect at scrollable edges\n * @default false\n */\n fadeEdges?: boolean;\n /**\n * Callback fired when the scroll position changes\n */\n onScroll?: (event: Event) => void;\n}\n\nexport const ScrollArea = ({\n children,\n className,\n classNames = {},\n orientation = \"vertical\",\n fadeEdges = false,\n onScroll,\n styles = {},\n ...rest\n}: ScrollAreaProps) => {\n const cls = useCls();\n const viewportRef = useRef<HTMLDivElement>(null);\n const [scrollState, setScrollState] = useState({\n isAtStart: true,\n isAtEnd: false,\n isScrollable: false,\n });\n\n useEffect(() => {\n if (!viewportRef.current) return;\n\n const viewport = viewportRef.current;\n\n const handleScroll = (event?: Event) => {\n // Call the onScroll callback if provided and event exists\n if (event && onScroll) {\n onScroll(event);\n }\n\n // Handle fade edges state update if enabled\n if (fadeEdges) {\n if (orientation === \"vertical\") {\n const { scrollTop, scrollHeight, clientHeight } = viewport;\n const isScrollable = scrollHeight > clientHeight;\n setScrollState({\n isAtStart: scrollTop <= 1,\n isAtEnd: scrollTop >= scrollHeight - clientHeight - 1,\n isScrollable,\n });\n } else {\n const { scrollLeft, scrollWidth, clientWidth } = viewport;\n // Add a small buffer (2px) to account for rounding errors\n const isScrollable = scrollWidth > clientWidth + 2;\n setScrollState({\n isAtStart: scrollLeft <= 1,\n isAtEnd: scrollLeft >= scrollWidth - clientWidth - 1,\n isScrollable,\n });\n }\n }\n };\n\n // Initial check (without event)\n handleScroll();\n\n // Use a timeout to check again after content might have rendered\n const timeoutId = setTimeout(handleScroll, 0);\n\n viewport.addEventListener(\"scroll\", handleScroll);\n\n // Add resize observer to detect content size changes\n const resizeObserver = new ResizeObserver(() => {\n handleScroll();\n });\n resizeObserver.observe(viewport);\n\n return () => {\n clearTimeout(timeoutId);\n viewport.removeEventListener(\"scroll\", handleScroll);\n resizeObserver.disconnect();\n };\n }, [fadeEdges, orientation, onScroll]);\n return (\n <BaseScrollArea.Root\n className={clsx(cls(\"scroll-area\"), className)}\n {...rest}\n >\n <BaseScrollArea.Viewport\n ref={viewportRef}\n className={clsx(\n cls(\"scroll-area-viewport\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n scrollState.isAtStart &&\n cls(\"scroll-area-fade-bottom-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n scrollState.isAtEnd &&\n cls(\"scroll-area-fade-top-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n !scrollState.isAtStart &&\n !scrollState.isAtEnd &&\n cls(\"scroll-area-fade-both-vertical\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n scrollState.isAtStart &&\n cls(\"scroll-area-fade-right-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n scrollState.isAtEnd &&\n cls(\"scroll-area-fade-left-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n !scrollState.isAtStart &&\n !scrollState.isAtEnd &&\n cls(\"scroll-area-fade-both-horizontal\"),\n classNames?.viewport\n )}\n style={styles?.viewport}\n >\n {orientation == \"horizontal\" ? (\n <BaseScrollArea.Content\n className={clsx(cls(\"scroll-area-content\"), classNames?.content)}\n style={styles?.content}\n >\n {children}\n </BaseScrollArea.Content>\n ) : (\n children\n )}\n </BaseScrollArea.Viewport>\n <BaseScrollArea.Scrollbar\n className={clsx(cls(\"scroll-area-scrollbar\"), classNames?.scrollbar)}\n orientation={orientation}\n data-orientation={orientation}\n style={styles?.scrollbar}\n >\n <BaseScrollArea.Thumb\n className={clsx(cls(\"scroll-area-thumb\"), classNames?.thumb)}\n style={styles?.thumb}\n />\n </BaseScrollArea.Scrollbar>\n </BaseScrollArea.Root>\n );\n};\n"],"names":["ScrollArea","children","className","classNames","orientation","fadeEdges","onScroll","styles","rest","cls","useCls","viewportRef","useRef","scrollState","setScrollState","useState","useEffect","viewport","handleScroll","event","scrollTop","scrollHeight","clientHeight","isScrollable","scrollLeft","scrollWidth","clientWidth","timeoutId","resizeObserver","jsxs","BaseScrollArea","clsx","jsx"],"mappings":";;;;;;;AAyEO,MAAMA,IAAa,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC,IAAa,CAAA;AAAA,EACb,aAAAC,IAAc;AAAA,EACd,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,QAAAC,IAAS,CAAA;AAAA,EACT,GAAGC;AACL,MAAuB;AACrB,QAAMC,IAAMC,EAAA,GACNC,IAAcC,EAAuB,IAAI,GACzC,CAACC,GAAaC,CAAc,IAAIC,EAAS;AAAA,IAC7C,WAAW;AAAA,IACX,SAAS;AAAA,IACT,cAAc;AAAA,EAAA,CACf;AAED,SAAAC,EAAU,MAAM;AACd,QAAI,CAACL,EAAY,QAAS;AAE1B,UAAMM,IAAWN,EAAY,SAEvBO,IAAe,CAACC,MAAkB;AAOtC,UALIA,KAASb,KACXA,EAASa,CAAK,GAIZd;AACF,YAAID,MAAgB,YAAY;AAC9B,gBAAM,EAAE,WAAAgB,GAAW,cAAAC,GAAc,cAAAC,EAAA,IAAiBL,GAC5CM,IAAeF,IAAeC;AACpC,UAAAR,EAAe;AAAA,YACb,WAAWM,KAAa;AAAA,YACxB,SAASA,KAAaC,IAAeC,IAAe;AAAA,YACpD,cAAAC;AAAA,UAAA,CACD;AAAA,QACH,OAAO;AACL,gBAAM,EAAE,YA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I,4BAA4B;AAAA,cAClCJ,KACEQ,EAAY,gBACZT,MAAgB,gBAChB,CAACS,EAAY,aACb,CAACA,EAAY,WACbJ,EAAI,kCAAkC;AAAA,cACxCN,GAAY;AAAA,YAAA;AAAA,YAEd,OAAOI,GAAQ;AAAA,YAEd,eAAe,eACd,gBAAAyB;AAAA,cAACF,EAAe;AAAA,cAAf;AAAA,gBACC,WAAWC,EAAKtB,EAAI,qBAAqB,GAAGN,GAAY,OAAO;AAAA,gBAC/D,OAAOI,GAAQ;AAAA,gBAEd,UAAAN;AAAA,cAAA;AAAA,YAAA,IAGHA;AAAA,UAAA;AAAA,QAAA;AAAA,QAGJ,gBAAA+B;AAAA,UAACF,EAAe;AAAA,UAAf;AAAA,YACC,WAAWC,EAAKtB,EAAI,uBAAuB,GAAGN,GAAY,SAAS;AAAA,YACnE,aAAAC;AAAA,YACA,oBAAkBA;AAAA,YAClB,OAAOG,GAAQ;AAAA,YAEf,UAAA,gBAAAyB;AAAA,cAACF,EAAe;AAAA,cAAf;AAAA,gBACC,WAAWC,EAAKtB,EAAI,mBAAmB,GAAGN,GAAY,KAAK;AAAA,gBAC3D,OAAOI,GAAQ;AAAA,cAAA;AAAA,YAAA;AAAA,UACjB;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/scroll-area/component.tsx"],"sourcesContent":["\"use client\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { ScrollArea as BaseScrollArea } from \"@base-ui-components/react\";\nimport { clsx, useCls } from \"../utils\";\n\n// Import component-specific styles\nimport \"./style.css\";\n\nexport interface ScrollAreaProps\n extends Omit<BaseScrollArea.Root.Props, \"onScroll\"> {\n children: ReactNode;\n /**\n * Additional class name for the root component\n */\n className?: string;\n /**\n * Custom class names for each part of the scroll area\n */\n classNames?: {\n /**\n * Class name for the viewport element\n */\n viewport?: string;\n /**\n * Class name for the content element\n */\n content?: string;\n /**\n * Class name for the scrollbar element\n */\n scrollbar?: string;\n /**\n * Class name for the thumb element\n */\n thumb?: string;\n };\n /**\n * Custom styles for each part of the scroll area\n */\n styles?: {\n /**\n * Styles for the viewport element\n */\n viewport?: React.CSSProperties;\n /**\n * Styles for the content element\n */\n content?: React.CSSProperties;\n /**\n * Styles for the scrollbar element\n */\n scrollbar?: React.CSSProperties;\n /**\n * Styles for the thumb element\n */\n thumb?: React.CSSProperties;\n };\n /**\n * Orientation of the scrollbar\n * @default \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\" | \"both\";\n /**\n * Enable fade-out effect at scrollable edges\n * @default false\n */\n fadeEdges?: boolean;\n /**\n * Callback fired when the scroll position changes\n */\n onScroll?: (event: Event) => void;\n}\n\nexport const ScrollArea = ({\n children,\n className,\n classNames = {},\n orientation = \"vertical\",\n fadeEdges = false,\n onScroll,\n styles = {},\n ...rest\n}: ScrollAreaProps) => {\n const cls = useCls();\n const viewportRef = useRef<HTMLDivElement>(null);\n const [scrollState, setScrollState] = useState({\n isAtStart: true,\n isAtEnd: false,\n isScrollable: false,\n });\n\n useEffect(() => {\n if (!viewportRef.current) return;\n\n const viewport = viewportRef.current;\n\n const handleScroll = (event?: Event) => {\n // Call the onScroll callback if provided and event exists\n if (event && onScroll) {\n onScroll(event);\n }\n\n // Handle fade edges state update if enabled\n if (fadeEdges) {\n if (orientation === \"vertical\") {\n const { scrollTop, scrollHeight, clientHeight } = viewport;\n const isScrollable = scrollHeight > clientHeight;\n setScrollState({\n isAtStart: scrollTop <= 1,\n isAtEnd: scrollTop >= scrollHeight - clientHeight - 1,\n isScrollable,\n });\n } else {\n const { scrollLeft, scrollWidth, clientWidth } = viewport;\n // Add a small buffer (2px) to account for rounding errors\n const isScrollable = scrollWidth > clientWidth + 2;\n setScrollState({\n isAtStart: scrollLeft <= 1,\n isAtEnd: scrollLeft >= scrollWidth - clientWidth - 1,\n isScrollable,\n });\n }\n }\n };\n\n // Initial check (without event)\n handleScroll();\n\n // Use a timeout to check again after content might have rendered\n const timeoutId = setTimeout(handleScroll, 0);\n\n viewport.addEventListener(\"scroll\", handleScroll);\n\n // Add resize observer to detect content size changes\n const resizeObserver = new ResizeObserver(() => {\n handleScroll();\n });\n resizeObserver.observe(viewport);\n\n return () => {\n clearTimeout(timeoutId);\n viewport.removeEventListener(\"scroll\", handleScroll);\n resizeObserver.disconnect();\n };\n }, [fadeEdges, orientation, onScroll]);\n return (\n <BaseScrollArea.Root\n className={clsx(cls(\"scroll-area\"), className)}\n {...rest}\n >\n <BaseScrollArea.Viewport\n ref={viewportRef}\n className={clsx(\n cls(\"scroll-area-viewport\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n scrollState.isAtStart &&\n cls(\"scroll-area-fade-bottom-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n scrollState.isAtEnd &&\n cls(\"scroll-area-fade-top-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"vertical\" &&\n !scrollState.isAtStart &&\n !scrollState.isAtEnd &&\n cls(\"scroll-area-fade-both-vertical\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n scrollState.isAtStart &&\n cls(\"scroll-area-fade-right-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n scrollState.isAtEnd &&\n cls(\"scroll-area-fade-left-only\"),\n fadeEdges &&\n scrollState.isScrollable &&\n orientation === \"horizontal\" &&\n !scrollState.isAtStart &&\n !scrollState.isAtEnd &&\n cls(\"scroll-area-fade-both-horizontal\"),\n classNames?.viewport\n )}\n style={styles?.viewport}\n >\n {orientation == \"horizontal\" ? (\n <BaseScrollArea.Content\n className={clsx(cls(\"scroll-area-content\"), classNames?.content)}\n style={styles?.content}\n >\n {children}\n </BaseScrollArea.Content>\n ) : (\n children\n )}\n </BaseScrollArea.Viewport>\n {(orientation == \"horizontal\" || orientation == \"both\") && (\n <BaseScrollArea.Scrollbar\n className={clsx(cls(\"scroll-area-scrollbar\"), classNames?.scrollbar)}\n orientation={\"horizontal\"}\n data-orientation={\"horizontal\"}\n style={styles?.scrollbar}\n >\n <BaseScrollArea.Thumb\n className={clsx(cls(\"scroll-area-thumb\"), classNames?.thumb)}\n style={styles?.thumb}\n />\n </BaseScrollArea.Scrollbar>\n )}\n {(orientation == \"vertical\" || orientation == \"both\") && (\n <BaseScrollArea.Scrollbar\n className={clsx(cls(\"scroll-area-scrollbar\"), classNames?.scrollbar)}\n orientation={\"vertical\"}\n data-orientation={\"vertical\"}\n style={styles?.scrollbar}\n >\n <BaseScrollArea.Thumb\n className={clsx(cls(\"scroll-area-thumb\"), classNames?.thumb)}\n style={styles?.thumb}\n />\n </BaseScrollArea.Scrollbar>\n )}\n </BaseScrollArea.Root>\n );\n};\n"],"names":["ScrollArea","children","className","classNames","orientation","fadeEdges","onScroll","styles","rest","cls","useCls","viewportRef","useRef","scrollState","setScrollState","useState","useEffect","viewport","handleScroll","event","scrollTop","scrollHeight","clientHeight","isScrollable","scrollLeft","scrollWidth","clientWidth","timeoutId","resizeObserver","jsxs","BaseScrollArea","clsx","jsx"],"mappings":";;;;;;;AAyEO,MAAMA,IAAa,CAAC;AAAA,EACzB,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC,IAAa,CAAA;AAAA,EACb,aAAAC,IAAc;AAAA,EACd,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,QAAAC,IAAS,CAAA;AAAA,EACT,GAAGC;AACL,MAAuB;AACrB,QAAMC,IAAMC,EAAA,GACNC,IAAcC,EAAuB,IAAI,GACzC,CAACC,GAAaC,CAAc,IAAIC,EAAS;AAAA,IAC7C,WAAW;AAAA,IACX,SAAS;AAAA,IACT,cAAc;AAAA,EAAA,CACf;AAED,SAAAC,EAAU,MAAM;AACd,QAAI,CAACL,EAAY,QAAS;AAE1B,UAAMM,IAAWN,EAAY,SAEvBO,IAAe,CAACC,MAAkB;AAOtC,UALI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