@petrarca/sonnet-forms 0.1.3 → 0.1.5

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.js CHANGED
@@ -435,61 +435,41 @@ import {
435
435
  } from "@petrarca/sonnet-ui";
436
436
  import { Popover, PopoverContent, PopoverTrigger } from "@petrarca/sonnet-ui";
437
437
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
438
- function TriggerButton({
439
- selectId,
440
- open,
441
- selectedOption,
442
- placeholder,
443
- error,
444
- compact,
445
- label,
446
- description,
447
- clearable,
448
- value,
449
- isDisabled,
450
- autoFocus,
451
- className,
438
+ function useSelectState(value, onChange, onBlur) {
439
+ const [open, setOpen] = React5.useState(false);
440
+ const [searchQuery, setSearchQuery] = React5.useState("");
441
+ const handleSelect = (selectedValue) => {
442
+ onChange?.(selectedValue === value ? null : selectedValue);
443
+ setOpen(false);
444
+ setSearchQuery("");
445
+ };
446
+ const handleClear = (e) => {
447
+ e.stopPropagation();
448
+ onChange?.(null);
449
+ };
450
+ const handleOpenChange = (newOpen) => {
451
+ setOpen(newOpen);
452
+ if (newOpen) return;
453
+ setSearchQuery("");
454
+ onBlur?.();
455
+ };
456
+ return {
457
+ open,
458
+ searchQuery,
459
+ setSearchQuery,
460
+ handleSelect,
461
+ handleClear,
462
+ handleOpenChange
463
+ };
464
+ }
465
+ function TriggerIcons({
466
+ showClear,
452
467
  onClear
453
468
  }) {
454
- return /* @__PURE__ */ jsxs5(
455
- Button,
456
- {
457
- id: selectId,
458
- variant: "outline",
459
- role: "combobox",
460
- "aria-expanded": open,
461
- "aria-invalid": error ? "true" : "false",
462
- "aria-describedby": getAriaDescribedByCompact(
463
- selectId,
464
- error,
465
- description,
466
- compact
467
- ),
468
- "aria-label": getCompactAriaLabel(label, compact),
469
- title: getCompactTitle(error, compact),
470
- className: cn6(
471
- "w-full justify-between",
472
- !selectedOption && "text-muted-foreground",
473
- error && "border-destructive",
474
- className
475
- ),
476
- disabled: isDisabled,
477
- autoFocus,
478
- children: [
479
- /* @__PURE__ */ jsx6("span", { className: "truncate", children: selectedOption ? selectedOption.label : placeholder }),
480
- /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1", children: [
481
- clearable && value && !isDisabled && /* @__PURE__ */ jsx6(
482
- X,
483
- {
484
- className: "h-4 w-4 opacity-50 hover:opacity-100",
485
- onClick: onClear
486
- }
487
- ),
488
- /* @__PURE__ */ jsx6(ChevronsUpDown, { className: "h-4 w-4 shrink-0 opacity-50" })
489
- ] })
490
- ]
491
- }
492
- );
469
+ return /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1", children: [
470
+ showClear && /* @__PURE__ */ jsx6(X, { className: "h-4 w-4 opacity-50 hover:opacity-100", onClick: onClear }),
471
+ /* @__PURE__ */ jsx6(ChevronsUpDown, { className: "h-4 w-4 shrink-0 opacity-50" })
472
+ ] });
493
473
  }
494
474
  function SelectDropdown({
495
475
  searchPlaceholder,
@@ -537,34 +517,7 @@ function SelectDropdown({
537
517
  ] })
538
518
  ] });
539
519
  }
540
- function useSelectState(value, onChange, onBlur) {
541
- const [open, setOpen] = React5.useState(false);
542
- const [searchQuery, setSearchQuery] = React5.useState("");
543
- const handleSelect = (selectedValue) => {
544
- onChange?.(selectedValue === value ? null : selectedValue);
545
- setOpen(false);
546
- setSearchQuery("");
547
- };
548
- const handleClear = (e) => {
549
- e.stopPropagation();
550
- onChange?.(null);
551
- };
552
- const handleOpenChange = (newOpen) => {
553
- setOpen(newOpen);
554
- if (newOpen) return;
555
- setSearchQuery("");
556
- onBlur?.();
557
- };
558
- return {
559
- open,
560
- searchQuery,
561
- setSearchQuery,
562
- handleSelect,
563
- handleClear,
564
- handleOpenChange
565
- };
566
- }
567
- function resolveSelectDefaults(props) {
520
+ function resolveDefaults(props) {
568
521
  return {
569
522
  placeholder: props.placeholder ?? "Select...",
570
523
  searchPlaceholder: props.searchPlaceholder ?? "Search...",
@@ -599,7 +552,7 @@ function FormSelect(props) {
599
552
  disabled,
600
553
  readOnly,
601
554
  loading
602
- } = resolveSelectDefaults(props);
555
+ } = resolveDefaults(props);
603
556
  const generatedId = React5.useId();
604
557
  const selectId = id ?? generatedId;
605
558
  const {
@@ -623,23 +576,40 @@ function FormSelect(props) {
623
576
  compact,
624
577
  className: wrapperClassName,
625
578
  children: /* @__PURE__ */ jsxs5(Popover, { open, onOpenChange: handleOpenChange, children: [
626
- /* @__PURE__ */ jsx6(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
627
- TriggerButton,
579
+ /* @__PURE__ */ jsx6(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs5(
580
+ Button,
628
581
  {
629
- selectId,
630
- open,
631
- selectedOption,
632
- placeholder,
633
- error,
634
- compact,
635
- label,
636
- description,
637
- clearable,
638
- value,
639
- isDisabled,
582
+ id: selectId,
583
+ variant: "outline",
584
+ role: "combobox",
585
+ "aria-expanded": open,
586
+ "aria-invalid": error ? "true" : "false",
587
+ "aria-describedby": getAriaDescribedByCompact(
588
+ selectId,
589
+ error,
590
+ description,
591
+ compact
592
+ ),
593
+ "aria-label": getCompactAriaLabel(label, compact),
594
+ title: getCompactTitle(error, compact),
595
+ className: cn6(
596
+ "w-full justify-between",
597
+ !selectedOption && "text-muted-foreground",
598
+ error && "border-destructive",
599
+ className
600
+ ),
601
+ disabled: isDisabled,
640
602
  autoFocus,
641
- className,
642
- onClear: handleClear
603
+ children: [
604
+ /* @__PURE__ */ jsx6("span", { className: "truncate", children: selectedOption ? selectedOption.label : placeholder }),
605
+ /* @__PURE__ */ jsx6(
606
+ TriggerIcons,
607
+ {
608
+ showClear: clearable && !!value && !isDisabled,
609
+ onClear: handleClear
610
+ }
611
+ )
612
+ ]
643
613
  }
644
614
  ) }),
645
615
  /* @__PURE__ */ jsx6(
@@ -866,69 +836,14 @@ function resolveMultiSelectDefaults(props) {
866
836
  maxDisplay: props.maxDisplay ?? Infinity
867
837
  };
868
838
  }
869
- function MultiSelectTrigger({
870
- id,
871
- open,
872
- error,
873
- className,
874
- isDisabled,
875
- autoFocus,
876
- clearable,
877
- hasValues,
878
- selectedOptions,
879
- effectiveMaxDisplay,
880
- expanded,
881
- maxDisplay,
882
- badgeColor,
883
- placeholder,
884
- onRemove,
885
- onExpand,
886
- onCollapse,
887
- onClearAll
839
+ function TriggerIcons2({
840
+ showClear,
841
+ onClear
888
842
  }) {
889
- return /* @__PURE__ */ jsxs6(
890
- Button2,
891
- {
892
- id,
893
- variant: "outline",
894
- role: "combobox",
895
- "aria-expanded": open,
896
- className: cn7(
897
- "w-full justify-between min-h-10 h-auto",
898
- error && "border-destructive",
899
- className
900
- ),
901
- disabled: isDisabled,
902
- autoFocus,
903
- children: [
904
- /* @__PURE__ */ jsx7("div", { className: "flex flex-wrap gap-1 flex-1", children: /* @__PURE__ */ jsx7(
905
- SelectedBadges,
906
- {
907
- selectedOptions,
908
- effectiveMaxDisplay,
909
- expanded,
910
- maxDisplay,
911
- isDisabled,
912
- badgeColor,
913
- placeholder,
914
- onRemove,
915
- onExpand,
916
- onCollapse
917
- }
918
- ) }),
919
- /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-1 ml-2", children: [
920
- clearable && hasValues && !isDisabled && /* @__PURE__ */ jsx7(
921
- X2,
922
- {
923
- className: "h-4 w-4 opacity-50 hover:opacity-100",
924
- onClick: onClearAll
925
- }
926
- ),
927
- /* @__PURE__ */ jsx7(ChevronsUpDown2, { className: "h-4 w-4 shrink-0 opacity-50" })
928
- ] })
929
- ]
930
- }
931
- );
843
+ return /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-1 ml-2", children: [
844
+ showClear && /* @__PURE__ */ jsx7(X2, { className: "h-4 w-4 opacity-50 hover:opacity-100", onClick: onClear }),
845
+ /* @__PURE__ */ jsx7(ChevronsUpDown2, { className: "h-4 w-4 shrink-0 opacity-50" })
846
+ ] });
932
847
  }
933
848
  function FormMultiSelect(props) {
934
849
  const {
@@ -985,27 +900,44 @@ function FormMultiSelect(props) {
985
900
  className: wrapperClassName,
986
901
  children: [
987
902
  /* @__PURE__ */ jsxs6(Popover2, { open, onOpenChange: handleOpenChange, children: [
988
- /* @__PURE__ */ jsx7(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ jsx7(
989
- MultiSelectTrigger,
903
+ /* @__PURE__ */ jsx7(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs6(
904
+ Button2,
990
905
  {
991
906
  id: fieldId,
992
- open,
993
- error,
994
- className,
995
- isDisabled,
907
+ variant: "outline",
908
+ role: "combobox",
909
+ "aria-expanded": open,
910
+ className: cn7(
911
+ "w-full justify-between min-h-10 h-auto",
912
+ error && "border-destructive",
913
+ className
914
+ ),
915
+ disabled: isDisabled,
996
916
  autoFocus,
997
- clearable,
998
- hasValues: value.length > 0,
999
- selectedOptions,
1000
- effectiveMaxDisplay,
1001
- expanded,
1002
- maxDisplay,
1003
- badgeColor,
1004
- placeholder,
1005
- onRemove: handleRemove,
1006
- onExpand: handleExpand,
1007
- onCollapse: handleCollapse,
1008
- onClearAll: handleClearAll
917
+ children: [
918
+ /* @__PURE__ */ jsx7("div", { className: "flex flex-wrap gap-1 flex-1", children: /* @__PURE__ */ jsx7(
919
+ SelectedBadges,
920
+ {
921
+ selectedOptions,
922
+ effectiveMaxDisplay,
923
+ expanded,
924
+ maxDisplay,
925
+ isDisabled,
926
+ badgeColor,
927
+ placeholder,
928
+ onRemove: handleRemove,
929
+ onExpand: handleExpand,
930
+ onCollapse: handleCollapse
931
+ }
932
+ ) }),
933
+ /* @__PURE__ */ jsx7(
934
+ TriggerIcons2,
935
+ {
936
+ showClear: clearable && value.length > 0 && !isDisabled,
937
+ onClear: handleClearAll
938
+ }
939
+ )
940
+ ]
1009
941
  }
1010
942
  ) }),
1011
943
  /* @__PURE__ */ jsx7(