@sustaina/shared-ui 1.34.0 → 1.35.0
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.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +72 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -503,7 +503,7 @@ interface DialogAlertProps {
|
|
|
503
503
|
outlet?: React.ReactNode | null;
|
|
504
504
|
persistent?: boolean;
|
|
505
505
|
}
|
|
506
|
-
type TemplateKeys = "success.saved" | "success.deleted" | "success.removed" | "error.api_db_error" | "error.permission_denied" | "error.session_expired" | "error.user_not_found" | "error.data_not_found" | "error.data_restrict_editing" | "error.network_timeout_error" | "error.queue_full" | "error.invalid_data_format" | "error.data_linked_to_system_data" | "error.pending_workflow_conflict" | "error.invalid_incomplete_data" | "error.client_side_error" | "error.system_limitation" | "error.timeout" | "error.duplicate_data" | "error.something_went_wrong" | "confirm.delete" | "confirm.inactive" | "confirm.active" | "confirm.leave_page" | "confirm.remove" | "confirm.logout";
|
|
506
|
+
type TemplateKeys = "success.saved" | "success.deleted" | "success.removed" | "error.api_db_error" | "error.permission_denied" | "error.session_expired" | "error.user_not_found" | "error.data_not_found" | "error.data_restrict_editing" | "error.network_timeout_error" | "error.queue_full" | "error.invalid_data_format" | "error.data_linked_to_system_data" | "error.pending_workflow_conflict" | "error.invalid_incomplete_data" | "error.client_side_error" | "error.system_limitation" | "error.timeout" | "error.duplicate_data" | "error.something_went_wrong" | "confirm.delete" | "confirm.inactive" | "confirm.active" | "confirm.leave_page" | "confirm.reset_form" | "confirm.remove" | "confirm.logout";
|
|
507
507
|
type DialogAlertTemplateUnit = Omit<DialogAlertProps, "open" | "onOpenChange">;
|
|
508
508
|
type DialogAlertTemplates = Record<TemplateKeys, DialogAlertTemplateUnit>;
|
|
509
509
|
type DialogAlertI18nResource = Resource;
|
|
@@ -1458,6 +1458,10 @@ type ComboboxProps<TData extends OptionData> = React$1.AriaAttributes & Omit<Vir
|
|
|
1458
1458
|
showClear?: boolean;
|
|
1459
1459
|
onBlur?: (event: React$1.FocusEvent<HTMLButtonElement, Element>) => void;
|
|
1460
1460
|
onFocus?: (event: React$1.FocusEvent<HTMLButtonElement, Element>) => void;
|
|
1461
|
+
onClear?: (selected: string, option: VirtualizedCommandOption<TData>) => void;
|
|
1462
|
+
open?: boolean;
|
|
1463
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
1464
|
+
showValueWhenNoMatch?: boolean;
|
|
1461
1465
|
};
|
|
1462
1466
|
declare const Combobox: <TData extends OptionData>(props: ComboboxProps<TData> & React$1.RefAttributes<HTMLButtonElement>) => React$1.ReactElement | null;
|
|
1463
1467
|
|
|
@@ -1590,7 +1594,8 @@ type UseControllableStateOptions<T = any> = {
|
|
|
1590
1594
|
};
|
|
1591
1595
|
type UseControllableStateResult<T = any> = {
|
|
1592
1596
|
value: T;
|
|
1593
|
-
|
|
1597
|
+
setValue: (nextValue: T | ((prev: T) => T)) => void;
|
|
1598
|
+
isControlled: boolean;
|
|
1594
1599
|
};
|
|
1595
1600
|
declare const useControllableState: <T = any>({ defaultValue, value }: UseControllableStateOptions<T>) => UseControllableStateResult<T>;
|
|
1596
1601
|
|
package/dist/index.d.ts
CHANGED
|
@@ -503,7 +503,7 @@ interface DialogAlertProps {
|
|
|
503
503
|
outlet?: React.ReactNode | null;
|
|
504
504
|
persistent?: boolean;
|
|
505
505
|
}
|
|
506
|
-
type TemplateKeys = "success.saved" | "success.deleted" | "success.removed" | "error.api_db_error" | "error.permission_denied" | "error.session_expired" | "error.user_not_found" | "error.data_not_found" | "error.data_restrict_editing" | "error.network_timeout_error" | "error.queue_full" | "error.invalid_data_format" | "error.data_linked_to_system_data" | "error.pending_workflow_conflict" | "error.invalid_incomplete_data" | "error.client_side_error" | "error.system_limitation" | "error.timeout" | "error.duplicate_data" | "error.something_went_wrong" | "confirm.delete" | "confirm.inactive" | "confirm.active" | "confirm.leave_page" | "confirm.remove" | "confirm.logout";
|
|
506
|
+
type TemplateKeys = "success.saved" | "success.deleted" | "success.removed" | "error.api_db_error" | "error.permission_denied" | "error.session_expired" | "error.user_not_found" | "error.data_not_found" | "error.data_restrict_editing" | "error.network_timeout_error" | "error.queue_full" | "error.invalid_data_format" | "error.data_linked_to_system_data" | "error.pending_workflow_conflict" | "error.invalid_incomplete_data" | "error.client_side_error" | "error.system_limitation" | "error.timeout" | "error.duplicate_data" | "error.something_went_wrong" | "confirm.delete" | "confirm.inactive" | "confirm.active" | "confirm.leave_page" | "confirm.reset_form" | "confirm.remove" | "confirm.logout";
|
|
507
507
|
type DialogAlertTemplateUnit = Omit<DialogAlertProps, "open" | "onOpenChange">;
|
|
508
508
|
type DialogAlertTemplates = Record<TemplateKeys, DialogAlertTemplateUnit>;
|
|
509
509
|
type DialogAlertI18nResource = Resource;
|
|
@@ -1458,6 +1458,10 @@ type ComboboxProps<TData extends OptionData> = React$1.AriaAttributes & Omit<Vir
|
|
|
1458
1458
|
showClear?: boolean;
|
|
1459
1459
|
onBlur?: (event: React$1.FocusEvent<HTMLButtonElement, Element>) => void;
|
|
1460
1460
|
onFocus?: (event: React$1.FocusEvent<HTMLButtonElement, Element>) => void;
|
|
1461
|
+
onClear?: (selected: string, option: VirtualizedCommandOption<TData>) => void;
|
|
1462
|
+
open?: boolean;
|
|
1463
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
1464
|
+
showValueWhenNoMatch?: boolean;
|
|
1461
1465
|
};
|
|
1462
1466
|
declare const Combobox: <TData extends OptionData>(props: ComboboxProps<TData> & React$1.RefAttributes<HTMLButtonElement>) => React$1.ReactElement | null;
|
|
1463
1467
|
|
|
@@ -1590,7 +1594,8 @@ type UseControllableStateOptions<T = any> = {
|
|
|
1590
1594
|
};
|
|
1591
1595
|
type UseControllableStateResult<T = any> = {
|
|
1592
1596
|
value: T;
|
|
1593
|
-
|
|
1597
|
+
setValue: (nextValue: T | ((prev: T) => T)) => void;
|
|
1598
|
+
isControlled: boolean;
|
|
1594
1599
|
};
|
|
1595
1600
|
declare const useControllableState: <T = any>({ defaultValue, value }: UseControllableStateOptions<T>) => UseControllableStateResult<T>;
|
|
1596
1601
|
|
package/dist/index.js
CHANGED
|
@@ -4371,18 +4371,25 @@ var useControllableState = ({
|
|
|
4371
4371
|
defaultValue,
|
|
4372
4372
|
value
|
|
4373
4373
|
}) => {
|
|
4374
|
-
const
|
|
4374
|
+
const isControlled = typeof value !== "undefined";
|
|
4375
|
+
const [internalValue, setInternalValue] = React26__namespace.useState(() => {
|
|
4376
|
+
return isControlled ? value : defaultValue;
|
|
4377
|
+
});
|
|
4375
4378
|
React26__namespace.useEffect(() => {
|
|
4376
|
-
if (
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4379
|
+
if (!isControlled) return;
|
|
4380
|
+
setInternalValue(value);
|
|
4381
|
+
}, [isControlled, value]);
|
|
4382
|
+
const setValue = React26__namespace.useCallback(
|
|
4383
|
+
(nextValue) => {
|
|
4384
|
+
if (isControlled) return;
|
|
4385
|
+
setInternalValue(nextValue);
|
|
4386
|
+
},
|
|
4387
|
+
[isControlled]
|
|
4388
|
+
);
|
|
4383
4389
|
return {
|
|
4384
|
-
value: internalValue,
|
|
4385
|
-
|
|
4390
|
+
value: isControlled ? value : internalValue,
|
|
4391
|
+
setValue,
|
|
4392
|
+
isControlled
|
|
4386
4393
|
};
|
|
4387
4394
|
};
|
|
4388
4395
|
var useControllableState_default = useControllableState;
|
|
@@ -5542,6 +5549,11 @@ var defaultResource = {
|
|
|
5542
5549
|
description: "Unsaved changes. Do you want to leave this page?",
|
|
5543
5550
|
confirm_text: "Leave"
|
|
5544
5551
|
},
|
|
5552
|
+
"confirm.reset_form": {
|
|
5553
|
+
title: "Confirmation",
|
|
5554
|
+
description: "Unsaved changes. If you continue, all changes will be lost.",
|
|
5555
|
+
confirm_text: "Reset"
|
|
5556
|
+
},
|
|
5545
5557
|
"confirm.remove": {
|
|
5546
5558
|
title: "Confirmation",
|
|
5547
5559
|
description: "Are you sure you want to remove this item?",
|
|
@@ -5781,6 +5793,12 @@ var DIALOG_ALERT_TEMPLATES = {
|
|
|
5781
5793
|
description: "confirm.leave_page.description",
|
|
5782
5794
|
confirmText: "confirm.leave_page.confirm_text"
|
|
5783
5795
|
},
|
|
5796
|
+
"confirm.reset_form": {
|
|
5797
|
+
variant: "confirm",
|
|
5798
|
+
title: "confirm.reset_form.title",
|
|
5799
|
+
description: "confirm.reset_form.description",
|
|
5800
|
+
confirmText: "confirm.reset_form.confirm_text"
|
|
5801
|
+
},
|
|
5784
5802
|
"confirm.remove": {
|
|
5785
5803
|
variant: "confirm",
|
|
5786
5804
|
title: "confirm.remove.title",
|
|
@@ -11238,40 +11256,71 @@ var ComboboxInner = ({
|
|
|
11238
11256
|
notFoundContent,
|
|
11239
11257
|
searchPlaceholder,
|
|
11240
11258
|
showSearch,
|
|
11259
|
+
open,
|
|
11260
|
+
showValueWhenNoMatch,
|
|
11261
|
+
onOpenChange,
|
|
11262
|
+
onClear,
|
|
11241
11263
|
...props
|
|
11242
11264
|
}, ref) => {
|
|
11243
11265
|
const { getLabelField, getValueField } = useFieldNames_default({ fieldNames });
|
|
11244
|
-
const
|
|
11245
|
-
|
|
11266
|
+
const { value: openPopover, setValue: setOpenPopover } = useControllableState_default({
|
|
11267
|
+
defaultValue: false,
|
|
11268
|
+
value: open
|
|
11269
|
+
});
|
|
11270
|
+
const { value: selectedValue, setValue: setSelectedValue } = useControllableState_default({
|
|
11246
11271
|
defaultValue,
|
|
11247
11272
|
value
|
|
11248
11273
|
});
|
|
11249
|
-
const
|
|
11250
|
-
|
|
11251
|
-
const selectedOptionFound = options?.find((option) => {
|
|
11274
|
+
const currentSelectedOption = React26__namespace.useMemo(() => {
|
|
11275
|
+
return options?.find((option) => {
|
|
11252
11276
|
const optionValue = getValueField(option);
|
|
11253
11277
|
return optionValue === selectedValue;
|
|
11254
11278
|
});
|
|
11255
|
-
|
|
11256
|
-
|
|
11279
|
+
}, [getValueField, options, selectedValue]);
|
|
11280
|
+
const renderValue = React26__namespace.useMemo(() => {
|
|
11281
|
+
if (!selectedValue) return placeholder2;
|
|
11282
|
+
if (currentSelectedOption) {
|
|
11283
|
+
return getLabelField(currentSelectedOption);
|
|
11284
|
+
}
|
|
11285
|
+
if (showValueWhenNoMatch) {
|
|
11286
|
+
return selectedValue;
|
|
11287
|
+
}
|
|
11288
|
+
return null;
|
|
11289
|
+
}, [currentSelectedOption, getLabelField, placeholder2, selectedValue, showValueWhenNoMatch]);
|
|
11257
11290
|
const handleSelect = React26__namespace.useCallback(
|
|
11258
11291
|
(selected, option) => {
|
|
11259
11292
|
setSelectedValue(selected);
|
|
11260
|
-
|
|
11293
|
+
setOpenPopover(false);
|
|
11261
11294
|
if (typeof onSelect === "function") {
|
|
11262
11295
|
onSelect(selected, option);
|
|
11263
11296
|
}
|
|
11297
|
+
if (typeof onOpenChange === "function") {
|
|
11298
|
+
onOpenChange(false);
|
|
11299
|
+
}
|
|
11300
|
+
},
|
|
11301
|
+
[onOpenChange, onSelect, setOpenPopover, setSelectedValue]
|
|
11302
|
+
);
|
|
11303
|
+
const handleOpenPopover = React26__namespace.useCallback(
|
|
11304
|
+
(isOpen) => {
|
|
11305
|
+
if (disabled) return;
|
|
11306
|
+
setOpenPopover(isOpen);
|
|
11307
|
+
if (typeof onOpenChange === "function") {
|
|
11308
|
+
onOpenChange(isOpen);
|
|
11309
|
+
}
|
|
11264
11310
|
},
|
|
11265
|
-
[
|
|
11311
|
+
[disabled, onOpenChange, setOpenPopover]
|
|
11266
11312
|
);
|
|
11267
11313
|
const handleClear = React26__namespace.useCallback(
|
|
11268
11314
|
(event) => {
|
|
11269
11315
|
event.stopPropagation();
|
|
11270
11316
|
setSelectedValue(void 0);
|
|
11317
|
+
if (typeof onClear === "function") {
|
|
11318
|
+
onClear(selectedValue, currentSelectedOption);
|
|
11319
|
+
}
|
|
11271
11320
|
},
|
|
11272
|
-
[setSelectedValue]
|
|
11321
|
+
[currentSelectedOption, onClear, selectedValue, setSelectedValue]
|
|
11273
11322
|
);
|
|
11274
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open, onOpenChange:
|
|
11323
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: openPopover, onOpenChange: handleOpenPopover, children: [
|
|
11275
11324
|
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11276
11325
|
"button",
|
|
11277
11326
|
{
|
|
@@ -11279,7 +11328,7 @@ var ComboboxInner = ({
|
|
|
11279
11328
|
name,
|
|
11280
11329
|
type: "button",
|
|
11281
11330
|
role: "combobox",
|
|
11282
|
-
"aria-expanded":
|
|
11331
|
+
"aria-expanded": openPopover,
|
|
11283
11332
|
className: cn(
|
|
11284
11333
|
"flex items-center justify-between gap-2 rounded-md border bg-white px-3 h-9 text-sm whitespace-nowrap shadow-xs outline-none border-input",
|
|
11285
11334
|
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
@@ -11289,7 +11338,7 @@ var ComboboxInner = ({
|
|
|
11289
11338
|
"transition-all",
|
|
11290
11339
|
className
|
|
11291
11340
|
),
|
|
11292
|
-
"data-state":
|
|
11341
|
+
"data-state": openPopover ? "open" : "closed",
|
|
11293
11342
|
disabled,
|
|
11294
11343
|
onFocus,
|
|
11295
11344
|
onBlur,
|