@yenio-pld/blocks 1.2.0-rc.11 → 1.2.0-rc.13

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.cts CHANGED
@@ -704,8 +704,12 @@ type SearchablePickerProps = {
704
704
  className?: string;
705
705
  "aria-invalid"?: boolean;
706
706
  onOpenChange?: (open: boolean) => void;
707
+ /** When set, a create action appears for a non-empty query (not while loading). Presentation only. */
708
+ onCreate?: (query: string) => void;
709
+ /** Label for the create action. Defaults to `Add "{query}"`. */
710
+ createLabel?: string;
707
711
  };
708
- declare function SearchablePicker({ value, selectedLabel, onChange, options, query, onQueryChange, loading, loadingMore, hasMore, onLoadMore, placeholder, emptyLabel, loadMoreLabel, clearLabel, searchPlaceholder, openLabel, disabled, allowClear, title, id, className, "aria-invalid": ariaInvalid, onOpenChange, }: SearchablePickerProps): react.JSX.Element;
712
+ declare function SearchablePicker({ value, selectedLabel, onChange, options, query, onQueryChange, loading, loadingMore, hasMore, onLoadMore, placeholder, emptyLabel, loadMoreLabel, clearLabel, searchPlaceholder, openLabel, disabled, allowClear, title, id, className, "aria-invalid": ariaInvalid, onOpenChange, onCreate, createLabel, }: SearchablePickerProps): react.JSX.Element;
709
713
 
710
714
  type PaginatedComboboxItem = {
711
715
  value: string;
package/dist/index.d.ts CHANGED
@@ -704,8 +704,12 @@ type SearchablePickerProps = {
704
704
  className?: string;
705
705
  "aria-invalid"?: boolean;
706
706
  onOpenChange?: (open: boolean) => void;
707
+ /** When set, a create action appears for a non-empty query (not while loading). Presentation only. */
708
+ onCreate?: (query: string) => void;
709
+ /** Label for the create action. Defaults to `Add "{query}"`. */
710
+ createLabel?: string;
707
711
  };
708
- declare function SearchablePicker({ value, selectedLabel, onChange, options, query, onQueryChange, loading, loadingMore, hasMore, onLoadMore, placeholder, emptyLabel, loadMoreLabel, clearLabel, searchPlaceholder, openLabel, disabled, allowClear, title, id, className, "aria-invalid": ariaInvalid, onOpenChange, }: SearchablePickerProps): react.JSX.Element;
712
+ declare function SearchablePicker({ value, selectedLabel, onChange, options, query, onQueryChange, loading, loadingMore, hasMore, onLoadMore, placeholder, emptyLabel, loadMoreLabel, clearLabel, searchPlaceholder, openLabel, disabled, allowClear, title, id, className, "aria-invalid": ariaInvalid, onOpenChange, onCreate, createLabel, }: SearchablePickerProps): react.JSX.Element;
709
713
 
710
714
  type PaginatedComboboxItem = {
711
715
  value: string;
package/dist/index.js CHANGED
@@ -20,11 +20,11 @@ import { cva } from 'class-variance-authority';
20
20
  import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from './ui/alert-dialog.js';
21
21
  import { useTheme } from 'next-themes';
22
22
  import { Combobox } from './ui/combobox.js';
23
+ import { useDialogPortalContainer, DialogClose, Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from './ui/dialog.js';
23
24
  import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerClose, DrawerFooter } from './ui/drawer.js';
24
25
  import { Input } from './ui/input.js';
25
26
  import { Slider } from './ui/slider.js';
26
27
  import { Toggle } from './ui/toggle.js';
27
- import { DialogClose, Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from './ui/dialog.js';
28
28
  import { AnimatePresence, motion, useReducedMotion } from 'framer-motion';
29
29
  import { Badge } from './ui/badge.js';
30
30
 
@@ -3066,6 +3066,7 @@ function CountryPicker({
3066
3066
  const labels = { ...defaultLabels2(purpose, locale), ...labelsProp };
3067
3067
  const items = React3.useMemo(() => countryPickerItems(locale), [locale]);
3068
3068
  const selected = React3.useMemo(() => findItem(items, value), [items, value]);
3069
+ const dialogPortalContainer = useDialogPortalContainer();
3069
3070
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3070
3071
  name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value.trim().toUpperCase() }) : null,
3071
3072
  /* @__PURE__ */ jsxs(
@@ -3118,7 +3119,7 @@ function CountryPicker({
3118
3119
  ]
3119
3120
  }
3120
3121
  ),
3121
- /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(
3122
+ /* @__PURE__ */ jsx(Combobox.Portal, { container: dialogPortalContainer ?? void 0, children: /* @__PURE__ */ jsx(
3122
3123
  Combobox.Positioner,
3123
3124
  {
3124
3125
  className: "pointer-events-auto isolate z-[60] outline-none",
@@ -3214,9 +3215,12 @@ function SearchablePicker({
3214
3215
  id,
3215
3216
  className,
3216
3217
  "aria-invalid": ariaInvalid,
3217
- onOpenChange
3218
+ onOpenChange,
3219
+ onCreate,
3220
+ createLabel
3218
3221
  }) {
3219
3222
  const isMdUp = useMediaQuery(MD_UP);
3223
+ const dialogPortalContainer = useDialogPortalContainer();
3220
3224
  const [open, setOpen] = React3.useState(false);
3221
3225
  const searchRef = React3.useRef(null);
3222
3226
  function setOpenState(next) {
@@ -3245,9 +3249,29 @@ function SearchablePicker({
3245
3249
  onChange("");
3246
3250
  onQueryChange("");
3247
3251
  }
3252
+ const trimmedQuery = query.trim();
3253
+ const showCreate = Boolean(onCreate) && trimmedQuery !== "" && !loading;
3254
+ function handleCreate() {
3255
+ if (!onCreate || trimmedQuery === "") return;
3256
+ onCreate(trimmedQuery);
3257
+ setOpenState(false);
3258
+ }
3248
3259
  const display = selectedLabel || selected?.label || "";
3249
3260
  const sheetTitle = title || placeholder;
3250
3261
  const searchLabel = searchPlaceholder || placeholder;
3262
+ const createActionLabel = createLabel ?? `Add "${trimmedQuery}"`;
3263
+ const createButton = showCreate ? /* @__PURE__ */ jsx(
3264
+ Button,
3265
+ {
3266
+ className: "w-full justify-start",
3267
+ disabled,
3268
+ size: "sm",
3269
+ type: "button",
3270
+ variant: "ghost",
3271
+ onClick: handleCreate,
3272
+ children: createActionLabel
3273
+ }
3274
+ ) : null;
3251
3275
  const loadMoreButton = hasMore && onLoadMore ? /* @__PURE__ */ jsx(
3252
3276
  Button,
3253
3277
  {
@@ -3324,7 +3348,7 @@ function SearchablePicker({
3324
3348
  }
3325
3349
  ) : null
3326
3350
  ] }),
3327
- /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(
3351
+ /* @__PURE__ */ jsx(Combobox.Portal, { container: dialogPortalContainer ?? void 0, children: /* @__PURE__ */ jsx(
3328
3352
  Combobox.Positioner,
3329
3353
  {
3330
3354
  className: "pointer-events-auto isolate z-[60] outline-none",
@@ -3369,7 +3393,10 @@ function SearchablePicker({
3369
3393
  )
3370
3394
  }
3371
3395
  ),
3372
- loadMoreButton ? /* @__PURE__ */ jsx("div", { className: "border-t border-border p-1", children: loadMoreButton }) : null
3396
+ createButton || loadMoreButton ? /* @__PURE__ */ jsxs("div", { className: "border-t border-border p-1", children: [
3397
+ createButton,
3398
+ loadMoreButton
3399
+ ] }) : null
3373
3400
  ] })
3374
3401
  ]
3375
3402
  }
@@ -3456,8 +3483,9 @@ function SearchablePicker({
3456
3483
  onChange: (event) => onQueryChange(event.target.value)
3457
3484
  }
3458
3485
  ) }),
3459
- /* @__PURE__ */ jsxs("div", { className: "overflow-y-auto px-2 pb-4", children: [
3460
- loading ? /* @__PURE__ */ jsx(LoadingRows, {}) : options.length === 0 ? /* @__PURE__ */ jsx("p", { className: "px-2 py-3 text-sm text-muted-foreground", children: emptyLabel }) : /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1 p-1", children: options.map((option) => {
3486
+ /* @__PURE__ */ jsx("div", { className: "overflow-y-auto px-2 pb-4", children: loading ? /* @__PURE__ */ jsx(LoadingRows, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
3487
+ options.length === 0 && !showCreate ? /* @__PURE__ */ jsx("p", { className: "px-2 py-3 text-sm text-muted-foreground", children: emptyLabel }) : null,
3488
+ options.length > 0 ? /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1 p-1", children: options.map((option) => {
3461
3489
  const isSelected = option.id === value;
3462
3490
  return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
3463
3491
  "button",
@@ -3483,9 +3511,10 @@ function SearchablePicker({
3483
3511
  ]
3484
3512
  }
3485
3513
  ) }, option.id);
3486
- }) }),
3514
+ }) }) : null,
3515
+ createButton,
3487
3516
  loadMoreButton
3488
- ] })
3517
+ ] }) })
3489
3518
  ] }) })
3490
3519
  ] });
3491
3520
  }
@@ -3526,6 +3555,7 @@ function PaginatedCombobox({
3526
3555
  "aria-invalid": ariaInvalid
3527
3556
  }) {
3528
3557
  const labels = { ...DEFAULT_LABELS, ...labelsProp };
3558
+ const dialogPortalContainer = useDialogPortalContainer();
3529
3559
  const selected = React3.useMemo(
3530
3560
  () => resolveSelected(value, items, selectedItem),
3531
3561
  [value, items, selectedItem]
@@ -3618,7 +3648,7 @@ function PaginatedCombobox({
3618
3648
  ]
3619
3649
  }
3620
3650
  ),
3621
- /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(
3651
+ /* @__PURE__ */ jsx(Combobox.Portal, { container: dialogPortalContainer ?? void 0, children: /* @__PURE__ */ jsx(
3622
3652
  Combobox.Positioner,
3623
3653
  {
3624
3654
  className: "pointer-events-auto isolate z-[60] outline-none",