@sybilion/uilib 1.4.2 → 1.4.4
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/esm/components/ui/Page/PageScroll/PageScroll.js +16 -21
- package/dist/esm/components/ui/Page/pageContext.js +1 -0
- package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.js +1 -1
- package/dist/esm/components/widgets/PerformanceChart/PerformanceTable.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/types/src/components/ui/Page/PageScroll/PageScroll.d.ts +10 -2
- package/dist/esm/types/src/components/ui/Page/index.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Page/pageContext.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/ui/Page/PageScroll/PageScroll.tsx +45 -25
- package/src/components/ui/Page/index.ts +1 -0
- package/src/components/ui/Page/pageContext.ts +2 -0
- package/src/docs/App/App.tsx +19 -18
- package/src/docs/DocsShell.styl +8 -1
- package/src/docs/DocsShell.styl.d.ts +1 -0
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import { useState,
|
|
3
|
+
import { useRef, useState, useMemo, useEffect } from 'react';
|
|
4
4
|
import { useLocation } from 'react-router-dom';
|
|
5
5
|
import { PageContext } from '../pageContext.js';
|
|
6
6
|
import { Scroll } from '@homecode/ui';
|
|
7
7
|
import S from './PageScroll.styl.js';
|
|
8
8
|
|
|
9
|
-
function PageScrollInner({ className, rootClassName, children, }) {
|
|
10
|
-
// const { setIsScrolled } = useContext(PageContext);
|
|
11
|
-
// const prevScrollTop = useRef(0);
|
|
9
|
+
function PageScrollInner({ className, rootClassName, children, scrollInnerRef, onScroll, resetScrollOnPathnameChange, }) {
|
|
12
10
|
const location = useLocation();
|
|
13
|
-
const scrollInnerRef = useRef(null);
|
|
14
11
|
useEffect(() => {
|
|
12
|
+
if (!resetScrollOnPathnameChange)
|
|
13
|
+
return;
|
|
15
14
|
scrollInnerRef.current?.scrollTo({ top: 0 });
|
|
16
|
-
}, [location.pathname]);
|
|
17
|
-
|
|
18
|
-
// if (e.currentTarget.scrollTop > prevScrollTop.current) {
|
|
19
|
-
// // if (e.currentTarget.scrollTop > 0) {
|
|
20
|
-
// setIsScrolled(true);
|
|
21
|
-
// } else {
|
|
22
|
-
// setIsScrolled(false);
|
|
23
|
-
// }
|
|
24
|
-
// prevScrollTop.current = e.currentTarget.scrollTop;
|
|
25
|
-
// };
|
|
26
|
-
return (jsx(Scroll, { y: true,
|
|
27
|
-
// fadeSize="l"
|
|
28
|
-
offset: { y: { before: 120, after: 130 } }, className: cn(S.root, rootClassName), autoHide: true, innerClassName: cn(S.inner, className), yScrollbarClassName: S.scrollbar, onInnerRef: el => {
|
|
15
|
+
}, [location.pathname, resetScrollOnPathnameChange, scrollInnerRef]);
|
|
16
|
+
return (jsx(Scroll, { y: true, offset: { y: { before: 120, after: 130 } }, className: cn(S.root, rootClassName), autoHide: true, innerClassName: cn(S.inner, className), yScrollbarClassName: S.scrollbar, onInnerRef: el => {
|
|
29
17
|
scrollInnerRef.current = el;
|
|
30
|
-
}, children: children }));
|
|
18
|
+
}, onScroll: onScroll, children: children }));
|
|
31
19
|
}
|
|
32
|
-
const PageScroll = ({ children, className, rootClassName, }) => {
|
|
20
|
+
const PageScroll = ({ children, className, rootClassName, scrollInnerRef: scrollInnerRefProp, onScroll, resetScrollOnPathnameChange = true, }) => {
|
|
21
|
+
const internalScrollInnerRef = useRef(null);
|
|
22
|
+
const scrollInnerRef = scrollInnerRefProp ?? internalScrollInnerRef;
|
|
33
23
|
const [isScrolled, setIsScrolled] = useState(false);
|
|
34
|
-
|
|
24
|
+
const pageContextValue = useMemo(() => ({
|
|
25
|
+
isScrolled,
|
|
26
|
+
setIsScrolled,
|
|
27
|
+
getPageScrollElement: () => scrollInnerRef.current,
|
|
28
|
+
}), [isScrolled, scrollInnerRef]);
|
|
29
|
+
return (jsx(PageContext.Provider, { value: pageContextValue, children: jsx(PageScrollInner, { className: className, rootClassName: rootClassName, scrollInnerRef: scrollInnerRef, onScroll: onScroll, resetScrollOnPathnameChange: resetScrollOnPathnameChange, children: children }) }));
|
|
35
30
|
};
|
|
36
31
|
|
|
37
32
|
export { PageScroll };
|
|
@@ -9,10 +9,10 @@ import '../../ui/Button/Button.styl.js';
|
|
|
9
9
|
import '../../ui/Page/AppBanner/AppBanner.styl.js';
|
|
10
10
|
import { InfoIcon } from 'lucide-react';
|
|
11
11
|
import '../../ui/Page/AppShell/AppShell.js';
|
|
12
|
+
import '../../ui/Page/pageContext.js';
|
|
12
13
|
import 'react-router-dom';
|
|
13
14
|
import '../../ui/Sidebar/Sidebar.js';
|
|
14
15
|
import '../../ui/Page/Breadcrumbs/Breadcrumbs.styl.js';
|
|
15
|
-
import '../../ui/Page/pageContext.js';
|
|
16
16
|
import { Tooltip, TooltipTrigger, TooltipContent } from '../../ui/Tooltip/Tooltip.js';
|
|
17
17
|
import '../../ui/Page/PageHeader/PageHeader.styl.js';
|
|
18
18
|
import '../../ui/Page/PageEmptyCanvas/PageEmptyCanvas.styl.js';
|
|
@@ -9,10 +9,10 @@ import { FORECAST_LINE_COLORS } from '../../ui/ChartAreaInteractive/ChartLines.j
|
|
|
9
9
|
import '../../ui/Page/AppBanner/AppBanner.styl.js';
|
|
10
10
|
import 'classnames';
|
|
11
11
|
import '../../ui/Page/AppShell/AppShell.js';
|
|
12
|
+
import '../../ui/Page/pageContext.js';
|
|
12
13
|
import 'react-router-dom';
|
|
13
14
|
import '../../ui/Sidebar/Sidebar.js';
|
|
14
15
|
import '../../ui/Page/Breadcrumbs/Breadcrumbs.styl.js';
|
|
15
|
-
import '../../ui/Page/pageContext.js';
|
|
16
16
|
import '../../ui/Page/PageHeader/PageHeader.styl.js';
|
|
17
17
|
import '../../ui/Page/PageEmptyCanvas/PageEmptyCanvas.styl.js';
|
|
18
18
|
import '../../ui/Page/PageContent/PageContent.styl.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -72,6 +72,7 @@ export { NavUserHeader } from './components/ui/NavUserHeader/NavUserHeader.js';
|
|
|
72
72
|
export { NumberControl } from './components/ui/NumberControl/NumberControl.js';
|
|
73
73
|
export { AppBanner } from './components/ui/Page/AppBanner/AppBanner.js';
|
|
74
74
|
export { AppShell, AppShellMainContent } from './components/ui/Page/AppShell/AppShell.js';
|
|
75
|
+
export { PageContext } from './components/ui/Page/pageContext.js';
|
|
75
76
|
export { PageHeader } from './components/ui/Page/PageHeader/PageHeader.js';
|
|
76
77
|
export { PageEmptyCanvas } from './components/ui/Page/PageEmptyCanvas/PageEmptyCanvas.js';
|
|
77
78
|
export { PageContent, PageContentSection } from './components/ui/Page/PageContent/PageContent.js';
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
export type PageScrollProps = {
|
|
2
3
|
children: React.ReactNode;
|
|
3
4
|
className?: string;
|
|
5
|
+
/** Merged onto the outer Scroll root (e.g. embed previews that must not use `100vh`). */
|
|
4
6
|
rootClassName?: string;
|
|
5
|
-
|
|
7
|
+
/** Optional external ref for the scrollable inner element (e.g. app scroll restoration). */
|
|
8
|
+
scrollInnerRef?: RefObject<HTMLDivElement | null>;
|
|
9
|
+
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
10
|
+
/** When false, pathname changes do not reset scroll (caller owns navigation scroll). */
|
|
11
|
+
resetScrollOnPathnameChange?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const PageScroll: ({ children, className, rootClassName, scrollInnerRef: scrollInnerRefProp, onScroll, resetScrollOnPathnameChange, }: PageScrollProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AppBanner, type AppBannerProps } from './AppBanner/AppBanner';
|
|
2
2
|
export { AppShell, AppShellMainContent, type AppShellMainContentProps, type AppShellProps, } from './AppShell/AppShell';
|
|
3
|
+
export { PageContext } from './pageContext';
|
|
3
4
|
export { PageHeader } from './PageHeader/PageHeader';
|
|
4
5
|
export { PageEmptyCanvas } from './PageEmptyCanvas/PageEmptyCanvas';
|
|
5
6
|
export { PageContent, PageContentSection } from './PageContent/PageContent';
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { type RefObject, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { useLocation } from 'react-router-dom';
|
|
4
4
|
|
|
5
5
|
import { PageContext } from '#uilib/components/ui/Page/pageContext';
|
|
@@ -7,39 +7,43 @@ import { Scroll } from '@homecode/ui';
|
|
|
7
7
|
|
|
8
8
|
import S from './PageScroll.styl';
|
|
9
9
|
|
|
10
|
+
export type PageScrollProps = {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Merged onto the outer Scroll root (e.g. embed previews that must not use `100vh`). */
|
|
14
|
+
rootClassName?: string;
|
|
15
|
+
/** Optional external ref for the scrollable inner element (e.g. app scroll restoration). */
|
|
16
|
+
scrollInnerRef?: RefObject<HTMLDivElement | null>;
|
|
17
|
+
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
18
|
+
/** When false, pathname changes do not reset scroll (caller owns navigation scroll). */
|
|
19
|
+
resetScrollOnPathnameChange?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
10
22
|
function PageScrollInner({
|
|
11
23
|
className,
|
|
12
24
|
rootClassName,
|
|
13
25
|
children,
|
|
26
|
+
scrollInnerRef,
|
|
27
|
+
onScroll,
|
|
28
|
+
resetScrollOnPathnameChange,
|
|
14
29
|
}: {
|
|
15
30
|
className?: string;
|
|
16
|
-
/** Merged onto the outer Scroll root (e.g. embed previews that must not use `100vh`). */
|
|
17
31
|
rootClassName?: string;
|
|
18
32
|
children: React.ReactNode;
|
|
33
|
+
scrollInnerRef: RefObject<HTMLDivElement | null>;
|
|
34
|
+
onScroll?: (e: React.UIEvent<HTMLDivElement>) => void;
|
|
35
|
+
resetScrollOnPathnameChange: boolean;
|
|
19
36
|
}) {
|
|
20
|
-
// const { setIsScrolled } = useContext(PageContext);
|
|
21
|
-
// const prevScrollTop = useRef(0);
|
|
22
37
|
const location = useLocation();
|
|
23
|
-
const scrollInnerRef = useRef<HTMLDivElement | null>(null);
|
|
24
38
|
|
|
25
39
|
useEffect(() => {
|
|
40
|
+
if (!resetScrollOnPathnameChange) return;
|
|
26
41
|
scrollInnerRef.current?.scrollTo({ top: 0 });
|
|
27
|
-
}, [location.pathname]);
|
|
28
|
-
|
|
29
|
-
// const onScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
|
30
|
-
// if (e.currentTarget.scrollTop > prevScrollTop.current) {
|
|
31
|
-
// // if (e.currentTarget.scrollTop > 0) {
|
|
32
|
-
// setIsScrolled(true);
|
|
33
|
-
// } else {
|
|
34
|
-
// setIsScrolled(false);
|
|
35
|
-
// }
|
|
36
|
-
// prevScrollTop.current = e.currentTarget.scrollTop;
|
|
37
|
-
// };
|
|
42
|
+
}, [location.pathname, resetScrollOnPathnameChange, scrollInnerRef]);
|
|
38
43
|
|
|
39
44
|
return (
|
|
40
45
|
<Scroll
|
|
41
46
|
y
|
|
42
|
-
// fadeSize="l"
|
|
43
47
|
offset={{ y: { before: 120, after: 130 } }}
|
|
44
48
|
className={cn(S.root, rootClassName)}
|
|
45
49
|
autoHide
|
|
@@ -48,7 +52,7 @@ function PageScrollInner({
|
|
|
48
52
|
onInnerRef={el => {
|
|
49
53
|
scrollInnerRef.current = el;
|
|
50
54
|
}}
|
|
51
|
-
|
|
55
|
+
onScroll={onScroll}
|
|
52
56
|
>
|
|
53
57
|
{children}
|
|
54
58
|
</Scroll>
|
|
@@ -59,16 +63,32 @@ export const PageScroll = ({
|
|
|
59
63
|
children,
|
|
60
64
|
className,
|
|
61
65
|
rootClassName,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
scrollInnerRef: scrollInnerRefProp,
|
|
67
|
+
onScroll,
|
|
68
|
+
resetScrollOnPathnameChange = true,
|
|
69
|
+
}: PageScrollProps) => {
|
|
70
|
+
const internalScrollInnerRef = useRef<HTMLDivElement | null>(null);
|
|
71
|
+
const scrollInnerRef = scrollInnerRefProp ?? internalScrollInnerRef;
|
|
67
72
|
const [isScrolled, setIsScrolled] = useState(false);
|
|
68
73
|
|
|
74
|
+
const pageContextValue = useMemo(
|
|
75
|
+
() => ({
|
|
76
|
+
isScrolled,
|
|
77
|
+
setIsScrolled,
|
|
78
|
+
getPageScrollElement: () => scrollInnerRef.current,
|
|
79
|
+
}),
|
|
80
|
+
[isScrolled, scrollInnerRef],
|
|
81
|
+
);
|
|
82
|
+
|
|
69
83
|
return (
|
|
70
|
-
<PageContext.Provider value={
|
|
71
|
-
<PageScrollInner
|
|
84
|
+
<PageContext.Provider value={pageContextValue}>
|
|
85
|
+
<PageScrollInner
|
|
86
|
+
className={className}
|
|
87
|
+
rootClassName={rootClassName}
|
|
88
|
+
scrollInnerRef={scrollInnerRef}
|
|
89
|
+
onScroll={onScroll}
|
|
90
|
+
resetScrollOnPathnameChange={resetScrollOnPathnameChange}
|
|
91
|
+
>
|
|
72
92
|
{children}
|
|
73
93
|
</PageScrollInner>
|
|
74
94
|
</PageContext.Provider>
|
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
type AppShellMainContentProps,
|
|
6
6
|
type AppShellProps,
|
|
7
7
|
} from './AppShell/AppShell';
|
|
8
|
+
export { PageContext } from './pageContext';
|
|
8
9
|
export { PageHeader } from './PageHeader/PageHeader';
|
|
9
10
|
export { PageEmptyCanvas } from './PageEmptyCanvas/PageEmptyCanvas';
|
|
10
11
|
export { PageContent, PageContentSection } from './PageContent/PageContent';
|
|
@@ -3,7 +3,9 @@ import { createContext } from 'react';
|
|
|
3
3
|
export const PageContext = createContext<{
|
|
4
4
|
isScrolled: boolean;
|
|
5
5
|
setIsScrolled: (isScrolled: boolean) => void;
|
|
6
|
+
getPageScrollElement: () => HTMLDivElement | null;
|
|
6
7
|
}>({
|
|
7
8
|
isScrolled: false,
|
|
8
9
|
setIsScrolled: () => {},
|
|
10
|
+
getPageScrollElement: () => null,
|
|
9
11
|
});
|
package/src/docs/App/App.tsx
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
AppShell,
|
|
4
|
-
AppShellMainContent,
|
|
5
|
-
} from '#uilib/components/ui/Page';
|
|
6
|
-
import {
|
|
7
|
-
DOCS_CHAT_USER_KEY,
|
|
8
|
-
DOCS_SIDEBAR_WIDTH_LS_KEY,
|
|
9
|
-
} from '../docsConstants';
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { useState } from 'react';
|
|
10
3
|
import {
|
|
11
4
|
Link,
|
|
12
5
|
Navigate,
|
|
@@ -19,20 +12,28 @@ import {
|
|
|
19
12
|
|
|
20
13
|
import { AppHeaderHost } from '#uilib/components/ui/AppHeader';
|
|
21
14
|
import { Button } from '#uilib/components/ui/Button';
|
|
22
|
-
import { ChatProvider } from '#uilib/contexts/chat-context';
|
|
23
|
-
import type { ChatResponse } from '#uilib/types/chat-api.types';
|
|
24
|
-
import { DOC_DEFAULT_SLUG } from '../registry';
|
|
25
|
-
import { DocPage } from '../DocPage';
|
|
26
|
-
import { DocsSidebar } from '#uilib/docs/components/DocsSidebar/DocsSidebar';
|
|
27
15
|
import { Logo } from '#uilib/components/ui/Logo';
|
|
16
|
+
import {
|
|
17
|
+
AppBanner,
|
|
18
|
+
AppShell,
|
|
19
|
+
AppShellMainContent,
|
|
20
|
+
} from '#uilib/components/ui/Page';
|
|
28
21
|
import { PageFooter } from '#uilib/components/ui/Page/PageFooter/PageFooter';
|
|
29
22
|
import { PageScroll } from '#uilib/components/ui/Page/PageScroll/PageScroll';
|
|
30
|
-
import S from '../DocsShell.styl';
|
|
31
23
|
import { SidebarProvider } from '#uilib/components/ui/Sidebar/Sidebar';
|
|
32
24
|
import { SybilionAppHeader } from '#uilib/components/widgets/SybilionAppHeader';
|
|
25
|
+
import { ChatProvider } from '#uilib/contexts/chat-context';
|
|
26
|
+
import { DocsSidebar } from '#uilib/docs/components/DocsSidebar/DocsSidebar';
|
|
27
|
+
import type { ChatResponse } from '#uilib/types/chat-api.types';
|
|
28
|
+
|
|
29
|
+
import { DocPage } from '../DocPage';
|
|
30
|
+
import S from '../DocsShell.styl';
|
|
31
|
+
import {
|
|
32
|
+
DOCS_CHAT_USER_KEY,
|
|
33
|
+
DOCS_SIDEBAR_WIDTH_LS_KEY,
|
|
34
|
+
} from '../docsConstants';
|
|
35
|
+
import { DOC_DEFAULT_SLUG } from '../registry';
|
|
33
36
|
import { ThemeToggle } from './ThemeToggle';
|
|
34
|
-
import cn from 'classnames';
|
|
35
|
-
import { useState } from 'react';
|
|
36
37
|
|
|
37
38
|
async function mockDocsSendChatMessage(
|
|
38
39
|
message: string,
|
|
@@ -63,7 +64,7 @@ function DocsLayout() {
|
|
|
63
64
|
</div>
|
|
64
65
|
) : null}
|
|
65
66
|
<div className={S.pageScrollSlot}>
|
|
66
|
-
<PageScroll className={S.root}>
|
|
67
|
+
<PageScroll className={S.root} rootClassName={S.pageScrollRoot}>
|
|
67
68
|
<AppShell>
|
|
68
69
|
<DocsSidebar />
|
|
69
70
|
|
package/src/docs/DocsShell.styl
CHANGED
|
@@ -26,10 +26,17 @@
|
|
|
26
26
|
height 100%
|
|
27
27
|
min-height 0
|
|
28
28
|
|
|
29
|
+
// PageScroll default is 100vh; inside banner viewport the slot is shorter — fill slot, not viewport.
|
|
30
|
+
.pageScrollRoot
|
|
31
|
+
flex 1
|
|
32
|
+
min-height 0
|
|
33
|
+
height 100% !important
|
|
34
|
+
max-height 100% !important
|
|
35
|
+
|
|
29
36
|
.root
|
|
30
37
|
display flex
|
|
31
38
|
flex-direction column
|
|
32
|
-
height
|
|
39
|
+
min-height 100%
|
|
33
40
|
|
|
34
41
|
.mainHeaderBar
|
|
35
42
|
flex-shrink 0
|