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

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;
@@ -9,8 +9,23 @@ 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 light_1 = require("./themes/light");
13
+ const dark_1 = require("./themes/dark");
14
+ const brand_1 = require("./themes/brand");
15
+ const ServerTimerUI = ({ serverNow, endTime, size = 'md', layout = 'horizontal', theme = 'light', showProgress = true, customColors, showUnits = { days: true, hours: true, minutes: true, seconds: true }, onEnd }) => {
16
+ var _a, _b, _c, _d;
13
17
  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 })] }));
18
+ // 1️⃣ Base theme (ALWAYS defined)
19
+ const baseTheme = theme === 'dark' ? dark_1.dark :
20
+ theme === 'brand' ? brand_1.brand :
21
+ light_1.light;
22
+ // 2️⃣ Final resolved colors (NO undefined)
23
+ const colors = {
24
+ background: (_a = customColors === null || customColors === void 0 ? void 0 : customColors.background) !== null && _a !== void 0 ? _a : baseTheme.background,
25
+ text: (_b = customColors === null || customColors === void 0 ? void 0 : customColors.text) !== null && _b !== void 0 ? _b : baseTheme.text,
26
+ unitBackground: (_c = customColors === null || customColors === void 0 ? void 0 : customColors.unitBackground) !== null && _c !== void 0 ? _c : baseTheme.unitBackground,
27
+ progress: (_d = customColors === null || customColors === void 0 ? void 0 : customColors.progress) !== null && _d !== void 0 ? _d : baseTheme.progress
28
+ };
29
+ return ((0, jsx_runtime_1.jsxs)(TimerContainer_1.default, { size: size, layout: layout, background: colors.background, color: colors.text, children: [showUnits.days && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Days", value: time.days, size: size, layout: layout, background: colors.unitBackground, color: colors.text })), showUnits.hours && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Hours", value: time.hours, size: size, layout: layout, background: colors.unitBackground, color: colors.text })), showUnits.minutes && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Minutes", value: time.minutes, size: size, layout: layout, background: colors.unitBackground, color: colors.text })), showUnits.seconds && ((0, jsx_runtime_1.jsx)(TimerUnit_1.default, { label: "Seconds", value: time.seconds, size: size, layout: layout, background: colors.unitBackground, color: colors.text })), showProgress && ((0, jsx_runtime_1.jsx)(TimerProgress_1.default, { value: time.progress, color: colors.progress }))] }));
15
30
  };
16
31
  exports.ServerTimerUI = ServerTimerUI;
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
- import { TimerSize, TimerLayout } from '../types';
3
- interface TimerContainerProps {
2
+ import { TimerLayout, TimerSize } from '../types';
3
+ interface Props {
4
4
  children: React.ReactNode;
5
- size?: TimerSize;
6
- layout?: TimerLayout;
7
- className?: string;
8
- background?: string;
9
- color?: string;
5
+ size: TimerSize;
6
+ layout: TimerLayout;
7
+ background: string;
8
+ color: string;
10
9
  }
11
- declare const TimerContainer: React.FC<TimerContainerProps>;
12
- export default TimerContainer;
10
+ export default function TimerContainer({ children, size, layout, background, color }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -1,24 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = TimerContainer;
3
4
  const jsx_runtime_1 = require("react/jsx-runtime");
4
- const paddingMap = { sm: '0.25rem 0.5rem', md: '0.5rem 1rem', lg: '1rem 1.5rem' };
5
- const gapMap = { sm: '0.25rem', md: '0.5rem', lg: '0.75rem' };
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';
9
- return ((0, jsx_runtime_1.jsx)("div", { className: className, style: {
10
- backgroundColor: background,
5
+ const paddingMap = {
6
+ sm: '6px 10px',
7
+ md: '10px 16px',
8
+ lg: '16px 22px'
9
+ };
10
+ function TimerContainer({ children, size, layout, background, color }) {
11
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
12
+ display: 'flex',
13
+ flexDirection: layout === 'vertical' ? 'column' : 'row',
14
+ alignItems: 'center',
15
+ gap: layout === 'compact' ? '4px' : '10px',
16
+ padding: paddingMap[size],
17
+ background,
11
18
  color,
12
19
  border: '1px solid #e1e1e1',
13
- borderRadius: '4px',
14
- boxShadow: '0 1px 3px rgba(0,0,0,0.1)',
15
- padding: isCompact ? '0.25rem 0.5rem' : paddingMap[size],
16
- display: 'inline-flex',
17
- flexDirection,
18
- alignItems: 'center',
19
- gap: isCompact ? '0.25rem' : gapMap[size],
20
- fontFamily: `'Segoe UI', sans-serif`,
21
- fontSize: isCompact ? '0.75rem' : '1rem'
20
+ borderRadius: 4,
21
+ fontFamily: `'Segoe UI', system-ui`,
22
+ flexWrap: 'wrap',
23
+ maxWidth: '100%'
22
24
  }, children: children }));
23
- };
24
- exports.default = TimerContainer;
25
+ }
@@ -1,7 +1,4 @@
1
- import React from 'react';
2
- interface TimerProgressProps {
1
+ export default function TimerProgress({ value, color }: {
3
2
  value: number;
4
- color?: string;
5
- }
6
- declare const TimerProgress: React.FC<TimerProgressProps>;
7
- export default TimerProgress;
3
+ color: string;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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: {
12
- width: `${value}%`,
13
- background: color,
14
- height: '100%'
15
- } }) }));
16
3
  exports.default = TimerProgress;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ function TimerProgress({ value, color }) {
6
+ return ((0, jsx_runtime_1.jsx)("div", { style: { width: '100%', height: 4, background: '#e1e1e1', borderRadius: 2 }, children: (0, jsx_runtime_1.jsx)("div", { style: {
7
+ width: `${value}%`,
8
+ height: '100%',
9
+ background: color,
10
+ transition: 'width 0.3s linear'
11
+ } }) }));
12
+ }
@@ -1,12 +1,11 @@
1
- import React from 'react';
2
- import { TimerSize } from '../types';
3
- interface TimerUnitProps {
1
+ import { TimerLayout, TimerSize } from '../types';
2
+ interface Props {
4
3
  label: string;
5
4
  value: number;
6
- size?: TimerSize;
7
- numberSize?: 'sm' | 'md' | 'lg';
8
- background?: string;
9
- color?: string;
5
+ size: TimerSize;
6
+ layout: TimerLayout;
7
+ background: string;
8
+ color: string;
10
9
  }
11
- declare const TimerUnit: React.FC<TimerUnitProps>;
12
- export default TimerUnit;
10
+ export default function TimerUnit({ label, value, size, layout, background, color }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -1,15 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = TimerUnit;
3
4
  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 })] }));
5
+ const numberSizeMap = {
6
+ sm: '0.9rem',
7
+ md: '1.2rem',
8
+ lg: '1.6rem'
14
9
  };
15
- exports.default = TimerUnit;
10
+ const minWidthMap = {
11
+ sm: '2ch',
12
+ md: '2.5ch',
13
+ lg: '3ch'
14
+ };
15
+ function TimerUnit({ label, value, size, layout, background, color }) {
16
+ return ((0, jsx_runtime_1.jsxs)("div", { role: "group", "aria-label": label, style: {
17
+ display: 'flex',
18
+ flexDirection: layout === 'compact' ? 'row' : 'column',
19
+ alignItems: 'center',
20
+ padding: '6px 8px',
21
+ background,
22
+ borderRadius: 4,
23
+ minWidth: layout === 'compact' ? 'auto' : '64px'
24
+ }, children: [(0, jsx_runtime_1.jsx)("span", { "aria-live": "polite", "aria-atomic": "true", style: {
25
+ fontSize: numberSizeMap[size],
26
+ fontWeight: 600,
27
+ fontFamily: `'Segoe UI Mono', Consolas, monospace`,
28
+ minWidth: minWidthMap[size],
29
+ textAlign: 'center',
30
+ transition: 'transform 0.15s ease, opacity 0.15s ease'
31
+ }, children: value.toString().padStart(2, '0') }), layout !== 'compact' && ((0, jsx_runtime_1.jsx)("span", { style: {
32
+ fontSize: '0.7rem',
33
+ opacity: 0.75,
34
+ marginTop: 2
35
+ }, children: label }))] }));
36
+ }
@@ -1,4 +1,6 @@
1
1
  export declare const brand: {
2
2
  background: string;
3
- color: string;
3
+ text: string;
4
+ unitBackground: string;
5
+ progress: string;
4
6
  };
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.brand = void 0;
4
- exports.brand = { background: '#0078d4', color: '#ffffff' };
4
+ exports.brand = {
5
+ background: '#f5f9ff',
6
+ text: '#003a8f',
7
+ unitBackground: '#e6f0ff',
8
+ progress: '#005fb8'
9
+ };
@@ -1,4 +1,6 @@
1
1
  export declare const dark: {
2
2
  background: string;
3
- color: string;
3
+ text: string;
4
+ unitBackground: string;
5
+ progress: string;
4
6
  };
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dark = void 0;
4
- exports.dark = { background: '#323130', color: '#f3f2f1' };
4
+ exports.dark = {
5
+ background: '#1f1f1f',
6
+ text: '#ffffff',
7
+ unitBackground: '#2d2d2d',
8
+ progress: '#2899f5'
9
+ };
@@ -1,4 +1,6 @@
1
1
  export declare const light: {
2
2
  background: string;
3
- color: string;
3
+ text: string;
4
+ unitBackground: string;
5
+ progress: string;
4
6
  };
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.light = void 0;
4
- exports.light = { background: '#f3f2f1', color: '#323130' };
4
+ exports.light = {
5
+ background: '#ffffff',
6
+ text: '#323130',
7
+ unitBackground: '#f3f2f1',
8
+ progress: '#0078d4',
9
+ };
@@ -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 CustomColors {
5
+ background?: string;
6
+ text?: string;
7
+ unitBackground?: string;
8
+ progress?: string;
9
+ }
10
+ export interface ShowUnits {
11
+ days?: boolean;
12
+ hours?: boolean;
13
+ minutes?: boolean;
14
+ seconds?: boolean;
15
+ }
4
16
  export interface ServerTimerUIProps {
5
17
  serverNow: string;
6
18
  endTime: string;
@@ -8,18 +20,7 @@ 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
- 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
26
  }
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.7",
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",