@sybilion/uilib 1.4.3 → 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.
@@ -1,37 +1,32 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import cn from 'classnames';
3
- import { useState, useRef, useEffect } from 'react';
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
- // const onScroll = (e: React.UIEvent<HTMLDivElement>) => {
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
- return (jsx(PageContext.Provider, { value: { isScrolled, setIsScrolled }, children: jsx(PageScrollInner, { className: className, rootClassName: rootClassName, children: children }) }));
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 };
@@ -3,6 +3,7 @@ import { createContext } from 'react';
3
3
  const PageContext = createContext({
4
4
  isScrolled: false,
5
5
  setIsScrolled: () => { },
6
+ getPageScrollElement: () => null,
6
7
  });
7
8
 
8
9
  export { PageContext };
@@ -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
- export declare const PageScroll: ({ children, className, rootClassName, }: {
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
- }) => import("react/jsx-runtime").JSX.Element;
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';
@@ -1,4 +1,5 @@
1
1
  export declare const PageContext: import("react").Context<{
2
2
  isScrolled: boolean;
3
3
  setIsScrolled: (isScrolled: boolean) => void;
4
+ getPageScrollElement: () => HTMLDivElement | null;
4
5
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybilion/uilib",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Sybilion Design System — React UI components (Webpack + Stylus)",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -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
- // onScroll={onScroll}
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
- children: React.ReactNode;
64
- className?: string;
65
- rootClassName?: string;
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={{ isScrolled, setIsScrolled }}>
71
- <PageScrollInner className={className} rootClassName={rootClassName}>
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
  });