@pagamio/frontend-commons-lib 0.8.263 → 0.8.265
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.
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { MRT_Cell } from 'mantine-react-table';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
2
3
|
export interface StatusCellProps<T extends Record<string, any> = {}> {
|
|
3
4
|
readonly cell: MRT_Cell<T>;
|
|
4
5
|
readonly color: string;
|
|
5
6
|
readonly displayValue: string;
|
|
6
7
|
readonly className?: string;
|
|
8
|
+
readonly icon?: ReactNode;
|
|
7
9
|
}
|
|
8
|
-
declare function StatusCell<T extends Record<string, any> = {}>({ displayValue, className, }: Readonly<StatusCellProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
declare function StatusCell<T extends Record<string, any> = {}>({ displayValue, className, icon, }: Readonly<StatusCellProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
9
11
|
export default StatusCell;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
function StatusCell({ displayValue, className = '', }) {
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
function StatusCell({ displayValue, className = '', icon, }) {
|
|
3
3
|
const baseClass = 'rounded-full px-4 py-1.5 whitespace-nowrap';
|
|
4
|
+
if (icon) {
|
|
5
|
+
return (_jsxs("span", { className: `inline-flex items-center gap-1 ${baseClass} ${className}`.trim(), children: [icon, displayValue] }));
|
|
6
|
+
}
|
|
4
7
|
return _jsx("span", { className: `${baseClass} ${className}`.trim(), children: displayValue });
|
|
5
8
|
}
|
|
6
9
|
export default StatusCell;
|
|
@@ -14,6 +14,8 @@ import * as React from 'react';
|
|
|
14
14
|
export interface TimerBadgeProps {
|
|
15
15
|
/** ISO date string or Date object marking when the timer started */
|
|
16
16
|
startTime: string | Date;
|
|
17
|
+
/** ISO date string or Date object marking when the timer stopped. When set, the timer freezes at this time instead of counting up. */
|
|
18
|
+
stopTime?: string | Date | null;
|
|
17
19
|
/** Minutes elapsed before turning amber (default: 15) */
|
|
18
20
|
warningMinutes?: number;
|
|
19
21
|
/** Minutes elapsed before turning red (default: 30) */
|
|
@@ -16,9 +16,10 @@ import { cn } from '../../helpers/utils';
|
|
|
16
16
|
// =============================================================================
|
|
17
17
|
// HELPERS
|
|
18
18
|
// =============================================================================
|
|
19
|
-
function getElapsedSeconds(startTime) {
|
|
19
|
+
function getElapsedSeconds(startTime, stopTime) {
|
|
20
20
|
const start = typeof startTime === 'string' ? new Date(startTime) : startTime;
|
|
21
|
-
|
|
21
|
+
const end = stopTime ? (typeof stopTime === 'string' ? new Date(stopTime) : stopTime).getTime() : Date.now();
|
|
22
|
+
return Math.max(0, Math.floor((end - start.getTime()) / 1000));
|
|
22
23
|
}
|
|
23
24
|
function formatElapsed(totalSeconds) {
|
|
24
25
|
const minutes = Math.floor(totalSeconds / 60);
|
|
@@ -28,14 +29,19 @@ function formatElapsed(totalSeconds) {
|
|
|
28
29
|
// =============================================================================
|
|
29
30
|
// COMPONENT
|
|
30
31
|
// =============================================================================
|
|
31
|
-
const TimerBadge = ({ startTime, warningMinutes = 15, dangerMinutes = 30, size = 'sm', className, }) => {
|
|
32
|
-
const
|
|
32
|
+
const TimerBadge = ({ startTime, stopTime, warningMinutes = 15, dangerMinutes = 30, size = 'sm', className, }) => {
|
|
33
|
+
const isStopped = !!stopTime;
|
|
34
|
+
const [elapsed, setElapsed] = React.useState(() => getElapsedSeconds(startTime, stopTime));
|
|
33
35
|
React.useEffect(() => {
|
|
36
|
+
if (isStopped) {
|
|
37
|
+
setElapsed(getElapsedSeconds(startTime, stopTime));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
34
40
|
const interval = setInterval(() => {
|
|
35
41
|
setElapsed(getElapsedSeconds(startTime));
|
|
36
42
|
}, 1000);
|
|
37
43
|
return () => clearInterval(interval);
|
|
38
|
-
}, [startTime]);
|
|
44
|
+
}, [startTime, stopTime, isStopped]);
|
|
39
45
|
const minutes = elapsed / 60;
|
|
40
46
|
const urgency = minutes >= dangerMinutes ? 'danger' : minutes >= warningMinutes ? 'warning' : 'safe';
|
|
41
47
|
return (_jsxs("span", { className: cn('inline-flex items-center gap-1 rounded-full font-mono font-medium tabular-nums', size === 'sm' ? 'px-2 py-0.5 text-xs' : 'px-2.5 py-1 text-sm', urgency === 'safe' && 'bg-emerald-500/15 text-emerald-600 dark:text-emerald-400', urgency === 'warning' && 'bg-amber-500/15 text-amber-600 dark:text-amber-400', urgency === 'danger' && 'bg-red-500/15 text-red-600 dark:text-red-400', className), children: [_jsxs("svg", { className: cn('h-3 w-3 flex-shrink-0', size === 'md' && 'h-3.5 w-3.5'), fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("polyline", { points: "12 6 12 12 16 14" })] }), formatElapsed(elapsed)] }));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.265",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|