@rehagro/ui 1.0.1 → 1.0.3

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
@@ -13,7 +13,11 @@ var TOKEN_MAP = {
13
13
  danger: { var: "--rh-danger", isColor: true },
14
14
  dangerHover: { var: "--rh-danger-hover", isColor: true },
15
15
  warning: { var: "--rh-warning", isColor: true },
16
+ warningHover: { var: "--rh-warning-hover", isColor: true },
16
17
  success: { var: "--rh-success", isColor: true },
18
+ successHover: { var: "--rh-success-hover", isColor: true },
19
+ info: { var: "--rh-info", isColor: true },
20
+ infoHover: { var: "--rh-info-hover", isColor: true },
17
21
  text: { var: "--rh-text", isColor: true },
18
22
  textMuted: { var: "--rh-text-muted", isColor: true },
19
23
  surface: { var: "--rh-surface", isColor: true },
@@ -613,11 +617,62 @@ function RehagroProvider({ theme, toastPosition, children }) {
613
617
  }, [theme]);
614
618
  return /* @__PURE__ */ jsx("div", { className: "rh-root", style, children: /* @__PURE__ */ jsx(ToastProvider, { position: toastPosition, children }) });
615
619
  }
616
- var variantClasses = {
617
- solid: "rh-bg-primary rh-text-surface rh-border-primary hover:rh-bg-primary-hover hover:rh-border-primary-hover",
618
- outline: "rh-bg-transparent rh-text-primary rh-border-primary hover:rh-bg-primary hover:rh-text-surface",
619
- ghost: "rh-bg-transparent rh-text-primary rh-border-transparent hover:rh-bg-primary/10"
620
+ function toRgbTriplet2(value) {
621
+ if (value.startsWith("#")) {
622
+ const h = value.replace("#", "");
623
+ const full = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
624
+ const r = parseInt(full.slice(0, 2), 16);
625
+ const g = parseInt(full.slice(2, 4), 16);
626
+ const b = parseInt(full.slice(4, 6), 16);
627
+ if ([r, g, b].some(Number.isNaN)) return void 0;
628
+ return `${r} ${g} ${b}`;
629
+ }
630
+ const m = value.match(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i);
631
+ if (m) return `${m[1]} ${m[2]} ${m[3]}`;
632
+ const parts = value.trim().split(/\s+/);
633
+ if (parts.length === 3 && parts.every((p) => !Number.isNaN(Number(p)))) return value.trim();
634
+ return void 0;
635
+ }
636
+ var PRESET_COLORS = /* @__PURE__ */ new Set([
637
+ "primary",
638
+ "secondary",
639
+ "danger",
640
+ "warning",
641
+ "success",
642
+ "info"
643
+ ]);
644
+ var isPresetColor = (c) => PRESET_COLORS.has(c);
645
+ var variantColorClasses = {
646
+ solid: {
647
+ primary: "rh-bg-primary rh-text-surface rh-border-primary hover:rh-bg-primary-hover hover:rh-border-primary-hover",
648
+ secondary: "rh-bg-secondary rh-text-surface rh-border-secondary hover:rh-bg-secondary-hover hover:rh-border-secondary-hover",
649
+ danger: "rh-bg-danger rh-text-surface rh-border-danger hover:rh-bg-danger-hover hover:rh-border-danger-hover",
650
+ warning: "rh-bg-warning rh-text-surface rh-border-warning hover:rh-bg-warning-hover hover:rh-border-warning-hover",
651
+ success: "rh-bg-success rh-text-surface rh-border-success hover:rh-bg-success-hover hover:rh-border-success-hover",
652
+ info: "rh-bg-info rh-text-surface rh-border-info hover:rh-bg-info-hover hover:rh-border-info-hover"
653
+ },
654
+ outline: {
655
+ primary: "rh-bg-transparent rh-text-primary rh-border-primary hover:rh-bg-primary hover:rh-text-surface",
656
+ secondary: "rh-bg-transparent rh-text-secondary rh-border-secondary hover:rh-bg-secondary hover:rh-text-surface",
657
+ danger: "rh-bg-transparent rh-text-danger rh-border-danger hover:rh-bg-danger hover:rh-text-surface",
658
+ warning: "rh-bg-transparent rh-text-warning rh-border-warning hover:rh-bg-warning hover:rh-text-surface",
659
+ success: "rh-bg-transparent rh-text-success rh-border-success hover:rh-bg-success hover:rh-text-surface",
660
+ info: "rh-bg-transparent rh-text-info rh-border-info hover:rh-bg-info hover:rh-text-surface"
661
+ },
662
+ ghost: {
663
+ primary: "rh-bg-transparent rh-text-primary rh-border-transparent hover:rh-bg-primary/10",
664
+ secondary: "rh-bg-transparent rh-text-secondary rh-border-transparent hover:rh-bg-secondary/10",
665
+ danger: "rh-bg-transparent rh-text-danger rh-border-transparent hover:rh-bg-danger/10",
666
+ warning: "rh-bg-transparent rh-text-warning rh-border-transparent hover:rh-bg-warning/10",
667
+ success: "rh-bg-transparent rh-text-success rh-border-transparent hover:rh-bg-success/10",
668
+ info: "rh-bg-transparent rh-text-info rh-border-transparent hover:rh-bg-info/10"
669
+ }
620
670
  };
671
+ function getArbitraryColorStyle(variant, color) {
672
+ if (variant === "solid") return { backgroundColor: color, borderColor: color, color: "#fff" };
673
+ if (variant === "outline") return { borderColor: color, color };
674
+ return { color, borderColor: "transparent" };
675
+ }
621
676
  var sizeClasses = {
622
677
  sm: "rh-text-sm rh-px-3 rh-py-1.5",
623
678
  md: "rh-text-sm rh-px-4 rh-py-2",
@@ -637,27 +692,40 @@ var Button = forwardRef(function Button2({
637
692
  variant = "solid",
638
693
  size = "md",
639
694
  radius = "sm",
695
+ color = "primary",
696
+ hoverColor,
640
697
  loading = false,
641
698
  disabled,
642
699
  leftIcon,
643
700
  rightIcon,
644
701
  className = "",
702
+ style,
645
703
  children,
646
704
  ...rest
647
705
  }, ref) {
648
706
  const isDisabled = React8.useMemo(() => disabled || loading, [disabled, loading]);
707
+ const preset = isPresetColor(color);
708
+ const computedStyle = React8.useMemo(() => {
709
+ if (preset) {
710
+ if (!hoverColor) return style ?? {};
711
+ const triplet = toRgbTriplet2(hoverColor);
712
+ return { ...style, [`--rh-${color}-hover`]: triplet ?? hoverColor };
713
+ }
714
+ return { ...style, ...getArbitraryColorStyle(variant, color) };
715
+ }, [preset, color, variant, hoverColor, style]);
649
716
  return /* @__PURE__ */ jsxs(
650
717
  "button",
651
718
  {
652
719
  ref,
653
720
  disabled: isDisabled,
654
721
  "aria-busy": loading || void 0,
722
+ style: computedStyle,
655
723
  className: [
656
724
  "rh-inline-flex rh-items-center rh-justify-center rh-gap-2",
657
725
  "rh-border rh-font-sans rh-font-medium",
658
726
  "rh-transition-colors rh-duration-150",
659
727
  "focus-visible:rh-outline-none focus-visible:rh-ring-2 focus-visible:rh-ring-ring focus-visible:rh-ring-offset-2",
660
- variantClasses[variant],
728
+ preset ? variantColorClasses[variant][color] : "hover:rh-brightness-90",
661
729
  sizeClasses[size],
662
730
  radiusClasses[radius],
663
731
  isDisabled ? "rh-opacity-50 rh-cursor-not-allowed rh-pointer-events-none" : "",
@@ -703,29 +771,46 @@ var Button = forwardRef(function Button2({
703
771
  }
704
772
  );
705
773
  });
706
- var variantColorClasses = {
774
+ var PRESET_COLORS2 = /* @__PURE__ */ new Set([
775
+ "primary",
776
+ "secondary",
777
+ "danger",
778
+ "warning",
779
+ "success",
780
+ "info"
781
+ ]);
782
+ var isPresetColor2 = (c) => PRESET_COLORS2.has(c);
783
+ var variantColorClasses2 = {
707
784
  solid: {
708
785
  primary: "rh-bg-primary rh-text-surface rh-border-primary hover:rh-bg-primary-hover hover:rh-border-primary-hover",
786
+ secondary: "rh-bg-secondary rh-text-surface rh-border-secondary hover:rh-bg-secondary-hover hover:rh-border-secondary-hover",
709
787
  danger: "rh-bg-danger rh-text-surface rh-border-danger hover:rh-bg-danger-hover hover:rh-border-danger-hover",
710
788
  warning: "rh-bg-warning rh-text-surface rh-border-warning hover:rh-bg-warning-hover hover:rh-border-warning-hover",
711
789
  success: "rh-bg-success rh-text-surface rh-border-success hover:rh-bg-success-hover hover:rh-border-success-hover",
712
- secondary: "rh-bg-secondary rh-text-surface rh-border-secondary hover:rh-bg-secondary-hover hover:rh-border-secondary-hover"
790
+ info: "rh-bg-info rh-text-surface rh-border-info hover:rh-bg-info-hover hover:rh-border-info-hover"
713
791
  },
714
792
  outline: {
715
793
  primary: "rh-bg-transparent rh-text-primary rh-border-primary hover:rh-bg-primary hover:rh-text-surface",
794
+ secondary: "rh-bg-transparent rh-text-secondary rh-border-secondary hover:rh-bg-secondary hover:rh-text-surface",
716
795
  danger: "rh-bg-transparent rh-text-danger rh-border-danger hover:rh-bg-danger hover:rh-text-surface",
717
796
  warning: "rh-bg-transparent rh-text-warning rh-border-warning hover:rh-bg-warning hover:rh-text-surface",
718
797
  success: "rh-bg-transparent rh-text-success rh-border-success hover:rh-bg-success hover:rh-text-surface",
719
- secondary: "rh-bg-transparent rh-text-secondary rh-border-secondary hover:rh-bg-secondary hover:rh-text-surface"
798
+ info: "rh-bg-transparent rh-text-info rh-border-info hover:rh-bg-info hover:rh-text-surface"
720
799
  },
721
800
  ghost: {
722
801
  primary: "rh-bg-transparent rh-text-primary rh-border-transparent hover:rh-bg-primary/10",
802
+ secondary: "rh-bg-transparent rh-text-secondary rh-border-transparent hover:rh-bg-secondary/10",
723
803
  danger: "rh-bg-transparent rh-text-danger rh-border-transparent hover:rh-bg-danger/10",
724
804
  warning: "rh-bg-transparent rh-text-warning rh-border-transparent hover:rh-bg-warning/10",
725
805
  success: "rh-bg-transparent rh-text-success rh-border-transparent hover:rh-bg-success/10",
726
- secondary: "rh-bg-transparent rh-text-secondary rh-border-transparent hover:rh-bg-secondary/10"
806
+ info: "rh-bg-transparent rh-text-info rh-border-transparent hover:rh-bg-info/10"
727
807
  }
728
808
  };
809
+ function getArbitraryColorStyle2(variant, color) {
810
+ if (variant === "solid") return { backgroundColor: color, borderColor: color, color: "#fff" };
811
+ if (variant === "outline") return { borderColor: color, color };
812
+ return { color, borderColor: "transparent" };
813
+ }
729
814
  var sizeClasses2 = {
730
815
  sm: "rh-h-8 rh-w-8 rh-text-sm",
731
816
  md: "rh-h-10 rh-w-10 rh-text-base",
@@ -749,22 +834,29 @@ var IconButton = forwardRef(function IconButton2({
749
834
  loading = false,
750
835
  disabled,
751
836
  className = "",
837
+ style,
752
838
  children,
753
839
  ...rest
754
840
  }, ref) {
755
841
  const isDisabled = disabled || loading;
842
+ const preset = isPresetColor2(color);
843
+ const computedStyle = React8.useMemo(
844
+ () => preset ? style ?? {} : { ...style, ...getArbitraryColorStyle2(variant, color) },
845
+ [preset, color, variant, style]
846
+ );
756
847
  return /* @__PURE__ */ jsx(
757
848
  "button",
758
849
  {
759
850
  ref,
760
851
  disabled: isDisabled,
761
852
  "aria-busy": loading || void 0,
853
+ style: computedStyle,
762
854
  className: [
763
855
  "rh-inline-flex rh-items-center rh-justify-center",
764
856
  "rh-border rh-font-sans",
765
857
  "rh-transition-colors rh-duration-150",
766
858
  "focus-visible:rh-outline-none focus-visible:rh-ring-2 focus-visible:rh-ring-ring focus-visible:rh-ring-offset-2",
767
- variantColorClasses[variant][color],
859
+ preset ? variantColorClasses2[variant][color] : "hover:rh-brightness-90",
768
860
  sizeClasses2[size],
769
861
  radiusClasses2[radius],
770
862
  isDisabled ? "rh-opacity-50 rh-cursor-not-allowed rh-pointer-events-none" : "",
@@ -1464,7 +1556,7 @@ var Select = forwardRef(
1464
1556
  );
1465
1557
  }
1466
1558
  );
1467
- var variantClasses2 = {
1559
+ var variantClasses = {
1468
1560
  light: "rh-bg-surface rh-text-text rh-border rh-border-border rh-shadow-md",
1469
1561
  default: "rh-bg-primary/10 rh-text-text rh-border rh-border-primary/20 rh-shadow-md",
1470
1562
  dark: "rh-bg-primary rh-text-surface rh-shadow-md"
@@ -1604,7 +1696,7 @@ var Tooltip = forwardRef(
1604
1696
  className: [
1605
1697
  "rh-absolute rh-z-50 rh-w-max rh-max-w-xs rh-rounded-xs",
1606
1698
  tooltipPlacementClasses[placement],
1607
- variantClasses2[variant],
1699
+ variantClasses[variant],
1608
1700
  sizeClasses6[size],
1609
1701
  className
1610
1702
  ].filter(Boolean).join(" "),
@@ -1691,7 +1783,7 @@ var imageSizeClasses = {
1691
1783
  lg: "rh-w-12 rh-h-12",
1692
1784
  xl: "rh-w-16 rh-h-16"
1693
1785
  };
1694
- var variantClasses3 = {
1786
+ var variantClasses2 = {
1695
1787
  circle: "rh-rounded-full",
1696
1788
  square: "rh-rounded-sm"
1697
1789
  };
@@ -1709,7 +1801,7 @@ var Avatar = forwardRef(function Avatar2({ src, alt = "", initials, size = "md",
1709
1801
  "rh-inline-flex rh-items-center rh-justify-center rh-shrink-0 rh-overflow-hidden",
1710
1802
  "rh-bg-primary rh-text-surface rh-font-sans rh-font-medium rh-select-none",
1711
1803
  sizeClasses7[size],
1712
- variantClasses3[variant],
1804
+ variantClasses2[variant],
1713
1805
  className
1714
1806
  ].filter(Boolean).join(" "),
1715
1807
  ...rest,
@@ -1718,13 +1810,118 @@ var Avatar = forwardRef(function Avatar2({ src, alt = "", initials, size = "md",
1718
1810
  {
1719
1811
  src,
1720
1812
  alt,
1721
- className: [imageSizeClasses[size], variantClasses3[variant], "rh-object-cover"].join(" "),
1813
+ className: [imageSizeClasses[size], variantClasses2[variant], "rh-object-cover"].join(" "),
1722
1814
  onError: () => setImgError(true)
1723
1815
  }
1724
1816
  ) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: fallbackLabel })
1725
1817
  }
1726
1818
  );
1727
1819
  });
1820
+ var PRESET_COLORS3 = /* @__PURE__ */ new Set([
1821
+ "primary",
1822
+ "secondary",
1823
+ "danger",
1824
+ "warning",
1825
+ "success",
1826
+ "info"
1827
+ ]);
1828
+ var isPresetColor3 = (color) => PRESET_COLORS3.has(color);
1829
+ var activePresetClasses = {
1830
+ primary: "rh-bg-primary rh-text-surface rh-border-primary",
1831
+ secondary: "rh-bg-secondary rh-text-surface rh-border-secondary",
1832
+ danger: "rh-bg-danger rh-text-surface rh-border-danger",
1833
+ warning: "rh-bg-warning rh-text-surface rh-border-warning",
1834
+ success: "rh-bg-success rh-text-surface rh-border-success",
1835
+ info: "rh-bg-info rh-text-surface rh-border-info"
1836
+ };
1837
+ var inactivePresetClasses = {
1838
+ primary: "rh-bg-primary/10 rh-text-primary rh-border-primary/30",
1839
+ secondary: "rh-bg-secondary/10 rh-text-secondary rh-border-secondary/30",
1840
+ danger: "rh-bg-danger/10 rh-text-danger rh-border-danger/30",
1841
+ warning: "rh-bg-warning/10 rh-text-warning rh-border-warning/30",
1842
+ success: "rh-bg-success/10 rh-text-success rh-border-success/30",
1843
+ info: "rh-bg-info/10 rh-text-info rh-border-info/30"
1844
+ };
1845
+ var hoverActivePresetClasses = {
1846
+ primary: "hover:rh-bg-primary-hover hover:rh-border-primary-hover",
1847
+ secondary: "hover:rh-bg-secondary-hover hover:rh-border-secondary-hover",
1848
+ danger: "hover:rh-bg-danger-hover hover:rh-border-danger-hover",
1849
+ warning: "hover:rh-bg-warning-hover hover:rh-border-warning-hover",
1850
+ success: "hover:rh-bg-success-hover hover:rh-border-success-hover",
1851
+ info: "hover:rh-bg-info-hover hover:rh-border-info-hover"
1852
+ };
1853
+ var hoverInactivePresetClasses = {
1854
+ primary: "hover:rh-bg-primary/20 hover:rh-border-primary/50",
1855
+ secondary: "hover:rh-bg-secondary/20 hover:rh-border-secondary/50",
1856
+ danger: "hover:rh-bg-danger/20 hover:rh-border-danger/50",
1857
+ warning: "hover:rh-bg-warning/20 hover:rh-border-warning/50",
1858
+ success: "hover:rh-bg-success/20 hover:rh-border-success/50",
1859
+ info: "hover:rh-bg-info/20 hover:rh-border-info/50"
1860
+ };
1861
+ var sizeClasses8 = {
1862
+ sm: "rh-text-xs rh-px-2 rh-py-0.5 rh-gap-1",
1863
+ md: "rh-text-sm rh-px-2.5 rh-py-1 rh-gap-1.5",
1864
+ lg: "rh-text-sm rh-px-3 rh-py-1.5 rh-gap-1.5"
1865
+ };
1866
+ function getCustomColorStyles(color, active) {
1867
+ if (active) {
1868
+ return { backgroundColor: color, borderColor: color, color: "#fff" };
1869
+ }
1870
+ return {
1871
+ backgroundColor: `color-mix(in srgb, ${color} 10%, transparent)`,
1872
+ borderColor: `color-mix(in srgb, ${color} 30%, transparent)`,
1873
+ color
1874
+ };
1875
+ }
1876
+ var Tag = forwardRef(function Tag2({
1877
+ color = "primary",
1878
+ size = "md",
1879
+ active = false,
1880
+ title,
1881
+ leftIcon,
1882
+ rightIcon,
1883
+ className = "",
1884
+ disabled,
1885
+ style,
1886
+ children,
1887
+ ...rest
1888
+ }, ref) {
1889
+ const preset = isPresetColor3(color);
1890
+ const clickable = !!rest.onClick && !disabled;
1891
+ const colorClasses = preset ? active ? activePresetClasses[color] : inactivePresetClasses[color] : "";
1892
+ const hoverClasses = clickable && preset ? active ? hoverActivePresetClasses[color] : hoverInactivePresetClasses[color] : clickable ? "hover:rh-brightness-95" : "";
1893
+ const customStyles = preset ? {} : getCustomColorStyles(color, active);
1894
+ return /* @__PURE__ */ jsxs(
1895
+ "span",
1896
+ {
1897
+ ref,
1898
+ role: clickable ? "button" : void 0,
1899
+ tabIndex: clickable ? 0 : void 0,
1900
+ "aria-pressed": clickable ? active : void 0,
1901
+ "aria-disabled": disabled || void 0,
1902
+ className: [
1903
+ "rh-inline-flex rh-items-center rh-font-sans rh-font-medium rh-rounded-full",
1904
+ "rh-border rh-whitespace-nowrap rh-select-none",
1905
+ "rh-transition-colors rh-duration-150",
1906
+ "rh-cursor-pointer",
1907
+ clickable ? "rh-cursor-pointer" : "",
1908
+ sizeClasses8[size],
1909
+ colorClasses,
1910
+ hoverClasses,
1911
+ disabled ? "rh-opacity-50 rh-cursor-not-allowed rh-pointer-events-none" : "",
1912
+ className
1913
+ ].filter(Boolean).join(" "),
1914
+ style: { ...customStyles, ...style },
1915
+ ...rest,
1916
+ children: [
1917
+ leftIcon,
1918
+ title,
1919
+ children,
1920
+ rightIcon
1921
+ ]
1922
+ }
1923
+ );
1924
+ });
1728
1925
  var Container = forwardRef(
1729
1926
  function Container2({ fluid = false, className = "", children, ...rest }, ref) {
1730
1927
  return /* @__PURE__ */ jsx(
@@ -1894,6 +2091,6 @@ var GridItem = forwardRef(
1894
2091
  }
1895
2092
  );
1896
2093
 
1897
- export { Avatar, Button, Checkbox, CloseIcon, Container, DeleteIcon, EditIcon, ErrorIcon, GridContainer, GridItem, IconButton, InfoIcon, NeutralIcon, PlusIcon, RehagroProvider, SearchIcon, Select, SuccessIcon, TextInput, Toast, ToastContainer, ToastProvider, Tooltip, WarningIcon, useToast };
2094
+ export { Avatar, Button, Checkbox, CloseIcon, Container, DeleteIcon, EditIcon, ErrorIcon, GridContainer, GridItem, IconButton, InfoIcon, NeutralIcon, PlusIcon, RehagroProvider, SearchIcon, Select, SuccessIcon, Tag, TextInput, Toast, ToastContainer, ToastProvider, Tooltip, WarningIcon, useToast };
1898
2095
  //# sourceMappingURL=index.mjs.map
1899
2096
  //# sourceMappingURL=index.mjs.map