server-time-timer-yolabs-ui 1.0.4 → 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.
- package/dist/hooks/useServerTimer.d.ts +10 -7
- package/dist/hooks/useServerTimer.js +25 -21
- package/dist/ui/ServerTimerUI.d.ts +1 -0
- package/dist/ui/ServerTimerUI.js +3 -2
- package/dist/ui/components/TimerContainer.d.ts +2 -1
- package/dist/ui/components/TimerContainer.js +32 -17
- package/dist/ui/components/TimerProgress.js +5 -10
- package/dist/ui/components/TimerUnit.d.ts +3 -1
- package/dist/ui/components/TimerUnit.js +13 -15
- package/dist/ui/types/index.d.ts +14 -12
- package/package.json +1 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 =
|
|
3
|
+
exports.useServerTimer = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
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
|
-
|
|
13
|
-
progress: 100
|
|
12
|
+
progress: 100,
|
|
14
13
|
});
|
|
15
14
|
(0, react_1.useEffect)(() => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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;
|
package/dist/ui/ServerTimerUI.js
CHANGED
|
@@ -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',
|
|
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;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TimerSize } from '../types';
|
|
2
|
+
import { TimerSize, TimerLayout } from '../types';
|
|
3
3
|
interface TimerContainerProps {
|
|
4
4
|
children: React.ReactNode;
|
|
5
5
|
size?: TimerSize;
|
|
6
|
+
layout?: TimerLayout;
|
|
6
7
|
className?: string;
|
|
7
8
|
background?: string;
|
|
8
9
|
color?: string;
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
const paddingMap = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
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
|
+
}
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: className, style: {
|
|
20
|
+
backgroundColor: background,
|
|
21
|
+
color,
|
|
22
|
+
border: '1px solid #e1e1e1',
|
|
23
|
+
borderRadius: '4px',
|
|
24
|
+
boxShadow: '0 1px 3px rgba(0,0,0,0.1)',
|
|
25
|
+
padding,
|
|
26
|
+
display: 'flex',
|
|
27
|
+
flexDirection,
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
gap,
|
|
30
|
+
fontFamily: `'Segoe UI', sans-serif`,
|
|
31
|
+
fontSize,
|
|
32
|
+
flexWrap: 'wrap',
|
|
33
|
+
maxWidth: '100%',
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
}, children: children }));
|
|
8
36
|
};
|
|
9
|
-
const TimerContainer = ({ children, size = 'md', className, background = '#ffffff', color = '#323130' }) => ((0, jsx_runtime_1.jsx)("div", { className: className, style: {
|
|
10
|
-
backgroundColor: background,
|
|
11
|
-
color,
|
|
12
|
-
border: '1px solid #e1e1e1',
|
|
13
|
-
borderRadius: '4px',
|
|
14
|
-
boxShadow: '0 1px 3px rgba(0,0,0,0.1)',
|
|
15
|
-
padding: paddingMap[size],
|
|
16
|
-
display: 'inline-flex',
|
|
17
|
-
alignItems: 'center',
|
|
18
|
-
gap: '0.75rem',
|
|
19
|
-
fontFamily: `'Segoe UI', sans-serif`,
|
|
20
|
-
fontSize: '1rem'
|
|
21
|
-
}, children: children }));
|
|
22
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
|
-
|
|
14
|
-
|
|
6
|
+
height: '100%',
|
|
7
|
+
backgroundColor: color,
|
|
8
|
+
borderRadius: '3px',
|
|
9
|
+
transition: 'width 0.2s ease'
|
|
15
10
|
} }) }));
|
|
16
11
|
exports.default = TimerProgress;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TimerSize } from '../types';
|
|
2
|
+
import { TimerSize, TimerLayout } from '../types';
|
|
3
3
|
export interface TimerUnitProps {
|
|
4
4
|
label: string;
|
|
5
5
|
value: number;
|
|
6
6
|
size?: TimerSize;
|
|
7
|
+
numberSize?: 'sm' | 'md' | 'lg';
|
|
8
|
+
layout?: TimerLayout;
|
|
7
9
|
background?: string;
|
|
8
10
|
color?: string;
|
|
9
11
|
}
|
|
@@ -1,22 +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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
lg: '0.75rem 1.5rem'
|
|
8
|
-
};
|
|
9
|
-
const fontSizeMap = {
|
|
10
|
-
sm: '0.625rem',
|
|
11
|
-
md: '0.75rem',
|
|
12
|
-
lg: '0.875rem'
|
|
13
|
-
};
|
|
14
|
-
const TimerUnit = ({ label, value, size = 'md', background = '#f3f2f1', color = '#323130' }) => ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
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: {
|
|
15
7
|
backgroundColor: background,
|
|
16
8
|
color,
|
|
17
|
-
borderRadius: '4px',
|
|
18
9
|
padding: paddingMap[size],
|
|
19
|
-
|
|
20
|
-
textAlign: 'center'
|
|
21
|
-
|
|
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 })] }));
|
|
22
20
|
exports.default = TimerUnit;
|
package/dist/ui/types/index.d.ts
CHANGED
|
@@ -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