bianic-ui 1.16.0-alpha.0 → 1.16.0-alpha.1

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/cjs/index.js CHANGED
@@ -1724,6 +1724,51 @@ var TreeItem = function (_a) {
1724
1724
  })))));
1725
1725
  };
1726
1726
 
1727
+ var getContextualPopupStyle = function (anchorRef, popupRef, position) {
1728
+ if (!anchorRef.current || !popupRef.current) {
1729
+ return {};
1730
+ }
1731
+ var style = {};
1732
+ var anchorRect = anchorRef.current.getBoundingClientRect();
1733
+ var popupRect = popupRef.current.getBoundingClientRect();
1734
+ var popupHeight = popupRect.height;
1735
+ var popupWidth = popupRect.width;
1736
+ switch (position) {
1737
+ case 'top':
1738
+ style.top = "".concat(anchorRect.top - popupHeight + window.scrollY - 10, "px");
1739
+ style.left = "".concat(anchorRect.left - 0.5 * popupWidth + 0.5 * anchorRect.width + window.scrollX, "px");
1740
+ break;
1741
+ case 'bottom':
1742
+ style.top = "".concat(anchorRect.top + anchorRect.height + window.scrollY + 10, "px");
1743
+ style.left = "".concat(anchorRect.left - 0.5 * popupWidth + 0.5 * anchorRect.width + window.scrollX, "px");
1744
+ break;
1745
+ case 'left':
1746
+ style.top = "".concat(anchorRect.top - 0.5 * popupHeight + window.scrollY + 0.5 * anchorRect.height, "px");
1747
+ style.left = "".concat(anchorRect.left - popupWidth - 10 + window.scrollX, "px");
1748
+ break;
1749
+ case 'right':
1750
+ style.top = "".concat(anchorRect.top - 0.5 * popupHeight + window.scrollY + 0.5 * anchorRect.height, "px");
1751
+ style.left = "".concat(anchorRect.right + 10 + window.scrollX, "px");
1752
+ break;
1753
+ case 'top-left':
1754
+ style.top = "".concat(anchorRect.top - popupHeight + window.scrollY - 10, "px");
1755
+ style.left = "".concat(anchorRect.left + window.scrollX, "px");
1756
+ break;
1757
+ case 'top-right':
1758
+ style.top = "".concat(anchorRect.top - popupHeight + window.scrollY - 10, "px");
1759
+ style.left = "".concat(anchorRect.left + anchorRect.width - popupWidth + window.scrollX, "px");
1760
+ break;
1761
+ case 'bottom-left':
1762
+ style.top = "".concat(anchorRect.top + anchorRect.height + window.scrollY + 10, "px");
1763
+ style.left = "".concat(anchorRect.left + window.scrollX, "px");
1764
+ break;
1765
+ case 'bottom-right':
1766
+ style.top = "".concat(anchorRect.top + anchorRect.height + window.scrollY + 10, "px");
1767
+ style.left = "".concat(anchorRect.left + anchorRect.width - popupWidth + window.scrollX, "px");
1768
+ break;
1769
+ }
1770
+ return style;
1771
+ };
1727
1772
  var getDropdownStyle = function (anchorRef, popupRef) {
1728
1773
  if (!anchorRef.current || !popupRef.current) {
1729
1774
  return {};
@@ -1733,48 +1778,50 @@ var getDropdownStyle = function (anchorRef, popupRef) {
1733
1778
  var spaceToBottom = window.innerHeight - anchorRect.bottom;
1734
1779
  var spaceToTop = anchorRect.top;
1735
1780
  var style = {
1736
- left: "".concat(anchorRect.left, "px"),
1781
+ left: "".concat(anchorRect.left + window.scrollX, "px"),
1737
1782
  };
1738
1783
  // If space below is less than popup height,
1739
1784
  // AND space above is more than space below
1740
1785
  // then flip up
1741
1786
  if (spaceToBottom < popupHeight && spaceToTop > spaceToBottom) {
1742
- style.bottom = "".concat(window.innerHeight - anchorRect.top, "px");
1787
+ style.top = "".concat(anchorRect.top - popupHeight + window.scrollY, "px");
1743
1788
  }
1744
1789
  else {
1745
- style.top = "".concat(anchorRect.bottom, "px");
1790
+ style.top = "".concat(anchorRect.bottom + window.scrollY, "px");
1746
1791
  }
1747
1792
  return style;
1748
1793
  };
1749
- var usePopupPosition = function (anchorRef, popupRef) {
1794
+ var usePopupPosition = function (anchorRef, popupRef, position) {
1750
1795
  // In projects where bianic-ui is installed,
1751
1796
  // there is a delay in rendering styles,
1752
1797
  // which causes popups to lose their position and need to be re-rendered.
1753
1798
  var _a = React.useState(0), repeateRender = _a[0], setRepeateRender = _a[1];
1754
1799
  var _b = React.useState({}), positionStyle = _b[0], setPositionStyle = _b[1];
1800
+ var calcPosition = function () {
1801
+ var newStyle = position !== undefined
1802
+ ? getContextualPopupStyle(anchorRef, popupRef, position)
1803
+ : getDropdownStyle(anchorRef, popupRef);
1804
+ setPositionStyle(newStyle);
1805
+ };
1755
1806
  React.useLayoutEffect(function () {
1756
1807
  if (!(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current))
1757
1808
  return;
1758
- var newStyle = getDropdownStyle(anchorRef, popupRef);
1759
- setPositionStyle(newStyle);
1760
- var handleScrollOrResize = function () {
1761
- setPositionStyle(getDropdownStyle(anchorRef, popupRef));
1762
- };
1763
- window.addEventListener('scroll', handleScrollOrResize);
1764
- window.addEventListener('resize', handleScrollOrResize);
1809
+ calcPosition();
1810
+ window.addEventListener('scroll', calcPosition);
1811
+ window.addEventListener('resize', calcPosition);
1765
1812
  setRepeateRender(0);
1766
1813
  return function () {
1767
- window.removeEventListener('scroll', handleScrollOrResize);
1768
- window.removeEventListener('resize', handleScrollOrResize);
1814
+ window.removeEventListener('scroll', calcPosition);
1815
+ window.removeEventListener('resize', calcPosition);
1769
1816
  };
1770
1817
  }, [anchorRef]);
1771
1818
  React.useEffect(function () {
1772
1819
  if (repeateRender < 5 && (anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current)) {
1773
- setPositionStyle(getDropdownStyle(anchorRef, popupRef));
1820
+ calcPosition();
1774
1821
  setRepeateRender(repeateRender + 1);
1775
1822
  }
1776
1823
  }, [repeateRender]);
1777
- return [positionStyle];
1824
+ return [positionStyle, calcPosition];
1778
1825
  };
1779
1826
 
1780
1827
  var MenuContainer = function (props) {
@@ -1869,53 +1916,16 @@ MenuItem.defaultProps = {
1869
1916
  onClick: function () { },
1870
1917
  };
1871
1918
 
1872
- var classConfig$1 = {
1873
- top: {
1874
- tooltipContainer: 'bottom-[calc(100%+5px)] left-1/2 -translate-x-1/2',
1875
- triangleContainer: 'left-0 -bottom-[4px] flex justify-center w-full h-auto',
1876
- triangleShape: 'border-l-[8px] border-l-transparent border-t-[5px] border-t-primary-black border-r-[8px] border-r-transparent',
1877
- },
1878
- right: {
1879
- tooltipContainer: 'left-[calc(100%+5px)] top-1/2 -translate-y-1/2',
1880
- triangleContainer: '-left-[4px] bottom-0 flex items-center w-auto h-full',
1881
- triangleShape: 'border-t-[8px] border-t-transparent border-r-[5px] border-r-primary-black border-b-[8px] border-b-transparent',
1882
- },
1883
- bottom: {
1884
- tooltipContainer: 'top-[calc(100%+5px)] left-1/2 -translate-x-1/2',
1885
- triangleContainer: 'left-0 -top-[4px] flex justify-center w-full h-auto',
1886
- triangleShape: 'border-l-[8px] border-l-transparent border-b-[5px] border-b-primary-black border-r-[8px] border-r-transparent',
1887
- },
1888
- left: {
1889
- tooltipContainer: 'right-[calc(100%+5px)] top-1/2 -translate-y-1/2',
1890
- triangleContainer: '-right-[4px] bottom-0 flex items-center w-auto h-full',
1891
- triangleShape: 'border-t-[8px] border-t-transparent border-l-[5px] border-l-primary-black border-b-[8px] border-b-transparent',
1892
- },
1893
- 'top-right': {
1894
- tooltipContainer: 'bottom-[calc(100%+5px)] right-0',
1895
- triangleContainer: 'left-0 -bottom-[4px] flex justify-center w-full h-auto',
1896
- triangleShape: 'border-l-[8px] border-l-transparent border-t-[5px] border-t-primary-black border-r-[8px] border-r-transparent',
1897
- },
1898
- 'top-left': {
1899
- tooltipContainer: 'bottom-[calc(100%+5px)] left-0',
1900
- triangleContainer: 'left-0 -bottom-[4px] flex justify-center w-full h-auto',
1901
- triangleShape: 'border-l-[8px] border-l-transparent border-t-[5px] border-t-primary-black border-r-[8px] border-r-transparent',
1902
- },
1903
- 'bottom-right': {
1904
- tooltipContainer: 'top-[calc(100%+5px)] right-0',
1905
- triangleContainer: 'left-0 -top-[4px] flex justify-center w-full h-auto',
1906
- triangleShape: 'border-l-[8px] border-l-transparent border-b-[5px] border-b-primary-black border-r-[8px] border-r-transparent',
1907
- },
1908
- 'bottom-left': {
1909
- tooltipContainer: 'top-[calc(100%+5px)] left-0',
1910
- triangleContainer: 'left-0 -top-[4px] flex justify-center w-full h-auto',
1911
- triangleShape: 'border-l-[8px] border-l-transparent border-b-[5px] border-b-primary-black border-r-[8px] border-r-transparent',
1912
- },
1913
- };
1914
-
1915
1919
  function Tooltip(props) {
1916
1920
  var children = props.children, content = props.content, delay = props.delay, _a = props.direction, direction = _a === void 0 ? 'top' : _a, _b = props.maxWidth, maxWidth = _b === void 0 ? undefined : _b;
1917
1921
  var timeout;
1918
1922
  var _c = React.useState(false), active = _c[0], setActive = _c[1];
1923
+ var anchorRef = React.useRef(null);
1924
+ var tooltipContainerRef = React.useRef(null);
1925
+ var _d = React.useState({
1926
+ maxWidth: maxWidth + 'px',
1927
+ whiteSpace: 'nowrap',
1928
+ }), tooltipContainerStyle = _d[0], setTooltipContainerStyle = _d[1];
1919
1929
  var showTip = function () {
1920
1930
  timeout = setTimeout(function () {
1921
1931
  setActive(true);
@@ -1925,12 +1935,6 @@ function Tooltip(props) {
1925
1935
  clearInterval(timeout);
1926
1936
  setActive(false);
1927
1937
  };
1928
- var _d = classConfig$1[direction], tooltipContainer = _d.tooltipContainer; _d.triangleContainer; _d.triangleShape;
1929
- var tooltipContainerRef = React.useRef(null);
1930
- var _e = React.useState({
1931
- maxWidth: maxWidth + 'px',
1932
- whiteSpace: 'nowrap',
1933
- }), tooltipContainerStyle = _e[0], setTooltipContainerStyle = _e[1];
1934
1938
  var tooltipContainerElement = tooltipContainerRef === null || tooltipContainerRef === void 0 ? void 0 : tooltipContainerRef.current;
1935
1939
  var scrollWidth = tooltipContainerElement === null || tooltipContainerElement === void 0 ? void 0 : tooltipContainerElement.scrollWidth; // Mendapatkan lebar konten aktual
1936
1940
  var offsetWidth = tooltipContainerElement === null || tooltipContainerElement === void 0 ? void 0 : tooltipContainerElement.offsetWidth;
@@ -1963,10 +1967,15 @@ function Tooltip(props) {
1963
1967
  setTooltipContainerStyle(function (prev) { return (__assign(__assign({}, prev), { width: newWidth_1, whiteSpace: newWhiteSpace_1 })); });
1964
1968
  }
1965
1969
  }, [content, maxWidth, scrollWidth, offsetHeight]);
1966
- return (React.createElement("div", { className: "tooltip-wrapper relative inline-flex h-fit w-fit flex-col", onMouseEnter: showTip, onMouseLeave: hideTip },
1970
+ return (React.createElement("div", { className: "tooltip-wrapper relative inline-flex h-fit w-fit flex-col", onMouseEnter: showTip, onMouseLeave: hideTip, ref: anchorRef },
1967
1971
  children,
1968
- active && (React.createElement("div", { className: "tooltip-container break-word absolute z-50 inline-block break-all rounded-[4px] bg-primary-black px-[7px] py-[4px] text-size-sm text-primary-white ".concat(tooltipContainer), style: tooltipContainerStyle, ref: tooltipContainerRef }, content))));
1972
+ active && (React.createElement(TooltipItem, { anchorRef: anchorRef, direction: direction, content: content, tooltipContainerRef: tooltipContainerRef, tooltipContainerStyle: tooltipContainerStyle }))));
1969
1973
  }
1974
+ var TooltipItem = function (_a) {
1975
+ var anchorRef = _a.anchorRef, direction = _a.direction, content = _a.content, tooltipContainerRef = _a.tooltipContainerRef, tooltipContainerStyle = _a.tooltipContainerStyle;
1976
+ var positionStyle = usePopupPosition(anchorRef, tooltipContainerRef, direction)[0];
1977
+ return reactDom.createPortal(React.createElement("div", { className: "tooltip-container break-word absolute z-50 inline-block break-all rounded-[4px] bg-primary-black px-[7px] py-[4px] text-size-sm text-primary-white", style: __assign(__assign({}, positionStyle), tooltipContainerStyle), ref: tooltipContainerRef }, content), document.body);
1978
+ };
1970
1979
  Tooltip.defaultProps = {
1971
1980
  delay: 400,
1972
1981
  direction: 'top',
@@ -2478,7 +2487,9 @@ var DropdownContainer = function (propsComp) {
2478
2487
  };
2479
2488
  return (React.createElement(React.Fragment, null,
2480
2489
  isWithOverlay && (React.createElement("div", { className: "bianic-dropdown-overlay fixed left-0 top-0 h-screen w-screen", style: { zIndex: zIndex }, onClick: function () { return onClose(); } })),
2481
- reactDom.createPortal(React.createElement("div", __assign({ ref: dropdownRef, className: "fixed max-w-fit bianic-dropdown-container bg-bia-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] ".concat(containerClass), style: __assign({ minWidth: anchorRef.current ? anchorRef.current.offsetWidth : undefined, zIndex: zIndex + 10 }, positionStyle) }, restProps), React.Children.map(children, function (child) {
2490
+ reactDom.createPortal(React.createElement("div", __assign({ ref: dropdownRef, className: "bianic-dropdown-container absolute max-w-fit bg-bia-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] ".concat(containerClass), style: __assign({ minWidth: anchorRef.current
2491
+ ? anchorRef.current.offsetWidth
2492
+ : undefined, zIndex: zIndex + 10 }, positionStyle) }, restProps), React.Children.map(children, function (child) {
2482
2493
  return React.isValidElement(child)
2483
2494
  ? // Kirimkan handleItemClick sebagai props onClick ke setiap DropdownItem
2484
2495
  React.cloneElement(child, {
@@ -2668,9 +2679,7 @@ function LiveSearch(_a) {
2668
2679
  var filteredOptions = filterOptions(options || [], value.label);
2669
2680
  var _p = processRenderedChildren(children, searchTerm, searchVariant, handleDropdownItemClick), renderedChildren = _p.renderedChildren, hasFilteredResults = _p.hasFilteredResults;
2670
2681
  return (React.createElement("div", { className: "bianic-livesearch field-group group/form flex w-full flex-col gap-y-2 " },
2671
- label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly },
2672
- label,
2673
- " Test")),
2682
+ label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
2674
2683
  React.createElement("div", { className: "group relative w-full" },
2675
2684
  React.createElement("input", { className: "bianic-livesearch-input field peer w-full rounded border border-bia-grey-dark-10 bg-primary-white read-only:pointer-events-none read-only:border-bia-grey-disabled focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-10 disabled:text-bia-coolgrey ".concat(inputClass), onClick: function () { return setIsOpen(!isOpen); }, value: searchTerm, required: required, disabled: disabled, id: id, placeholder: placeholder, ref: inputRef, onChange: function (e) {
2676
2685
  onChangeText(e);
@@ -3573,17 +3582,24 @@ var classConfig = {
3573
3582
  function Popover(_a) {
3574
3583
  var children = _a.children, content = _a.content; _a.delay; var _c = _a.direction, direction = _c === void 0 ? 'bottom' : _c, _d = _a.title, title = _d === void 0 ? '' : _d; _a.maxWidth;
3575
3584
  var wrapperRef = React.useRef(null);
3585
+ React.useRef(null);
3576
3586
  var _e = useDetectOutsideClick(wrapperRef, false), isOpen = _e[0], setIsOpen = _e[1];
3577
- var _f = classConfig[direction], tooltipContainer = _f.tooltipContainer, triangleContainer = _f.triangleContainer, triangleShape = _f.triangleShape;
3578
- return (React.createElement("div", { className: "Bianic-popover-Wrapper relative block h-fit w-fit", role: "button", ref: wrapperRef, onClick: function () { return setIsOpen(true); } },
3587
+ return (React.createElement("div", { className: "Bianic-popover-Wrapper relative block h-fit w-fit bg-bia-blue", role: "button", ref: wrapperRef, onClick: function () { return setIsOpen(true); } },
3579
3588
  children,
3580
- isOpen && (React.createElement("div", { className: "Bianic-popover-Tip text-bia-sm absolute z-50 w-[245px] space-y-[5px] rounded-[4px] bg-primary-black px-[20px] py-[17.5px] text-primary-white ".concat(tooltipContainer) },
3581
- React.createElement("div", { className: "flex flex-col" },
3582
- React.createElement("div", { className: "mb-[5px] font-humnst777 text-[16px] font-bold leading-[19.42px]" }, title),
3583
- React.createElement("div", { className: "break-words font-segoe text-[12px] font-normal" }, content)),
3584
- React.createElement("div", { className: "triangle absolute ".concat(triangleContainer) },
3585
- React.createElement("div", { className: "h-0 w-0 ".concat(triangleShape) }))))));
3589
+ isOpen && (React.createElement(PopoverItem, { title: title, content: content, anchorRef: wrapperRef, direction: direction }))));
3586
3590
  }
3591
+ var PopoverItem = function (_a) {
3592
+ var title = _a.title, content = _a.content, anchorRef = _a.anchorRef, direction = _a.direction;
3593
+ var popoverRef = React.useRef(null);
3594
+ var positionStyle = usePopupPosition(anchorRef, popoverRef, direction)[0];
3595
+ var _b = classConfig[direction], triangleContainer = _b.triangleContainer, triangleShape = _b.triangleShape;
3596
+ return reactDom.createPortal(React.createElement("div", { ref: popoverRef, style: positionStyle, className: "Bianic-popover-Tip text-bia-sm absolute z-50 w-[245px] space-y-[5px] rounded-[4px] bg-primary-black px-[20px] py-[17.5px] text-primary-white" },
3597
+ React.createElement("div", { className: "flex flex-col" },
3598
+ React.createElement("div", { className: "mb-[5px] font-humnst777 text-[16px] font-bold leading-[19.42px]" }, title),
3599
+ React.createElement("div", { className: "break-words font-segoe text-[12px] font-normal" }, content)),
3600
+ React.createElement("div", { className: "triangle absolute ".concat(triangleContainer) },
3601
+ React.createElement("div", { className: "h-0 w-0 ".concat(triangleShape) }))), document.body);
3602
+ };
3587
3603
  Popover.defaultProps = {
3588
3604
  delay: 400,
3589
3605
  direction: 'top',