server-time-timer-yolabs-ui 1.0.5 → 1.0.6

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,12 +1,15 @@
1
- export declare function useServerTimer({ serverNow, endTime, onEnd }: {
2
- serverNow: string;
3
- endTime: string;
4
- onEnd?: () => void;
5
- }): {
1
+ interface TimeState {
2
+ totalMs: number;
6
3
  days: number;
7
4
  hours: number;
8
5
  minutes: number;
9
6
  seconds: number;
10
- totalMs: number;
11
7
  progress: number;
12
- };
8
+ }
9
+ interface UseServerTimerProps {
10
+ serverNow: string;
11
+ endTime: string;
12
+ onEnd?: () => void;
13
+ }
14
+ export declare const useServerTimer: ({ serverNow, endTime, onEnd }: UseServerTimerProps) => TimeState;
15
+ export {};
@@ -1,34 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useServerTimer = useServerTimer;
3
+ exports.useServerTimer = void 0;
4
4
  const react_1 = require("react");
5
- const server_time_timer_yolabs_1 = require("server-time-timer-yolabs");
6
- function useServerTimer({ serverNow, endTime, onEnd }) {
5
+ const useServerTimer = ({ serverNow, endTime, onEnd }) => {
7
6
  const [time, setTime] = (0, react_1.useState)({
7
+ totalMs: 0,
8
8
  days: 0,
9
9
  hours: 0,
10
10
  minutes: 0,
11
11
  seconds: 0,
12
- totalMs: 0,
13
- progress: 100
12
+ progress: 100,
14
13
  });
15
14
  (0, react_1.useEffect)(() => {
16
- const timer = (0, server_time_timer_yolabs_1.createServerTimer)({ serverNow, endTime });
17
- timer.onTick((t) => {
18
- const totalDuration = new Date(endTime).getTime() - new Date(serverNow).getTime();
19
- setTime({
20
- days: t.days,
21
- hours: t.hours,
22
- minutes: t.minutes,
23
- seconds: t.seconds,
24
- totalMs: t.totalMs,
25
- progress: Math.max(0, (t.totalMs / totalDuration) * 100)
26
- });
27
- if (t.totalMs <= 0 && onEnd)
15
+ const start = new Date(serverNow).getTime();
16
+ const end = new Date(endTime).getTime();
17
+ const totalDuration = end - start;
18
+ const update = () => {
19
+ const now = Date.now();
20
+ const totalMs = end - now;
21
+ const clampedMs = Math.max(totalMs, 0);
22
+ const remaining = clampedMs;
23
+ const days = Math.floor(remaining / (1000 * 60 * 60 * 24));
24
+ const hours = Math.floor((remaining / (1000 * 60 * 60)) % 24);
25
+ const minutes = Math.floor((remaining / (1000 * 60)) % 60);
26
+ const seconds = Math.floor((remaining / 1000) % 60);
27
+ const progress = Math.max((remaining / totalDuration) * 100, 0);
28
+ setTime({ totalMs: clampedMs, days, hours, minutes, seconds, progress });
29
+ if (clampedMs <= 0 && onEnd)
28
30
  onEnd();
29
- });
30
- timer.start();
31
- return () => timer.stop();
31
+ };
32
+ update();
33
+ const interval = setInterval(update, 1000);
34
+ return () => clearInterval(interval);
32
35
  }, [serverNow, endTime, onEnd]);
33
36
  return time;
34
- }
37
+ };
38
+ exports.useServerTimer = useServerTimer;
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
2
  import { ServerTimerUIProps } from './types';
3
3
  export declare const ServerTimerUI: React.FC<ServerTimerUIProps>;
4
+ export default ServerTimerUI;
@@ -9,8 +9,9 @@ const TimerContainer_1 = __importDefault(require("./components/TimerContainer"))
9
9
  const TimerUnit_1 = __importDefault(require("./components/TimerUnit"));
10
10
  const TimerProgress_1 = __importDefault(require("./components/TimerProgress"));
11
11
  const useServerTimer_1 = require("../hooks/useServerTimer");
12
- const ServerTimerUI = ({ serverNow, endTime, size = 'md', theme = 'light', layout = 'horizontal', showProgress = true, customColors, showUnits = { days: true, hours: true, minutes: true, seconds: true }, onEnd }) => {
12
+ const ServerTimerUI = ({ serverNow, endTime, size = 'md', layout = 'horizontal', theme = 'light', showProgress = true, customColors, showUnits = { days: true, hours: true, minutes: true, seconds: true }, onEnd }) => {
13
13
  const time = (0, useServerTimer_1.useServerTimer)({ serverNow, endTime, onEnd });
14
- return ((0, jsx_runtime_1.jsxs)(TimerContainer_1.default, { size: size, background: customColors === null || customColors === void 0 ? void 0 : customColors.background, color: customColors === null || customColors === void 0 ? void 0 : customColors.text, children: [showUnits.days && (0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Days", value: time.days, size: size, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground }), showUnits.hours && (0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Hours", value: time.hours, size: size, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground }), showUnits.minutes && (0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Minutes", value: time.minutes, size: size, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground }), showUnits.seconds && (0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Seconds", value: time.seconds, size: size, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground }), showProgress && (0, jsx_runtime_1.jsx)(TimerProgress_1.default, { value: time.progress, color: customColors === null || customColors === void 0 ? void 0 : customColors.progress })] }));
14
+ return ((0, jsx_runtime_1.jsxs)(TimerContainer_1.default, { size: size, layout: layout, background: customColors === null || customColors === void 0 ? void 0 : customColors.background, color: customColors === null || customColors === void 0 ? void 0 : customColors.text, children: [showUnits.days && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Days", value: time.days, size: size, numberSize: "lg", layout: layout, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground, color: customColors === null || customColors === void 0 ? void 0 : customColors.text })), showUnits.hours && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Hours", value: time.hours, size: size, numberSize: "lg", layout: layout, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground, color: customColors === null || customColors === void 0 ? void 0 : customColors.text })), showUnits.minutes && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Minutes", value: time.minutes, size: size, numberSize: "lg", layout: layout, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground, color: customColors === null || customColors === void 0 ? void 0 : customColors.text })), showUnits.seconds && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Seconds", value: time.seconds, size: size, numberSize: "lg", layout: layout, background: customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground, color: customColors === null || customColors === void 0 ? void 0 : customColors.text })), showProgress && ((0, jsx_runtime_1.jsx)(TimerProgress_1.default, { value: time.progress, color: customColors === null || customColors === void 0 ? void 0 : customColors.progress }))] }));
15
15
  };
16
16
  exports.ServerTimerUI = ServerTimerUI;
17
+ exports.default = exports.ServerTimerUI;
@@ -4,21 +4,34 @@ const jsx_runtime_1 = require("react/jsx-runtime");
4
4
  const paddingMap = { sm: '0.25rem 0.5rem', md: '0.5rem 1rem', lg: '1rem 1.5rem' };
5
5
  const gapMap = { sm: '0.25rem', md: '0.5rem', lg: '0.75rem' };
6
6
  const TimerContainer = ({ children, size = 'md', layout = 'horizontal', className, background = '#ffffff', color = '#323130' }) => {
7
- const flexDirection = layout === 'vertical' ? 'column' : 'row';
8
- const isCompact = layout === 'compact';
7
+ let flexDirection = 'row';
8
+ let padding = paddingMap[size];
9
+ let gap = gapMap[size];
10
+ let fontSize = '1rem';
11
+ if (layout === 'vertical')
12
+ flexDirection = 'column';
13
+ if (layout === 'compact') {
14
+ flexDirection = 'row';
15
+ padding = '0.25rem 0.5rem';
16
+ gap = '0.25rem';
17
+ fontSize = '0.75rem';
18
+ }
9
19
  return ((0, jsx_runtime_1.jsx)("div", { className: className, style: {
10
20
  backgroundColor: background,
11
21
  color,
12
22
  border: '1px solid #e1e1e1',
13
23
  borderRadius: '4px',
14
24
  boxShadow: '0 1px 3px rgba(0,0,0,0.1)',
15
- padding: isCompact ? '0.25rem 0.5rem' : paddingMap[size],
16
- display: 'inline-flex',
25
+ padding,
26
+ display: 'flex',
17
27
  flexDirection,
18
28
  alignItems: 'center',
19
- gap: isCompact ? '0.25rem' : gapMap[size],
29
+ gap,
20
30
  fontFamily: `'Segoe UI', sans-serif`,
21
- fontSize: isCompact ? '0.75rem' : '1rem'
31
+ fontSize,
32
+ flexWrap: 'wrap',
33
+ maxWidth: '100%',
34
+ overflow: 'hidden',
22
35
  }, children: children }));
23
36
  };
24
37
  exports.default = TimerContainer;
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const jsx_runtime_1 = require("react/jsx-runtime");
4
- const TimerProgress = ({ value, color = '#0078d4' }) => ((0, jsx_runtime_1.jsx)("div", { style: {
5
- flex: 1,
6
- height: '6px',
7
- background: '#e1e1e1',
8
- borderRadius: '3px',
9
- overflow: 'hidden',
10
- marginLeft: '0.5rem'
11
- }, children: (0, jsx_runtime_1.jsx)("div", { style: {
4
+ const TimerProgress = ({ value, color = '#0078d4' }) => ((0, jsx_runtime_1.jsx)("div", { style: { flex: 1, height: '6px', backgroundColor: '#e1e1e1', borderRadius: '3px', margin: '0 0.5rem', minWidth: '50px' }, children: (0, jsx_runtime_1.jsx)("div", { style: {
12
5
  width: `${value}%`,
13
- background: color,
14
- height: '100%'
6
+ height: '100%',
7
+ backgroundColor: color,
8
+ borderRadius: '3px',
9
+ transition: 'width 0.2s ease'
15
10
  } }) }));
16
11
  exports.default = TimerProgress;
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
- import { TimerSize } from '../types';
3
- interface TimerUnitProps {
2
+ import { TimerSize, TimerLayout } from '../types';
3
+ export interface TimerUnitProps {
4
4
  label: string;
5
5
  value: number;
6
6
  size?: TimerSize;
7
7
  numberSize?: 'sm' | 'md' | 'lg';
8
+ layout?: TimerLayout;
8
9
  background?: string;
9
10
  color?: string;
10
11
  }
@@ -1,15 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const jsx_runtime_1 = require("react/jsx-runtime");
4
- const TimerUnit = ({ label, value, size = 'md', numberSize = 'md', background = '#f3f2f1', color = '#323130' }) => {
5
- const fontMap = { sm: '0.75rem', md: '1rem', lg: '1.5rem' };
6
- return ((0, jsx_runtime_1.jsxs)("div", { style: {
7
- backgroundColor: background,
8
- color,
9
- padding: '0.25rem 0.5rem',
10
- borderRadius: '4px',
11
- textAlign: 'center',
12
- minWidth: '2.5rem'
13
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: { fontSize: fontMap[numberSize], fontWeight: 600 }, children: value.toString().padStart(2, '0') }), (0, jsx_runtime_1.jsx)("div", { style: { fontSize: '0.75rem' }, children: label })] }));
14
- };
4
+ const fontMap = { sm: '0.75rem', md: '1rem', lg: '1.5rem' };
5
+ const paddingMap = { sm: '0.25rem 0.5rem', md: '0.5rem 1rem', lg: '1rem 1.5rem' };
6
+ const TimerUnit = ({ label, value, size = 'md', numberSize = 'md', layout = 'horizontal', background = '#f3f2f1', color = '#323130' }) => ((0, jsx_runtime_1.jsxs)("div", { style: {
7
+ backgroundColor: background,
8
+ color,
9
+ padding: paddingMap[size],
10
+ borderRadius: '4px',
11
+ textAlign: 'center',
12
+ minWidth: layout === 'compact' ? '2rem' : '3rem',
13
+ flex: layout === 'horizontal' ? '1 1 auto' : undefined,
14
+ display: 'flex',
15
+ flexDirection: 'column',
16
+ alignItems: 'center',
17
+ marginBottom: layout === 'vertical' ? '0.25rem' : undefined,
18
+ overflow: 'hidden'
19
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { fontSize: fontMap[numberSize], fontWeight: 600, whiteSpace: 'nowrap' }, children: value.toString().padStart(2, '0') }), (0, jsx_runtime_1.jsx)("div", { style: { fontSize: '0.75rem', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }, children: label })] }));
15
20
  exports.default = TimerUnit;
@@ -1,6 +1,18 @@
1
1
  export type TimerSize = 'sm' | 'md' | 'lg';
2
2
  export type TimerLayout = 'horizontal' | 'vertical' | 'compact';
3
3
  export type TimerTheme = 'light' | 'dark' | 'brand';
4
+ export interface ShowUnits {
5
+ days?: boolean;
6
+ hours?: boolean;
7
+ minutes?: boolean;
8
+ seconds?: boolean;
9
+ }
10
+ export interface CustomColors {
11
+ background?: string;
12
+ text?: string;
13
+ unitBackground?: string;
14
+ progress?: string;
15
+ }
4
16
  export interface ServerTimerUIProps {
5
17
  serverNow: string;
6
18
  endTime: string;
@@ -8,18 +20,8 @@ export interface ServerTimerUIProps {
8
20
  layout?: TimerLayout;
9
21
  theme?: TimerTheme;
10
22
  showProgress?: boolean;
23
+ customColors?: CustomColors;
24
+ showUnits?: ShowUnits;
11
25
  onEnd?: () => void;
12
26
  className?: string;
13
- customColors?: {
14
- background?: string;
15
- text?: string;
16
- unitBackground?: string;
17
- progress?: string;
18
- };
19
- showUnits?: {
20
- days?: boolean;
21
- hours?: boolean;
22
- minutes?: boolean;
23
- seconds?: boolean;
24
- };
25
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "server-time-timer-yolabs-ui",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "FluentUI/SharePoint styled React countdown timer UI for server-time-timer-yoLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",