@g4rcez/components 2.0.13 → 2.0.15
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/components/core/tag.d.ts +1 -0
- package/dist/components/core/tag.d.ts.map +1 -1
- package/dist/components/core/tag.js +1 -0
- package/dist/components/display/calendar.js +2 -2
- package/dist/components/floating/menu.js +1 -1
- package/dist/components/floating/modal.d.ts.map +1 -1
- package/dist/components/floating/modal.js +38 -38
- package/dist/components/floating/tooltip.d.ts.map +1 -1
- package/dist/components/floating/tooltip.js +11 -15
- package/dist/components/table/index.d.ts +2 -26
- package/dist/components/table/index.d.ts.map +1 -1
- package/dist/components/table/index.js +4 -85
- package/dist/components/table/inner-table.d.ts +28 -0
- package/dist/components/table/inner-table.d.ts.map +1 -0
- package/dist/components/table/inner-table.js +85 -0
- package/dist/components/table/row.js +1 -1
- package/dist/components/table/table.context.d.ts +10 -0
- package/dist/components/table/table.context.d.ts.map +1 -0
- package/dist/components/table/table.context.js +4 -0
- package/dist/components/table/thead.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5761 -5682
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +46 -46
- package/dist/index.umd.js.map +1 -1
- package/dist/preset/preset.tailwind.d.ts.map +1 -1
- package/dist/preset/preset.tailwind.js +2 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../src/components/core/tag.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAA,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../src/components/core/tag.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;CAqBb,CAAC;AAEF,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE7C,KAAK,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAsB7C,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,MAAM,IAAI,gBAAgB,CACzE,WAAW,CAAC,OAAO,QAAQ,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,EAC5F,CAAC,CACJ,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,GAkB9E,CAAC"}
|
|
@@ -44,12 +44,12 @@ const focusDate = (origin, root, next, delay = 0) => {
|
|
|
44
44
|
const select = () => {
|
|
45
45
|
if (origin?.dataset.focustrap) {
|
|
46
46
|
const el = root.current?.querySelector(`button[data-focustrap="${origin?.dataset.focustrap}"]`);
|
|
47
|
-
return setTimeout(() => el?.focus({ preventScroll:
|
|
47
|
+
return setTimeout(() => el?.focus({ preventScroll: true }), delay);
|
|
48
48
|
}
|
|
49
49
|
if (root.current) {
|
|
50
50
|
const element = root.current.querySelector(`button[data-date="${d}"]`);
|
|
51
51
|
if (element)
|
|
52
|
-
return element.focus({ preventScroll:
|
|
52
|
+
return element.focus({ preventScroll: true });
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
if (delay === 0)
|
|
@@ -98,7 +98,7 @@ const MenuComponent = React.forwardRef(({ children, FloatingComponent = "div", h
|
|
|
98
98
|
setHasFocusInside(false);
|
|
99
99
|
parent.setHasFocusInside(true);
|
|
100
100
|
},
|
|
101
|
-
})), children: [label, isNested && (_jsxs("span", { style: { marginLeft: 10, fontSize: 10 }, children: [_jsx("span", { className: "sr-only", children: "Next menu" }), _jsx(ChevronRightIcon, { size: 14 })] }))] })) }), _jsx(MenuContext.Provider, { value: { activeIndex, setActiveIndex, getItemProps, setHasFocusInside, isOpen }, children: _jsx(FloatingList, { elementsRef: elementsRef, labelsRef: labelsRef, children: isOpen && (_jsx(FloatingPortal, {
|
|
101
|
+
})), children: [label, isNested && (_jsxs("span", { style: { marginLeft: 10, fontSize: 10 }, children: [_jsx("span", { className: "sr-only", children: "Next menu" }), _jsx(ChevronRightIcon, { size: 14 })] }))] })) }), _jsx(MenuContext.Provider, { value: { activeIndex, setActiveIndex, getItemProps, setHasFocusInside, isOpen }, children: _jsx(FloatingList, { elementsRef: elementsRef, labelsRef: labelsRef, children: isOpen && (_jsx(FloatingPortal, { children: _jsx(FloatingFocusManager, { context: context, modal: false, initialFocus: isNested ? -1 : 0, returnFocus: isParent ? restoreFocus : !isNested, children: _jsx(FloatingComponent, { ...getFloatingProps(), ref: refs.setFloating, style: { ...props.style, ...floatingStyles }, className: css("isolate z-tooltip flex max-h-80 flex-col items-start overflow-y-auto rounded-lg border border-floating-border bg-floating-background text-left shadow-shadow-floating outline-none", floatingClassName), children: children }) }) })) }) })] }));
|
|
102
102
|
});
|
|
103
103
|
export const MenuItem = React.forwardRef(({ title, Right, disabled, children, ...props }, forwardedRef) => {
|
|
104
104
|
const menu = useContext(MenuContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../../src/components/floating/modal.tsx"],"names":[],"mappings":"AACA,OAAO,EASH,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAmB,eAAe,
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../../src/components/floating/modal.tsx"],"names":[],"mappings":"AACA,OAAO,EASH,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAmB,eAAe,EAAmF,MAAM,cAAc,CAAC;AAEjJ,OAAO,KAA+G,MAAM,OAAO,CAAC;AAIpI,OAAO,EAAE,KAAK,EAAO,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMnD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC;AAuD9C,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC7B,eAAe,CAAC,KAAK,CAAC,EACtB,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,GAAG;IAC5E,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C,GAAG,OAAO,CAAC;IACR,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,cAAc,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,OAAO,EAAE,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;CAClC,CAAC,CACL,CAAC;AAgFF,KAAK,QAAQ,GAAG;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;CAAE,CAAC;AAI/D,eAAO,MAAM,KAAK;WAzGJ,KAAK;gBAAc,MAAM;;UACzB,OAAO;cACH,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI;;YAE9B,KAAK;UACP,SAAS;cACL,OAAO;aACR,OAAO;cACN,MAAM;aACP,OAAO;eACL,MAAM;cACP,OAAO;eACN,OAAO;mBACH,MAAM;sBACH,MAAM;cACd,cAAc;uBACL,OAAO;UACpB,QAAQ,GAAG,SAAS;kBACZ,YAAY,EAAE;aACnB,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC;;;;eAnBmB,MAAM;YAAU,KAAK;;UAChE,OAAO;cACH,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI;;YAE9B,KAAK;UACP,SAAS;cACL,OAAO;aACR,OAAO;cACN,MAAM;aACP,OAAO;eACL,MAAM;cACP,OAAO;eACN,OAAO;mBACH,MAAM;sBACH,MAAM;cACd,cAAc;uBACL,OAAO;UACpB,QAAQ,GAAG,SAAS;kBACZ,YAAY,EAAE;aACnB,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC;;;2CA8UrC,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { FloatingFocusManager, FloatingOverlay, FloatingPortal, useClick, useDismiss, useFloating, useInteractions, useRole, } from "@floating-ui/react";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { XIcon } from "lucide-react";
|
|
6
|
-
import { AnimatePresence, motion, useMotionValue } from "motion/react";
|
|
6
|
+
import { AnimatePresence, motion, MotionConfig, useMotionValue } from "motion/react";
|
|
7
7
|
import { Slot as RadixSlot } from "radix-ui";
|
|
8
8
|
import { forwardRef, Fragment, useEffect, useId, useImperativeHandle, useRef } from "react";
|
|
9
9
|
import { useMediaQuery } from "../../hooks/use-media-query";
|
|
@@ -82,7 +82,7 @@ const Draggable = (props) => {
|
|
|
82
82
|
? "top-1 flex h-3 w-full justify-center py-2"
|
|
83
83
|
: props.position === "left"
|
|
84
84
|
? "right-5 top-1/2 h-10 w-2"
|
|
85
|
-
: "left-2 top-1/2 h-10 w-2"), children: props.sheet ? _jsx("div", { className: "
|
|
85
|
+
: "left-2 top-1/2 h-10 w-2"), children: props.sheet ? _jsx("div", { className: "w-1/4 h-2 rounded-lg bg-floating-border" }) : null }));
|
|
86
86
|
};
|
|
87
87
|
const positions = { drawer: "right", sheet: "none", dialog: "none" };
|
|
88
88
|
const fetchPosition = (isDesktop, forceType, propsType, propsPosition) => {
|
|
@@ -168,41 +168,41 @@ export const Modal = forwardRef(({ open, title, footer, asChild, trigger, childr
|
|
|
168
168
|
} : { animate: animated, initial: false };
|
|
169
169
|
const scrollInitial = useMotionValue(undefined);
|
|
170
170
|
const scroll = useMotionValue(undefined);
|
|
171
|
-
return (_jsxs(Fragment, { children: [trigger ? (_jsx(Fragment, { children: asChild ? (_jsx(Slot, { ref: floating.refs.setReference, ...interactions.getReferenceProps({ layoutId: layoutId }), children: Trigger })) : (_jsx(motion.button, { ref: floating.refs.setReference, ...interactions.getReferenceProps(), layoutId: layoutId, type: "button", children: Trigger })) })) : null, _jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(AnimatePresence, { propagate: true, mode: "wait", initial: false, children: open ? (_jsx(FloatingOverlay, { lockScroll: true, className: css("inset-0 isolate z-overlay h-[100dvh] !overflow-clip bg-floating-overlay/70", type === "drawer" ? "" : "flex items-start justify-center p-10", overlayClassName), children: _jsx(FloatingFocusManager, { guards: true, visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: floating.context, children: _jsxs(motion.div, { ...props, ...(title
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
171
|
+
return (_jsxs(Fragment, { children: [trigger ? (_jsx(Fragment, { children: asChild ? (_jsx(Slot, { ref: floating.refs.setReference, ...interactions.getReferenceProps({ layoutId: layoutId }), children: Trigger })) : (_jsx(motion.button, { ref: floating.refs.setReference, ...interactions.getReferenceProps(), layoutId: layoutId, type: "button", children: Trigger })) })) : null, _jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(AnimatePresence, { propagate: true, mode: "wait", initial: false, children: open ? (_jsx(FloatingOverlay, { lockScroll: true, className: css("inset-0 isolate z-overlay h-[100dvh] !overflow-clip bg-floating-overlay/70", type === "drawer" ? "" : "flex items-start justify-center p-10", overlayClassName), children: _jsx(MotionConfig, { reducedMotion: animated ? "user" : "always", children: _jsx(FloatingFocusManager, { guards: true, visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: floating.context, children: _jsxs(motion.div, { ...props, ...(title
|
|
172
|
+
? {
|
|
173
|
+
"aria-labelledby": headingId,
|
|
174
|
+
"aria-describedby": descriptionId,
|
|
175
|
+
}
|
|
176
|
+
: { "aria-label": ariaTitle }), ...interactions.getFloatingProps({
|
|
177
|
+
"aria-modal": open,
|
|
178
|
+
ref: mergeRefs(floating.refs.setFloating, removeScrollRef),
|
|
179
|
+
className: css(variants({ position, type }), className, "isolate overscroll-contain"),
|
|
180
|
+
}), exit: "exit", layout: true, animate: "enter", initial: "initial", layoutId: layoutId, variants: animation, "data-component": "modal", style: type === "drawer" ? { width: floatingSize } : { height: floatingSize }, children: [useResizer && resizer ? (_jsx(Draggable, { onChange: onChange, value: floatingSize, sheet: type === "sheet", position: position, parent: floating.refs.floating })) : null, title ? (_jsx(motion.header, { ...draggableMotionProps, className: "relative w-full isolate", children: title ? (_jsx("h2", { id: headingId, className: "block px-8 pb-2 text-3xl font-medium leading-relaxed border-b select-text border-floating-border", children: title })) : null })) : null, _jsx(motion.section, { ref: innerContent, "data-component": "modal-body", dragConstraints: dragConstraints, drag: isDesktop ? "y" : undefined, onDrag: type === "sheet" ? (isDesktop ? onDragBody : undefined) : undefined, className: css("flex-1 select-text overflow-y-auto px-8 py-1", bodyClassName), onTouchEnd: () => {
|
|
181
|
+
scroll.set(undefined);
|
|
182
|
+
scrollInitial.set(undefined);
|
|
183
|
+
}, onTouchStart: e => {
|
|
184
|
+
const touch = e.changedTouches[0];
|
|
185
|
+
scrollInitial.set(touch.pageY);
|
|
186
|
+
scroll.set(touch.pageY);
|
|
187
|
+
}, onTouchMove: e => {
|
|
188
|
+
const touch = e.changedTouches[0];
|
|
189
|
+
const y = touch.pageY;
|
|
190
|
+
const initial = scrollInitial.get();
|
|
191
|
+
if (initial < y) {
|
|
192
|
+
const distanceFromTop = innerContent.current?.scrollTop;
|
|
193
|
+
if (distanceFromTop === 0) {
|
|
194
|
+
const div = floating.refs.floating.current;
|
|
195
|
+
const rect = div.getBoundingClientRect();
|
|
196
|
+
const v = floatingSize.get() || rect.height;
|
|
197
|
+
const diff = (initial - y) / 10;
|
|
198
|
+
const down = v + diff;
|
|
199
|
+
const max = window.outerHeight;
|
|
200
|
+
const screenHeightToClose = calculateClose(max);
|
|
201
|
+
if (down < screenHeightToClose)
|
|
202
|
+
onChange?.(false);
|
|
203
|
+
floatingSize.set(down);
|
|
204
|
+
}
|
|
204
205
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}, children: children }), footer ? (_jsx("footer", { className: "w-full select-text border-t border-floating-border px-8 pt-4", children: footer })) : null, closable ? (_jsx("nav", { className: "absolute right-4 top-1 z-floating", children: _jsx("button", { type: "button", onClick: onClose, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) })) : null] }) }) })) : null }, headingId) })] }));
|
|
206
|
+
scroll.set(touch.pageY);
|
|
207
|
+
}, children: children }), footer ? (_jsx("footer", { className: "px-8 pt-4 w-full border-t select-text border-floating-border", children: footer })) : null, closable ? (_jsx("nav", { className: "absolute top-1 right-4 z-floating", children: _jsx("button", { type: "button", onClick: onClose, className: "p-1 opacity-70 transition-colors hover:opacity-100 hover:text-danger focus:text-danger", children: _jsx(XIcon, {}) }) })) : null] }) }) }) })) : null }, headingId) })] }));
|
|
208
208
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/floating/tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/floating/tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,EAQH,KAAK,SAAS,EAWjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAA4D,MAAM,OAAO,CAAC;AACjF,OAAO,EAAa,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAI9E,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,MAAM,IAAI,gBAAgB,CAC7E;IACI,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC,EACD,CAAC,CACJ,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,SAAS,aAAa,GAAG,MAAM,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAyF9E,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { arrow, autoUpdate, flip, FloatingArrow, FloatingPortal, offset, safePolygon, shift, useClick, useClientPoint, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole, } from "@floating-ui/react";
|
|
3
|
+
import { arrow, autoPlacement, autoUpdate, flip, FloatingArrow, FloatingPortal, offset, safePolygon, shift, useClick, useClientPoint, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole, } from "@floating-ui/react";
|
|
4
4
|
import { forwardRef, Fragment, useEffect, useRef, useState } from "react";
|
|
5
5
|
import { Polymorph } from "../../components/core/polymorph";
|
|
6
6
|
import { FLOATING_DELAY } from "../../constants";
|
|
7
7
|
import { mergeRefs } from "../../lib/dom";
|
|
8
8
|
import { noop } from "../../lib/fns";
|
|
9
|
-
export const Tooltip = forwardRef(function Tooltip({ as, title, children, placement,
|
|
9
|
+
export const Tooltip = forwardRef(function Tooltip({ as, open, title, children, placement, focus = true, hover = true, enabled = true, popover = true, onChange = noop, followCursor = false, ...props }, outerRef) {
|
|
10
10
|
const [innerOpen, setInnerOpen] = useState(open ?? false);
|
|
11
11
|
const arrowRef = useRef(null);
|
|
12
12
|
const Component = as || "span";
|
|
@@ -15,33 +15,29 @@ export const Tooltip = forwardRef(function Tooltip({ as, title, children, placem
|
|
|
15
15
|
onChange?.(b);
|
|
16
16
|
};
|
|
17
17
|
const { refs, floatingStyles, context } = useFloating({
|
|
18
|
-
open: innerOpen,
|
|
19
18
|
placement,
|
|
20
|
-
|
|
21
|
-
strategy: "absolute",
|
|
19
|
+
open: innerOpen,
|
|
22
20
|
whileElementsMounted: autoUpdate,
|
|
23
21
|
onOpenChange: open ? undefined : toggleBoth,
|
|
24
22
|
middleware: [
|
|
25
23
|
shift(),
|
|
26
24
|
offset(5),
|
|
25
|
+
autoPlacement(),
|
|
26
|
+
arrow({ padding: 5, element: arrowRef }),
|
|
27
27
|
flip({ fallbackAxisSideDirection: "start" }),
|
|
28
|
-
arrow({
|
|
29
|
-
padding: 5,
|
|
30
|
-
element: arrowRef,
|
|
31
|
-
}),
|
|
32
28
|
],
|
|
33
29
|
});
|
|
30
|
+
const dismiss = useDismiss(context, { enabled });
|
|
31
|
+
const role = useRole(context, { role: "tooltip", enabled });
|
|
32
|
+
const focusController = useFocus(context, { enabled: enabled ? focus : false });
|
|
33
|
+
const clickController = useClick(context, { enabled: enabled ? popover : false });
|
|
34
|
+
const clientPoint = useClientPoint(context, { enabled: !!enabled && !!followCursor });
|
|
34
35
|
const hoverController = useHover(context, {
|
|
35
36
|
move: true,
|
|
36
37
|
delay: { open: FLOATING_DELAY },
|
|
37
38
|
enabled: enabled ? hover : false,
|
|
38
39
|
handleClose: popover ? safePolygon() : null,
|
|
39
40
|
});
|
|
40
|
-
const focusController = useFocus(context, { enabled: enabled ? focus : false });
|
|
41
|
-
const clickController = useClick(context, { enabled: enabled ? popover : false });
|
|
42
|
-
const dismiss = useDismiss(context, { enabled });
|
|
43
|
-
const role = useRole(context, { role: "tooltip", enabled });
|
|
44
|
-
const clientPoint = useClientPoint(context, { enabled: !!enabled && !!followCursor });
|
|
45
41
|
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
46
42
|
role,
|
|
47
43
|
dismiss,
|
|
@@ -55,5 +51,5 @@ export const Tooltip = forwardRef(function Tooltip({ as, title, children, placem
|
|
|
55
51
|
return setInnerOpen(false);
|
|
56
52
|
return setInnerOpen(open);
|
|
57
53
|
}, [open]);
|
|
58
|
-
return (_jsxs(Fragment, { children: [_jsx(Component, { ...getReferenceProps(props), ref: mergeRefs(refs.setReference, outerRef), children: title }), innerOpen && (_jsx(FloatingPortal, {
|
|
54
|
+
return (_jsxs(Fragment, { children: [_jsx(Component, { ...getReferenceProps(props), ref: mergeRefs(refs.setReference, outerRef), children: title }), innerOpen && (_jsx(FloatingPortal, { children: _jsxs(Polymorph, { ...getFloatingProps(), ref: refs.setFloating, style: floatingStyles, className: "isolate z-tooltip rounded-lg border border-tooltip-border bg-tooltip-background p-3 text-tooltip-foreground shadow-shadow-floating", children: [_jsx(FloatingArrow, { ref: arrowRef, context: context, strokeWidth: 0.1, className: "fill-tooltip-background stroke-tooltip-border" }), children] }) }))] }));
|
|
59
55
|
});
|
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from "react";
|
|
2
1
|
import { Any } from "../../types";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { GroupItem } from "./group";
|
|
6
|
-
import { Sorter } from "./sort";
|
|
7
|
-
import { CellAsideElement, Col, TableOperationProps } from "./table-lib";
|
|
8
|
-
type InnerTableProps<T extends Any> = HTMLAttributes<HTMLTableElement> & TableOperationProps<T> & {
|
|
9
|
-
rows: T[];
|
|
10
|
-
index: number;
|
|
11
|
-
cols: Col<T>[];
|
|
12
|
-
border?: boolean;
|
|
13
|
-
loading?: boolean;
|
|
14
|
-
group?: GroupItem<T>;
|
|
15
|
-
useControl?: boolean;
|
|
16
|
-
loadingMore?: boolean;
|
|
17
|
-
sorters?: Sorter<T>[];
|
|
18
|
-
showMetadata?: boolean;
|
|
19
|
-
groups?: GroupItem<T>[];
|
|
20
|
-
onScrollEnd?: () => void;
|
|
21
|
-
optionCols: OptionProps[];
|
|
22
|
-
filters?: FilterConfig<T>[];
|
|
23
|
-
Aside?: React.FC<CellAsideElement<T>>;
|
|
24
|
-
getScrollRef?: () => HTMLElement | undefined;
|
|
25
|
-
setGroups: React.Dispatch<React.SetStateAction<GroupItem<T>[]>>;
|
|
26
|
-
};
|
|
2
|
+
import { InnerTableProps } from "./inner-table";
|
|
3
|
+
import { TableOperationProps } from "./table-lib";
|
|
27
4
|
export type TableProps<T extends Any> = Pick<InnerTableProps<T>, "cols" | "rows" | "loadingMore" | "border" | "Aside"> & {
|
|
28
5
|
name: string;
|
|
29
6
|
} & Partial<TableOperationProps<T> & {
|
|
@@ -38,5 +15,4 @@ export type TableProps<T extends Any> = Pick<InnerTableProps<T>, "cols" | "rows"
|
|
|
38
15
|
getScrollRef?: () => HTMLElement | undefined;
|
|
39
16
|
}>;
|
|
40
17
|
export declare const Table: <T extends Any>(props: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
41
|
-
export {};
|
|
42
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/table/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/table/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAc,eAAe,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,EAAyB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIzE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC,GAAG;IACrH,IAAI,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CACP,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;CAChD,CACJ,CAAC;AASF,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,GAAG,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,4CAgHxD,CAAC"}
|
|
@@ -1,94 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import Linq from "linq-arrays";
|
|
4
3
|
import { AnimatePresence } from "motion/react";
|
|
5
|
-
import
|
|
6
|
-
import { TableVirtuoso } from "react-virtuoso";
|
|
7
|
-
import { Is } from "sidekicker";
|
|
4
|
+
import { useMemo } from "react";
|
|
8
5
|
import { useReducer } from "use-typed-reducer";
|
|
9
|
-
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
10
6
|
import { useTweaks } from "../../hooks/use-tweaks";
|
|
11
|
-
import {
|
|
12
|
-
import { SkeletonCell } from "../display/skeleton";
|
|
7
|
+
import { InnerTable } from "./inner-table";
|
|
13
8
|
import { Metadata } from "./metadata";
|
|
14
|
-
import { Pagination } from "./pagination";
|
|
15
|
-
import { Row } from "./row";
|
|
16
|
-
import { multiSort } from "./sort";
|
|
17
9
|
import { createOptionCols } from "./table-lib";
|
|
18
|
-
import {
|
|
19
|
-
const TableContext = createContext({});
|
|
20
|
-
const useTable = () => useContext(TableContext);
|
|
21
|
-
const TableBody = React.forwardRef(({ context, className = "", ...props }, ref) => {
|
|
22
|
-
return (_jsx("tbody", { ...props, role: "rowgroup", className: `divide-y divide-table-border ${className}`, ref: ref, children: _jsx(AnimatePresence, { children: props.children }) }));
|
|
23
|
-
});
|
|
24
|
-
const VirtualTable = React.forwardRef(({ context, className = "", ...props }, ref) => (_jsx("table", { ...props, ref: ref, role: "table", className: `table min-w-full table-fixed border-spacing-0 border-separate text-left ${className ?? ""}` })));
|
|
25
|
-
const Thead = React.forwardRef(({ context, ...props }, ref) => {
|
|
26
|
-
const ctx = useTable();
|
|
27
|
-
const style = {
|
|
28
|
-
...props?.style,
|
|
29
|
-
top: Is.number(ctx.sticky) ? `${ctx.sticky}px` : undefined,
|
|
30
|
-
};
|
|
31
|
-
return (_jsx("thead", { ...props, ref: ref, style: style, role: "rowgroup", className: "hidden top-0 bg-transparent md:table-header-group shadow-shadow-card group:sticky" }));
|
|
32
|
-
});
|
|
33
|
-
const TRow = React.forwardRef(({ context, item, ...props }, ref) => {
|
|
34
|
-
return (_jsx("tr", { ...props, role: "row", ref: ref, className: `group-table-row flex h-fit flex-col flex-wrap justify-center gap-1 md:table-row ${props?.className ?? ""}` }));
|
|
35
|
-
});
|
|
36
|
-
const TFoot = React.forwardRef((props, ref) => {
|
|
37
|
-
if (props.context.loadingMore) {
|
|
38
|
-
return (_jsx("tfoot", { ...props, ref: ref, className: "bg-card-background", children: _jsx("tr", { role: "row", className: "bg-card-background", children: _jsx("td", { colSpan: 999, className: "px-2 h-14 bg-card-background", children: _jsx("span", { className: "block w-full h-2 rounded opacity-60 animate-pulse bg-foreground" }) }) }) }));
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
});
|
|
42
|
-
const components = {
|
|
43
|
-
TableHead: Thead,
|
|
44
|
-
Table: VirtualTable,
|
|
45
|
-
TableBody: TableBody,
|
|
46
|
-
TableRow: TRow,
|
|
47
|
-
TableFoot: TFoot,
|
|
48
|
-
};
|
|
49
|
-
const loadingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
50
|
-
const EmptyContent = (props) => (_jsx("div", { className: "flex justify-center items-center px-2 w-full h-48", children: props.loading ? SkeletonCell : _jsx(Empty, {}) }));
|
|
51
|
-
const EmptyCell = () => _jsx(Fragment, {});
|
|
52
|
-
const Frag = () => _jsx(Fragment, {});
|
|
53
|
-
const emptyRows = [];
|
|
54
|
-
const InnerTable = ({ cols, filters, setCols, sorters, setFilters, setSorters, onScrollEnd, getScrollRef, border = false, pagination = null, useControl = false, ...props }) => {
|
|
55
|
-
const ref = useRef(null);
|
|
56
|
-
const [showLoadingFooter, setShowLoadingFooter] = useState(false);
|
|
57
|
-
const onScrollEndRef = useStableRef(onScrollEnd);
|
|
58
|
-
const loadingMoreRef = useStableRef(props.loadingMore);
|
|
59
|
-
const rows = useMemo(() => {
|
|
60
|
-
if (props.loading)
|
|
61
|
-
return loadingArray;
|
|
62
|
-
if (useControl)
|
|
63
|
-
return props.rows;
|
|
64
|
-
const linq = new Linq(props.rows);
|
|
65
|
-
if (filters.length > 0) {
|
|
66
|
-
filters.forEach((x) => x.value === "" || Number.isNaN(x.value) ? undefined : linq.Where(x.name, x.operation.symbol, x.value));
|
|
67
|
-
}
|
|
68
|
-
if (sorters.length === 0)
|
|
69
|
-
return linq.Select();
|
|
70
|
-
return multiSort(linq.Select(), sorters);
|
|
71
|
-
}, [props.loading, props.rows, useControl, filters, sorters]);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (ref.current === null)
|
|
74
|
-
return () => { };
|
|
75
|
-
const div = ref.current;
|
|
76
|
-
const observer = new IntersectionObserver((entries) => {
|
|
77
|
-
const endOfPage = entries[entries.length - 1];
|
|
78
|
-
const condition = endOfPage.isIntersecting && loadingMoreRef.current;
|
|
79
|
-
if (condition) {
|
|
80
|
-
onScrollEndRef.current?.();
|
|
81
|
-
return void setShowLoadingFooter(true);
|
|
82
|
-
}
|
|
83
|
-
return setShowLoadingFooter(false);
|
|
84
|
-
});
|
|
85
|
-
observer.observe(div);
|
|
86
|
-
return () => observer.disconnect();
|
|
87
|
-
}, [loadingMoreRef, onScrollEndRef]);
|
|
88
|
-
const empty = rows.length === 0;
|
|
89
|
-
const context = { loading: props.loading, loadingMore: props.loadingMore, cols: cols, Aside: props.Aside };
|
|
90
|
-
return (_jsxs("div", { className: "min-w-full", children: [_jsxs("div", { className: `group h-full w-full relative rounded-lg ${border ? "border border-table-border" : ""}`, children: [_jsx(TableVirtuoso, { context: context, components: components, totalCount: rows.length, itemContent: empty ? EmptyCell : Row, data: empty ? emptyRows : rows, useWindowScroll: getScrollRef ? false : true, fixedFooterContent: showLoadingFooter ? Frag : null, customScrollParent: getScrollRef ? getScrollRef() : undefined, fixedHeaderContent: () => (_jsx(TableHeader, { headers: cols, filters: filters, setCols: setCols, sorters: sorters, setFilters: setFilters, setSorters: setSorters, loading: !!props.loading, inlineFilter: props.inlineFilter, inlineSorter: props.inlineSorter })) }), empty ? _jsx(EmptyContent, { loading: props.loading }) : null, _jsx("div", { "aria-hidden": "true", ref: ref, className: "w-full h-0.5" })] }), pagination !== null ? _jsx(Pagination, { ...pagination }) : null] }));
|
|
91
|
-
};
|
|
10
|
+
import { TableProvider } from "./table.context";
|
|
92
11
|
const dispatcherFun = (prev, setter) => typeof setter === "function" ? setter(prev) : setter;
|
|
93
12
|
const compareAndExec = (prev, state, exec) => (prev === state ? undefined : exec?.(state));
|
|
94
13
|
export const Table = (props) => {
|
|
@@ -126,5 +45,5 @@ export const Table = (props) => {
|
|
|
126
45
|
},
|
|
127
46
|
],
|
|
128
47
|
});
|
|
129
|
-
return (
|
|
48
|
+
return (_jsx(TableProvider, { value: contextState, children: _jsxs(AnimatePresence, { initial: false, children: [operations ? (_jsx(Metadata, { cols: state.cols, rows: props.rows, options: optionCols, groups: state.groups, filters: state.filters, setCols: dispatch.cols, sorters: state.sorters, setGroups: dispatch.groups, setFilters: dispatch.filters, setSorters: dispatch.sorters, pagination: props.pagination ?? null, inlineFilter: props.inlineFilter ?? true, inlineSorter: props.inlineSorter ?? true })) : null, state.groups.length === 0 ? (_jsx(InnerTable, { ...props, index: 0, cols: state.cols, options: optionCols, groups: state.groups, filters: state.filters, optionCols: optionCols, setCols: dispatch.cols, sorters: state.sorters, setGroups: dispatch.groups, setFilters: dispatch.filters, setSorters: dispatch.sorters, onScrollEnd: props.onScrollEnd, pagination: props.pagination ?? null, inlineFilter: props.inlineFilter ?? true, inlineSorter: props.inlineSorter ?? true })) : (_jsx("div", { className: "flex flex-wrap gap-4", children: state.groups.map((group, index) => (_jsx("div", { className: "min-w-full", children: _jsx(InnerTable, { ...props, group: group, index: index, cols: state.cols, pagination: null, rows: group.rows, options: optionCols, groups: state.groups, filters: state.filters, optionCols: optionCols, setCols: dispatch.cols, sorters: state.sorters, setGroups: dispatch.groups, setFilters: dispatch.filters, setSorters: dispatch.sorters, onScrollEnd: props.onScrollEnd, inlineFilter: props.inlineFilter ?? true, inlineSorter: props.inlineSorter ?? true }) }, `group-${group.groupId}`))) }))] }) }));
|
|
130
49
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from "react";
|
|
2
|
+
import { Any } from "../../types";
|
|
3
|
+
import { OptionProps } from "../form/select";
|
|
4
|
+
import { FilterConfig } from "./filter";
|
|
5
|
+
import { GroupItem } from "./group";
|
|
6
|
+
import { Sorter } from "./sort";
|
|
7
|
+
import { CellAsideElement, Col, TableOperationProps } from "./table-lib";
|
|
8
|
+
export type InnerTableProps<T extends Any> = HTMLAttributes<HTMLTableElement> & TableOperationProps<T> & {
|
|
9
|
+
rows: T[];
|
|
10
|
+
index: number;
|
|
11
|
+
cols: Col<T>[];
|
|
12
|
+
border?: boolean;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
group?: GroupItem<T>;
|
|
15
|
+
useControl?: boolean;
|
|
16
|
+
loadingMore?: boolean;
|
|
17
|
+
sorters?: Sorter<T>[];
|
|
18
|
+
showMetadata?: boolean;
|
|
19
|
+
groups?: GroupItem<T>[];
|
|
20
|
+
onScrollEnd?: () => void;
|
|
21
|
+
optionCols: OptionProps[];
|
|
22
|
+
filters?: FilterConfig<T>[];
|
|
23
|
+
Aside?: React.FC<CellAsideElement<T>>;
|
|
24
|
+
getScrollRef?: () => HTMLElement | undefined;
|
|
25
|
+
setGroups: React.Dispatch<React.SetStateAction<GroupItem<T>[]>>;
|
|
26
|
+
};
|
|
27
|
+
export declare const InnerTable: <T extends Any>({ cols, filters, setCols, sorters, setFilters, setSorters, onScrollEnd, getScrollRef, border, pagination, useControl, ...props }: InnerTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
//# sourceMappingURL=inner-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inner-table.d.ts","sourceRoot":"","sources":["../../../src/components/table/inner-table.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAA2B,cAAc,EAAwC,MAAM,OAAO,CAAC;AAI7G,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIzE,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAC3E,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACvB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,EAAE,WAAW,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,WAAW,GAAG,SAAS,CAAC;IAC7C,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACjE,CAAC;AA8FJ,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,GAAG,EAAE,kIAavC,eAAe,CAAC,CAAC,CAAC,4CAoEpB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Linq from "linq-arrays";
|
|
3
|
+
import { AnimatePresence } from "motion/react";
|
|
4
|
+
import React, { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { TableVirtuoso } from "react-virtuoso";
|
|
6
|
+
import { Is } from "sidekicker";
|
|
7
|
+
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
8
|
+
import { Empty } from "../display/empty";
|
|
9
|
+
import { SkeletonCell } from "../display/skeleton";
|
|
10
|
+
import { Pagination } from "./pagination";
|
|
11
|
+
import { Row } from "./row";
|
|
12
|
+
import { multiSort } from "./sort";
|
|
13
|
+
import { useTable } from "./table.context";
|
|
14
|
+
import { TableHeader } from "./thead";
|
|
15
|
+
const TableBody = React.forwardRef(({ context, className = "", ...props }, ref) => {
|
|
16
|
+
return (_jsx("tbody", { ...props, role: "rowgroup", className: `divide-y divide-table-border ${className}`, ref: ref, children: _jsx(AnimatePresence, { children: props.children }) }));
|
|
17
|
+
});
|
|
18
|
+
const VirtualTable = React.forwardRef(({ context, className = "", ...props }, ref) => (_jsx("table", { ...props, role: "table", ref: ref, style: { ...props.style, "--table-cell-padding": "0.75rem" }, className: `table w-full table-fixed border-spacing-0 border-separate text-left ${className ?? ""}` })));
|
|
19
|
+
const Thead = React.forwardRef(({ context, ...props }, ref) => {
|
|
20
|
+
const ctx = useTable();
|
|
21
|
+
const style = {
|
|
22
|
+
...props?.style,
|
|
23
|
+
top: Is.number(ctx.sticky) ? `${ctx.sticky}px` : undefined,
|
|
24
|
+
};
|
|
25
|
+
return (_jsx("thead", { ...props, ref: ref, style: style, role: "rowgroup", className: "hidden top-0 bg-transparent md:table-header-group shadow-shadow-card group:sticky" }));
|
|
26
|
+
});
|
|
27
|
+
const TRow = React.forwardRef(({ context, item, ...props }, ref) => {
|
|
28
|
+
return (_jsx("tr", { ...props, role: "row", ref: ref, className: `group-table-row pb-4 flex h-fit flex-col flex-wrap justify-center gap-1 md:table-row ${props?.className ?? ""}` }));
|
|
29
|
+
});
|
|
30
|
+
const TFoot = React.forwardRef((props, ref) => {
|
|
31
|
+
if (props.context.loadingMore) {
|
|
32
|
+
return (_jsx("tfoot", { ...props, ref: ref, className: "bg-card-background", children: _jsx("tr", { role: "row", className: "bg-card-background", children: _jsx("td", { colSpan: 999, className: "px-2 h-14 bg-card-background", children: _jsx("span", { className: "block w-full h-2 rounded opacity-60 animate-pulse bg-foreground" }) }) }) }));
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
});
|
|
36
|
+
const components = {
|
|
37
|
+
TableHead: Thead,
|
|
38
|
+
Table: VirtualTable,
|
|
39
|
+
TableBody: TableBody,
|
|
40
|
+
TableRow: TRow,
|
|
41
|
+
TableFoot: TFoot,
|
|
42
|
+
};
|
|
43
|
+
const loadingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
44
|
+
const EmptyContent = (props) => (_jsx("div", { className: "flex justify-center items-center px-2 w-full h-48", children: props.loading ? SkeletonCell : _jsx(Empty, {}) }));
|
|
45
|
+
const EmptyCell = () => _jsx(Fragment, {});
|
|
46
|
+
const Frag = () => _jsx(Fragment, {});
|
|
47
|
+
const emptyRows = [];
|
|
48
|
+
export const InnerTable = ({ cols, filters, setCols, sorters, setFilters, setSorters, onScrollEnd, getScrollRef, border = true, pagination = null, useControl = false, ...props }) => {
|
|
49
|
+
const ref = useRef(null);
|
|
50
|
+
const [showLoadingFooter, setShowLoadingFooter] = useState(false);
|
|
51
|
+
const onScrollEndRef = useStableRef(onScrollEnd);
|
|
52
|
+
const loadingMoreRef = useStableRef(props.loadingMore);
|
|
53
|
+
const rows = useMemo(() => {
|
|
54
|
+
if (props.loading)
|
|
55
|
+
return loadingArray;
|
|
56
|
+
if (useControl)
|
|
57
|
+
return props.rows;
|
|
58
|
+
const linq = new Linq(props.rows);
|
|
59
|
+
if (filters.length > 0) {
|
|
60
|
+
filters.forEach((x) => x.value === "" || Number.isNaN(x.value) ? undefined : linq.Where(x.name, x.operation.symbol, x.value));
|
|
61
|
+
}
|
|
62
|
+
if (sorters.length === 0)
|
|
63
|
+
return linq.Select();
|
|
64
|
+
return multiSort(linq.Select(), sorters);
|
|
65
|
+
}, [props.loading, props.rows, useControl, filters, sorters]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (ref.current === null)
|
|
68
|
+
return () => { };
|
|
69
|
+
const div = ref.current;
|
|
70
|
+
const observer = new IntersectionObserver((entries) => {
|
|
71
|
+
const endOfPage = entries[entries.length - 1];
|
|
72
|
+
const condition = endOfPage.isIntersecting && loadingMoreRef.current;
|
|
73
|
+
if (condition) {
|
|
74
|
+
onScrollEndRef.current?.();
|
|
75
|
+
return void setShowLoadingFooter(true);
|
|
76
|
+
}
|
|
77
|
+
return setShowLoadingFooter(false);
|
|
78
|
+
});
|
|
79
|
+
observer.observe(div);
|
|
80
|
+
return () => observer.disconnect();
|
|
81
|
+
}, [loadingMoreRef, onScrollEndRef]);
|
|
82
|
+
const empty = rows.length === 0;
|
|
83
|
+
const context = { loading: props.loading, loadingMore: props.loadingMore, cols: cols, Aside: props.Aside };
|
|
84
|
+
return (_jsxs("div", { className: "flex relative flex-col w-full whitespace-nowrap rounded-lg group", children: [_jsx(TableVirtuoso, { context: context, components: components, totalCount: rows.length, itemContent: empty ? EmptyCell : Row, data: empty ? emptyRows : rows, useWindowScroll: getScrollRef ? false : true, customScrollParent: getScrollRef ? getScrollRef() : undefined, fixedHeaderContent: () => (_jsx(TableHeader, { headers: cols, filters: filters, setCols: setCols, sorters: sorters, setFilters: setFilters, setSorters: setSorters, loading: !!props.loading, inlineFilter: props.inlineFilter, inlineSorter: props.inlineSorter })) }), empty ? _jsx(EmptyContent, { loading: props.loading }) : null, _jsx("div", { "aria-hidden": "true", ref: ref, className: "w-full h-0.5" }), pagination !== null ? _jsx(Pagination, { ...pagination }) : null] }));
|
|
85
|
+
};
|
|
@@ -39,7 +39,7 @@ export const Row = (index, row, context) => {
|
|
|
39
39
|
const className = col.cellProps?.className || "";
|
|
40
40
|
const exposeAside = colIndex === 0 && context.Aside && loading === false;
|
|
41
41
|
const Aside = context.Aside;
|
|
42
|
-
return (_createElement("td", { ...col.cellProps, role: "cell", "data-matrix": matrix, key: `accessor-${index}-${colIndex}`, className: `group-table-cell
|
|
42
|
+
return (_createElement("td", { ...col.cellProps, role: "cell", "data-matrix": matrix, key: `accessor-${index}-${colIndex}`, className: `typography group-table-cell p-[var(--table-cell-padding)] whitespace-pre-wrap flex flex-col md:table-cell border-b border md:border-l-transparent md:border-b-0 border-y border-collapse border-table-border md:border-r md:last:border-r-transparent ${className}` },
|
|
43
43
|
exposeAside ? (_jsx(RowAside, { children: _jsx(Aside, { col: col, row: row, rowIndex: index }) })) : null,
|
|
44
44
|
_jsx("span", { className: "block text-sm font-bold leading-tight md:hidden", children: col.thead }),
|
|
45
45
|
_jsx("span", { className: "relative", children: loading ? (SkeletonCell) : Component ? (_jsx(Fragment, { children: _jsx(Component, { row: row, matrix: matrix, col: col, rowIndex: index, value: value }) })) : (_jsx(Fragment, { children: Is.nil(value) ? "" : value })) })));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type TableContextProps = Partial<{
|
|
2
|
+
sticky: number;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const TableProvider: import("react").Provider<Partial<{
|
|
5
|
+
sticky: number;
|
|
6
|
+
}>>;
|
|
7
|
+
export declare const useTable: () => Partial<{
|
|
8
|
+
sticky: number;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=table.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.context.d.ts","sourceRoot":"","sources":["../../../src/components/table/table.context.tsx"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAI5D,eAAO,MAAM,aAAa;YAJwB,MAAM;GAIN,CAAC;AAEnD,eAAO,MAAM,QAAQ;YAN6B,MAAM;EAMF,CAAC"}
|
|
@@ -42,7 +42,7 @@ const HeaderChild = (props) => {
|
|
|
42
42
|
const ownSorter = props.sorters.find((x) => props.header.id === x.value);
|
|
43
43
|
const ariaSort = !ownSorter?.type ? "none" : ownSorter.type === Order.Asc ? "ascending" : "descending";
|
|
44
44
|
const label = getLabel(props.header);
|
|
45
|
-
return (_jsxs(Reorder.Item, { ...props.header.thProps, as: "th", ref: dragRef, initial: false, dragSnapToOrigin: true, dragDirectionLock: true, role: "columnheader", "aria-sort": ariaSort, value: props.header, "aria-busy": props.loading, "data-tableheader": props.header.id, whileDrag: { cursor: "grabbing" }, className: `relative min-w-0 cursor-grab font-medium ${props.header.thProps?.className ?? ""}`, children: [_jsx("span", { className: `flex h-full items-center justify-between bg-table-header
|
|
45
|
+
return (_jsxs(Reorder.Item, { ...props.header.thProps, as: "th", ref: dragRef, initial: false, dragSnapToOrigin: true, dragDirectionLock: true, role: "columnheader", "aria-sort": ariaSort, value: props.header, "aria-busy": props.loading, "data-tableheader": props.header.id, whileDrag: { cursor: "grabbing" }, className: `relative md:h-14 typography min-w-0 cursor-grab font-medium ${props.header.thProps?.className ?? ""}`, children: [_jsx("span", { className: `flex h-full items-center justify-between bg-table-header p-[var(--table-cell-padding)] ${props.isLast ? "rounded-tr-lg" : ""} ${props.index === 0 ? "rounded-tl-lg" : ""}`, children: _jsxs("span", { className: "flex gap-1 items-center", children: [props.inlineFilter && defaultAllowFilter ? (_jsx(Dropdown, { arrow: true, trigger: _jsxs("span", { children: [_jsxs("span", { id: `${props.header.id}-filter-dropdown-button`, className: "sr-only", children: [translation.tableFilterDropdownTitleUnique, " ", label] }), _jsx(FilterIcon, { "aria-labelledby": `${props.header.id}-filter-dropdown-button`, size: 14 })] }), title: _jsxs("span", { className: "text-lg", children: [translation.tableFilterDropdownTitleUnique, " ", _jsx("span", { className: "font-medium", children: label })] }), children: _jsxs("ul", { className: "font-medium", children: [ownFilters.length === 0 ? null : (_jsx(Fragment, { children: ownFilters.map((filter) => (_jsx("li", { className: "my-1", children: _jsx(ColumnHeaderFilter, { onDelete: onDelete, filter: filter, set: props.setFilters }) }, `thead-filter-${filter.id}`))) })), _jsx("li", { children: _jsxs("button", { type: "button", className: "flex gap-1 items-center text-primary", onClick: () => props.setFilters((prev) => prev.concat(createFilterFromCol(props.header, operators.options, operators.operations))), children: [_jsx(PlusIcon, { size: 14 }), " ", translation.tableFilterNewFilter] }) })] }) })) : null, _jsx("span", { className: "text-base pointer-events-auto text-balance", children: props.header.thead }), props.inlineSorter && defaultAllowSort ? (_jsx(SorterHead, { col: props.header, setSorters: props.setSorters, sorters: props.sorters })) : null] }) }), props.isLast ? null : (_jsx(motion.button, { drag: "x", draggable: true, dragListener: true, dragMomentum: true, type: "button", animate: false, dragElastic: 0, dragPropagation: true, initial: false, dragSnapToOrigin: true, dragDirectionLock: true, "data-type": "resizer", title: props.header.id, dragConstraints: dragConstraints, className: "block absolute top-0 h-full hover:w-1.5 active:w-1.5 -right-[0.5px] z-calendar w-[1px] cursor-col-resize bg-table-border hover:bg-primary active:bg-primary", onClick: (e) => void e.currentTarget.focus(), onKeyDown: (e) => {
|
|
46
46
|
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
47
47
|
if (th.current === null)
|
|
48
48
|
return;
|