@rehagro/ui 1.0.49 → 1.0.51

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
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import React9, { forwardRef, createContext, useState, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
2
+ import React9, { forwardRef, createContext, useState, useRef, useMemo, useEffect, useCallback, useContext } from 'react';
3
3
  import { jsxs, jsx } from 'react/jsx-runtime';
4
4
  import { createPortal } from 'react-dom';
5
5
 
@@ -1580,6 +1580,19 @@ var CheckIcon2 = ({ className }) => /* @__PURE__ */ jsx(
1580
1580
  )
1581
1581
  }
1582
1582
  );
1583
+ var RadioIcon = ({ isSelected }) => /* @__PURE__ */ jsx(
1584
+ "span",
1585
+ {
1586
+ className: [
1587
+ "rh-inline-flex rh-items-center rh-justify-center",
1588
+ "rh-w-4 rh-h-4 rh-shrink-0",
1589
+ "rh-border rh-rounded-full rh-transition-colors rh-duration-150",
1590
+ isSelected ? "rh-border-primary" : "rh-border-border rh-bg-surface"
1591
+ ].filter(Boolean).join(" "),
1592
+ "aria-hidden": "true",
1593
+ children: isSelected && /* @__PURE__ */ jsx("span", { className: "rh-w-2.5 rh-h-2.5 rh-rounded-full rh-bg-primary" })
1594
+ }
1595
+ );
1583
1596
  var Select = forwardRef(function Select2(props, ref) {
1584
1597
  const {
1585
1598
  options,
@@ -1590,6 +1603,7 @@ var Select = forwardRef(function Select2(props, ref) {
1590
1603
  size = "md",
1591
1604
  radius = "xs",
1592
1605
  helperText,
1606
+ radio = false,
1593
1607
  disabled = false,
1594
1608
  className = "",
1595
1609
  wrapperClassName = "",
@@ -1853,7 +1867,7 @@ var Select = forwardRef(function Select2(props, ref) {
1853
1867
  ].filter(Boolean).join(" "),
1854
1868
  children: [
1855
1869
  /* @__PURE__ */ jsx("span", { className: "rh-flex-1 rh-truncate rh-text-text", children: option.label }),
1856
- multiple ? /* @__PURE__ */ jsx(
1870
+ radio ? /* @__PURE__ */ jsx(RadioIcon, { isSelected }) : multiple ? /* @__PURE__ */ jsx(
1857
1871
  "span",
1858
1872
  {
1859
1873
  className: [
@@ -2041,6 +2055,7 @@ var DateSelect = forwardRef(
2041
2055
  const helperId = React9.useId();
2042
2056
  const [isOpen, setIsOpen] = useState(false);
2043
2057
  const [isHelperDismissed, setIsHelperDismissed] = useState(false);
2058
+ const [dropdownAlign, setDropdownAlign] = useState("left");
2044
2059
  const [internalValue, setInternalValue] = useState(
2045
2060
  props.defaultValue ?? { mode: "day" }
2046
2061
  );
@@ -2057,8 +2072,9 @@ var DateSelect = forwardRef(
2057
2072
  const [yearGridStart, setYearGridStart] = useState(
2058
2073
  Math.floor((/* @__PURE__ */ new Date()).getFullYear() / 12) * 12
2059
2074
  );
2060
- const wrapperRef = React9.useRef(null);
2061
- const innerRef = React9.useRef(null);
2075
+ const wrapperRef = useRef(null);
2076
+ const innerRef = useRef(null);
2077
+ const dropdownRef = useRef(null);
2062
2078
  React9.useImperativeHandle(ref, () => innerRef.current);
2063
2079
  const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
2064
2080
  const yearStart = startYear ?? currentYear - 10;
@@ -2092,7 +2108,22 @@ var DateSelect = forwardRef(
2092
2108
  if (!isControlled) setInternalValue(newValue);
2093
2109
  props.onChange?.(newValue);
2094
2110
  };
2095
- const displayText = React9.useMemo(() => {
2111
+ const handleMonthClear = () => {
2112
+ const newValue = { mode: "month" };
2113
+ if (!isControlled) setInternalValue(newValue);
2114
+ props.onChange?.(newValue);
2115
+ };
2116
+ const handleDayClear = () => {
2117
+ const newValue = { mode: "day" };
2118
+ if (!isControlled) setInternalValue(newValue);
2119
+ props.onChange?.(newValue);
2120
+ };
2121
+ const handleYearClear = () => {
2122
+ const newValue = { mode: "year" };
2123
+ if (!isControlled) setInternalValue(newValue);
2124
+ props.onChange?.(newValue);
2125
+ };
2126
+ const displayText = useMemo(() => {
2096
2127
  if (value.mode === "year" && value.year) return value.year.toString();
2097
2128
  if (value.mode === "month" && value.year != null)
2098
2129
  return `${MONTHS_SHORT[value.month || 0]} ${value.year}`;
@@ -2103,7 +2134,7 @@ var DateSelect = forwardRef(
2103
2134
  }
2104
2135
  return null;
2105
2136
  }, [value]);
2106
- React9.useEffect(() => {
2137
+ useEffect(() => {
2107
2138
  if (!isOpen) return;
2108
2139
  const handleClickOutside = (e) => {
2109
2140
  if (wrapperRef.current && !wrapperRef.current.contains(e.target)) {
@@ -2113,7 +2144,7 @@ var DateSelect = forwardRef(
2113
2144
  document.addEventListener("mousedown", handleClickOutside);
2114
2145
  return () => document.removeEventListener("mousedown", handleClickOutside);
2115
2146
  }, [isOpen]);
2116
- React9.useEffect(() => {
2147
+ useEffect(() => {
2117
2148
  if (!isOpen) return;
2118
2149
  const handleEscape = (e) => {
2119
2150
  if (e.key === "Escape") {
@@ -2124,6 +2155,18 @@ var DateSelect = forwardRef(
2124
2155
  document.addEventListener("keydown", handleEscape);
2125
2156
  return () => document.removeEventListener("keydown", handleEscape);
2126
2157
  }, [isOpen]);
2158
+ useEffect(() => {
2159
+ if (!isOpen || !innerRef.current || !dropdownRef.current) return;
2160
+ const triggerRect = innerRef.current.getBoundingClientRect();
2161
+ const dropdownWidth = activeMode === "interval" ? 720 : 385;
2162
+ const spaceLeft = triggerRect.left;
2163
+ const spaceRight = window.innerWidth - triggerRect.right;
2164
+ if (spaceLeft < dropdownWidth && spaceRight >= dropdownWidth) {
2165
+ setDropdownAlign("right");
2166
+ } else {
2167
+ setDropdownAlign("left");
2168
+ }
2169
+ }, [isOpen, activeMode]);
2127
2170
  const getDaysInMonth2 = (year, month) => new Date(year, month + 1, 0).getDate();
2128
2171
  const getFirstDayOfMonth2 = (year, month) => new Date(year, month, 1).getDay();
2129
2172
  const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
@@ -2200,7 +2243,18 @@ var DateSelect = forwardRef(
2200
2243
  },
2201
2244
  year
2202
2245
  );
2203
- }) })
2246
+ }) }),
2247
+ /* @__PURE__ */ jsx("div", { className: "rh-flex rh-items-center rh-justify-between rh-pt-3 rh-mt-3 rh-border-t rh-border-border/30", children: /* @__PURE__ */ jsxs(
2248
+ "button",
2249
+ {
2250
+ onClick: handleYearClear,
2251
+ className: "rh-flex rh-items-center rh-gap-1.5 rh-text-sm rh-text-text rh-font-medium rh-px-2 rh-py-1.5 rh-rounded-sm hover:rh-bg-background rh-transition-colors rh-duration-150",
2252
+ children: [
2253
+ /* @__PURE__ */ jsx(EraserIcon, { className: "rh-w-4 rh-h-4" }),
2254
+ "Limpar"
2255
+ ]
2256
+ }
2257
+ ) })
2204
2258
  ] });
2205
2259
  const renderMonthGrid = () => /* @__PURE__ */ jsxs("div", { className: "rh-p-1", children: [
2206
2260
  /* @__PURE__ */ jsxs("div", { className: "rh-flex rh-items-center rh-justify-between", children: [
@@ -2248,7 +2302,18 @@ var DateSelect = forwardRef(
2248
2302
  },
2249
2303
  month
2250
2304
  );
2251
- }) })
2305
+ }) }),
2306
+ /* @__PURE__ */ jsx("div", { className: "rh-flex rh-items-center rh-justify-between rh-pt-3 rh-mt-3 rh-border-t rh-border-border/30", children: /* @__PURE__ */ jsxs(
2307
+ "button",
2308
+ {
2309
+ onClick: handleMonthClear,
2310
+ className: "rh-flex rh-items-center rh-gap-1.5 rh-text-sm rh-text-text rh-font-medium rh-px-2 rh-py-1.5 rh-rounded-sm hover:rh-bg-background rh-transition-colors rh-duration-150",
2311
+ children: [
2312
+ /* @__PURE__ */ jsx(EraserIcon, { className: "rh-w-4 rh-h-4" }),
2313
+ "Limpar"
2314
+ ]
2315
+ }
2316
+ ) })
2252
2317
  ] });
2253
2318
  const renderIntervalNav = () => /* @__PURE__ */ jsxs("div", { children: [
2254
2319
  /* @__PURE__ */ jsxs("div", { className: "rh-flex rh-gap-4 rh-p-1", children: [
@@ -2506,7 +2571,18 @@ var DateSelect = forwardRef(
2506
2571
  },
2507
2572
  i
2508
2573
  )) }),
2509
- renderDayGrid(selectedYear, selectedMonth)
2574
+ renderDayGrid(selectedYear, selectedMonth),
2575
+ /* @__PURE__ */ jsx("div", { className: "rh-flex rh-items-center rh-justify-between rh-pt-3 rh-mt-3 rh-border-t rh-border-border/30", children: /* @__PURE__ */ jsxs(
2576
+ "button",
2577
+ {
2578
+ onClick: handleDayClear,
2579
+ className: "rh-flex rh-items-center rh-gap-1.5 rh-text-sm rh-text-text rh-font-medium rh-px-2 rh-py-1.5 rh-rounded-sm hover:rh-bg-background rh-transition-colors rh-duration-150",
2580
+ children: [
2581
+ /* @__PURE__ */ jsx(EraserIcon, { className: "rh-w-4 rh-h-4" }),
2582
+ "Limpar"
2583
+ ]
2584
+ }
2585
+ ) })
2510
2586
  ] });
2511
2587
  case "month":
2512
2588
  return renderMonthGrid();
@@ -2626,11 +2702,13 @@ var DateSelect = forwardRef(
2626
2702
  isOpen && /* @__PURE__ */ jsxs(
2627
2703
  "div",
2628
2704
  {
2705
+ ref: dropdownRef,
2629
2706
  className: [
2630
2707
  "rh-absolute rh-z-50 rh-mt-1 rh-p-5",
2631
2708
  "rh-bg-surface rh-rounded-md",
2632
2709
  dropdownRadiusClasses2[radius],
2633
- activeMode === "interval" ? "rh-w-[720px]" : "rh-w-[385px]"
2710
+ activeMode === "interval" ? "rh-w-[720px]" : "rh-w-[385px]",
2711
+ dropdownAlign === "left" ? "rh-right-0" : "rh-left-0"
2634
2712
  ].filter(Boolean).join(" "),
2635
2713
  style: {
2636
2714
  top: "100%",
@@ -4265,7 +4343,7 @@ function TableInner({
4265
4343
  style: bodyStyleInline,
4266
4344
  className: [
4267
4345
  "rh-border-b rh-border-border rh-transition-colors",
4268
- "hover:rh-bg-background",
4346
+ "hover:rh-bg-background/50",
4269
4347
  variant === "striped" && index % 2 === 1 ? "rh-bg-background/50" : ""
4270
4348
  ].filter(Boolean).join(" "),
4271
4349
  children: columns.map((column) => /* @__PURE__ */ jsx(
@@ -4287,7 +4365,7 @@ function TableInner({
4287
4365
  onChange: (value) => column.onEditChange?.(row, index, value),
4288
4366
  className: "rh-w-full rh-h-full"
4289
4367
  }
4290
- ) : /* @__PURE__ */ jsx("span", { children: column.render(row, index) }),
4368
+ ) : /* @__PURE__ */ jsx("span", { style: { width: "100%" }, children: column.render(row, index) }),
4291
4369
  column.actionIcon && /* @__PURE__ */ jsx(
4292
4370
  "span",
4293
4371
  {
@@ -4306,7 +4384,7 @@ function TableInner({
4306
4384
  },
4307
4385
  rowKey(row, index)
4308
4386
  )),
4309
- addRowButton && !loading && /* @__PURE__ */ jsx("tr", { className: "rh-border-border hover:rh-bg-background/100 rh-rounde-lg", children: /* @__PURE__ */ jsx(
4387
+ addRowButton && !loading && /* @__PURE__ */ jsx("tr", { className: "rh-border-border hover:rh-bg-background/50 rh-rounde-lg", children: /* @__PURE__ */ jsx(
4310
4388
  "td",
4311
4389
  {
4312
4390
  colSpan,