elseware-ui 2.36.4 → 2.36.6

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
@@ -21040,16 +21040,70 @@ function UnderConstructionBanner({
21040
21040
  }) {
21041
21041
  return /* @__PURE__ */ jsx("div", { className: "my-5", children: /* @__PURE__ */ jsx(Info_default, { children: text ? text : "This component is currently under construction and will be made available soon" }) });
21042
21042
  }
21043
+ function AsyncStateCard({
21044
+ type,
21045
+ title,
21046
+ message,
21047
+ actionText,
21048
+ actionLoading,
21049
+ onAction,
21050
+ className
21051
+ }) {
21052
+ const isError = type === "error";
21053
+ return /* @__PURE__ */ jsx(
21054
+ "div",
21055
+ {
21056
+ className: cn(
21057
+ "flex min-h-[220px] w-full items-center justify-center rounded-xl border p-6",
21058
+ "border-eui-dark-300/10 bg-white/70 shadow-sm",
21059
+ "dark:border-eui-light-400/10 dark:bg-eui-dark-900/40",
21060
+ className
21061
+ ),
21062
+ children: /* @__PURE__ */ jsxs("div", { className: "flex max-w-md flex-col items-center gap-4 text-center", children: [
21063
+ /* @__PURE__ */ jsx(
21064
+ "div",
21065
+ {
21066
+ className: cn(
21067
+ "flex h-12 w-12 items-center justify-center rounded-full text-xl font-bold",
21068
+ isError ? "bg-eui-danger-500/10 text-eui-danger-500" : "bg-eui-dark-500/10 text-eui-dark-500 dark:bg-eui-light-500/10 dark:text-eui-light-400"
21069
+ ),
21070
+ children: isError ? "!" : "\u2013"
21071
+ }
21072
+ ),
21073
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
21074
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-eui-dark-900 dark:text-eui-light-50", children: title }),
21075
+ isError ? /* @__PURE__ */ jsx(FormResponse_default, { text: message, variant: "danger" }) : /* @__PURE__ */ jsx("p", { className: "text-sm text-eui-dark-500 dark:text-eui-light-400", children: message })
21076
+ ] }),
21077
+ onAction && actionText && /* @__PURE__ */ jsx(
21078
+ Button_default,
21079
+ {
21080
+ type: "button",
21081
+ text: actionText,
21082
+ loading: actionLoading,
21083
+ disabled: actionLoading,
21084
+ onClick: onAction,
21085
+ variant: isError ? "danger" : "primary",
21086
+ appearance: "solid",
21087
+ size: "sm"
21088
+ }
21089
+ )
21090
+ ] })
21091
+ }
21092
+ );
21093
+ }
21094
+ var AsyncStateCard_default = React2.memo(AsyncStateCard);
21095
+
21096
+ // src/components/utils/async-component-wrapper/asyncError.utils.ts
21043
21097
  var getDefaultErrorMessage = (error) => {
21044
21098
  if (!error) return "Something went wrong.";
21045
21099
  if (typeof error === "string") return error;
21046
21100
  if (error instanceof Error) return error.message;
21047
21101
  if (typeof error === "object") {
21048
21102
  const anyErr = error;
21049
- if (anyErr?.data?.message && typeof anyErr.data.message === "string") {
21103
+ if (typeof anyErr?.data?.message === "string") {
21050
21104
  return anyErr.data.message;
21051
21105
  }
21052
- if (anyErr?.message && typeof anyErr.message === "string") {
21106
+ if (typeof anyErr?.message === "string") {
21053
21107
  return anyErr.message;
21054
21108
  }
21055
21109
  if (anyErr?.status) {
@@ -21065,20 +21119,118 @@ var getDefaultErrorMessage = (error) => {
21065
21119
  };
21066
21120
  function AsyncComponentWrapper({
21067
21121
  children,
21068
- isLoading,
21069
- isSuccess = true,
21070
- isError,
21122
+ isLoading = false,
21123
+ isFetching = false,
21124
+ isSuccess,
21125
+ isError = false,
21126
+ isUninitialized = false,
21071
21127
  error,
21072
- errorFormatter
21128
+ isEmpty = false,
21129
+ loadingText = "Loading...",
21130
+ fetchingText = "Updating...",
21131
+ emptyTitle = "No data found",
21132
+ emptyText = "No data available.",
21133
+ errorTitle = "Something went wrong",
21134
+ retryText = "Retry",
21135
+ loadingType = "spinner",
21136
+ skeletonCount = 3,
21137
+ skeletonClassName = "h-24 w-full rounded-md",
21138
+ skeletonWrapperClassName = "flex flex-col gap-3 py-4",
21139
+ spinnerProps,
21140
+ fetchingSpinnerProps,
21141
+ loadingFallback,
21142
+ emptyFallback,
21143
+ errorFallback,
21144
+ showFetchingIndicator = true,
21145
+ onRetry,
21146
+ errorFormatter,
21147
+ className,
21148
+ contentClassName,
21149
+ stateClassName
21073
21150
  }) {
21074
- const errorMessage = isError && error ? errorFormatter ? errorFormatter(error) : getDefaultErrorMessage(error) : void 0;
21075
- return /* @__PURE__ */ jsxs("div", { children: [
21076
- isLoading && /* @__PURE__ */ jsx("div", { className: "flex w-full py-10 items-center justify-center", children: /* @__PURE__ */ jsx(AiOutlineLoading, { className: "animate-spin" }) }),
21077
- isError && errorMessage && /* @__PURE__ */ jsx("div", { className: "p-5", children: /* @__PURE__ */ jsx(FormResponse_default, { text: errorMessage, variant: "danger" }) }),
21078
- !isLoading && !isError && isSuccess && /* @__PURE__ */ jsx("div", { children })
21151
+ const errorMessage = useMemo(() => {
21152
+ if (!isError) return "";
21153
+ return errorFormatter ? errorFormatter(error) : getDefaultErrorMessage(error);
21154
+ }, [isError, error, errorFormatter]);
21155
+ const hasSuccess = isSuccess ?? (!isLoading && !isError && !isUninitialized);
21156
+ const renderLoading = () => {
21157
+ if (loadingFallback) return loadingFallback;
21158
+ if (loadingType === "skeleton") {
21159
+ return /* @__PURE__ */ jsx("div", { className: cn(skeletonWrapperClassName), children: Array.from({ length: skeletonCount }).map((_, index) => /* @__PURE__ */ jsx(Skeleton, { className: skeletonClassName }, index)) });
21160
+ }
21161
+ return /* @__PURE__ */ jsx(
21162
+ Spinner_default,
21163
+ {
21164
+ centered: true,
21165
+ label: loadingText,
21166
+ type: "bars",
21167
+ size: "md",
21168
+ variant: "primary",
21169
+ ...spinnerProps
21170
+ }
21171
+ );
21172
+ };
21173
+ const renderError = () => {
21174
+ if (typeof errorFallback === "function") {
21175
+ return errorFallback(errorMessage);
21176
+ }
21177
+ if (errorFallback) return errorFallback;
21178
+ return /* @__PURE__ */ jsx(
21179
+ AsyncStateCard_default,
21180
+ {
21181
+ type: "error",
21182
+ title: errorTitle,
21183
+ message: errorMessage,
21184
+ actionText: onRetry ? retryText : void 0,
21185
+ actionLoading: isFetching,
21186
+ onAction: onRetry,
21187
+ className: stateClassName
21188
+ }
21189
+ );
21190
+ };
21191
+ const renderEmpty = () => {
21192
+ if (emptyFallback) return emptyFallback;
21193
+ return /* @__PURE__ */ jsx(
21194
+ AsyncStateCard_default,
21195
+ {
21196
+ type: "empty",
21197
+ title: emptyTitle,
21198
+ message: emptyText,
21199
+ className: stateClassName
21200
+ }
21201
+ );
21202
+ };
21203
+ if (isLoading) {
21204
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderLoading() });
21205
+ }
21206
+ if (isError) {
21207
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderError() });
21208
+ }
21209
+ if (hasSuccess && isEmpty) {
21210
+ return /* @__PURE__ */ jsx("div", { className, "aria-live": "polite", children: renderEmpty() });
21211
+ }
21212
+ if (!hasSuccess) {
21213
+ return null;
21214
+ }
21215
+ return /* @__PURE__ */ jsxs("div", { className, children: [
21216
+ showFetchingIndicator && isFetching && /* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center gap-2 text-sm text-eui-dark-500 dark:text-eui-light-400", children: [
21217
+ /* @__PURE__ */ jsx(
21218
+ Spinner_default,
21219
+ {
21220
+ size: "xs",
21221
+ type: "bars",
21222
+ variant: "primary",
21223
+ showLabel: false,
21224
+ ariaLabel: fetchingText,
21225
+ ...fetchingSpinnerProps
21226
+ }
21227
+ ),
21228
+ /* @__PURE__ */ jsx("span", { children: fetchingText })
21229
+ ] }),
21230
+ /* @__PURE__ */ jsx("div", { className: cn(contentClassName), children })
21079
21231
  ] });
21080
21232
  }
21081
- var AsyncComponentWrapper_default = AsyncComponentWrapper;
21233
+ var AsyncComponentWrapper_default = React2.memo(AsyncComponentWrapper);
21082
21234
  function Modal({
21083
21235
  title,
21084
21236
  show = false,