@oniratec/onira-react-ui 1.2.10 → 1.2.12

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.d.ts CHANGED
@@ -18,6 +18,8 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
18
18
  import { UseFormReturn } from 'react-hook-form';
19
19
  import { z } from 'zod';
20
20
 
21
+ export declare function AsyncSelect<T>({ value, onValueChange, placeholder, searchPlaceholder, disabled, hasError, minChars, debounceMs, fetcher, getOptionValue, getOptionLabel, emptyLabel, loadingLabel, emptyActionLabel, onEmptyActionClick, contentClassName, triggerClassName, }: Props<T>): JSX.Element;
22
+
21
23
  /** =========================
22
24
  * Async select field
23
25
  * ========================= */
@@ -55,7 +57,7 @@ export declare type AsyncSelectFilter<T> = BaseFilter & {
55
57
  optionsCache?: AsyncSelectOption[];
56
58
  };
57
59
 
58
- declare type AsyncSelectOption = {
60
+ export declare type AsyncSelectOption = {
59
61
  value: string;
60
62
  label: string;
61
63
  meta?: unknown;
@@ -175,7 +177,7 @@ declare type CustomField<T extends FieldValues> = BaseFieldCommon<T> & {
175
177
  }) => ReactNode;
176
178
  };
177
179
 
178
- export declare function DataTable<T>({ columns, data, enableSorting, sortState, defaultSortState, onSortChange, unsortedIcon, sortMode, manualSorting, emptyContent, loadingContent, errorContent, isLoading, }: Props<T>): JSX.Element;
180
+ export declare function DataTable<T>({ columns, data, enableSorting, sortState, defaultSortState, onSortChange, unsortedIcon, sortMode, manualSorting, emptyContent, loadingContent, errorContent, isLoading, }: Props_2<T>): JSX.Element;
179
181
 
180
182
  declare type DataTableProps<T> = Parameters<typeof DataTable<T>>[0];
181
183
 
@@ -216,6 +218,8 @@ export declare const DropdownMenuSubTrigger: React_2.ForwardRefExoticComponent<O
216
218
 
217
219
  export declare const DropdownMenuTrigger: React_2.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuTriggerProps & React_2.RefAttributes<HTMLButtonElement>>;
218
220
 
221
+ declare type Fetcher<T> = (query: string) => Promise<T[]>;
222
+
219
223
  export declare function Field({ className, error, required, ...props }: FieldProps): JSX.Element;
220
224
 
221
225
  declare interface FieldContextValue {
@@ -250,6 +254,7 @@ declare type FileUploadField<T extends FieldValues> = BaseFieldCommon<T> & {
250
254
  helperText?: string;
251
255
  allowDrop?: boolean;
252
256
  placeholder?: string;
257
+ defaultPreviewUrl?: string;
253
258
  };
254
259
 
255
260
  export declare type FileUploadProps = {
@@ -334,7 +339,7 @@ export declare interface FormFactoryConfig<TFormModel extends FieldValues, TEnti
334
339
  crossRules?: CrossRule<TFormModel>[];
335
340
  }
336
341
 
337
- export declare function FormFactoryRenderer<TFormModel extends FieldValues, TEntity>({ config, form, onSubmitAction, handleErrors, submitLabel, maxWidthClass, children, }: Props_4<TFormModel, TEntity>): JSX.Element;
342
+ export declare function FormFactoryRenderer<TFormModel extends FieldValues, TEntity>({ config, form, onSubmitAction, handleErrors, submitLabel, maxWidthClass, children, }: Props_5<TFormModel, TEntity>): JSX.Element;
338
343
 
339
344
  declare type FormFactoryRendererProps<TFormModel extends FieldValues, TEntity> = Parameters<typeof FormFactoryRenderer<TFormModel, TEntity>>[0];
340
345
 
@@ -391,9 +396,9 @@ declare type Option_2<T extends string | number = string> = {
391
396
  label: string;
392
397
  };
393
398
 
394
- export declare const PageSizeSelector: ({ value, onChange, options }: Props_2) => JSX.Element;
399
+ export declare const PageSizeSelector: ({ value, onChange, options }: Props_3) => JSX.Element;
395
400
 
396
- export declare const Pagination: ({ page, pageSize, total, onPageChange, onPageSizeChange }: Props_3) => JSX.Element;
401
+ export declare const Pagination: ({ page, pageSize, total, onPageChange, onPageSizeChange }: Props_4) => JSX.Element;
397
402
 
398
403
  export declare const PasswordInput: ForwardRefExoticComponent<PasswordInputProps & RefAttributes<HTMLInputElement>>;
399
404
 
@@ -415,7 +420,29 @@ declare interface ProfileAvatar_2 {
415
420
 
416
421
  declare const ProfileAvatar: FC<ProfileAvatar_2>;
417
422
 
418
- declare interface Props<T> {
423
+ declare type Props<T> = {
424
+ value?: string;
425
+ onValueChange: (value: string) => void;
426
+ placeholder?: string;
427
+ searchPlaceholder?: string;
428
+ disabled?: boolean;
429
+ hasError?: boolean;
430
+ minChars?: number;
431
+ debounceMs?: number;
432
+ fetcher: Fetcher<T>;
433
+ getOptionValue: (item: T) => string;
434
+ getOptionLabel: (item: T) => string;
435
+ emptyLabel?: string;
436
+ loadingLabel?: string;
437
+ /** CTA opcional cuando no hay resultados */
438
+ emptyActionLabel?: string;
439
+ onEmptyActionClick?: () => void;
440
+ /** Si quieres controlar ancho del popover */
441
+ contentClassName?: string;
442
+ triggerClassName?: string;
443
+ };
444
+
445
+ declare interface Props_2<T> {
419
446
  columns: Column<T>[];
420
447
  data: T[];
421
448
  enableSorting?: boolean;
@@ -431,13 +458,13 @@ declare interface Props<T> {
431
458
  isLoading?: boolean;
432
459
  }
433
460
 
434
- declare interface Props_2 {
461
+ declare interface Props_3 {
435
462
  value: number;
436
463
  onChange: (size: number) => void;
437
464
  options?: number[];
438
465
  }
439
466
 
440
- declare interface Props_3 {
467
+ declare interface Props_4 {
441
468
  page: number;
442
469
  pageSize: number;
443
470
  total: number;
@@ -445,7 +472,7 @@ declare interface Props_3 {
445
472
  onPageSizeChange: (size: number) => void;
446
473
  }
447
474
 
448
- declare interface Props_4<TFormModel extends FieldValues, TEntity> {
475
+ declare interface Props_5<TFormModel extends FieldValues, TEntity> {
449
476
  config: FormFactoryConfig<TFormModel, TEntity>;
450
477
  form: UseFormReturn<TFormModel>;
451
478
  onSubmitAction: (data: TFormModel) => void | Promise<void>;
package/dist/index.js CHANGED
@@ -8977,6 +8977,152 @@ const SelectItem = React.forwardRef(({ className: e, children: t, ...r }, i) =>
8977
8977
  /* @__PURE__ */ jsx(SelectPrimitive.ItemIndicator, { className: "oniratec-select__indicator", children: /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) })
8978
8978
  ] }));
8979
8979
  SelectItem.displayName = "SelectItem";
8980
+ function useDebouncedValue(e, t) {
8981
+ const [r, i] = React.useState(e);
8982
+ return React.useEffect(() => {
8983
+ const s = setTimeout(() => i(e), t);
8984
+ return () => clearTimeout(s);
8985
+ }, [e, t]), r;
8986
+ }
8987
+ function AsyncSelect({
8988
+ value: e,
8989
+ onValueChange: t,
8990
+ placeholder: r = "Seleccionar",
8991
+ searchPlaceholder: i = "Buscar...",
8992
+ disabled: s,
8993
+ hasError: a,
8994
+ minChars: n = 2,
8995
+ debounceMs: l = 300,
8996
+ fetcher: h,
8997
+ getOptionValue: d,
8998
+ getOptionLabel: V,
8999
+ emptyLabel: K = "Sin resultados",
9000
+ loadingLabel: y = "Buscando...",
9001
+ emptyActionLabel: q,
9002
+ onEmptyActionClick: H,
9003
+ contentClassName: G,
9004
+ triggerClassName: te
9005
+ }) {
9006
+ const [M, j] = React.useState(!1), [F, Z] = React.useState(""), [J, ee] = React.useState(!1), [ie, se] = React.useState([]), [le, ue] = React.useState(""), de = useDebouncedValue(F, l), fe = de.trim().length >= n, pe = React.useRef(null);
9007
+ React.useEffect(() => {
9008
+ const he = (re) => {
9009
+ pe.current && (pe.current.contains(re.target) || j(!1));
9010
+ };
9011
+ return document.addEventListener("mousedown", he), () => document.removeEventListener("mousedown", he);
9012
+ }, []), React.useEffect(() => {
9013
+ let he = !0;
9014
+ return (async () => {
9015
+ if (M) {
9016
+ if (!fe) {
9017
+ se([]);
9018
+ return;
9019
+ }
9020
+ ee(!0);
9021
+ try {
9022
+ const ae = await h(de.trim());
9023
+ if (!he) return;
9024
+ se(ae ?? []);
9025
+ } finally {
9026
+ he && ee(!1);
9027
+ }
9028
+ }
9029
+ })(), () => {
9030
+ he = !1;
9031
+ };
9032
+ }, [M, de, fe, h]), React.useEffect(() => {
9033
+ if (!e) {
9034
+ ue("");
9035
+ return;
9036
+ }
9037
+ const he = ie.find((re) => d(re) === e);
9038
+ he && ue(V(he));
9039
+ }, [e, ie, d, V]);
9040
+ const ve = le || r;
9041
+ return /* @__PURE__ */ jsxs("div", { ref: pe, className: "relative w-full", children: [
9042
+ /* @__PURE__ */ jsxs(
9043
+ "button",
9044
+ {
9045
+ type: "button",
9046
+ disabled: s,
9047
+ "aria-invalid": a ? "true" : "false",
9048
+ onClick: () => j((he) => !he),
9049
+ className: cn(
9050
+ "oniratec-async-select__trigger",
9051
+ a && "oniratec-async-select__trigger--error",
9052
+ te
9053
+ ),
9054
+ children: [
9055
+ /* @__PURE__ */ jsx(
9056
+ "span",
9057
+ {
9058
+ className: cn(
9059
+ "oniratec-async-select__value",
9060
+ !le && "oniratec-async-select__value--placeholder"
9061
+ ),
9062
+ children: ve
9063
+ }
9064
+ ),
9065
+ /* @__PURE__ */ jsx(ChevronDown, { className: cn("oniratec-async-select__chevron", M && "rotate-180") })
9066
+ ]
9067
+ }
9068
+ ),
9069
+ M && /* @__PURE__ */ jsxs("div", { className: cn("oniratec-async-select", G), children: [
9070
+ /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__search", children: [
9071
+ /* @__PURE__ */ jsx(
9072
+ "input",
9073
+ {
9074
+ className: "oniratec-async-select__search-input",
9075
+ value: F,
9076
+ onChange: (he) => Z(he.target.value),
9077
+ placeholder: i,
9078
+ autoFocus: !0
9079
+ }
9080
+ ),
9081
+ J && /* @__PURE__ */ jsx(Loader2, { className: "oniratec-async-select__loader" })
9082
+ ] }),
9083
+ /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__viewport", children: [
9084
+ !fe && /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__hint", children: [
9085
+ "Escribe al menos ",
9086
+ n,
9087
+ " caracteres"
9088
+ ] }),
9089
+ fe && J && /* @__PURE__ */ jsx("div", { className: "oniratec-async-select__hint", children: y }),
9090
+ fe && !J && ie.length === 0 && /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__empty", children: [
9091
+ /* @__PURE__ */ jsx("span", { children: K }),
9092
+ q && H && /* @__PURE__ */ jsx(
9093
+ "button",
9094
+ {
9095
+ type: "button",
9096
+ className: "oniratec-async-select__empty-action",
9097
+ onClick: H,
9098
+ children: q
9099
+ }
9100
+ )
9101
+ ] }),
9102
+ ie.length > 0 && /* @__PURE__ */ jsx("ul", { className: "oniratec-async-select__list", children: ie.map((he) => {
9103
+ const re = d(he), ae = V(he), W = re === e;
9104
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
9105
+ "button",
9106
+ {
9107
+ type: "button",
9108
+ className: cn(
9109
+ "oniratec-async-select__item",
9110
+ W && "oniratec-async-select__item--selected"
9111
+ ),
9112
+ onClick: () => {
9113
+ t(re), ue(ae), j(!1), Z("");
9114
+ },
9115
+ children: [
9116
+ /* @__PURE__ */ jsx("span", { children: ae }),
9117
+ W && /* @__PURE__ */ jsx("span", { className: "oniratec-async-select__indicator", children: /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) })
9118
+ ]
9119
+ }
9120
+ ) }, re);
9121
+ }) })
9122
+ ] })
9123
+ ] })
9124
+ ] });
9125
+ }
8980
9126
  function Skeleton({ className: e }) {
8981
9127
  return /* @__PURE__ */ jsx(
8982
9128
  "div",
@@ -9188,152 +9334,6 @@ const DEFAULT_PAGE_SIZES = [5, 10, 25, 50], PageSizeSelector = ({ value: e, onCh
9188
9334
  ] })
9189
9335
  ] });
9190
9336
  };
9191
- function useDebouncedValue(e, t) {
9192
- const [r, i] = React.useState(e);
9193
- return React.useEffect(() => {
9194
- const s = setTimeout(() => i(e), t);
9195
- return () => clearTimeout(s);
9196
- }, [e, t]), r;
9197
- }
9198
- function AsyncSelect({
9199
- value: e,
9200
- onValueChange: t,
9201
- placeholder: r = "Seleccionar",
9202
- searchPlaceholder: i = "Buscar...",
9203
- disabled: s,
9204
- hasError: a,
9205
- minChars: n = 2,
9206
- debounceMs: l = 300,
9207
- fetcher: h,
9208
- getOptionValue: d,
9209
- getOptionLabel: V,
9210
- emptyLabel: K = "Sin resultados",
9211
- loadingLabel: y = "Buscando...",
9212
- emptyActionLabel: q,
9213
- onEmptyActionClick: H,
9214
- contentClassName: G,
9215
- triggerClassName: te
9216
- }) {
9217
- const [M, j] = React.useState(!1), [F, Z] = React.useState(""), [J, ee] = React.useState(!1), [ie, se] = React.useState([]), [le, ue] = React.useState(""), de = useDebouncedValue(F, l), fe = de.trim().length >= n, pe = React.useRef(null);
9218
- React.useEffect(() => {
9219
- const he = (re) => {
9220
- pe.current && (pe.current.contains(re.target) || j(!1));
9221
- };
9222
- return document.addEventListener("mousedown", he), () => document.removeEventListener("mousedown", he);
9223
- }, []), React.useEffect(() => {
9224
- let he = !0;
9225
- return (async () => {
9226
- if (M) {
9227
- if (!fe) {
9228
- se([]);
9229
- return;
9230
- }
9231
- ee(!0);
9232
- try {
9233
- const ae = await h(de.trim());
9234
- if (!he) return;
9235
- se(ae ?? []);
9236
- } finally {
9237
- he && ee(!1);
9238
- }
9239
- }
9240
- })(), () => {
9241
- he = !1;
9242
- };
9243
- }, [M, de, fe, h]), React.useEffect(() => {
9244
- if (!e) {
9245
- ue("");
9246
- return;
9247
- }
9248
- const he = ie.find((re) => d(re) === e);
9249
- he && ue(V(he));
9250
- }, [e, ie, d, V]);
9251
- const ve = le || r;
9252
- return /* @__PURE__ */ jsxs("div", { ref: pe, className: "relative w-full", children: [
9253
- /* @__PURE__ */ jsxs(
9254
- "button",
9255
- {
9256
- type: "button",
9257
- disabled: s,
9258
- "aria-invalid": a ? "true" : "false",
9259
- onClick: () => j((he) => !he),
9260
- className: cn(
9261
- "oniratec-async-select__trigger",
9262
- a && "oniratec-async-select__trigger--error",
9263
- te
9264
- ),
9265
- children: [
9266
- /* @__PURE__ */ jsx(
9267
- "span",
9268
- {
9269
- className: cn(
9270
- "oniratec-async-select__value",
9271
- !le && "oniratec-async-select__value--placeholder"
9272
- ),
9273
- children: ve
9274
- }
9275
- ),
9276
- /* @__PURE__ */ jsx(ChevronDown, { className: cn("oniratec-async-select__chevron", M && "rotate-180") })
9277
- ]
9278
- }
9279
- ),
9280
- M && /* @__PURE__ */ jsxs("div", { className: cn("oniratec-async-select", G), children: [
9281
- /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__search", children: [
9282
- /* @__PURE__ */ jsx(
9283
- "input",
9284
- {
9285
- className: "oniratec-async-select__search-input",
9286
- value: F,
9287
- onChange: (he) => Z(he.target.value),
9288
- placeholder: i,
9289
- autoFocus: !0
9290
- }
9291
- ),
9292
- J && /* @__PURE__ */ jsx(Loader2, { className: "oniratec-async-select__loader" })
9293
- ] }),
9294
- /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__viewport", children: [
9295
- !fe && /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__hint", children: [
9296
- "Escribe al menos ",
9297
- n,
9298
- " caracteres"
9299
- ] }),
9300
- fe && J && /* @__PURE__ */ jsx("div", { className: "oniratec-async-select__hint", children: y }),
9301
- fe && !J && ie.length === 0 && /* @__PURE__ */ jsxs("div", { className: "oniratec-async-select__empty", children: [
9302
- /* @__PURE__ */ jsx("span", { children: K }),
9303
- q && H && /* @__PURE__ */ jsx(
9304
- "button",
9305
- {
9306
- type: "button",
9307
- className: "oniratec-async-select__empty-action",
9308
- onClick: H,
9309
- children: q
9310
- }
9311
- )
9312
- ] }),
9313
- ie.length > 0 && /* @__PURE__ */ jsx("ul", { className: "oniratec-async-select__list", children: ie.map((he) => {
9314
- const re = d(he), ae = V(he), W = re === e;
9315
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
9316
- "button",
9317
- {
9318
- type: "button",
9319
- className: cn(
9320
- "oniratec-async-select__item",
9321
- W && "oniratec-async-select__item--selected"
9322
- ),
9323
- onClick: () => {
9324
- t(re), ue(ae), j(!1), Z("");
9325
- },
9326
- children: [
9327
- /* @__PURE__ */ jsx("span", { children: ae }),
9328
- W && /* @__PURE__ */ jsx("span", { className: "oniratec-async-select__indicator", children: /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) })
9329
- ]
9330
- }
9331
- ) }, re);
9332
- }) })
9333
- ] })
9334
- ] })
9335
- ] });
9336
- }
9337
9337
  function FiltersPanel({
9338
9338
  filters: e,
9339
9339
  value: t,
@@ -12610,7 +12610,8 @@ function FieldRenderer({
12610
12610
  multiple: t.multiple,
12611
12611
  helperText: t.helperText,
12612
12612
  allowDrop: t.allowDrop,
12613
- placeholder: t.placeholder
12613
+ placeholder: t.placeholder,
12614
+ defaultPreviewUrl: t.defaultPreviewUrl
12614
12615
  }
12615
12616
  ) }),
12616
12617
  /* @__PURE__ */ jsx(FieldMessage, {})
@@ -12748,6 +12749,7 @@ function renderFiltersModal(e, t, r, i) {
12748
12749
  );
12749
12750
  }
12750
12751
  export {
12752
+ AsyncSelect,
12751
12753
  Box,
12752
12754
  Breadcrumbs,
12753
12755
  Button,