@pagamio/frontend-commons-lib 0.8.264 → 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.
@@ -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
- return Math.floor((Date.now() - start.getTime()) / 1000);
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 [elapsed, setElapsed] = React.useState(() => getElapsedSeconds(startTime));
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.264",
4
+ "version": "0.8.265",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false