@grandbazar/ui-baza 1.2.8 → 1.2.9

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/index.cjs CHANGED
@@ -1810,38 +1810,6 @@ function handleDropdownMouseLeave(event, { ignoreRelatedTargetRef, setIsOpen })
1810
1810
  setIsOpen(false);
1811
1811
  }
1812
1812
 
1813
- function usePortalHandlersByEventTrigger() {
1814
- const { triggerRef, setIsOpen } = useDropdownMenuContext();
1815
- const handlePortalBlur = React.useCallback(
1816
- (event) => {
1817
- const relatedTarget = event.relatedTarget;
1818
- if (!(relatedTarget instanceof Node)) {
1819
- setIsOpen(false);
1820
- return;
1821
- }
1822
- if (event.currentTarget.contains(relatedTarget) || triggerRef.current?.contains(relatedTarget)) {
1823
- return;
1824
- }
1825
- setIsOpen(false);
1826
- },
1827
- [setIsOpen, triggerRef]
1828
- );
1829
- const portalHandlersByEvent = React.useMemo(
1830
- () => ({
1831
- click: {},
1832
- hover: {
1833
- onMouseLeave: (event) => handleDropdownMouseLeave(event, {
1834
- ignoreRelatedTargetRef: triggerRef,
1835
- setIsOpen
1836
- }),
1837
- onBlur: handlePortalBlur
1838
- }
1839
- }),
1840
- [handlePortalBlur, setIsOpen, triggerRef]
1841
- );
1842
- return portalHandlersByEvent;
1843
- }
1844
-
1845
1813
  const getAdjustedAlign = ({
1846
1814
  align,
1847
1815
  translateAxis,
@@ -1934,42 +1902,131 @@ function getAdjustedPlacement({
1934
1902
  return { position: adjustedPosition, align: adjustedAlign };
1935
1903
  }
1936
1904
 
1937
- function usePortalPosition({ align, position, offset, portalWidth, portalHeight }) {
1905
+ function syncPortalPosition({
1906
+ align,
1907
+ position,
1908
+ offset,
1909
+ portalWidth,
1910
+ portalHeight,
1911
+ triggerRect,
1912
+ setPortalPlacement,
1913
+ setPortalPosition,
1914
+ scrollContainer
1915
+ }) {
1916
+ const isWindowScrollContainer = !scrollContainer;
1917
+ const scrollCoords = {
1918
+ x: isWindowScrollContainer ? window.scrollX : scrollContainer.scrollLeft,
1919
+ y: isWindowScrollContainer ? window.scrollY : scrollContainer.scrollTop
1920
+ };
1921
+ const viewportPosition = {
1922
+ left: scrollCoords.x,
1923
+ right: scrollCoords.x + (isWindowScrollContainer ? window.innerWidth : scrollContainer.clientWidth),
1924
+ top: scrollCoords.y,
1925
+ bottom: scrollCoords.y + (isWindowScrollContainer ? window.innerHeight : scrollContainer.clientHeight)
1926
+ };
1927
+ const { position: adjustedPosition, align: adjustedAlign } = getAdjustedPlacement({
1928
+ align,
1929
+ position,
1930
+ viewportPosition,
1931
+ portalWidth,
1932
+ portalHeight,
1933
+ scrollCoords,
1934
+ triggerRect
1935
+ });
1936
+ setPortalPlacement({ position: adjustedPosition, align: adjustedAlign });
1937
+ const newPortalPosition = getPortalPosition({
1938
+ align: adjustedAlign,
1939
+ position: adjustedPosition,
1940
+ offset,
1941
+ triggerRect,
1942
+ scrollCoords
1943
+ });
1944
+ setPortalPosition(newPortalPosition);
1945
+ }
1946
+
1947
+ function usePortalHandlersByEventTrigger() {
1948
+ const { triggerRef, setIsOpen } = useDropdownMenuContext();
1949
+ const handlePortalBlur = React.useCallback(
1950
+ (event) => {
1951
+ const relatedTarget = event.relatedTarget;
1952
+ if (!(relatedTarget instanceof Node)) {
1953
+ setIsOpen(false);
1954
+ return;
1955
+ }
1956
+ if (event.currentTarget.contains(relatedTarget) || triggerRef.current?.contains(relatedTarget)) {
1957
+ return;
1958
+ }
1959
+ setIsOpen(false);
1960
+ },
1961
+ [setIsOpen, triggerRef]
1962
+ );
1963
+ const portalHandlersByEvent = React.useMemo(
1964
+ () => ({
1965
+ click: {},
1966
+ hover: {
1967
+ onMouseLeave: (event) => handleDropdownMouseLeave(event, {
1968
+ ignoreRelatedTargetRef: triggerRef,
1969
+ setIsOpen
1970
+ }),
1971
+ onBlur: handlePortalBlur
1972
+ }
1973
+ }),
1974
+ [handlePortalBlur, setIsOpen, triggerRef]
1975
+ );
1976
+ return portalHandlersByEvent;
1977
+ }
1978
+
1979
+ function usePortalPosition({
1980
+ align,
1981
+ position,
1982
+ offset,
1983
+ portalWidth,
1984
+ portalHeight,
1985
+ scrollContainerRef
1986
+ }) {
1938
1987
  const { isOpen, triggerRef, setPortalPlacement } = useDropdownMenuContext();
1939
1988
  const [portalPosition, setPortalPosition] = React.useState();
1940
1989
  React.useEffect(() => {
1941
- if (isOpen && triggerRef.current) {
1942
- const triggerRect = triggerRef.current.getBoundingClientRect();
1943
- const scrollCoords = {
1944
- x: window.scrollX,
1945
- y: window.scrollY
1946
- };
1947
- const viewportPosition = {
1948
- left: scrollCoords.x,
1949
- right: scrollCoords.x + window.innerWidth,
1950
- top: scrollCoords.y,
1951
- bottom: scrollCoords.y + window.innerHeight
1990
+ if (!isOpen || !triggerRef.current) {
1991
+ return;
1992
+ }
1993
+ const triggerRect = triggerRef.current.getBoundingClientRect();
1994
+ const scrollContainer = scrollContainerRef?.current;
1995
+ if (scrollContainer) {
1996
+ const containerRect = scrollContainer.getBoundingClientRect();
1997
+ const normalizedTriggerRect = {
1998
+ ...triggerRect,
1999
+ x: triggerRect.x - containerRect.left - scrollContainer.clientLeft,
2000
+ y: triggerRect.y - containerRect.top - scrollContainer.clientTop,
2001
+ top: triggerRect.top - containerRect.top - scrollContainer.clientTop,
2002
+ right: triggerRect.right - containerRect.left - scrollContainer.clientLeft,
2003
+ bottom: triggerRect.bottom - containerRect.top - scrollContainer.clientTop,
2004
+ left: triggerRect.left - containerRect.left - scrollContainer.clientLeft
1952
2005
  };
1953
- const { position: adjustedPosition, align: adjustedAlign } = getAdjustedPlacement({
2006
+ syncPortalPosition({
1954
2007
  align,
1955
2008
  position,
1956
- viewportPosition,
2009
+ offset,
1957
2010
  portalWidth,
1958
2011
  portalHeight,
1959
- scrollCoords,
1960
- triggerRect
1961
- });
1962
- setPortalPlacement({ position: adjustedPosition, align: adjustedAlign });
1963
- const newPortalPosition = getPortalPosition({
1964
- align: adjustedAlign,
1965
- position: adjustedPosition,
1966
- offset,
1967
- triggerRect,
1968
- scrollCoords
2012
+ triggerRect: normalizedTriggerRect,
2013
+ setPortalPlacement,
2014
+ setPortalPosition,
2015
+ scrollContainer
1969
2016
  });
1970
- setPortalPosition(newPortalPosition);
2017
+ return;
1971
2018
  }
1972
- }, [align, isOpen, offset, portalHeight, portalWidth, position, setPortalPlacement, triggerRef]);
2019
+ syncPortalPosition({
2020
+ align,
2021
+ position,
2022
+ offset,
2023
+ portalWidth,
2024
+ portalHeight,
2025
+ triggerRect,
2026
+ setPortalPlacement,
2027
+ setPortalPosition
2028
+ });
2029
+ }, [align, isOpen, offset, portalHeight, portalWidth, position, scrollContainerRef, setPortalPlacement, triggerRef]);
1973
2030
  return portalPosition;
1974
2031
  }
1975
2032
 
@@ -2016,7 +2073,8 @@ function DropdownPortal({
2016
2073
  isNested,
2017
2074
  offset = DROPDOWN_PORTAL_DEFAULT_OFFSET,
2018
2075
  maxWidth,
2019
- maxHeight
2076
+ maxHeight,
2077
+ scrollContainerRef
2020
2078
  }) {
2021
2079
  const { portalRef, triggerEvent, isOpen } = useDropdownMenuContext();
2022
2080
  const handlersByTrigger = usePortalHandlersByEventTrigger();
@@ -2025,7 +2083,8 @@ function DropdownPortal({
2025
2083
  position,
2026
2084
  offset,
2027
2085
  ...maxWidth && { portalWidth: maxWidth + offset },
2028
- ...maxHeight && { portalHeight: maxHeight + offset }
2086
+ ...maxHeight && { portalHeight: maxHeight + offset },
2087
+ scrollContainerRef
2029
2088
  });
2030
2089
  if (!isOpen || !portalPosition) {
2031
2090
  return null;
@@ -2046,7 +2105,7 @@ function DropdownPortal({
2046
2105
  children
2047
2106
  }
2048
2107
  ),
2049
- document.body
2108
+ scrollContainerRef?.current ?? document.body
2050
2109
  );
2051
2110
  }
2052
2111
 
@@ -2774,6 +2833,7 @@ function TooltipRoot({
2774
2833
  maxWidth,
2775
2834
  maxHeight,
2776
2835
  withoutArrow = false,
2836
+ scrollContainerRef,
2777
2837
  ...tooltipContentProps
2778
2838
  }) {
2779
2839
  return /* @__PURE__ */ jsxRuntime.jsx(DropdownMenu.Root, { children: ({ portalPlacement }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -2786,6 +2846,7 @@ function TooltipRoot({
2786
2846
  offset: TOOLTIP_OFFSET,
2787
2847
  maxWidth,
2788
2848
  maxHeight,
2849
+ scrollContainerRef,
2789
2850
  children: /* @__PURE__ */ jsxRuntime.jsx(
2790
2851
  TooltipContent,
2791
2852
  {
package/dist/index.d.ts CHANGED
@@ -190,7 +190,7 @@ export declare namespace DropdownMenu {
190
190
  var Portal: typeof DropdownPortal;
191
191
  }
192
192
 
193
- declare function DropdownPortal({ children, className, align, position, isNested, offset, maxWidth, maxHeight, }: TDropdownPortalProps): ReactPortal | null;
193
+ declare function DropdownPortal({ children, className, align, position, isNested, offset, maxWidth, maxHeight, scrollContainerRef, }: TDropdownPortalProps): ReactPortal | null;
194
194
 
195
195
  declare function DropdownRoot({ children }: TDropdownRootProps): JSX.Element;
196
196
 
@@ -670,6 +670,7 @@ declare type TDropdownPortalProps = {
670
670
  offset?: number;
671
671
  maxWidth?: number;
672
672
  maxHeight?: number;
673
+ scrollContainerRef?: React.RefObject<HTMLElement | null>;
673
674
  };
674
675
 
675
676
  declare type TDropdownRootProps = {
@@ -742,7 +743,7 @@ export declare namespace Tooltip {
742
743
 
743
744
  declare function TooltipContent({ className, role, title, description, arrowAlign, arrowPosition, arrowOffset, ...props }: TTooltipContentProps): JSX.Element;
744
745
 
745
- declare function TooltipRoot({ children, align, position, triggerEvent, maxWidth, maxHeight, withoutArrow, ...tooltipContentProps }: TTooltipRootProps): JSX.Element;
746
+ declare function TooltipRoot({ children, align, position, triggerEvent, maxWidth, maxHeight, withoutArrow, scrollContainerRef, ...tooltipContentProps }: TTooltipRootProps): JSX.Element;
746
747
 
747
748
  declare type TPaginationItemProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
748
749
  size?: TArrayElement<typeof PAGINATION_SIZES>;
@@ -882,6 +883,7 @@ declare type TTooltipRootProps = Omit<React.ComponentProps<typeof TooltipContent
882
883
  maxWidth?: number;
883
884
  maxHeight?: number;
884
885
  withoutArrow?: boolean;
886
+ scrollContainerRef?: React.RefObject<HTMLElement | null>;
885
887
  };
886
888
 
887
889
  declare type TWithRef<TProps, TElement = HTMLElement> = TProps & {
package/dist/index.js CHANGED
@@ -1806,38 +1806,6 @@ function handleDropdownMouseLeave(event, { ignoreRelatedTargetRef, setIsOpen })
1806
1806
  setIsOpen(false);
1807
1807
  }
1808
1808
 
1809
- function usePortalHandlersByEventTrigger() {
1810
- const { triggerRef, setIsOpen } = useDropdownMenuContext();
1811
- const handlePortalBlur = useCallback(
1812
- (event) => {
1813
- const relatedTarget = event.relatedTarget;
1814
- if (!(relatedTarget instanceof Node)) {
1815
- setIsOpen(false);
1816
- return;
1817
- }
1818
- if (event.currentTarget.contains(relatedTarget) || triggerRef.current?.contains(relatedTarget)) {
1819
- return;
1820
- }
1821
- setIsOpen(false);
1822
- },
1823
- [setIsOpen, triggerRef]
1824
- );
1825
- const portalHandlersByEvent = useMemo(
1826
- () => ({
1827
- click: {},
1828
- hover: {
1829
- onMouseLeave: (event) => handleDropdownMouseLeave(event, {
1830
- ignoreRelatedTargetRef: triggerRef,
1831
- setIsOpen
1832
- }),
1833
- onBlur: handlePortalBlur
1834
- }
1835
- }),
1836
- [handlePortalBlur, setIsOpen, triggerRef]
1837
- );
1838
- return portalHandlersByEvent;
1839
- }
1840
-
1841
1809
  const getAdjustedAlign = ({
1842
1810
  align,
1843
1811
  translateAxis,
@@ -1930,42 +1898,131 @@ function getAdjustedPlacement({
1930
1898
  return { position: adjustedPosition, align: adjustedAlign };
1931
1899
  }
1932
1900
 
1933
- function usePortalPosition({ align, position, offset, portalWidth, portalHeight }) {
1901
+ function syncPortalPosition({
1902
+ align,
1903
+ position,
1904
+ offset,
1905
+ portalWidth,
1906
+ portalHeight,
1907
+ triggerRect,
1908
+ setPortalPlacement,
1909
+ setPortalPosition,
1910
+ scrollContainer
1911
+ }) {
1912
+ const isWindowScrollContainer = !scrollContainer;
1913
+ const scrollCoords = {
1914
+ x: isWindowScrollContainer ? window.scrollX : scrollContainer.scrollLeft,
1915
+ y: isWindowScrollContainer ? window.scrollY : scrollContainer.scrollTop
1916
+ };
1917
+ const viewportPosition = {
1918
+ left: scrollCoords.x,
1919
+ right: scrollCoords.x + (isWindowScrollContainer ? window.innerWidth : scrollContainer.clientWidth),
1920
+ top: scrollCoords.y,
1921
+ bottom: scrollCoords.y + (isWindowScrollContainer ? window.innerHeight : scrollContainer.clientHeight)
1922
+ };
1923
+ const { position: adjustedPosition, align: adjustedAlign } = getAdjustedPlacement({
1924
+ align,
1925
+ position,
1926
+ viewportPosition,
1927
+ portalWidth,
1928
+ portalHeight,
1929
+ scrollCoords,
1930
+ triggerRect
1931
+ });
1932
+ setPortalPlacement({ position: adjustedPosition, align: adjustedAlign });
1933
+ const newPortalPosition = getPortalPosition({
1934
+ align: adjustedAlign,
1935
+ position: adjustedPosition,
1936
+ offset,
1937
+ triggerRect,
1938
+ scrollCoords
1939
+ });
1940
+ setPortalPosition(newPortalPosition);
1941
+ }
1942
+
1943
+ function usePortalHandlersByEventTrigger() {
1944
+ const { triggerRef, setIsOpen } = useDropdownMenuContext();
1945
+ const handlePortalBlur = useCallback(
1946
+ (event) => {
1947
+ const relatedTarget = event.relatedTarget;
1948
+ if (!(relatedTarget instanceof Node)) {
1949
+ setIsOpen(false);
1950
+ return;
1951
+ }
1952
+ if (event.currentTarget.contains(relatedTarget) || triggerRef.current?.contains(relatedTarget)) {
1953
+ return;
1954
+ }
1955
+ setIsOpen(false);
1956
+ },
1957
+ [setIsOpen, triggerRef]
1958
+ );
1959
+ const portalHandlersByEvent = useMemo(
1960
+ () => ({
1961
+ click: {},
1962
+ hover: {
1963
+ onMouseLeave: (event) => handleDropdownMouseLeave(event, {
1964
+ ignoreRelatedTargetRef: triggerRef,
1965
+ setIsOpen
1966
+ }),
1967
+ onBlur: handlePortalBlur
1968
+ }
1969
+ }),
1970
+ [handlePortalBlur, setIsOpen, triggerRef]
1971
+ );
1972
+ return portalHandlersByEvent;
1973
+ }
1974
+
1975
+ function usePortalPosition({
1976
+ align,
1977
+ position,
1978
+ offset,
1979
+ portalWidth,
1980
+ portalHeight,
1981
+ scrollContainerRef
1982
+ }) {
1934
1983
  const { isOpen, triggerRef, setPortalPlacement } = useDropdownMenuContext();
1935
1984
  const [portalPosition, setPortalPosition] = useState();
1936
1985
  useEffect(() => {
1937
- if (isOpen && triggerRef.current) {
1938
- const triggerRect = triggerRef.current.getBoundingClientRect();
1939
- const scrollCoords = {
1940
- x: window.scrollX,
1941
- y: window.scrollY
1942
- };
1943
- const viewportPosition = {
1944
- left: scrollCoords.x,
1945
- right: scrollCoords.x + window.innerWidth,
1946
- top: scrollCoords.y,
1947
- bottom: scrollCoords.y + window.innerHeight
1986
+ if (!isOpen || !triggerRef.current) {
1987
+ return;
1988
+ }
1989
+ const triggerRect = triggerRef.current.getBoundingClientRect();
1990
+ const scrollContainer = scrollContainerRef?.current;
1991
+ if (scrollContainer) {
1992
+ const containerRect = scrollContainer.getBoundingClientRect();
1993
+ const normalizedTriggerRect = {
1994
+ ...triggerRect,
1995
+ x: triggerRect.x - containerRect.left - scrollContainer.clientLeft,
1996
+ y: triggerRect.y - containerRect.top - scrollContainer.clientTop,
1997
+ top: triggerRect.top - containerRect.top - scrollContainer.clientTop,
1998
+ right: triggerRect.right - containerRect.left - scrollContainer.clientLeft,
1999
+ bottom: triggerRect.bottom - containerRect.top - scrollContainer.clientTop,
2000
+ left: triggerRect.left - containerRect.left - scrollContainer.clientLeft
1948
2001
  };
1949
- const { position: adjustedPosition, align: adjustedAlign } = getAdjustedPlacement({
2002
+ syncPortalPosition({
1950
2003
  align,
1951
2004
  position,
1952
- viewportPosition,
2005
+ offset,
1953
2006
  portalWidth,
1954
2007
  portalHeight,
1955
- scrollCoords,
1956
- triggerRect
1957
- });
1958
- setPortalPlacement({ position: adjustedPosition, align: adjustedAlign });
1959
- const newPortalPosition = getPortalPosition({
1960
- align: adjustedAlign,
1961
- position: adjustedPosition,
1962
- offset,
1963
- triggerRect,
1964
- scrollCoords
2008
+ triggerRect: normalizedTriggerRect,
2009
+ setPortalPlacement,
2010
+ setPortalPosition,
2011
+ scrollContainer
1965
2012
  });
1966
- setPortalPosition(newPortalPosition);
2013
+ return;
1967
2014
  }
1968
- }, [align, isOpen, offset, portalHeight, portalWidth, position, setPortalPlacement, triggerRef]);
2015
+ syncPortalPosition({
2016
+ align,
2017
+ position,
2018
+ offset,
2019
+ portalWidth,
2020
+ portalHeight,
2021
+ triggerRect,
2022
+ setPortalPlacement,
2023
+ setPortalPosition
2024
+ });
2025
+ }, [align, isOpen, offset, portalHeight, portalWidth, position, scrollContainerRef, setPortalPlacement, triggerRef]);
1969
2026
  return portalPosition;
1970
2027
  }
1971
2028
 
@@ -2012,7 +2069,8 @@ function DropdownPortal({
2012
2069
  isNested,
2013
2070
  offset = DROPDOWN_PORTAL_DEFAULT_OFFSET,
2014
2071
  maxWidth,
2015
- maxHeight
2072
+ maxHeight,
2073
+ scrollContainerRef
2016
2074
  }) {
2017
2075
  const { portalRef, triggerEvent, isOpen } = useDropdownMenuContext();
2018
2076
  const handlersByTrigger = usePortalHandlersByEventTrigger();
@@ -2021,7 +2079,8 @@ function DropdownPortal({
2021
2079
  position,
2022
2080
  offset,
2023
2081
  ...maxWidth && { portalWidth: maxWidth + offset },
2024
- ...maxHeight && { portalHeight: maxHeight + offset }
2082
+ ...maxHeight && { portalHeight: maxHeight + offset },
2083
+ scrollContainerRef
2025
2084
  });
2026
2085
  if (!isOpen || !portalPosition) {
2027
2086
  return null;
@@ -2042,7 +2101,7 @@ function DropdownPortal({
2042
2101
  children
2043
2102
  }
2044
2103
  ),
2045
- document.body
2104
+ scrollContainerRef?.current ?? document.body
2046
2105
  );
2047
2106
  }
2048
2107
 
@@ -2770,6 +2829,7 @@ function TooltipRoot({
2770
2829
  maxWidth,
2771
2830
  maxHeight,
2772
2831
  withoutArrow = false,
2832
+ scrollContainerRef,
2773
2833
  ...tooltipContentProps
2774
2834
  }) {
2775
2835
  return /* @__PURE__ */ jsx(DropdownMenu.Root, { children: ({ portalPlacement }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
@@ -2782,6 +2842,7 @@ function TooltipRoot({
2782
2842
  offset: TOOLTIP_OFFSET,
2783
2843
  maxWidth,
2784
2844
  maxHeight,
2845
+ scrollContainerRef,
2785
2846
  children: /* @__PURE__ */ jsx(
2786
2847
  TooltipContent,
2787
2848
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandbazar/ui-baza",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "A lightweight and modular UI kit for building modern, accessible web interfaces. Designed for flexibility, scalability, and developer happiness.",
5
5
  "repository": {
6
6
  "type": "git",