@rehagro/ui 1.0.45 → 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
 
@@ -1099,6 +1100,7 @@ var getSubtitleClassName = (subtitle) => subtitle.trim() === "*" ? "rh-text-dang
1099
1100
  var TextInput = forwardRef(function TextInput2({
1100
1101
  label,
1101
1102
  labelWeight = "medium",
1103
+ labelColor = "#080B12",
1102
1104
  subtitle,
1103
1105
  status = "default",
1104
1106
  size = "md",
@@ -1125,7 +1127,14 @@ var TextInput = forwardRef(function TextInput2({
1125
1127
  className: ["rh-flex rh-flex-col rh-gap-[0.5rem] rh-font-body", wrapperClassName].filter(Boolean).join(" "),
1126
1128
  children: [
1127
1129
  label && /* @__PURE__ */ jsxs("label", { htmlFor: inputId, className: "rh-flex rh-items-baseline rh-gap-1", children: [
1128
- /* @__PURE__ */ jsx("span", { className: `rh-text-sm ${labelWeightClasses[labelWeight]} rh-text-text`, children: label }),
1130
+ /* @__PURE__ */ jsx(
1131
+ "span",
1132
+ {
1133
+ className: `rh-text-sm ${labelWeightClasses[labelWeight]}`,
1134
+ style: { color: labelColor },
1135
+ children: label
1136
+ }
1137
+ ),
1129
1138
  subtitle && /* @__PURE__ */ jsx("span", { className: `rh-text-sm ${getSubtitleClassName(subtitle)}`, children: subtitle })
1130
1139
  ] }),
1131
1140
  /* @__PURE__ */ jsxs(
@@ -1180,8 +1189,9 @@ var TextInput = forwardRef(function TextInput2({
1180
1189
  "span",
1181
1190
  {
1182
1191
  className: [
1183
- "rh-inline-flex rh-shrink-0 rh-text-text-muted",
1184
- iconSizeClasses[size]
1192
+ "rh-inline-flex rh-shrink-0 rh-items-center rh-justify-center rh-whitespace-nowrap rh-text-text-muted",
1193
+ iconSizeClasses[size],
1194
+ "rh-w-auto rh-min-w-fit"
1185
1195
  ].join(" "),
1186
1196
  "aria-hidden": "true",
1187
1197
  children: rightIcon
@@ -2902,6 +2912,103 @@ var Spinner = forwardRef(function Spinner2({ size = "md", color = "primary", lab
2902
2912
  }
2903
2913
  );
2904
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
+ };
2905
3012
  var sizeClasses12 = {
2906
3013
  sm: { cell: "rh-px-2 rh-py-2 rh-text-xs", header: "rh-px-2 rh-py-2 rh-text-xs" },
2907
3014
  md: { cell: "rh-px-3 rh-py-3 rh-text-sm", header: "rh-px-3 rh-py-3 rh-text-xs" },
@@ -2926,6 +3033,12 @@ function TableInner({
2926
3033
  stickyHeader = false,
2927
3034
  headerStyle,
2928
3035
  headerTextClassName,
3036
+ headerTextStyle,
3037
+ bodyBackground,
3038
+ bodyTextStyle,
3039
+ rowPadding,
3040
+ addRowButton,
3041
+ onAddRow,
2929
3042
  className = "",
2930
3043
  ...rest
2931
3044
  }, ref) {
@@ -2967,34 +3080,81 @@ function TableInner({
2967
3080
  };
2968
3081
  const isEmpty = !loading && data.length === 0;
2969
3082
  const colSpan = columns.length;
2970
- 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(
2971
3115
  "table",
2972
3116
  {
2973
3117
  ref,
3118
+ style: { backgroundColor: bodyBackground },
2974
3119
  className: ["rh-w-full rh-border-collapse rh-font-body", className].filter(Boolean).join(" "),
2975
3120
  ...rest,
2976
3121
  children: [
2977
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { className: "rh-border-b rh-border-border", style: headerStyle, children: columns.map((column) => /* @__PURE__ */ jsx(
2978
- "th",
3122
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx(
3123
+ "tr",
2979
3124
  {
2980
- scope: "col",
2981
- style: { width: column.width },
2982
- className: [
2983
- sizeClasses12[size].header,
2984
- alignClasses[column.align || "left"],
2985
- `rh-font-semibold rh-whitespace-nowrap ${headerTextClassName || "rh-text-text-muted"}`,
2986
- stickyHeader ? "rh-sticky rh-top-0 rh-bg-surface rh-z-10" : "",
2987
- column.sortable ? "rh-cursor-pointer rh-select-none hover:rh-text-text" : ""
2988
- ].filter(Boolean).join(" "),
2989
- onClick: () => handleSort(column),
2990
- children: /* @__PURE__ */ jsxs("span", { className: "rh-inline-flex rh-items-center", children: [
2991
- column.header,
2992
- renderSortIcon(column)
2993
- ] })
2994
- },
2995
- column.key
2996
- )) }) }),
2997
- /* @__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: [
2998
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: [
2999
3159
  /* @__PURE__ */ jsxs(
3000
3160
  "svg",
@@ -3032,6 +3192,7 @@ function TableInner({
3032
3192
  !loading && data.map((row, index) => /* @__PURE__ */ jsx(
3033
3193
  "tr",
3034
3194
  {
3195
+ style: bodyStyleInline,
3035
3196
  className: [
3036
3197
  "rh-border-b rh-border-border rh-transition-colors",
3037
3198
  "hover:rh-bg-background",
@@ -3040,18 +3201,56 @@ function TableInner({
3040
3201
  children: columns.map((column) => /* @__PURE__ */ jsx(
3041
3202
  "td",
3042
3203
  {
3204
+ style: { width: column.width, maxWidth: column.maxWidth, ...rowPaddingStyle },
3043
3205
  className: [
3044
- sizeClasses12[size].cell,
3206
+ rowPadding ? "" : sizeClasses12[size].cell,
3045
3207
  alignClasses[column.align || "left"],
3046
3208
  "rh-text-text"
3047
3209
  ].filter(Boolean).join(" "),
3048
- 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
+ ] })
3049
3232
  },
3050
3233
  column.key
3051
3234
  ))
3052
3235
  },
3053
3236
  rowKey(row, index)
3054
- ))
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
+ ) })
3055
3254
  ] })
3056
3255
  ]
3057
3256
  }