@sustaina/shared-ui 1.7.1 → 1.7.3

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);
@@ -1643,7 +1556,7 @@ function SortableRow({
1643
1556
  }
1644
1557
  ) });
1645
1558
  }
1646
- var buttonVariants2 = cva(
1559
+ var buttonVariants = cva(
1647
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",
1648
1561
  {
1649
1562
  variants: {
@@ -1677,7 +1590,7 @@ var buttonVariants2 = cva(
1677
1590
  }
1678
1591
  }
1679
1592
  );
1680
- function Button2({
1593
+ function Button({
1681
1594
  className,
1682
1595
  variant,
1683
1596
  size,
@@ -1690,13 +1603,14 @@ function Button2({
1690
1603
  Comp,
1691
1604
  {
1692
1605
  "data-slot": "button",
1693
- className: cn(buttonVariants2({ variant, size, className, active })),
1606
+ className: cn(buttonVariants({ variant, size, className, active })),
1694
1607
  ...props
1695
1608
  }
1696
1609
  );
1697
1610
  }
1698
1611
  var ColumnSchema = z.object({
1699
- id: z.string().nonempty("This field is required")
1612
+ id: z.string().nonempty("This field is required"),
1613
+ label: z.string().optional()
1700
1614
  });
1701
1615
  var GridSettingsSchema = z.object({
1702
1616
  columns: z.array(ColumnSchema).min(1, "At least one column is required")
@@ -1745,7 +1659,7 @@ var GridSettingsModal = ({
1745
1659
  );
1746
1660
  const pinning = { left: [data.columns[0].id] };
1747
1661
  if (onSaveColumns) {
1748
- onSaveColumns({ ordering, visibility, pinning });
1662
+ onSaveColumns({ ordering, visibility, pinning }, data.columns);
1749
1663
  }
1750
1664
  };
1751
1665
  const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } }));
@@ -1774,12 +1688,12 @@ var GridSettingsModal = ({
1774
1688
  children: /* @__PURE__ */ jsx(X, { className: "w-6 h-6 text-white" })
1775
1689
  }
1776
1690
  ) }),
1777
- /* @__PURE__ */ jsxs(DialogHeader, { className: cn("bg-[#82B495] text-white h-25 rounded-t-lg", headerClassname), children: [
1778
- /* @__PURE__ */ jsx(DialogTitle, { className: "text-2xl p-4", children: "Grid Settings" }),
1691
+ /* @__PURE__ */ jsxs(DialogHeader, { className: cn("bg-[#41875C] text-white h-20 rounded-t-lg", headerClassname), children: [
1692
+ /* @__PURE__ */ jsx(DialogTitle, { className: "text-xl p-2 px-4", children: "Grid Settings" }),
1779
1693
  /* @__PURE__ */ jsx(
1780
1694
  DialogDescription,
1781
1695
  {
1782
- className: cn("bg-[#8B8B8B] text-white px-4 py-2.5", descriptionClassname),
1696
+ className: cn("bg-[#A7ADB8] text-white px-4 py-2.5", descriptionClassname),
1783
1697
  children: "Add or remove columns. To change the column order, drag and drop a field."
1784
1698
  }
1785
1699
  )
@@ -1830,7 +1744,7 @@ var GridSettingsModal = ({
1830
1744
  }
1831
1745
  ) }),
1832
1746
  /* @__PURE__ */ jsx("div", { className: "px-6", children: /* @__PURE__ */ jsxs(
1833
- Button2,
1747
+ Button,
1834
1748
  {
1835
1749
  type: "button",
1836
1750
  className: cn("bg-[#41875C99] text-white w-full rounded-t-lg", addButtonClassname),
@@ -1845,7 +1759,7 @@ var GridSettingsModal = ({
1845
1759
  ] }) }),
1846
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: [
1847
1761
  /* @__PURE__ */ jsx(
1848
- Button2,
1762
+ Button,
1849
1763
  {
1850
1764
  type: "button",
1851
1765
  variant: "outline",
@@ -1855,7 +1769,7 @@ var GridSettingsModal = ({
1855
1769
  }
1856
1770
  ),
1857
1771
  /* @__PURE__ */ jsx(
1858
- Button2,
1772
+ Button,
1859
1773
  {
1860
1774
  type: "submit",
1861
1775
  className: cn("w-18 bg-[#379A2A] text-white", saveButtonClassname),
@@ -1867,6 +1781,99 @@ var GridSettingsModal = ({
1867
1781
  ] }) }) });
1868
1782
  };
1869
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
+ }
1870
1877
  var InfoIcon = (props) => {
1871
1878
  return /* @__PURE__ */ jsxs(
1872
1879
  "svg",
@@ -2041,7 +2048,7 @@ var Navbar = ({
2041
2048
  ] }),
2042
2049
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2043
2050
  mainButtonText && /* @__PURE__ */ jsx(
2044
- Button,
2051
+ Button2,
2045
2052
  {
2046
2053
  disabled: mainButtonDisable,
2047
2054
  className: cn("bg-sus-secondary-1 hover:bg-sus-secondary-hover", mainButtonClassName),
@@ -2051,7 +2058,7 @@ var Navbar = ({
2051
2058
  }
2052
2059
  ),
2053
2060
  subButtonText && /* @__PURE__ */ jsx(
2054
- Button,
2061
+ Button2,
2055
2062
  {
2056
2063
  disabled: subButtonDisable,
2057
2064
  className: cn("bg-sus-primary-2 hover:bg-sus-primary-2-hover", subButtonClassName),
@@ -5270,6 +5277,6 @@ function variantClass(variant) {
5270
5277
  }
5271
5278
  }
5272
5279
 
5273
- 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 };
5274
5281
  //# sourceMappingURL=index.mjs.map
5275
5282
  //# sourceMappingURL=index.mjs.map