react-better-html 1.1.286 → 1.1.288

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.mjs CHANGED
@@ -1485,6 +1485,7 @@ Image.profileImage = forwardRef3(function ProfileImage({ size = 40, letters, let
1485
1485
  const betterHtmlContextInternal = useBetterHtmlContextInternal();
1486
1486
  const props = useComponentsPropsMerger(betterHtmlContextInternal.components.image?.style?.default, ImageProps3);
1487
1487
  const theme2 = useTheme4();
1488
+ const lettersSplit = letters?.split(" ") ?? [];
1488
1489
  return letters ? /* @__PURE__ */ jsx3(
1489
1490
  Div_default.row,
1490
1491
  {
@@ -1498,7 +1499,7 @@ Image.profileImage = forwardRef3(function ProfileImage({ size = 40, letters, let
1498
1499
  ...props,
1499
1500
  width: size,
1500
1501
  height: size,
1501
- children: /* @__PURE__ */ jsx3(Text_default, { fontSize: size / 2.5, fontWeight: 700, color: letterColor ?? theme2.colors.textPrimary, children: letters.toUpperCase().slice(0, 2) })
1502
+ children: /* @__PURE__ */ jsx3(Text_default, { fontSize: size / 2.5, fontWeight: 700, color: letterColor ?? theme2.colors.textPrimary, children: lettersSplit.length > 1 ? lettersSplit[0][0] + (lettersSplit.at(-1)?.[0] ?? lettersSplit[0][1] ?? "") : letters.toUpperCase().slice(0, 2) })
1502
1503
  }
1503
1504
  ) : /* @__PURE__ */ jsx3(
1504
1505
  Image,
@@ -3800,6 +3801,7 @@ var DropdownComponent = forwardRef10(function Dropdown(dropdownProps, ref) {
3800
3801
  labelGap,
3801
3802
  errorText,
3802
3803
  infoText,
3804
+ infoTextColor,
3803
3805
  required,
3804
3806
  name,
3805
3807
  disabled,
@@ -4046,6 +4048,7 @@ var DropdownComponent = forwardRef10(function Dropdown(dropdownProps, ref) {
4046
4048
  labelGap,
4047
4049
  errorText,
4048
4050
  infoText,
4051
+ infoTextColor,
4049
4052
  required: withMultiselect ? (Array.isArray(value) ? value.length > 0 : value !== void 0) ? false : required : required,
4050
4053
  textAlign,
4051
4054
  name,
@@ -4698,6 +4701,7 @@ var InputFieldComponent = forwardRef11(function InputField(inputFieldProps, ref)
4698
4701
  labelGap,
4699
4702
  errorText,
4700
4703
  infoText,
4704
+ infoTextColor,
4701
4705
  leftIcon,
4702
4706
  rightIcon,
4703
4707
  prefix,
@@ -4863,7 +4867,7 @@ var InputFieldComponent = forwardRef11(function InputField(inputFieldProps, ref)
4863
4867
  as: "span",
4864
4868
  display: "block",
4865
4869
  fontSize: 14,
4866
- color: errorText ? theme2.colors.error : labelColor ?? theme2.colors.textSecondary,
4870
+ color: errorText ? theme2.colors.error : infoTextColor ?? labelColor ?? theme2.colors.textSecondary,
4867
4871
  children: errorText || infoText
4868
4872
  }
4869
4873
  )
@@ -5867,6 +5871,7 @@ var ToggleInputComponent = forwardRef12(function ToggleInput({
5867
5871
  textAdvanced,
5868
5872
  errorText,
5869
5873
  infoText,
5874
+ infoTextColor,
5870
5875
  size = componentSize,
5871
5876
  value,
5872
5877
  onChange,
@@ -5996,7 +6001,7 @@ var ToggleInputComponent = forwardRef12(function ToggleInput({
5996
6001
  as: "span",
5997
6002
  display: "block",
5998
6003
  fontSize: 14,
5999
- color: errorText ? theme2.colors.error : labelColor ?? theme2.colors.textSecondary,
6004
+ color: errorText ? theme2.colors.error : infoTextColor ?? labelColor ?? theme2.colors.textSecondary,
6000
6005
  children: errorText || infoText
6001
6006
  }
6002
6007
  )
@@ -6123,30 +6128,32 @@ var ToggleInput_default = {
6123
6128
  import { Children, forwardRef as forwardRef13, Fragment as Fragment7, memo as memo19, useMemo as useMemo7 } from "react";
6124
6129
  import { useTheme as useTheme21 } from "react-better-core";
6125
6130
  import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
6126
- var FormComponent = forwardRef13(function Form({
6127
- form,
6128
- name,
6129
- submitButtonText,
6130
- submitButtonLoaderName,
6131
- submitButtonIsLoading,
6132
- submitButtonId,
6133
- submitButtonIsDisabled,
6134
- cancelButtonText,
6135
- cancelButtonLoaderName,
6136
- cancelButtonIsLoading,
6137
- cancelButtonId,
6138
- cancelButtonIsDisabled,
6139
- actionButtonsLocation = "right",
6140
- gap,
6141
- isDestructive,
6142
- withDividers,
6143
- renderActionButtons,
6144
- onClickCancel,
6145
- onSubmit,
6146
- id,
6147
- children,
6148
- ...props
6149
- }, ref) {
6131
+ var FormComponent = forwardRef13(function Form(formProps, ref) {
6132
+ const betterHtmlContextInternal = useBetterHtmlContextInternal();
6133
+ const {
6134
+ form,
6135
+ name,
6136
+ submitButtonText,
6137
+ submitButtonLoaderName,
6138
+ submitButtonIsLoading,
6139
+ submitButtonId,
6140
+ submitButtonIsDisabled,
6141
+ cancelButtonText,
6142
+ cancelButtonLoaderName,
6143
+ cancelButtonIsLoading,
6144
+ cancelButtonId,
6145
+ cancelButtonIsDisabled,
6146
+ actionButtonsLocation = "right",
6147
+ gap,
6148
+ isDestructive,
6149
+ withDividers,
6150
+ renderActionButtons,
6151
+ onClickCancel,
6152
+ onSubmit,
6153
+ id,
6154
+ children,
6155
+ ...props
6156
+ } = useComponentsPropsMerger(betterHtmlContextInternal.components.form?.style?.default, formProps);
6150
6157
  const theme2 = useTheme21();
6151
6158
  const submitButtonIsDisabledInternal = useMemo7(() => {
6152
6159
  if (!form || !form.requiredFields) return false;
@@ -6156,6 +6163,17 @@ var FormComponent = forwardRef13(function Form({
6156
6163
  }, [form]);
6157
6164
  const SubmitButtonTag = isDestructive ? Button_default.destructive : Button_default;
6158
6165
  const submitButtonIsDisabledFinal = submitButtonIsDisabled || submitButtonIsDisabledInternal;
6166
+ const cancelButton = /* @__PURE__ */ jsx20(
6167
+ Button_default.secondary,
6168
+ {
6169
+ text: cancelButtonText ?? "Cancel",
6170
+ isLoading: cancelButtonIsLoading,
6171
+ loaderName: cancelButtonLoaderName,
6172
+ disabled: cancelButtonIsDisabled,
6173
+ id: cancelButtonId,
6174
+ onClick: onClickCancel
6175
+ }
6176
+ );
6159
6177
  return /* @__PURE__ */ jsx20(Div_default, { width: "100%", ...props, children: /* @__PURE__ */ jsxs16("form", { name, onSubmit: onSubmit ?? form?.onSubmit, id, ref, children: [
6160
6178
  gap !== void 0 || withDividers ? /* @__PURE__ */ jsx20(Div_default.column, { gap: gap ?? (withDividers ? theme2.styles.space : theme2.styles.gap), children: withDividers ? Children.toArray(children).map((child, index) => /* @__PURE__ */ jsxs16(Fragment7, { children: [
6161
6179
  child,
@@ -6174,18 +6192,8 @@ var FormComponent = forwardRef13(function Form({
6174
6192
  gap: theme2.styles.gap,
6175
6193
  marginTop: theme2.styles.space,
6176
6194
  children: [
6177
- renderActionButtons,
6178
- onClickCancel && /* @__PURE__ */ jsx20(
6179
- Button_default.secondary,
6180
- {
6181
- text: cancelButtonText ?? "Cancel",
6182
- isLoading: cancelButtonIsLoading,
6183
- loaderName: cancelButtonLoaderName,
6184
- disabled: cancelButtonIsDisabled,
6185
- id: cancelButtonId,
6186
- onClick: onClickCancel
6187
- }
6188
- ),
6195
+ actionButtonsLocation === "right" && renderActionButtons,
6196
+ actionButtonsLocation === "right" && onClickCancel ? cancelButton : void 0,
6189
6197
  /* @__PURE__ */ jsx20(
6190
6198
  SubmitButtonTag,
6191
6199
  {
@@ -6196,7 +6204,9 @@ var FormComponent = forwardRef13(function Form({
6196
6204
  id: submitButtonId,
6197
6205
  isSubmit: true
6198
6206
  }
6199
- )
6207
+ ),
6208
+ actionButtonsLocation === "left" && onClickCancel ? cancelButton : void 0,
6209
+ actionButtonsLocation === "left" && renderActionButtons
6200
6210
  ]
6201
6211
  }
6202
6212
  )
@@ -7263,73 +7273,38 @@ import {
7263
7273
  useImperativeHandle as useImperativeHandle3,
7264
7274
  useMemo as useMemo10
7265
7275
  } from "react";
7276
+ import { createPortal as createPortal2 } from "react-dom";
7266
7277
  import { useTheme as useTheme26 } from "react-better-core";
7267
7278
  import styled13, { css as css6 } from "styled-components";
7268
7279
  import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
7269
- var tooltipContainerStyle = (props) => ({
7280
+ var isStartAlign = (align) => align === "left" || align === "top";
7281
+ var tooltipClosedTransform = (props) => ({
7270
7282
  top: css6`
7271
- bottom: calc(100% + ${props.gap}px + ${props.arrowSize}px);
7272
- ${props.align === "center" ? "left: 50%;" : props.align === "left" ? "left: 0;" : "right: 0;"}
7283
+ transform: translateY(${props.theme.styles.gap}px);
7273
7284
  `,
7274
7285
  bottom: css6`
7275
- top: calc(100% + ${props.gap}px + ${props.arrowSize}px);
7276
- ${props.align === "center" ? "left: 50%;" : props.align === "left" ? "left: 0;" : "right: 0;"};
7286
+ transform: translateY(-${props.theme.styles.gap}px);
7277
7287
  `,
7278
7288
  left: css6`
7279
- ${props.align === "center" ? "top: 50%;" : props.align === "top" ? "top: 0;" : "bottom: 0;"};
7280
- right: calc(100% + ${props.gap}px + ${props.arrowSize}px);
7289
+ transform: translateX(${props.theme.styles.gap}px);
7281
7290
  `,
7282
7291
  right: css6`
7283
- ${props.align === "center" ? "top: 50%;" : props.align === "top" ? "top: 0;" : "bottom: 0;"};
7284
- left: calc(100% + ${props.gap}px + ${props.arrowSize}px);
7292
+ transform: translateX(-${props.theme.styles.gap}px);
7285
7293
  `
7286
7294
  });
7287
- var tooltipPositionStyle = (props) => ({
7288
- top: {
7289
- opened: css6`
7290
- transform: translateX(${props.align === "center" ? "-50%" : "0"});
7291
- `,
7292
- closed: css6`
7293
- transform: translateX(${props.align === "center" ? "-50%" : "0"}) translateY(${props.theme.styles.gap}px);
7294
- `
7295
- },
7296
- bottom: {
7297
- opened: css6`
7298
- transform: translateX(${props.align === "center" ? "-50%" : "0"});
7299
- `,
7300
- closed: css6`
7301
- transform: translateX(${props.align === "center" ? "-50%" : "0"}) translateY(-${props.theme.styles.gap}px);
7302
- `
7303
- },
7304
- left: {
7305
- opened: css6`
7306
- transform: translateY(${props.align === "center" ? "-50%" : "0"});
7307
- `,
7308
- closed: css6`
7309
- transform: translateX(${props.theme.styles.gap}px) translateY(${props.align === "center" ? "-50%" : "0"});
7310
- `
7311
- },
7312
- right: {
7313
- opened: css6`
7314
- transform: translateY(${props.align === "center" ? "-50%" : "0"});
7315
- `,
7316
- closed: css6`
7317
- transform: translateX(-${props.theme.styles.gap}px) translateY(${props.align === "center" ? "-50%" : "0"});
7318
- `
7319
- }
7320
- });
7321
7295
  var TooltipContainer = styled13.div.withConfig({
7322
- shouldForwardProp: (prop) => !["theme", "position", "align", "pointerEvents", "withArrow", "arrowSize", "isOpen", "gap"].includes(prop)
7296
+ shouldForwardProp: (prop) => !["theme", "position", "pointerEvents", "isOpen"].includes(prop)
7323
7297
  })`
7324
- position: absolute;
7298
+ position: fixed;
7299
+ top: 0;
7300
+ left: 0;
7325
7301
  opacity: ${(props) => props.isOpen ? 1 : 0};
7326
7302
  pointer-events: ${(props) => props.isOpen ? props.pointerEvents : "none"};
7327
7303
  transition: ${(props) => props.theme.styles.transition};
7304
+ transition-property: opacity, transform;
7328
7305
  z-index: 1000;
7329
7306
 
7330
- ${(props) => tooltipContainerStyle(props)[props.position]}
7331
-
7332
- ${(props) => props.isOpen ? tooltipPositionStyle(props)[props.position].opened : tooltipPositionStyle(props)[props.position].closed}
7307
+ ${(props) => props.isOpen ? "transform: none;" : tooltipClosedTransform(props)[props.position]}
7333
7308
  `;
7334
7309
  var arrowStyle = (props, borderWidth) => ({
7335
7310
  top: {
@@ -7425,6 +7400,7 @@ var TooltipComponent = forwardRef16(function Tooltip({
7425
7400
  const wrapperRef = useRef7(null);
7426
7401
  const triggerHolderRef = useRef7(null);
7427
7402
  const contentRef = useRef7(null);
7403
+ const tooltipContainerRef = useRef7(null);
7428
7404
  const closeTimerRef = useRef7(void 0);
7429
7405
  const [isOpen, setIsOpen] = useState12(false);
7430
7406
  const [isOpenLate, setIsOpenLate] = useState12(false);
@@ -7432,6 +7408,8 @@ var TooltipComponent = forwardRef16(function Tooltip({
7432
7408
  const gap = theme2.styles.gap / 2;
7433
7409
  const outsideScreenGap = theme2.styles.gap / 2;
7434
7410
  const totalGap = arrowSize + gap;
7411
+ const arrowSideSpace = theme2.styles.borderRadius;
7412
+ const arrowAnchorOffset = withArrow ? arrowSideSpace + arrowSize : 0;
7435
7413
  const openTooltip = useCallback16(() => {
7436
7414
  if (disabled) return;
7437
7415
  if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
@@ -7469,19 +7447,25 @@ var TooltipComponent = forwardRef16(function Tooltip({
7469
7447
  },
7470
7448
  [trigger, isOpen, closeTooltip]
7471
7449
  );
7472
- const clampContentInsideViewport = useCallback16(() => {
7473
- if (!wrapperRef.current || !contentRef.current) return;
7450
+ const updateContainerPosition = useCallback16(() => {
7451
+ if (!wrapperRef.current || !contentRef.current || !tooltipContainerRef.current) return;
7474
7452
  const wrapperRect = wrapperRef.current.getBoundingClientRect();
7475
7453
  const contentWidth2 = contentRef.current.offsetWidth;
7476
7454
  const contentHeight = contentRef.current.offsetHeight;
7455
+ const getCrossAxisStart = (wrapperStart, wrapperSize, contentSize) => {
7456
+ const wrapperCenter = wrapperStart + wrapperSize / 2;
7457
+ if (align === "center") return wrapperCenter - contentSize / 2;
7458
+ if (isStartAlign(align)) return arrowAnchorOffset ? wrapperCenter - arrowAnchorOffset : wrapperStart;
7459
+ return arrowAnchorOffset ? wrapperCenter + arrowAnchorOffset - contentSize : wrapperStart + wrapperSize - contentSize;
7460
+ };
7477
7461
  let expectedLeft;
7478
7462
  let expectedTop;
7479
7463
  if (position === "top" || position === "bottom") {
7480
7464
  expectedTop = position === "top" ? wrapperRect.top - totalGap - contentHeight : wrapperRect.bottom + totalGap;
7481
- expectedLeft = align === "left" ? wrapperRect.left : align === "right" ? wrapperRect.right - contentWidth2 : wrapperRect.left + wrapperRect.width / 2 - contentWidth2 / 2;
7465
+ expectedLeft = getCrossAxisStart(wrapperRect.left, wrapperRect.width, contentWidth2);
7482
7466
  } else {
7483
7467
  expectedLeft = position === "left" ? wrapperRect.left - totalGap - contentWidth2 : wrapperRect.right + totalGap;
7484
- expectedTop = align === "top" ? wrapperRect.top : align === "bottom" ? wrapperRect.bottom - contentHeight : wrapperRect.top + wrapperRect.height / 2 - contentHeight / 2;
7468
+ expectedTop = getCrossAxisStart(wrapperRect.top, wrapperRect.height, contentHeight);
7485
7469
  }
7486
7470
  const getShift = (start, size, viewportSize) => {
7487
7471
  if (start < outsideScreenGap) return outsideScreenGap - start;
@@ -7490,8 +7474,9 @@ var TooltipComponent = forwardRef16(function Tooltip({
7490
7474
  };
7491
7475
  const shiftX = getShift(expectedLeft, contentWidth2, window.innerWidth);
7492
7476
  const shiftY = getShift(expectedTop, contentHeight, window.innerHeight);
7493
- contentRef.current.style.transform = shiftX || shiftY ? `translate(${shiftX}px, ${shiftY}px)` : "";
7494
- }, [position, align, totalGap, outsideScreenGap]);
7477
+ tooltipContainerRef.current.style.left = `${expectedLeft + shiftX}px`;
7478
+ tooltipContainerRef.current.style.top = `${expectedTop + shiftY}px`;
7479
+ }, [position, align, totalGap, outsideScreenGap, arrowAnchorOffset]);
7495
7480
  useEffect13(() => {
7496
7481
  if (trigger === "click") {
7497
7482
  document.addEventListener("mousedown", onClickOutside);
@@ -7505,8 +7490,15 @@ var TooltipComponent = forwardRef16(function Tooltip({
7505
7490
  closeTooltip();
7506
7491
  }, [disabled]);
7507
7492
  useLayoutEffect(() => {
7508
- if (isOpen) clampContentInsideViewport();
7509
- }, [isOpen, clampContentInsideViewport]);
7493
+ if (!isOpen) return;
7494
+ updateContainerPosition();
7495
+ window.addEventListener("scroll", updateContainerPosition, true);
7496
+ window.addEventListener("resize", updateContainerPosition);
7497
+ return () => {
7498
+ window.removeEventListener("scroll", updateContainerPosition, true);
7499
+ window.removeEventListener("resize", updateContainerPosition);
7500
+ };
7501
+ }, [isOpen, updateContainerPosition]);
7510
7502
  useImperativeHandle3(ref, () => {
7511
7503
  return {
7512
7504
  isOpen,
@@ -7535,60 +7527,60 @@ var TooltipComponent = forwardRef16(function Tooltip({
7535
7527
  children
7536
7528
  }
7537
7529
  ),
7538
- /* @__PURE__ */ jsx25(
7539
- TooltipContainer,
7540
- {
7541
- theme: theme2,
7542
- position,
7543
- align,
7544
- pointerEvents: contentPointerEvents,
7545
- withArrow,
7546
- arrowSize,
7547
- gap,
7548
- isOpen,
7549
- role: "tooltip",
7550
- children: (isOpen || isOpenLate) && /* @__PURE__ */ jsxs21(Div_default, { position: "relative", ref: contentRef, children: [
7551
- /* @__PURE__ */ jsx25(
7552
- Div_default.box,
7553
- {
7554
- position: "relative",
7555
- width: contentWidth,
7556
- minWidth: contentMinWidth,
7557
- backgroundColor: backgroundColor ?? theme2.colors.backgroundContent,
7558
- boxShadow: "0px 10px 20px #00000020",
7559
- paddingBlock: contentPaddingBlock ?? (isSmall ? theme2.styles.gap / 2 : theme2.styles.gap),
7560
- paddingInline: contentPaddingInline ?? (asContextMenu ? 0 : isSmall ? theme2.styles.space / 2 : theme2.styles.space),
7561
- overflow: asContextMenu ? "hidden" : void 0,
7562
- children: content
7563
- }
7564
- ),
7565
- /* @__PURE__ */ jsx25(
7566
- Div_default,
7567
- {
7568
- position: "absolute",
7569
- width: position === "left" || position === "right" ? totalGap : "100%",
7570
- height: position === "top" || position === "bottom" ? totalGap : "100%",
7571
- top: position === "top" ? "100%" : position === "bottom" ? void 0 : 0,
7572
- bottom: position === "bottom" ? "100%" : position === "top" ? void 0 : 0,
7573
- left: position === "left" ? "100%" : position === "right" ? void 0 : 0,
7574
- right: position === "right" ? "100%" : position === "left" ? void 0 : 0,
7575
- borderTopLeftRadius: 999,
7576
- borderTopRightRadius: 999
7577
- }
7578
- ),
7579
- withArrow && /* @__PURE__ */ jsx25(
7580
- Arrow,
7581
- {
7582
- position,
7583
- align,
7584
- sideSpace: theme2.styles.borderRadius,
7585
- size: arrowSize,
7586
- color: backgroundColor ?? theme2.colors.backgroundContent,
7587
- isOpen
7588
- }
7589
- )
7590
- ] })
7591
- }
7530
+ createPortal2(
7531
+ /* @__PURE__ */ jsx25(
7532
+ TooltipContainer,
7533
+ {
7534
+ theme: theme2,
7535
+ position,
7536
+ pointerEvents: contentPointerEvents,
7537
+ isOpen,
7538
+ role: "tooltip",
7539
+ ref: tooltipContainerRef,
7540
+ children: (isOpen || isOpenLate) && /* @__PURE__ */ jsxs21(Div_default, { position: "relative", ref: contentRef, children: [
7541
+ /* @__PURE__ */ jsx25(
7542
+ Div_default.box,
7543
+ {
7544
+ position: "relative",
7545
+ width: contentWidth,
7546
+ minWidth: contentMinWidth,
7547
+ backgroundColor: backgroundColor ?? theme2.colors.backgroundContent,
7548
+ boxShadow: "0px 10px 20px #00000020",
7549
+ paddingBlock: contentPaddingBlock ?? (isSmall ? theme2.styles.gap / 2 : theme2.styles.gap),
7550
+ paddingInline: contentPaddingInline ?? (asContextMenu ? 0 : isSmall ? theme2.styles.space / 2 : theme2.styles.space),
7551
+ overflow: asContextMenu ? "hidden" : void 0,
7552
+ children: content
7553
+ }
7554
+ ),
7555
+ /* @__PURE__ */ jsx25(
7556
+ Div_default,
7557
+ {
7558
+ position: "absolute",
7559
+ width: position === "left" || position === "right" ? totalGap : "100%",
7560
+ height: position === "top" || position === "bottom" ? totalGap : "100%",
7561
+ top: position === "top" ? "100%" : position === "bottom" ? void 0 : 0,
7562
+ bottom: position === "bottom" ? "100%" : position === "top" ? void 0 : 0,
7563
+ left: position === "left" ? "100%" : position === "right" ? void 0 : 0,
7564
+ right: position === "right" ? "100%" : position === "left" ? void 0 : 0,
7565
+ borderTopLeftRadius: 999,
7566
+ borderTopRightRadius: 999
7567
+ }
7568
+ ),
7569
+ withArrow && /* @__PURE__ */ jsx25(
7570
+ Arrow,
7571
+ {
7572
+ position,
7573
+ align,
7574
+ sideSpace: arrowSideSpace,
7575
+ size: arrowSize,
7576
+ color: backgroundColor ?? theme2.colors.backgroundContent,
7577
+ isOpen
7578
+ }
7579
+ )
7580
+ ] })
7581
+ }
7582
+ ),
7583
+ document.body
7592
7584
  )
7593
7585
  ]
7594
7586
  }