@sustaina/shared-ui 1.1.8 → 1.2.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.js CHANGED
@@ -1449,19 +1449,17 @@ function TooltipContent({
1449
1449
  ) });
1450
1450
  }
1451
1451
  function SortableRow({
1452
- itemId,
1453
- index,
1454
- control,
1455
1452
  availableColumns,
1456
1453
  currentColumns,
1457
- disableDrag = false,
1458
- disableEdit = false,
1459
- hideFormMessage,
1460
- removeColumn
1454
+ control,
1455
+ name,
1456
+ value,
1457
+ isDragging,
1458
+ onRemove
1461
1459
  }) {
1462
1460
  const { attributes, listeners, setNodeRef, transform, transition } = sortable.useSortable({
1463
- id: itemId,
1464
- disabled: disableDrag
1461
+ id: value,
1462
+ disabled: name == "columns.0.id"
1465
1463
  });
1466
1464
  const style = {
1467
1465
  transform: utilities.CSS.Transform.toString(transform),
@@ -1476,35 +1474,33 @@ function SortableRow({
1476
1474
  FormField2,
1477
1475
  {
1478
1476
  control,
1479
- name: `columns.${index}.id`,
1477
+ name,
1480
1478
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem2, { className: "flex-1", children: [
1481
1479
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
1482
1480
  /* @__PURE__ */ jsxRuntime.jsx(
1483
1481
  lucideReact.GripVertical,
1484
1482
  {
1483
+ ...attributes,
1484
+ ...listeners,
1485
1485
  className: cn(
1486
1486
  "h-5 w-5 text-[#B9B9B9] focus:outline-none cursor-grab",
1487
- index == 0 && "opacity-0 pointer-events-none"
1488
- ),
1489
- ...attributes,
1490
- ...listeners
1487
+ name == "columns.0.id" && "opacity-0 pointer-events-none"
1488
+ )
1491
1489
  }
1492
1490
  ),
1493
1491
  /* @__PURE__ */ jsxRuntime.jsxs(
1494
1492
  Select,
1495
1493
  {
1496
1494
  value: field.value,
1497
- onValueChange: (val) => {
1498
- field.onChange(val);
1499
- },
1500
- disabled: disableEdit || index == 0,
1495
+ onValueChange: field.onChange,
1496
+ disabled: name == "columns.0.id",
1501
1497
  children: [
1502
1498
  /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
1503
1499
  SelectTrigger,
1504
1500
  {
1505
1501
  className: cn(
1506
1502
  "w-full border-[#DDDDDD] data-[disabled]:opacity-100 aria-invalid:border-[#BB0B0E]",
1507
- index == 0 ? "text-[#8B8B8B] bg-[#EAEAEA] cursor-not-allowed" : ""
1503
+ name == "columns.0.id" ? "text-[#8B8B8B] bg-[#EAEAEA] cursor-not-allowed" : ""
1508
1504
  ),
1509
1505
  children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: "Choose column..." })
1510
1506
  }
@@ -1526,7 +1522,7 @@ function SortableRow({
1526
1522
  ]
1527
1523
  }
1528
1524
  ),
1529
- index == 0 ? /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
1525
+ name == "columns.0.id" ? /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
1530
1526
  /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { className: "h-5 w-5", stroke: "white", fill: "#8B8B8B" }) }),
1531
1527
  /* @__PURE__ */ jsxRuntime.jsx(
1532
1528
  TooltipContent,
@@ -1541,14 +1537,14 @@ function SortableRow({
1541
1537
  ] }) }) : /* @__PURE__ */ jsxRuntime.jsx(
1542
1538
  lucideReact.CircleMinus,
1543
1539
  {
1544
- onClick: () => index > 0 && removeColumn(index),
1540
+ onClick: onRemove,
1545
1541
  className: "h-5 w-5 cursor-pointer",
1546
1542
  stroke: "white",
1547
1543
  fill: "#C32A2C"
1548
1544
  }
1549
1545
  )
1550
1546
  ] }),
1551
- /* @__PURE__ */ jsxRuntime.jsx(FormMessage, { className: cn("pl-6 text-[#BB0B0E]", hideFormMessage && "hidden") })
1547
+ !isDragging && /* @__PURE__ */ jsxRuntime.jsx(FormMessage, { className: cn("pl-6 text-[#BB0B0E]") })
1552
1548
  ] })
1553
1549
  }
1554
1550
  ) });
@@ -1623,18 +1619,31 @@ var GridSettingsModal = ({
1623
1619
  onClose,
1624
1620
  onSaveColumns
1625
1621
  }) => {
1626
- const [hideFormMessage, setHideFormMessage] = React3.useState(false);
1622
+ const [isDragging, setIsDragging] = React3.useState(false);
1627
1623
  const form = reactHookForm.useForm({
1628
1624
  resolver: t2(GridSettingsSchema),
1629
1625
  defaultValues: { columns: currentColumns },
1630
1626
  mode: "onChange"
1631
1627
  });
1628
+ const { control, trigger } = form;
1629
+ const { fields, append, remove, move } = reactHookForm.useFieldArray({
1630
+ control,
1631
+ name: "columns",
1632
+ keyName: "fieldId"
1633
+ });
1632
1634
  React3.useEffect(() => {
1633
1635
  if (isOpen) {
1634
1636
  form.reset({ columns: currentColumns });
1635
1637
  }
1636
1638
  }, [isOpen, currentColumns, form]);
1637
- const columns = form.watch("columns");
1639
+ const addColumn = async () => {
1640
+ const isValid2 = await trigger("columns");
1641
+ if (isValid2) {
1642
+ append({ id: "" });
1643
+ } else {
1644
+ return;
1645
+ }
1646
+ };
1638
1647
  const onSubmit = (data) => {
1639
1648
  const ordering = data.columns.map((i2) => i2.id);
1640
1649
  const visibility = Object.fromEntries(
@@ -1645,28 +1654,16 @@ var GridSettingsModal = ({
1645
1654
  onSaveColumns({ ordering, visibility, pinning });
1646
1655
  }
1647
1656
  };
1648
- const addColumn = async () => {
1649
- const isValid2 = await form.trigger("columns");
1650
- if (!isValid2) {
1651
- return;
1652
- }
1653
- form.setValue("columns", [...columns, { id: "" }], { shouldValidate: false });
1654
- };
1655
- const removeColumn = (index) => {
1656
- const newCols = [...columns];
1657
- newCols.splice(index, 1);
1658
- form.setValue("columns", newCols);
1659
- };
1660
1657
  const sensors = core.useSensors(core.useSensor(core.PointerSensor, { activationConstraint: { distance: 5 } }));
1661
- const handleDragEnd = (event) => {
1658
+ function handleDragEnd(event) {
1662
1659
  const { active, over } = event;
1663
1660
  if (!over || active.id === over.id) return;
1664
- const oldIndex = columns.findIndex((c) => c.id === active.id);
1665
- const newIndex = columns.findIndex((c) => c.id === over.id);
1666
- if (newIndex === 0) return;
1667
- const reordered = sortable.arrayMove(columns, oldIndex, newIndex);
1668
- form.setValue("columns", reordered, { shouldValidate: true });
1669
- };
1661
+ const oldIndex = fields.findIndex((f) => f.fieldId === active.id);
1662
+ const newIndex = fields.findIndex((f) => f.fieldId === over.id);
1663
+ if (oldIndex !== -1 && newIndex !== -1) {
1664
+ move(oldIndex, newIndex);
1665
+ }
1666
+ }
1670
1667
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open: isOpen, onOpenChange: (open) => !open && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "sm:max-w-xl p-0 border-0", showCloseButton: false, children: [
1671
1668
  /* @__PURE__ */ jsxRuntime.jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
1672
1669
  "button",
@@ -1698,43 +1695,42 @@ var GridSettingsModal = ({
1698
1695
  /* @__PURE__ */ jsxRuntime.jsx(
1699
1696
  SortableRow,
1700
1697
  {
1701
- itemId: columns[0]?.id,
1702
- index: 0,
1703
- control: form.control,
1698
+ value: fields[0]?.fieldId,
1699
+ control,
1700
+ name: `columns.0.id`,
1701
+ isDragging,
1704
1702
  availableColumns,
1705
- currentColumns: columns,
1706
- disableDrag: true,
1707
- disableEdit: true,
1708
- removeColumn
1709
- }
1703
+ currentColumns: fields
1704
+ },
1705
+ fields[0]?.fieldId
1710
1706
  ),
1711
1707
  /* @__PURE__ */ jsxRuntime.jsx(
1712
1708
  core.DndContext,
1713
1709
  {
1714
1710
  sensors,
1715
1711
  collisionDetection: core.closestCenter,
1716
- onDragStart: () => setHideFormMessage(true),
1712
+ onDragStart: () => setIsDragging(true),
1717
1713
  onDragEnd: (event) => {
1718
- setHideFormMessage(false);
1714
+ setIsDragging(false);
1719
1715
  handleDragEnd(event);
1720
1716
  },
1721
1717
  children: /* @__PURE__ */ jsxRuntime.jsx(
1722
1718
  sortable.SortableContext,
1723
1719
  {
1724
- items: columns?.slice(1).map((c) => c.id),
1720
+ items: fields?.slice(1).map((c) => c?.fieldId),
1725
1721
  strategy: sortable.verticalListSortingStrategy,
1726
- children: columns?.slice(1).map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
1722
+ children: fields?.slice(1).map((col, index) => /* @__PURE__ */ jsxRuntime.jsx(
1727
1723
  SortableRow,
1728
1724
  {
1729
- itemId: item.id,
1730
- index: index + 1,
1731
- control: form.control,
1725
+ value: col?.fieldId,
1726
+ control,
1727
+ name: `columns.${index + 1}.id`,
1728
+ isDragging,
1732
1729
  availableColumns,
1733
- currentColumns: columns,
1734
- hideFormMessage,
1735
- removeColumn
1730
+ currentColumns: fields,
1731
+ onRemove: () => remove(index + 1)
1736
1732
  },
1737
- item.id + index
1733
+ col?.fieldId
1738
1734
  ))
1739
1735
  }
1740
1736
  )
@@ -1746,7 +1742,7 @@ var GridSettingsModal = ({
1746
1742
  type: "button",
1747
1743
  className: cn("bg-[#41875C99] text-white w-full rounded-t-lg", addButtonClassname),
1748
1744
  onClick: addColumn,
1749
- disabled: columns.length >= limit,
1745
+ disabled: fields.length >= limit,
1750
1746
  children: [
1751
1747
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "h-4 w-4 mr-1" }),
1752
1748
  " Add column"
@@ -4846,6 +4842,7 @@ var AdvanceSearch = ({
4846
4842
  onClick: () => {
4847
4843
  clearAllRow();
4848
4844
  Object.keys(getValues()).forEach((k) => resetField(k));
4845
+ onSubmit();
4849
4846
  },
4850
4847
  children: "Clear Search"
4851
4848
  }
@@ -4865,10 +4862,180 @@ var AdvanceSearch = ({
4865
4862
  );
4866
4863
  };
4867
4864
  var AdvanceSearch_default = AdvanceSearch;
4865
+ function cn3(...inputs) {
4866
+ return tailwindMerge.twMerge(clsx3.clsx(inputs));
4867
+ }
4868
+ function Dialog2({ ...props }) {
4869
+ return /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Root, { "data-slot": "dialog", ...props });
4870
+ }
4871
+ function DialogPortal2({ ...props }) {
4872
+ return /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Portal, { "data-slot": "dialog-portal", ...props });
4873
+ }
4874
+ function DialogOverlay2({ className, ...props }) {
4875
+ return /* @__PURE__ */ jsxRuntime.jsx(
4876
+ DialogPrimitive__namespace.Overlay,
4877
+ {
4878
+ "data-slot": "dialog-overlay",
4879
+ className: cn3(
4880
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
4881
+ className
4882
+ ),
4883
+ ...props
4884
+ }
4885
+ );
4886
+ }
4887
+ function DialogContent2({
4888
+ className,
4889
+ children,
4890
+ showCloseButton = true,
4891
+ ...props
4892
+ }) {
4893
+ return /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal2, { "data-slot": "dialog-portal", children: [
4894
+ /* @__PURE__ */ jsxRuntime.jsx(DialogOverlay2, {}),
4895
+ /* @__PURE__ */ jsxRuntime.jsxs(
4896
+ DialogPrimitive__namespace.Content,
4897
+ {
4898
+ "data-slot": "dialog-content",
4899
+ className: cn3(
4900
+ "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
4901
+ className
4902
+ ),
4903
+ ...props,
4904
+ children: [
4905
+ children,
4906
+ showCloseButton && /* @__PURE__ */ jsxRuntime.jsxs(
4907
+ DialogPrimitive__namespace.Close,
4908
+ {
4909
+ "data-slot": "dialog-close",
4910
+ className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
4911
+ children: [
4912
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, {}),
4913
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
4914
+ ]
4915
+ }
4916
+ )
4917
+ ]
4918
+ }
4919
+ )
4920
+ ] });
4921
+ }
4922
+ function DialogHeader2({ className, ...props }) {
4923
+ return /* @__PURE__ */ jsxRuntime.jsx(
4924
+ "div",
4925
+ {
4926
+ "data-slot": "dialog-header",
4927
+ className: cn3("flex flex-col gap-2 text-center sm:text-left", className),
4928
+ ...props
4929
+ }
4930
+ );
4931
+ }
4932
+ function DialogTitle2({ className, ...props }) {
4933
+ return /* @__PURE__ */ jsxRuntime.jsx(
4934
+ DialogPrimitive__namespace.Title,
4935
+ {
4936
+ "data-slot": "dialog-title",
4937
+ className: cn3("text-lg leading-none font-semibold", className),
4938
+ ...props
4939
+ }
4940
+ );
4941
+ }
4942
+ function DialogDescription2({
4943
+ className,
4944
+ ...props
4945
+ }) {
4946
+ return /* @__PURE__ */ jsxRuntime.jsx(
4947
+ DialogPrimitive__namespace.Description,
4948
+ {
4949
+ "data-slot": "dialog-description",
4950
+ className: cn3("text-muted-foreground text-sm", className),
4951
+ ...props
4952
+ }
4953
+ );
4954
+ }
4955
+ var buttonVariants4 = classVarianceAuthority.cva(
4956
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive cursor-pointer",
4957
+ {
4958
+ variants: {
4959
+ variant: {
4960
+ default: "bg-sus-primary-1 text-primary-foreground shadow-xs hover:bg-sus-primary/90",
4961
+ cancel: "border bg-[#8B8B8B] text-white shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:hover:bg-input/50",
4962
+ outlineLeave: "border border-[#BB0B0E] bg-background shadow-xs hover:bg-accent hover:text-accent-foreground text-[#BB0B0E]"
4963
+ },
4964
+ size: {
4965
+ default: "h-9 px-4 has-[>svg]:px-3",
4966
+ option: "py-5 h-9 px-4 has-[>svg]:px-3",
4967
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
4968
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
4969
+ icon: "size-9",
4970
+ "icon-xs": "size-5",
4971
+ "icon-sm": "size-[22px]",
4972
+ "icon-md": "size-7",
4973
+ "icon-lg": "size-10"
4974
+ },
4975
+ active: {
4976
+ true: "bg-sus-primary-1 text-white",
4977
+ false: ""
4978
+ }
4979
+ },
4980
+ defaultVariants: {
4981
+ variant: "default",
4982
+ size: "default"
4983
+ }
4984
+ }
4985
+ );
4986
+ function Button4({
4987
+ className,
4988
+ variant,
4989
+ size,
4990
+ active,
4991
+ asChild = false,
4992
+ ...props
4993
+ }) {
4994
+ const Comp = asChild ? reactSlot.Slot : "button";
4995
+ return /* @__PURE__ */ jsxRuntime.jsx(
4996
+ Comp,
4997
+ {
4998
+ "data-slot": "button",
4999
+ className: cn3(buttonVariants4({ variant, size, className, active })),
5000
+ ...props
5001
+ }
5002
+ );
5003
+ }
5004
+ function ConfirmDialog({ dialogData, setDialog, onClose }) {
5005
+ const handleClose = () => {
5006
+ setDialog({ state: false });
5007
+ onClose?.();
5008
+ };
5009
+ const titleColor = {
5010
+ default: "text-[#000000]",
5011
+ success: "text-[#3f9e33]",
5012
+ error: "text-[#c63638]"
5013
+ };
5014
+ const showCloseBtn = dialogData.showCloseBtn ?? true;
5015
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog2, { open: dialogData.state, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent2, { children: [
5016
+ /* @__PURE__ */ jsxRuntime.jsxs(DialogHeader2, { children: [
5017
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle2, { className: cn3(titleColor[dialogData.variant || "default"], "font-bold"), children: dialogData.title || "" }),
5018
+ /* @__PURE__ */ jsxRuntime.jsx(DialogDescription2, { children: dialogData.description || "" })
5019
+ ] }),
5020
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex justify-center py-5 gap-5", children: [
5021
+ showCloseBtn && /* @__PURE__ */ jsxRuntime.jsx(Button4, { variant: "cancel", onClick: handleClose, children: "Close" }),
5022
+ dialogData.btn && /* @__PURE__ */ jsxRuntime.jsx(
5023
+ Button4,
5024
+ {
5025
+ variant: dialogData.variantBtn || "default",
5026
+ disabled: dialogData.btnState === false,
5027
+ onClick: dialogData.onClickBtn,
5028
+ children: dialogData.btn
5029
+ }
5030
+ )
5031
+ ] })
5032
+ ] }) });
5033
+ }
4868
5034
 
4869
5035
  exports.AdvanceSearch = AdvanceSearch_default;
4870
5036
  exports.Button = Button;
4871
5037
  exports.DataTable = DataTable_default;
5038
+ exports.Dialog = ConfirmDialog;
4872
5039
  exports.FormErrorMessage = FormErrorMessage;
4873
5040
  exports.FormField = FormField;
4874
5041
  exports.FormFieldContext = FormFieldContext;