@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.mjs CHANGED
@@ -4331,18 +4331,25 @@ var useControllableState = ({
4331
4331
  defaultValue,
4332
4332
  value
4333
4333
  }) => {
4334
- const [internalValue, setInternalValue] = React26.useState(value ?? defaultValue);
4334
+ const isControlled = typeof value !== "undefined";
4335
+ const [internalValue, setInternalValue] = React26.useState(() => {
4336
+ return isControlled ? value : defaultValue;
4337
+ });
4335
4338
  React26.useEffect(() => {
4336
- if (value !== internalValue) {
4337
- setInternalValue(value);
4338
- }
4339
- }, [value]);
4340
- const updateState = React26.useCallback((nextValue) => {
4341
- setInternalValue(nextValue);
4342
- }, []);
4339
+ if (!isControlled) return;
4340
+ setInternalValue(value);
4341
+ }, [isControlled, value]);
4342
+ const setValue = React26.useCallback(
4343
+ (nextValue) => {
4344
+ if (isControlled) return;
4345
+ setInternalValue(nextValue);
4346
+ },
4347
+ [isControlled]
4348
+ );
4343
4349
  return {
4344
- value: internalValue,
4345
- updateState
4350
+ value: isControlled ? value : internalValue,
4351
+ setValue,
4352
+ isControlled
4346
4353
  };
4347
4354
  };
4348
4355
  var useControllableState_default = useControllableState;
@@ -5502,6 +5509,11 @@ var defaultResource = {
5502
5509
  description: "Unsaved changes. Do you want to leave this page?",
5503
5510
  confirm_text: "Leave"
5504
5511
  },
5512
+ "confirm.reset_form": {
5513
+ title: "Confirmation",
5514
+ description: "Unsaved changes. If you continue, all changes will be lost.",
5515
+ confirm_text: "Reset"
5516
+ },
5505
5517
  "confirm.remove": {
5506
5518
  title: "Confirmation",
5507
5519
  description: "Are you sure you want to remove this item?",
@@ -5741,6 +5753,12 @@ var DIALOG_ALERT_TEMPLATES = {
5741
5753
  description: "confirm.leave_page.description",
5742
5754
  confirmText: "confirm.leave_page.confirm_text"
5743
5755
  },
5756
+ "confirm.reset_form": {
5757
+ variant: "confirm",
5758
+ title: "confirm.reset_form.title",
5759
+ description: "confirm.reset_form.description",
5760
+ confirmText: "confirm.reset_form.confirm_text"
5761
+ },
5744
5762
  "confirm.remove": {
5745
5763
  variant: "confirm",
5746
5764
  title: "confirm.remove.title",
@@ -11198,40 +11216,71 @@ var ComboboxInner = ({
11198
11216
  notFoundContent,
11199
11217
  searchPlaceholder,
11200
11218
  showSearch,
11219
+ open,
11220
+ showValueWhenNoMatch,
11221
+ onOpenChange,
11222
+ onClear,
11201
11223
  ...props
11202
11224
  }, ref) => {
11203
11225
  const { getLabelField, getValueField } = useFieldNames_default({ fieldNames });
11204
- const [open, setOpen] = React26.useState(false);
11205
- const { value: selectedValue, updateState: setSelectedValue } = useControllableState_default({
11226
+ const { value: openPopover, setValue: setOpenPopover } = useControllableState_default({
11227
+ defaultValue: false,
11228
+ value: open
11229
+ });
11230
+ const { value: selectedValue, setValue: setSelectedValue } = useControllableState_default({
11206
11231
  defaultValue,
11207
11232
  value
11208
11233
  });
11209
- const renderValue = React26.useMemo(() => {
11210
- if (!selectedValue) return placeholder2;
11211
- const selectedOptionFound = options?.find((option) => {
11234
+ const currentSelectedOption = React26.useMemo(() => {
11235
+ return options?.find((option) => {
11212
11236
  const optionValue = getValueField(option);
11213
11237
  return optionValue === selectedValue;
11214
11238
  });
11215
- return selectedOptionFound ? getLabelField(selectedOptionFound) : null;
11216
- }, [getLabelField, getValueField, options, placeholder2, selectedValue]);
11239
+ }, [getValueField, options, selectedValue]);
11240
+ const renderValue = React26.useMemo(() => {
11241
+ if (!selectedValue) return placeholder2;
11242
+ if (currentSelectedOption) {
11243
+ return getLabelField(currentSelectedOption);
11244
+ }
11245
+ if (showValueWhenNoMatch) {
11246
+ return selectedValue;
11247
+ }
11248
+ return null;
11249
+ }, [currentSelectedOption, getLabelField, placeholder2, selectedValue, showValueWhenNoMatch]);
11217
11250
  const handleSelect = React26.useCallback(
11218
11251
  (selected, option) => {
11219
11252
  setSelectedValue(selected);
11220
- setOpen(false);
11253
+ setOpenPopover(false);
11221
11254
  if (typeof onSelect === "function") {
11222
11255
  onSelect(selected, option);
11223
11256
  }
11257
+ if (typeof onOpenChange === "function") {
11258
+ onOpenChange(false);
11259
+ }
11260
+ },
11261
+ [onOpenChange, onSelect, setOpenPopover, setSelectedValue]
11262
+ );
11263
+ const handleOpenPopover = React26.useCallback(
11264
+ (isOpen) => {
11265
+ if (disabled) return;
11266
+ setOpenPopover(isOpen);
11267
+ if (typeof onOpenChange === "function") {
11268
+ onOpenChange(isOpen);
11269
+ }
11224
11270
  },
11225
- [onSelect, setSelectedValue]
11271
+ [disabled, onOpenChange, setOpenPopover]
11226
11272
  );
11227
11273
  const handleClear = React26.useCallback(
11228
11274
  (event) => {
11229
11275
  event.stopPropagation();
11230
11276
  setSelectedValue(void 0);
11277
+ if (typeof onClear === "function") {
11278
+ onClear(selectedValue, currentSelectedOption);
11279
+ }
11231
11280
  },
11232
- [setSelectedValue]
11281
+ [currentSelectedOption, onClear, selectedValue, setSelectedValue]
11233
11282
  );
11234
- return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: (next) => !disabled && setOpen(next), children: [
11283
+ return /* @__PURE__ */ jsxs(Popover, { open: openPopover, onOpenChange: handleOpenPopover, children: [
11235
11284
  /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
11236
11285
  "button",
11237
11286
  {
@@ -11239,7 +11288,7 @@ var ComboboxInner = ({
11239
11288
  name,
11240
11289
  type: "button",
11241
11290
  role: "combobox",
11242
- "aria-expanded": open,
11291
+ "aria-expanded": openPopover,
11243
11292
  className: cn(
11244
11293
  "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",
11245
11294
  "disabled:cursor-not-allowed disabled:opacity-50",
@@ -11249,7 +11298,7 @@ var ComboboxInner = ({
11249
11298
  "transition-all",
11250
11299
  className
11251
11300
  ),
11252
- "data-state": open ? "open" : "closed",
11301
+ "data-state": openPopover ? "open" : "closed",
11253
11302
  disabled,
11254
11303
  onFocus,
11255
11304
  onBlur,