@idds/react 1.2.2 → 1.2.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/index.es.js CHANGED
@@ -5941,77 +5941,50 @@ function Tooltip({
5941
5941
  image,
5942
5942
  content,
5943
5943
  children,
5944
- customContent,
5945
5944
  variant = "basic",
5946
- placement = "bottom",
5945
+ placement = "top",
5947
5946
  showArrow = true,
5948
- className = "",
5949
- enterDelay = 0,
5950
- leaveDelay = 0,
5951
- onClose
5947
+ onClose,
5948
+ onNext,
5949
+ customContent = false,
5950
+ className = ""
5952
5951
  }) {
5953
- const [visible, setVisible] = useState(false);
5954
- const [finalPlacement, setFinalPlacement] = useState(placement);
5955
- const enterTimeout = useRef();
5956
- const leaveTimeout = useRef();
5957
- const triggerRef = useRef(null);
5958
- const tooltipRef = useRef(null);
5959
- useEffect(() => {
5960
- return () => {
5961
- window.clearTimeout(enterTimeout.current);
5962
- window.clearTimeout(leaveTimeout.current);
5963
- };
5964
- }, []);
5965
- const show = () => {
5966
- window.clearTimeout(leaveTimeout.current);
5967
- enterTimeout.current = window.setTimeout(() => {
5968
- setVisible(true);
5969
- requestAnimationFrame(checkAndFlip);
5970
- }, enterDelay);
5971
- };
5972
- const hide = () => {
5973
- window.clearTimeout(enterTimeout.current);
5974
- leaveTimeout.current = window.setTimeout(() => {
5975
- setVisible(false);
5976
- setFinalPlacement(placement);
5977
- }, leaveDelay);
5978
- };
5979
- function checkAndFlip() {
5980
- const trg = triggerRef.current;
5981
- const tip = tooltipRef.current;
5982
- if (!trg || !tip) return;
5983
- const tipRect = tip.getBoundingClientRect();
5984
- let newPlacement = placement;
5985
- if ((placement === "top" || placement.startsWith("top-")) && tipRect.top < 0) {
5986
- newPlacement = placement.replace("top", "bottom");
5987
- }
5988
- if ((placement === "bottom" || placement.startsWith("bottom-")) && tipRect.bottom > window.innerHeight) {
5989
- newPlacement = placement.replace("bottom", "top");
5990
- }
5991
- if ((placement === "left" || placement.startsWith("left-")) && tipRect.left < 0) {
5992
- newPlacement = placement.replace("left", "bottom");
5993
- }
5994
- if ((placement === "right" || placement.startsWith("right-")) && tipRect.right > window.innerWidth) {
5995
- newPlacement = placement.replace("right", "top");
5996
- }
5997
- if (newPlacement !== finalPlacement) {
5998
- setFinalPlacement(newPlacement);
5952
+ const [isClosed, setIsClosed] = useState(false);
5953
+ const handleClose = () => {
5954
+ setIsClosed(true);
5955
+ if (onClose) {
5956
+ onClose();
5999
5957
  }
6000
- }
6001
- const tooltipContainerClasses = clsx("ina-tooltip", className);
6002
- const tooltipContentClasses = clsx(
6003
- "ina-tooltip__content",
6004
- `ina-tooltip--placement-${finalPlacement}`,
6005
- `ina-tooltip--variant-${variant}`,
5958
+ };
5959
+ const handleNext = () => {
5960
+ setIsClosed(true);
5961
+ if (onNext) {
5962
+ onNext();
5963
+ }
5964
+ };
5965
+ const handleMouseEnter = () => {
5966
+ if (isClosed) {
5967
+ setIsClosed(false);
5968
+ }
5969
+ };
5970
+ const tooltipClasses = clsx(
5971
+ "ina-tooltip",
5972
+ `ina-tooltip--placement-${placement}`,
5973
+ className,
6006
5974
  {
6007
- "ina-tooltip__content--visible": visible,
6008
- "ina-tooltip__content--hidden": !visible,
6009
- "ina-tooltip__content--show-arrow": showArrow
5975
+ "ina-tooltip--closed": isClosed
6010
5976
  }
6011
5977
  );
5978
+ const contentClasses = clsx("ina-tooltip__content", {
5979
+ "ina-tooltip__content--show-arrow": showArrow,
5980
+ "ina-tooltip--variant-basic": variant === "basic",
5981
+ "ina-tooltip--variant-light": variant === "light",
5982
+ "ina-tooltip--variant-dark": variant === "dark",
5983
+ "ina-tooltip--variant-media": variant === "media"
5984
+ });
6012
5985
  const renderContent = () => {
6013
- if (variant === "custom") {
6014
- return customContent || null;
5986
+ if (customContent && content) {
5987
+ return content;
6015
5988
  }
6016
5989
  if (variant === "basic") {
6017
5990
  return /* @__PURE__ */ jsx("div", { className: "ina-tooltip__bubble ina-tooltip__bubble--basic", children: title });
@@ -6024,49 +5997,69 @@ function Tooltip({
6024
5997
  className: "ina-tooltip__close",
6025
5998
  onClick: (e) => {
6026
5999
  e.stopPropagation();
6027
- window.clearTimeout(leaveTimeout.current);
6028
- window.clearTimeout(enterTimeout.current);
6029
- setVisible(false);
6030
- setFinalPlacement(placement);
6031
- onClose();
6000
+ handleClose();
6032
6001
  },
6033
6002
  "aria-label": "Close tooltip",
6034
- children: /* @__PURE__ */ jsx(IconX, { size: 16 })
6003
+ children: /* @__PURE__ */ jsx(
6004
+ "svg",
6005
+ {
6006
+ width: "16",
6007
+ height: "16",
6008
+ viewBox: "0 0 24 24",
6009
+ fill: "none",
6010
+ xmlns: "http://www.w3.org/2000/svg",
6011
+ children: /* @__PURE__ */ jsx(
6012
+ "path",
6013
+ {
6014
+ d: "M18 6L6 18M6 6L18 18",
6015
+ stroke: "currentColor",
6016
+ strokeWidth: "2",
6017
+ strokeLinecap: "round",
6018
+ strokeLinejoin: "round"
6019
+ }
6020
+ )
6021
+ }
6022
+ )
6035
6023
  }
6036
6024
  ),
6037
6025
  variant === "media" && image && /* @__PURE__ */ jsx("div", { className: "ina-tooltip__image", children: typeof image === "string" ? /* @__PURE__ */ jsx("img", { src: image, alt: "" }) : image }),
6038
6026
  /* @__PURE__ */ jsxs("div", { className: "ina-tooltip__content-section", children: [
6039
6027
  title && /* @__PURE__ */ jsx("div", { className: "ina-tooltip__title", children: title }),
6040
6028
  description && /* @__PURE__ */ jsx("div", { className: "ina-tooltip__description", children: description }),
6041
- content && /* @__PURE__ */ jsx("div", { className: "ina-tooltip__custom-content", children: content })
6029
+ content && /* @__PURE__ */ jsx("div", { className: "ina-tooltip__custom-content", children: content }),
6030
+ (onClose || onNext) && /* @__PURE__ */ jsxs("div", { className: "ina-tooltip__actions", children: [
6031
+ onClose && /* @__PURE__ */ jsx(
6032
+ "button",
6033
+ {
6034
+ type: "button",
6035
+ className: "ina-tooltip__action ina-tooltip__action--close",
6036
+ onClick: (e) => {
6037
+ e.stopPropagation();
6038
+ handleClose();
6039
+ },
6040
+ children: "Tutup"
6041
+ }
6042
+ ),
6043
+ onNext && /* @__PURE__ */ jsx(
6044
+ "button",
6045
+ {
6046
+ type: "button",
6047
+ className: "ina-tooltip__action ina-tooltip__action--next",
6048
+ onClick: (e) => {
6049
+ e.stopPropagation();
6050
+ handleNext();
6051
+ },
6052
+ children: "Lanjut"
6053
+ }
6054
+ )
6055
+ ] })
6042
6056
  ] })
6043
6057
  ] });
6044
6058
  };
6045
- return /* @__PURE__ */ jsxs(
6046
- "div",
6047
- {
6048
- ref: triggerRef,
6049
- className: tooltipContainerClasses,
6050
- "data-hover": visible ? "true" : void 0,
6051
- onMouseEnter: show,
6052
- onMouseLeave: hide,
6053
- onFocus: show,
6054
- onBlur: hide,
6055
- children: [
6056
- children,
6057
- visible && /* @__PURE__ */ jsx(
6058
- "div",
6059
- {
6060
- ref: tooltipRef,
6061
- className: tooltipContentClasses,
6062
- onMouseEnter: show,
6063
- onMouseLeave: hide,
6064
- children: renderContent()
6065
- }
6066
- )
6067
- ]
6068
- }
6069
- );
6059
+ return /* @__PURE__ */ jsxs("div", { className: tooltipClasses, onMouseEnter: handleMouseEnter, children: [
6060
+ children,
6061
+ /* @__PURE__ */ jsx("div", { className: contentClasses, role: "tooltip", children: renderContent() })
6062
+ ] });
6070
6063
  }
6071
6064
  function ThemeToggle({
6072
6065
  className = "",