@rehagro/ui 1.0.46 → 1.0.47

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,6 +1,7 @@
1
1
  "use client";
2
2
  import React9, { forwardRef, createContext, useState, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
3
3
  import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { createPortal } from 'react-dom';
4
5
 
5
6
  // src/provider/RehagroProvider.tsx
6
7
 
@@ -2911,6 +2912,103 @@ var Spinner = forwardRef(function Spinner2({ size = "md", color = "primary", lab
2911
2912
  }
2912
2913
  );
2913
2914
  });
2915
+ var CustomSelect = ({ options, value, onChange, className = "" }) => {
2916
+ const [isOpen, setIsOpen] = useState(false);
2917
+ const [dropdownStyle, setDropdownStyle] = useState({});
2918
+ const containerRef = useRef(null);
2919
+ const selectedOption = options.find((opt) => opt.value === value);
2920
+ const handleOpen = () => {
2921
+ if (!isOpen && containerRef.current) {
2922
+ const rect = containerRef.current.getBoundingClientRect();
2923
+ setDropdownStyle({
2924
+ position: "fixed",
2925
+ top: rect.bottom + 4,
2926
+ left: rect.left,
2927
+ zIndex: 2
2928
+ });
2929
+ }
2930
+ setIsOpen((prev) => !prev);
2931
+ };
2932
+ useEffect(() => {
2933
+ const handleClickOutside = (e) => {
2934
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
2935
+ setIsOpen(false);
2936
+ }
2937
+ };
2938
+ if (isOpen) {
2939
+ document.addEventListener("mousedown", handleClickOutside);
2940
+ return () => document.removeEventListener("mousedown", handleClickOutside);
2941
+ }
2942
+ }, [isOpen]);
2943
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: `rh-relative ${className}`, children: [
2944
+ /* @__PURE__ */ jsx(
2945
+ "button",
2946
+ {
2947
+ type: "button",
2948
+ onClick: handleOpen,
2949
+ className: "rh-w-full rh-h-full rh-flex rh-items-center rh-justify-between rh-py-1 rh-bg-transparent hover:rh-bg-background/50 rh-cursor-pointer rh-text-left",
2950
+ children: /* @__PURE__ */ jsx("div", { className: "rh-flex rh-items-center rh-gap-2 rh-flex-1 rh-truncate", children: /* @__PURE__ */ jsx(
2951
+ "span",
2952
+ {
2953
+ className: "rh-truncate rh-text-[14px] rh-px-2 rh-py-1 rh-rounded-xl",
2954
+ style: {
2955
+ backgroundColor: selectedOption?.backgroundColor || "transparent",
2956
+ fontFamily: "Inter, sans-serif",
2957
+ color: selectedOption?.backgroundColor ? "white" : "inherit"
2958
+ },
2959
+ children: selectedOption?.label || value
2960
+ }
2961
+ ) })
2962
+ }
2963
+ ),
2964
+ isOpen && createPortal(
2965
+ /* @__PURE__ */ jsx(
2966
+ "div",
2967
+ {
2968
+ style: {
2969
+ ...dropdownStyle,
2970
+ boxShadow: "0 10px 20px 0 rgba(0, 0, 0, 0.05)"
2971
+ },
2972
+ className: "rh-bg-surface rh-border rh-border-border rh-rounded-xs rh-max-h-60 rh-overflow-auto rh-pr-3",
2973
+ children: options.map((option) => /* @__PURE__ */ jsxs(
2974
+ "button",
2975
+ {
2976
+ type: "button",
2977
+ onMouseDown: (e) => {
2978
+ e.preventDefault();
2979
+ onChange(option.value);
2980
+ setIsOpen(false);
2981
+ },
2982
+ className: "rh-flex rh-items-center rh-gap-2 rh-px-3 rh-py-2 rh-text-left hover:rh-bg-background/50 rh-cursor-pointer",
2983
+ children: [
2984
+ /* @__PURE__ */ jsx("div", { className: "rh-w-4 rh-h-4", children: option.value === value && /* @__PURE__ */ jsx("svg", { width: "13", height: "10", viewBox: "0 0 13 10", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx(
2985
+ "path",
2986
+ {
2987
+ d: "M12.7826 1.2813L4.78255 9.2813C4.71287 9.35122 4.63008 9.4067 4.53891 9.44455C4.44775 9.48241 4.35001 9.50189 4.2513 9.50189C4.15259 9.50189 4.05485 9.48241 3.96369 9.44455C3.87252 9.4067 3.78973 9.35122 3.72005 9.2813L0.220051 5.7813C0.150286 5.71154 0.0949458 5.62871 0.0571893 5.53756C0.0194329 5.44641 1.03958e-09 5.34871 0 5.25005C-1.03958e-09 5.15139 0.0194329 5.05369 0.0571893 4.96254C0.0949458 4.87139 0.150286 4.78857 0.220051 4.7188C0.289816 4.64904 0.372638 4.5937 0.46379 4.55594C0.554942 4.51818 0.652639 4.49875 0.751301 4.49875C0.849963 4.49875 0.947659 4.51818 1.03881 4.55594C1.12996 4.5937 1.21279 4.64904 1.28255 4.7188L4.25193 7.68818L11.7213 0.220051C11.8622 0.0791546 12.0533 0 12.2526 0C12.4518 0 12.6429 0.0791546 12.7838 0.220051C12.9247 0.360947 13.0039 0.552044 13.0039 0.751301C13.0039 0.950559 12.9247 1.14165 12.7838 1.28255L12.7826 1.2813Z",
2988
+ fill: "#374151"
2989
+ }
2990
+ ) }) }),
2991
+ /* @__PURE__ */ jsx(
2992
+ "span",
2993
+ {
2994
+ className: "rh-truncate rh-p-1 rh-px-2 rh-rounded-xl rh-text-white rh-text-[14px]",
2995
+ style: {
2996
+ backgroundColor: option.backgroundColor || "transparent",
2997
+ fontFamily: "Inter, sans-serif"
2998
+ },
2999
+ children: option.label
3000
+ }
3001
+ )
3002
+ ]
3003
+ },
3004
+ option.value
3005
+ ))
3006
+ }
3007
+ ),
3008
+ document.body
3009
+ )
3010
+ ] });
3011
+ };
2914
3012
  var sizeClasses12 = {
2915
3013
  sm: { cell: "rh-px-2 rh-py-2 rh-text-xs", header: "rh-px-2 rh-py-2 rh-text-xs" },
2916
3014
  md: { cell: "rh-px-3 rh-py-3 rh-text-sm", header: "rh-px-3 rh-py-3 rh-text-xs" },
@@ -2935,6 +3033,12 @@ function TableInner({
2935
3033
  stickyHeader = false,
2936
3034
  headerStyle,
2937
3035
  headerTextClassName,
3036
+ headerTextStyle,
3037
+ bodyBackground,
3038
+ bodyTextStyle,
3039
+ rowPadding,
3040
+ addRowButton,
3041
+ onAddRow,
2938
3042
  className = "",
2939
3043
  ...rest
2940
3044
  }, ref) {
@@ -2976,34 +3080,81 @@ function TableInner({
2976
3080
  };
2977
3081
  const isEmpty = !loading && data.length === 0;
2978
3082
  const colSpan = columns.length;
2979
- return /* @__PURE__ */ jsx("div", { className: "rh-w-full rh-overflow-x-auto", children: /* @__PURE__ */ jsxs(
3083
+ const headerTextStyleInline = {
3084
+ color: headerTextStyle?.color,
3085
+ fontFamily: headerTextStyle?.fontFamily,
3086
+ fontSize: headerTextStyle?.fontSize,
3087
+ fontWeight: headerTextStyle?.fontWeight
3088
+ };
3089
+ const bodyStyleInline = {
3090
+ color: bodyTextStyle?.color,
3091
+ fontFamily: bodyTextStyle?.fontFamily,
3092
+ fontSize: bodyTextStyle?.fontSize,
3093
+ fontWeight: bodyTextStyle?.fontWeight
3094
+ };
3095
+ const getRowPaddingStyle = () => {
3096
+ if (typeof rowPadding === "string") {
3097
+ return { padding: rowPadding };
3098
+ }
3099
+ if (typeof rowPadding === "object") {
3100
+ const style = {};
3101
+ if (rowPadding.x) {
3102
+ style.paddingLeft = rowPadding.x;
3103
+ style.paddingRight = rowPadding.x;
3104
+ }
3105
+ if (rowPadding.y) {
3106
+ style.paddingTop = rowPadding.y;
3107
+ style.paddingBottom = rowPadding.y;
3108
+ }
3109
+ return style;
3110
+ }
3111
+ return {};
3112
+ };
3113
+ const rowPaddingStyle = getRowPaddingStyle();
3114
+ return /* @__PURE__ */ jsx("div", { className: "rh-w-full rh-rounded rh-overflow-hidden", children: /* @__PURE__ */ jsxs(
2980
3115
  "table",
2981
3116
  {
2982
3117
  ref,
3118
+ style: { backgroundColor: bodyBackground },
2983
3119
  className: ["rh-w-full rh-border-collapse rh-font-body", className].filter(Boolean).join(" "),
2984
3120
  ...rest,
2985
3121
  children: [
2986
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { className: "rh-border-b rh-border-border", style: headerStyle, children: columns.map((column) => /* @__PURE__ */ jsx(
2987
- "th",
3122
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx(
3123
+ "tr",
2988
3124
  {
2989
- scope: "col",
2990
- style: { width: column.width },
2991
- className: [
2992
- sizeClasses12[size].header,
2993
- alignClasses[column.align || "left"],
2994
- `rh-font-semibold rh-whitespace-nowrap ${headerTextClassName || "rh-text-text-muted"}`,
2995
- stickyHeader ? "rh-sticky rh-top-0 rh-bg-surface rh-z-10" : "",
2996
- column.sortable ? "rh-cursor-pointer rh-select-none hover:rh-text-text" : ""
2997
- ].filter(Boolean).join(" "),
2998
- onClick: () => handleSort(column),
2999
- children: /* @__PURE__ */ jsxs("span", { className: "rh-inline-flex rh-items-center", children: [
3000
- column.header,
3001
- renderSortIcon(column)
3002
- ] })
3003
- },
3004
- column.key
3005
- )) }) }),
3006
- /* @__PURE__ */ jsxs("tbody", { children: [
3125
+ className: "rh-border-b rh-border-border",
3126
+ style: {
3127
+ backgroundColor: headerStyle?.backgroundColor,
3128
+ height: headerStyle?.height,
3129
+ border: headerStyle?.border
3130
+ },
3131
+ children: columns.map((column) => /* @__PURE__ */ jsx(
3132
+ "th",
3133
+ {
3134
+ scope: "col",
3135
+ style: {
3136
+ width: column.width,
3137
+ maxWidth: column.maxWidth,
3138
+ ...rowPaddingStyle
3139
+ },
3140
+ className: [
3141
+ rowPadding ? "" : sizeClasses12[size].header,
3142
+ alignClasses[column.align || "left"],
3143
+ `rh-font-semibold rh-whitespace-nowrap ${headerTextClassName || "rh-text-text-muted"}`,
3144
+ stickyHeader ? "rh-sticky rh-top-0 rh-bg-surface rh-z-10" : "",
3145
+ column.sortable ? "rh-cursor-pointer rh-select-none hover:rh-text-text" : ""
3146
+ ].filter(Boolean).join(" "),
3147
+ onClick: () => handleSort(column),
3148
+ children: /* @__PURE__ */ jsxs("span", { className: "rh-inline-flex rh-items-center", style: headerTextStyleInline, children: [
3149
+ column.header,
3150
+ renderSortIcon(column)
3151
+ ] })
3152
+ },
3153
+ column.key
3154
+ ))
3155
+ }
3156
+ ) }),
3157
+ /* @__PURE__ */ jsxs("tbody", { style: { backgroundColor: bodyBackground }, children: [
3007
3158
  loading && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan, className: "rh-text-center rh-py-8", children: loadingContent || /* @__PURE__ */ jsxs("div", { className: "rh-flex rh-items-center rh-justify-center rh-gap-2 rh-text-text-muted", children: [
3008
3159
  /* @__PURE__ */ jsxs(
3009
3160
  "svg",
@@ -3041,6 +3192,7 @@ function TableInner({
3041
3192
  !loading && data.map((row, index) => /* @__PURE__ */ jsx(
3042
3193
  "tr",
3043
3194
  {
3195
+ style: bodyStyleInline,
3044
3196
  className: [
3045
3197
  "rh-border-b rh-border-border rh-transition-colors",
3046
3198
  "hover:rh-bg-background",
@@ -3049,18 +3201,56 @@ function TableInner({
3049
3201
  children: columns.map((column) => /* @__PURE__ */ jsx(
3050
3202
  "td",
3051
3203
  {
3204
+ style: { width: column.width, maxWidth: column.maxWidth, ...rowPaddingStyle },
3052
3205
  className: [
3053
- sizeClasses12[size].cell,
3206
+ rowPadding ? "" : sizeClasses12[size].cell,
3054
3207
  alignClasses[column.align || "left"],
3055
3208
  "rh-text-text"
3056
3209
  ].filter(Boolean).join(" "),
3057
- children: column.render(row, index)
3210
+ children: /* @__PURE__ */ jsxs("div", { className: "rh-flex rh-items-center rh-justify-between rh-gap-2", children: [
3211
+ column.editable && column.choices && column.editableValue ? /* @__PURE__ */ jsx(
3212
+ CustomSelect,
3213
+ {
3214
+ options: column.choices,
3215
+ value: column.editableValue(row),
3216
+ onChange: (value) => column.onEditChange?.(row, index, value),
3217
+ className: "rh-w-full rh-h-full"
3218
+ }
3219
+ ) : /* @__PURE__ */ jsx("span", { children: column.render(row, index) }),
3220
+ column.actionIcon && /* @__PURE__ */ jsx(
3221
+ "span",
3222
+ {
3223
+ className: "rh-cursor-pointer hover:rh-bg-background/50 rh-p-1 rh-rounded",
3224
+ onClick: (e) => {
3225
+ e.stopPropagation();
3226
+ column.actionIcon?.onClick(row, index);
3227
+ },
3228
+ children: column.actionIcon.icon
3229
+ }
3230
+ )
3231
+ ] })
3058
3232
  },
3059
3233
  column.key
3060
3234
  ))
3061
3235
  },
3062
3236
  rowKey(row, index)
3063
- ))
3237
+ )),
3238
+ addRowButton && !loading && /* @__PURE__ */ jsx("tr", { className: "rh-border-border hover:rh-bg-background/100 rh-rounde-lg", children: /* @__PURE__ */ jsx(
3239
+ "td",
3240
+ {
3241
+ colSpan,
3242
+ style: rowPaddingStyle,
3243
+ className: [
3244
+ rowPadding ? "" : sizeClasses12[size].cell,
3245
+ "rh-text-center rh-cursor-pointer rh-text-[#9CA3AF] rh-font-medium"
3246
+ ].filter(Boolean).join(" "),
3247
+ onClick: onAddRow,
3248
+ children: /* @__PURE__ */ jsxs("div", { className: "rh-flex rh-items-center rh-justify-center rh-gap-2 rh-h-6 rh-font-bold rh-text-sm", children: [
3249
+ addRowButton.icon,
3250
+ addRowButton.text
3251
+ ] })
3252
+ }
3253
+ ) })
3064
3254
  ] })
3065
3255
  ]
3066
3256
  }