@sustaina/shared-ui 1.7.0 → 1.7.2

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
@@ -4,11 +4,10 @@ import { Controller, useFormContext, useForm, useFieldArray, FormProvider, useWa
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
  import clsx3, { clsx } from 'clsx';
6
6
  import { twMerge } from 'tailwind-merge';
7
- import { create } from 'zustand';
8
7
  import { reSplitAlphaNumeric, useReactTable, getCoreRowModel, getGroupedRowModel, getExpandedRowModel, getSortedRowModel, getFilteredRowModel, flexRender } from '@tanstack/react-table';
9
8
  import { CircleHelp, Triangle, X, Plus, Search, Bug, XIcon, GripVertical, Info, CircleMinus, CalendarIcon, Minus, ChevronDownIcon, CheckIcon, ChevronLeft, ChevronRight, Tag, ChevronUpIcon } from 'lucide-react';
9
+ import { create } from 'zustand';
10
10
  import { Slot } from '@radix-ui/react-slot';
11
- import { cva } from 'class-variance-authority';
12
11
  import * as LabelPrimitive2 from '@radix-ui/react-label';
13
12
  import * as DialogPrimitive from '@radix-ui/react-dialog';
14
13
  import { SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
@@ -17,6 +16,7 @@ import * as SelectPrimitive from '@radix-ui/react-select';
17
16
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
18
17
  import { useSensors, useSensor, PointerSensor, DndContext, closestCenter } from '@dnd-kit/core';
19
18
  import { restrictToParentElement, restrictToVerticalAxis } from '@dnd-kit/modifiers';
19
+ import { cva } from 'class-variance-authority';
20
20
  import { z } from 'zod';
21
21
  import { createPortal } from 'react-dom';
22
22
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -152,38 +152,6 @@ function stripNullishObject(value) {
152
152
  return {};
153
153
  }
154
154
  }
155
-
156
- // src/utils/getColumnIdFromTable.ts
157
- function getColumnIdFromTable(table) {
158
- const allColumns = table.getAllColumns();
159
- const availableColumns = allColumns.map((col) => ({ id: col.id }));
160
- const currentColumns = allColumns.filter((col) => col.getIsVisible()).map((col) => ({ id: col.id }));
161
- return { availableColumns, currentColumns };
162
- }
163
- var useGridSettingsStore = create(
164
- (set) => ({
165
- availableColumns: [],
166
- currentColumns: [],
167
- payload: {
168
- ordering: [],
169
- visibility: {},
170
- pinning: { left: [] }
171
- },
172
- setAvailableColumns: (cols) => set({ availableColumns: cols }),
173
- setCurrentColumns: (cols) => set({ currentColumns: cols }),
174
- setPayload: (payload) => set({ payload }),
175
- reset: () => set({
176
- availableColumns: [],
177
- currentColumns: [],
178
- payload: { ordering: [], visibility: {}, pinning: { left: [] } }
179
- }),
180
- extractColumns: (table) => {
181
- const availableColumns = table.getAllColumns().map((col) => ({ id: col.id }));
182
- const currentColumns = table.getVisibleLeafColumns().map((col) => ({ id: col.id }));
183
- return { availableColumns, currentColumns };
184
- }
185
- })
186
- );
187
155
  function TextInput({ className, ...props }) {
188
156
  return /* @__PURE__ */ jsx("input", { type: "text", className: cn("input", className), ...props });
189
157
  }
@@ -1098,61 +1066,6 @@ var usePreventPageLeave = ({ isPrevening }) => {
1098
1066
  }, [isPrevening, setPreventing]);
1099
1067
  };
1100
1068
  var usePreventPageLeave_default = usePreventPageLeave;
1101
- var buttonVariants = cva(
1102
- "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",
1103
- {
1104
- variants: {
1105
- variant: {
1106
- default: "bg-sus-primary-1 text-primary-foreground shadow-xs hover:bg-sus-primary/90",
1107
- destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
1108
- outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
1109
- secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
1110
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
1111
- link: "text-primary underline-offset-4 hover:underline",
1112
- cancel: "border bg-[#8B8B8B] text-white shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
1113
- defaultSelect: "bg-primary text-primary-foreground shadow-xs hover:bg-sus-primary/90 py-2",
1114
- defaultOutline: "border bg-background py-2 shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50"
1115
- },
1116
- size: {
1117
- default: "h-9 px-4 has-[>svg]:px-3",
1118
- option: "py-5 h-9 px-4 has-[>svg]:px-3",
1119
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
1120
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
1121
- icon: "size-9",
1122
- "icon-xs": "size-5",
1123
- "icon-sm": "size-[22px]",
1124
- "icon-md": "size-7",
1125
- "icon-lg": "size-10"
1126
- },
1127
- active: {
1128
- true: "bg-sus-primary-1 text-white",
1129
- false: ""
1130
- }
1131
- },
1132
- defaultVariants: {
1133
- variant: "default",
1134
- size: "default"
1135
- }
1136
- }
1137
- );
1138
- function Button({
1139
- className,
1140
- variant,
1141
- size,
1142
- active,
1143
- asChild = false,
1144
- ...props
1145
- }) {
1146
- const Comp = asChild ? Slot : "button";
1147
- return /* @__PURE__ */ jsx(
1148
- Comp,
1149
- {
1150
- "data-slot": "button",
1151
- className: cn(buttonVariants({ variant, size, className, active })),
1152
- ...props
1153
- }
1154
- );
1155
- }
1156
1069
  var s = (e2, s2, o3) => {
1157
1070
  if (e2 && "reportValidity" in e2) {
1158
1071
  const r2 = get(o3, s2);
@@ -1551,10 +1464,13 @@ function SortableRow({
1551
1464
  id: value,
1552
1465
  disabled: name == "columns.0.id"
1553
1466
  });
1554
- const style = {
1555
- transform: CSS.Transform.toString(transform),
1556
- transition
1557
- };
1467
+ const style = React4.useMemo(
1468
+ () => ({
1469
+ transform: CSS.Transform.toString(transform),
1470
+ transition
1471
+ }),
1472
+ [transform, transition]
1473
+ );
1558
1474
  const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
1559
1475
  const currentFormColumns = useWatch({ control, name: "columns" });
1560
1476
  return /* @__PURE__ */ jsx("div", { ref: setNodeRef, style, className: "flex items-center rounded-md bg-white", children: /* @__PURE__ */ jsx(
@@ -1563,7 +1479,7 @@ function SortableRow({
1563
1479
  control,
1564
1480
  name,
1565
1481
  render: ({ field }) => {
1566
- const options = availableColumns.filter((col) => col.id === field.value || !currentFormColumns?.some((c) => c.id === col.id)).map((col) => ({ id: col.id, label: capitalize(col.id) }));
1482
+ const options = availableColumns.filter((col) => col.id === field.value || !currentFormColumns?.some((c) => c.id === col.id)).map((col) => ({ id: col.id, label: col?.label ? col.label : capitalize(col.id) }));
1567
1483
  return /* @__PURE__ */ jsxs(FormItem2, { className: "flex-1", children: [
1568
1484
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1569
1485
  /* @__PURE__ */ jsx(
@@ -1640,7 +1556,7 @@ function SortableRow({
1640
1556
  }
1641
1557
  ) });
1642
1558
  }
1643
- var buttonVariants2 = cva(
1559
+ var buttonVariants = cva(
1644
1560
  "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",
1645
1561
  {
1646
1562
  variants: {
@@ -1674,7 +1590,7 @@ var buttonVariants2 = cva(
1674
1590
  }
1675
1591
  }
1676
1592
  );
1677
- function Button2({
1593
+ function Button({
1678
1594
  className,
1679
1595
  variant,
1680
1596
  size,
@@ -1687,13 +1603,14 @@ function Button2({
1687
1603
  Comp,
1688
1604
  {
1689
1605
  "data-slot": "button",
1690
- className: cn(buttonVariants2({ variant, size, className, active })),
1606
+ className: cn(buttonVariants({ variant, size, className, active })),
1691
1607
  ...props
1692
1608
  }
1693
1609
  );
1694
1610
  }
1695
1611
  var ColumnSchema = z.object({
1696
- id: z.string().nonempty("This field is required")
1612
+ id: z.string().nonempty("This field is required"),
1613
+ label: z.string().optional()
1697
1614
  });
1698
1615
  var GridSettingsSchema = z.object({
1699
1616
  columns: z.array(ColumnSchema).min(1, "At least one column is required")
@@ -1742,7 +1659,7 @@ var GridSettingsModal = ({
1742
1659
  );
1743
1660
  const pinning = { left: [data.columns[0].id] };
1744
1661
  if (onSaveColumns) {
1745
- onSaveColumns({ ordering, visibility, pinning });
1662
+ onSaveColumns({ ordering, visibility, pinning }, data.columns);
1746
1663
  }
1747
1664
  };
1748
1665
  const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));
@@ -1827,7 +1744,7 @@ var GridSettingsModal = ({
1827
1744
  }
1828
1745
  ) }),
1829
1746
  /* @__PURE__ */ jsx("div", { className: "px-6", children: /* @__PURE__ */ jsxs(
1830
- Button2,
1747
+ Button,
1831
1748
  {
1832
1749
  type: "button",
1833
1750
  className: cn("bg-[#41875C99] text-white w-full rounded-t-lg", addButtonClassname),
@@ -1842,7 +1759,7 @@ var GridSettingsModal = ({
1842
1759
  ] }) }),
1843
1760
  /* @__PURE__ */ jsx(DialogFooter, { className: "w-full px-6", children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between w-full py-4 border-t-1 border-[#B9B9B9]", children: [
1844
1761
  /* @__PURE__ */ jsx(
1845
- Button2,
1762
+ Button,
1846
1763
  {
1847
1764
  type: "button",
1848
1765
  variant: "outline",
@@ -1852,7 +1769,7 @@ var GridSettingsModal = ({
1852
1769
  }
1853
1770
  ),
1854
1771
  /* @__PURE__ */ jsx(
1855
- Button2,
1772
+ Button,
1856
1773
  {
1857
1774
  type: "submit",
1858
1775
  className: cn("w-18 bg-[#379A2A] text-white", saveButtonClassname),
@@ -1864,6 +1781,99 @@ var GridSettingsModal = ({
1864
1781
  ] }) }) });
1865
1782
  };
1866
1783
  var GridSettingsModal_default = GridSettingsModal;
1784
+ var useGridSettingsStore = create(
1785
+ (set, get) => ({
1786
+ availableColumns: [],
1787
+ currentColumns: [],
1788
+ payload: {
1789
+ ordering: [],
1790
+ visibility: {},
1791
+ pinning: { left: [] }
1792
+ },
1793
+ setAvailableColumns: (cols) => set({ availableColumns: cols }),
1794
+ setCurrentColumns: (cols) => set({ currentColumns: cols }),
1795
+ setPayload: (payload) => set({ payload }),
1796
+ reset: () => set({
1797
+ availableColumns: [],
1798
+ currentColumns: [],
1799
+ payload: { ordering: [], visibility: {}, pinning: { left: [] } }
1800
+ }),
1801
+ extractColumns: (table) => {
1802
+ const availableColumns = table.getAllColumns().map((col) => ({ id: col.id }));
1803
+ const currentColumns = table.getVisibleLeafColumns().map((col) => ({ id: col.id }));
1804
+ return { availableColumns, currentColumns };
1805
+ },
1806
+ syncColumnsState: (table, options) => {
1807
+ const { availableColumns, currentColumns } = get().extractColumns(table);
1808
+ const { excludeColumns = [], labelMap = {} } = options || {};
1809
+ const filteredExcludeColumnFn = (column) => !excludeColumns.includes(column.id);
1810
+ const mapLabel = (col) => ({
1811
+ id: col.id,
1812
+ label: labelMap?.[col.id] ?? col.label ?? col.id
1813
+ });
1814
+ set({
1815
+ availableColumns: availableColumns.filter(filteredExcludeColumnFn).map(mapLabel),
1816
+ currentColumns: currentColumns.filter(filteredExcludeColumnFn).map(mapLabel)
1817
+ });
1818
+ }
1819
+ })
1820
+ );
1821
+ var useGridSettingsStore_default = useGridSettingsStore;
1822
+ var buttonVariants2 = cva(
1823
+ "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",
1824
+ {
1825
+ variants: {
1826
+ variant: {
1827
+ default: "bg-sus-primary-1 text-primary-foreground shadow-xs hover:bg-sus-primary/90",
1828
+ destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
1829
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
1830
+ secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
1831
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
1832
+ link: "text-primary underline-offset-4 hover:underline",
1833
+ cancel: "border bg-[#8B8B8B] text-white shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
1834
+ defaultSelect: "bg-primary text-primary-foreground shadow-xs hover:bg-sus-primary/90 py-2",
1835
+ defaultOutline: "border bg-background py-2 shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50"
1836
+ },
1837
+ size: {
1838
+ default: "h-9 px-4 has-[>svg]:px-3",
1839
+ option: "py-5 h-9 px-4 has-[>svg]:px-3",
1840
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
1841
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
1842
+ icon: "size-9",
1843
+ "icon-xs": "size-5",
1844
+ "icon-sm": "size-[22px]",
1845
+ "icon-md": "size-7",
1846
+ "icon-lg": "size-10"
1847
+ },
1848
+ active: {
1849
+ true: "bg-sus-primary-1 text-white",
1850
+ false: ""
1851
+ }
1852
+ },
1853
+ defaultVariants: {
1854
+ variant: "default",
1855
+ size: "default"
1856
+ }
1857
+ }
1858
+ );
1859
+ function Button2({
1860
+ className,
1861
+ variant,
1862
+ size,
1863
+ active,
1864
+ asChild = false,
1865
+ ...props
1866
+ }) {
1867
+ const Comp = asChild ? Slot : "button";
1868
+ return /* @__PURE__ */ jsx(
1869
+ Comp,
1870
+ {
1871
+ "data-slot": "button",
1872
+ className: cn(buttonVariants2({ variant, size, className, active })),
1873
+ ...props
1874
+ }
1875
+ );
1876
+ }
1867
1877
  var InfoIcon = (props) => {
1868
1878
  return /* @__PURE__ */ jsxs(
1869
1879
  "svg",
@@ -2038,7 +2048,7 @@ var Navbar = ({
2038
2048
  ] }),
2039
2049
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2040
2050
  mainButtonText && /* @__PURE__ */ jsx(
2041
- Button,
2051
+ Button2,
2042
2052
  {
2043
2053
  disabled: mainButtonDisable,
2044
2054
  className: cn("bg-sus-secondary-1 hover:bg-sus-secondary-hover", mainButtonClassName),
@@ -2048,7 +2058,7 @@ var Navbar = ({
2048
2058
  }
2049
2059
  ),
2050
2060
  subButtonText && /* @__PURE__ */ jsx(
2051
- Button,
2061
+ Button2,
2052
2062
  {
2053
2063
  disabled: subButtonDisable,
2054
2064
  className: cn("bg-sus-primary-2 hover:bg-sus-primary-2-hover", subButtonClassName),
@@ -5267,6 +5277,6 @@ function variantClass(variant) {
5267
5277
  }
5268
5278
  }
5269
5279
 
5270
- export { AdvanceSearch_default as AdvanceSearch, Button, DataTable_default as DataTable, DialogAlert, FormErrorMessage, FormField, FormFieldContext, FormItem, FormItemContext, FormLabel, GridSettingsModal_default as GridSettingsModal, HeaderCell_default as HeaderCell, navbar_default as Navbar, NumberInput, PreventPageLeave_default as PreventPageLeave, TextInput, booleanToSelectValue, buttonVariants, cn, compareAlphanumeric, debounce, getColumnIdFromTable, isDefined, isEmptyObject, renderContentSlot, selectValueToBoolean, stripNullishObject, useFormField, useGridSettingsStore, useHover_default as useHover, useIntersectionObserver_default as useIntersectionObserver, useMediaQuery_default as useMediaQuery, usePreventPageLeave_default as usePreventPageLeave, usePreventPageLeaveStore_default as usePreventPageLeaveStore, useScreenSize_default as useScreenSize, useTruncated_default as useTruncated };
5280
+ export { AdvanceSearch_default as AdvanceSearch, Button2 as Button, DataTable_default as DataTable, DialogAlert, FormErrorMessage, FormField, FormFieldContext, FormItem, FormItemContext, FormLabel, GridSettingsModal_default as GridSettingsModal, HeaderCell_default as HeaderCell, navbar_default as Navbar, NumberInput, PreventPageLeave_default as PreventPageLeave, TextInput, booleanToSelectValue, buttonVariants2 as buttonVariants, cn, compareAlphanumeric, debounce, isDefined, isEmptyObject, renderContentSlot, selectValueToBoolean, stripNullishObject, useFormField, useGridSettingsStore_default as useGridSettingsStore, useHover_default as useHover, useIntersectionObserver_default as useIntersectionObserver, useMediaQuery_default as useMediaQuery, usePreventPageLeave_default as usePreventPageLeave, usePreventPageLeaveStore_default as usePreventPageLeaveStore, useScreenSize_default as useScreenSize, useTruncated_default as useTruncated };
5271
5281
  //# sourceMappingURL=index.mjs.map
5272
5282
  //# sourceMappingURL=index.mjs.map