@sustaina/shared-ui 1.5.0 → 1.6.1
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.mts +32 -16
- package/dist/index.d.ts +32 -16
- package/dist/index.js +123 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import { CSS } from '@dnd-kit/utilities';
|
|
|
16
16
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
17
17
|
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
18
18
|
import { useSensors, useSensor, PointerSensor, DndContext, closestCenter } from '@dnd-kit/core';
|
|
19
|
+
import { restrictToParentElement, restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
19
20
|
import { z } from 'zod';
|
|
20
21
|
import { createPortal } from 'react-dom';
|
|
21
22
|
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
@@ -123,6 +124,35 @@ function FormLabel({ children, className, errorClassName, required, ...props })
|
|
|
123
124
|
);
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
// src/utils/common.ts
|
|
128
|
+
function isDefined(value) {
|
|
129
|
+
return value !== null && value !== void 0;
|
|
130
|
+
}
|
|
131
|
+
function isEmptyObject(value) {
|
|
132
|
+
return !!value && Object.keys(value).length === 0 && value.constructor === Object;
|
|
133
|
+
}
|
|
134
|
+
function debounce(fn, delay = 150) {
|
|
135
|
+
let timeout = null;
|
|
136
|
+
return (...args) => {
|
|
137
|
+
if (timeout) clearTimeout(timeout);
|
|
138
|
+
timeout = setTimeout(() => {
|
|
139
|
+
fn(...args);
|
|
140
|
+
}, delay);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/utils/filters.ts
|
|
145
|
+
function stripNullishObject(value) {
|
|
146
|
+
if (!isDefined(value)) {
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
return Object.fromEntries(Object.entries(value).filter(([, propValue]) => isDefined(propValue)));
|
|
151
|
+
} catch {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
126
156
|
// src/utils/getColumnIdFromTable.ts
|
|
127
157
|
function getColumnIdFromTable(table) {
|
|
128
158
|
const allColumns = table.getAllColumns();
|
|
@@ -336,23 +366,36 @@ var useScreenSize = (breakpoints) => {
|
|
|
336
366
|
return { isMobile, isTablet, isDesktop };
|
|
337
367
|
};
|
|
338
368
|
var useScreenSize_default = useScreenSize;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
369
|
+
var useTruncated = ({
|
|
370
|
+
elementRef,
|
|
371
|
+
onChange,
|
|
372
|
+
resizeDetectDelay = 150
|
|
373
|
+
}) => {
|
|
374
|
+
const [isTruncated, setIsTruncated] = useState(false);
|
|
375
|
+
useEffect(() => {
|
|
376
|
+
const element = elementRef.current;
|
|
377
|
+
if (!element) return;
|
|
378
|
+
const checkTruncate = debounce(() => {
|
|
379
|
+
const truncated = element.scrollWidth > element.clientWidth;
|
|
380
|
+
setIsTruncated((prev) => {
|
|
381
|
+
if (prev !== truncated) {
|
|
382
|
+
onChange?.(truncated);
|
|
383
|
+
}
|
|
384
|
+
return truncated;
|
|
385
|
+
});
|
|
386
|
+
}, resizeDetectDelay);
|
|
387
|
+
checkTruncate();
|
|
388
|
+
const observer = new ResizeObserver(checkTruncate);
|
|
389
|
+
observer.observe(element);
|
|
390
|
+
window.addEventListener("resize", checkTruncate);
|
|
391
|
+
return () => {
|
|
392
|
+
observer.disconnect();
|
|
393
|
+
window.removeEventListener("resize", checkTruncate);
|
|
394
|
+
};
|
|
395
|
+
}, [elementRef, onChange, resizeDetectDelay]);
|
|
396
|
+
return isTruncated;
|
|
397
|
+
};
|
|
398
|
+
var useTruncated_default = useTruncated;
|
|
356
399
|
var HeaderCell = ({ rootClassName, labelClassName, context, label, sorterProps }) => {
|
|
357
400
|
const { ref, hovering } = useHover_default();
|
|
358
401
|
const showSorter = sorterProps?.show ?? context.column.getCanSort();
|
|
@@ -1371,6 +1414,7 @@ function SelectContent({
|
|
|
1371
1414
|
function SelectItem({
|
|
1372
1415
|
className,
|
|
1373
1416
|
children,
|
|
1417
|
+
hideCheckIcon,
|
|
1374
1418
|
...props
|
|
1375
1419
|
}) {
|
|
1376
1420
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1383,6 +1427,7 @@ function SelectItem({
|
|
|
1383
1427
|
),
|
|
1384
1428
|
...props,
|
|
1385
1429
|
children: [
|
|
1430
|
+
!hideCheckIcon && //
|
|
1386
1431
|
/* @__PURE__ */ jsx("span", { className: "absolute right-2 flex size-3.5 items-center justify-center", children: /* @__PURE__ */ jsx(SelectPrimitive.ItemIndicator, { children: /* @__PURE__ */ jsx(CheckIcon, { className: "size-4" }) }) }),
|
|
1387
1432
|
/* @__PURE__ */ jsx(SelectPrimitive.ItemText, { children })
|
|
1388
1433
|
]
|
|
@@ -1522,6 +1567,7 @@ function SortableRow({
|
|
|
1522
1567
|
SelectItem,
|
|
1523
1568
|
{
|
|
1524
1569
|
value: opt.id,
|
|
1570
|
+
hideCheckIcon: true,
|
|
1525
1571
|
className: cn(
|
|
1526
1572
|
"focus:bg-[#e8edea]",
|
|
1527
1573
|
opt.id === field.value ? "font-bold bg-[#dae5de] focus:bg-[#dae5de]" : ""
|
|
@@ -1715,11 +1761,12 @@ var GridSettingsModal = ({
|
|
|
1715
1761
|
},
|
|
1716
1762
|
fields[0]?.fieldId
|
|
1717
1763
|
),
|
|
1718
|
-
/* @__PURE__ */ jsx(
|
|
1764
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsx(
|
|
1719
1765
|
DndContext,
|
|
1720
1766
|
{
|
|
1721
1767
|
sensors,
|
|
1722
1768
|
collisionDetection: closestCenter,
|
|
1769
|
+
modifiers: [restrictToParentElement, restrictToVerticalAxis],
|
|
1723
1770
|
onDragStart: () => setIsDragging(true),
|
|
1724
1771
|
onDragEnd: (event) => {
|
|
1725
1772
|
setIsDragging(false);
|
|
@@ -1745,7 +1792,7 @@ var GridSettingsModal = ({
|
|
|
1745
1792
|
}
|
|
1746
1793
|
)
|
|
1747
1794
|
}
|
|
1748
|
-
),
|
|
1795
|
+
) }),
|
|
1749
1796
|
/* @__PURE__ */ jsx("div", { className: "px-6", children: /* @__PURE__ */ jsxs(
|
|
1750
1797
|
Button2,
|
|
1751
1798
|
{
|
|
@@ -4916,7 +4963,7 @@ function DialogContent2({
|
|
|
4916
4963
|
{
|
|
4917
4964
|
"data-slot": "dialog-content",
|
|
4918
4965
|
className: cn3(
|
|
4919
|
-
"bg-
|
|
4966
|
+
"bg-white 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",
|
|
4920
4967
|
className
|
|
4921
4968
|
),
|
|
4922
4969
|
...props,
|
|
@@ -4976,13 +5023,15 @@ var buttonVariants4 = cva(
|
|
|
4976
5023
|
{
|
|
4977
5024
|
variants: {
|
|
4978
5025
|
variant: {
|
|
4979
|
-
default: "bg-
|
|
4980
|
-
|
|
4981
|
-
|
|
5026
|
+
default: "border bg-[#8B8B8B] text-white shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:hover:bg-input/50",
|
|
5027
|
+
success: "bg-sus-primary-1 text-primary-foreground shadow-xs hover:bg-sus-primary/90",
|
|
5028
|
+
error: "border border-[#BB0B0E] bg-background shadow-xs hover:bg-accent hover:text-accent-foreground text-[#BB0B0E]",
|
|
5029
|
+
warning: "bg-yellow-500 text-black shadow-xs hover:bg-yellow-600 dark:hover:bg-yellow-400",
|
|
5030
|
+
cancel: "border bg-[#8B8B8B] text-white shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:hover:bg-input/50"
|
|
4982
5031
|
},
|
|
4983
5032
|
size: {
|
|
4984
|
-
default: "h-9 px-4
|
|
4985
|
-
option: "py-5 h-9 px-4
|
|
5033
|
+
default: "h-9 px-4 has-[>svg]:px-3",
|
|
5034
|
+
option: "py-5 h-9 px-4 has-[>svg]:px-3",
|
|
4986
5035
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
4987
5036
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
4988
5037
|
icon: "size-9",
|
|
@@ -4992,7 +5041,7 @@ var buttonVariants4 = cva(
|
|
|
4992
5041
|
"icon-lg": "size-10"
|
|
4993
5042
|
},
|
|
4994
5043
|
active: {
|
|
4995
|
-
true: "
|
|
5044
|
+
true: "opacity-90 ring-2 ring-offset-1 ring-ring",
|
|
4996
5045
|
false: ""
|
|
4997
5046
|
}
|
|
4998
5047
|
},
|
|
@@ -5015,42 +5064,58 @@ function Button4({
|
|
|
5015
5064
|
Comp,
|
|
5016
5065
|
{
|
|
5017
5066
|
"data-slot": "button",
|
|
5018
|
-
className: cn3(buttonVariants4({ variant, size,
|
|
5067
|
+
className: cn3(buttonVariants4({ variant, size, active, className })),
|
|
5019
5068
|
...props
|
|
5020
5069
|
}
|
|
5021
5070
|
);
|
|
5022
5071
|
}
|
|
5023
|
-
function
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5072
|
+
function DialogAlert({
|
|
5073
|
+
open,
|
|
5074
|
+
onOpenChange,
|
|
5075
|
+
title,
|
|
5076
|
+
description,
|
|
5077
|
+
variant = "default",
|
|
5078
|
+
confirmText,
|
|
5079
|
+
cancelText = "Cancel",
|
|
5080
|
+
onConfirm,
|
|
5081
|
+
onCancel,
|
|
5082
|
+
showCancel = true,
|
|
5083
|
+
align = "center",
|
|
5084
|
+
outlet
|
|
5085
|
+
}) {
|
|
5086
|
+
const alignClass = align === "start" ? "justify-start" : align === "end" ? "justify-end" : "justify-center";
|
|
5087
|
+
const handleCancel = useCallback(() => {
|
|
5088
|
+
onCancel?.();
|
|
5089
|
+
onOpenChange(false);
|
|
5090
|
+
}, [onCancel, onOpenChange]);
|
|
5091
|
+
const handleConfirm = useCallback(() => {
|
|
5092
|
+
onConfirm?.();
|
|
5093
|
+
}, [onConfirm]);
|
|
5094
|
+
return /* @__PURE__ */ jsx(Dialog2, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent2, { className: "max-w-md", children: [
|
|
5035
5095
|
/* @__PURE__ */ jsxs(DialogHeader2, { children: [
|
|
5036
|
-
/* @__PURE__ */ jsx(DialogTitle2, { className:
|
|
5037
|
-
/* @__PURE__ */ jsx(DialogDescription2, { children:
|
|
5096
|
+
title && /* @__PURE__ */ jsx(DialogTitle2, { className: variantClass(variant), children: title }),
|
|
5097
|
+
description && /* @__PURE__ */ jsx(DialogDescription2, { children: description })
|
|
5038
5098
|
] }),
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
{
|
|
5044
|
-
variant: dialogData.variantBtn || "default",
|
|
5045
|
-
disabled: dialogData.btnState === false,
|
|
5046
|
-
onClick: dialogData.onClickBtn,
|
|
5047
|
-
children: dialogData.btn
|
|
5048
|
-
}
|
|
5049
|
-
)
|
|
5099
|
+
outlet && outlet,
|
|
5100
|
+
/* @__PURE__ */ jsxs("div", { className: `flex gap-3 mt-3 ${alignClass}`, children: [
|
|
5101
|
+
showCancel && /* @__PURE__ */ jsx(Button4, { variant: "cancel", onClick: handleCancel, children: cancelText }),
|
|
5102
|
+
confirmText && /* @__PURE__ */ jsx(Button4, { variant, onClick: handleConfirm, children: confirmText })
|
|
5050
5103
|
] })
|
|
5051
5104
|
] }) });
|
|
5052
5105
|
}
|
|
5106
|
+
function variantClass(variant) {
|
|
5107
|
+
switch (variant) {
|
|
5108
|
+
case "success":
|
|
5109
|
+
return "text-green-600";
|
|
5110
|
+
case "error":
|
|
5111
|
+
return "text-red-600";
|
|
5112
|
+
case "warning":
|
|
5113
|
+
return "text-yellow-600";
|
|
5114
|
+
default:
|
|
5115
|
+
return "";
|
|
5116
|
+
}
|
|
5117
|
+
}
|
|
5053
5118
|
|
|
5054
|
-
export { AdvanceSearch_default as AdvanceSearch, Button, DataTable_default as DataTable,
|
|
5119
|
+
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 };
|
|
5055
5120
|
//# sourceMappingURL=index.mjs.map
|
|
5056
5121
|
//# sourceMappingURL=index.mjs.map
|