cynx-ui 1.3.13 → 1.3.15

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,184 +1,184 @@
1
- import { useMemo, useState, useRef } from 'react';
2
-
3
- const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
4
-
5
- function LegendDot({ color, label }) {
6
- return (
7
- <div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
8
- <span style={{ width: 7, height: 7, borderRadius: 2, background: color, flexShrink: 0 }} />
9
- <span style={{ fontSize: '.55rem', color: 'var(--muted)', fontWeight: 500 }}>{label}</span>
10
- </div>
11
- );
12
- }
13
-
14
- /**
15
- * ActivityCard — day-block bar with hover tooltip
16
- */
17
- export default function ActivityCard({
18
- title = 'Activity',
19
- subtitle,
20
- primary = [],
21
- additional = [],
22
- totalSlots = 90,
23
- greenColor = 'var(--success)',
24
- redColor = 'var(--danger)',
25
- emptyColor = 'var(--grey-1)',
26
- barHeight = 28,
27
- barRadius = 3,
28
- leftLabel,
29
- rightLabel,
30
- showDot = true,
31
- dotColor,
32
- style,
33
- }) {
34
- const [hovered, setHovered] = useState(null);
35
- const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });
36
- const containerRef = useRef(null);
37
-
38
- const bars = useMemo(() => {
39
- const len = Math.max(primary.length, additional.length, totalSlots);
40
- const result = [];
41
- const stepS = primary.length / len;
42
- const stepF = additional.length / len;
43
- for (let i = 0; i < len; i++) {
44
- const si = Math.min(Math.floor(i * stepS), primary.length - 1);
45
- const fi = Math.min(Math.floor(i * stepF), additional.length - 1);
46
- result.push({ success: primary[si] || 0, failed: additional[fi] || 0 });
47
- }
48
- return result;
49
- }, [primary, additional, totalSlots]);
50
-
51
- const dates = useMemo(() => {
52
- const result = [];
53
- const now = new Date();
54
- for (let i = 0; i < bars.length; i++) {
55
- const d = new Date(now);
56
- d.setDate(d.getDate() - (bars.length - 1 - i));
57
- result.push(d);
58
- }
59
- return result;
60
- }, [bars.length]);
61
-
62
- const totalSuccess = bars.reduce((a, b) => a + b.success, 0);
63
- const totalFailed = bars.reduce((a, b) => a + b.failed, 0);
64
- const totalAll = totalSuccess + totalFailed;
65
- const uptimePercent = totalAll > 0 ? Math.round((totalSuccess / totalAll) * 100) : 100;
66
-
67
- function handleMouseEnter(e, idx) {
68
- const rect = e.currentTarget.getBoundingClientRect();
69
- const containerRect = containerRef.current.getBoundingClientRect();
70
- setTooltipPos({
71
- x: rect.left - containerRect.left + rect.width / 2,
72
- y: rect.top - containerRect.top - 8,
73
- });
74
- setHovered(idx);
75
- }
76
-
77
- const h = hovered !== null ? bars[hovered] : null;
78
- const hTotal = h ? h.success + h.failed : 0;
79
-
80
- return (
81
- <div ref={containerRef} style={{
82
- background: 'var(--surface,#fff)', border: '1px solid var(--border)', borderRadius: 'var(--rad)',
83
- boxShadow: 'var(--shadow, 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04))',
84
- padding: '14px 18px', position: 'relative', ...style,
85
- }}>
86
- {/* Header */}
87
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 12 }}>
88
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
89
- {showDot && (
90
- <span style={{ width: 8, height: 8, borderRadius: '50%', background: dotColor || greenColor, flexShrink: 0 }} />
91
- )}
92
- <span style={{ fontSize: '.78rem', fontWeight: 700, color: 'var(--primary-text)', letterSpacing: '-.01em' }}>{title}</span>
93
- {subtitle && <span style={{ fontSize: '.65rem', color: 'var(--muted)', fontWeight: 500 }}>{subtitle}</span>}
94
- </div>
95
- <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
96
- <LegendDot color={greenColor} label="Success" />
97
- <LegendDot color={redColor} label="Failed" />
98
- <LegendDot color={emptyColor} label="None" />
99
- </div>
100
- </div>
101
-
102
- {/* Bars */}
103
- <div style={{ display: 'flex', alignItems: 'flex-end', gap: 2, height: barHeight, marginBottom: 6 }}>
104
- {bars.map((b, i) => {
105
- const total = b.success + b.failed;
106
- const hasData = total > 0;
107
- const successPct = hasData ? (b.success / total) * 100 : 0;
108
- const failedPct = hasData ? (b.failed / total) * 100 : 0;
109
-
110
- return (
111
- <div
112
- key={i}
113
- onMouseEnter={(e) => handleMouseEnter(e, i)}
114
- onMouseLeave={() => setHovered(null)}
115
- style={{
116
- flex: 1, height: '100%', borderRadius: barRadius, overflow: 'hidden',
117
- display: 'flex', flexDirection: 'column',
118
- background: hasData ? 'transparent' : emptyColor,
119
- cursor: hasData ? 'pointer' : 'default',
120
- }}
121
- >
122
- {hasData && (
123
- <>
124
- {b.failed > 0 && <div style={{ height: `${failedPct}%`, background: redColor, marginTop: 'auto' }} />}
125
- {b.success > 0 && <div style={{ height: `${successPct}%`, background: greenColor }} />}
126
- </>
127
- )}
128
- </div>
129
- );
130
- })}
131
- </div>
132
-
133
- {/* Tooltip */}
134
- {hovered !== null && (
135
- <div style={{
136
- position: 'absolute', left: tooltipPos.x, top: tooltipPos.y,
137
- transform: 'translate(-50%, -100%)', background: 'var(--surface,#fff)',
138
- border: '1px solid var(--border)', borderRadius: 'var(--rads, 8px)',
139
- boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))', padding: '10px 14px',
140
- pointerEvents: 'none', zIndex: 100, whiteSpace: 'nowrap',
141
- animation: 'hoverCardIn .15s ease',
142
- }}>
143
- <div style={{ fontSize: '.65rem', color: 'var(--muted)', fontWeight: 500, marginBottom: 4 }}>
144
- {dates[hovered]?.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}
145
- </div>
146
- {h.success > 0 && (
147
- <div style={{ fontSize: '.7rem', fontWeight: 700, color: greenColor }}>
148
- {h.success} success{h.success !== 1 ? 'es' : ''}
149
- {h.failed > 0 && <span style={{ fontWeight: 500, color: 'var(--muted)' }}> ({Math.round((h.success / hTotal) * 100)}%)</span>}
150
- </div>
151
- )}
152
- {h.failed > 0 && (
153
- <div style={{ fontSize: '.7rem', fontWeight: 700, color: redColor }}>
154
- {h.failed} failed{h.failed !== 1 ? 's' : ''}
155
- {h.success > 0 && <span style={{ fontWeight: 500, color: 'var(--muted)' }}> ({Math.round((h.failed / hTotal) * 100)}%)</span>}
156
- </div>
157
- )}
158
- {!h.success && !h.failed && (
159
- <div style={{ fontSize: '.7rem', fontWeight: 500, color: 'var(--muted)' }}>No activity</div>
160
- )}
161
- <div style={{
162
- position: 'absolute', left: '50%', bottom: -5,
163
- transform: 'translateX(-50%) rotate(45deg)',
164
- width: 8, height: 8, background: 'var(--surface,#fff)',
165
- borderRight: '1px solid var(--border)', borderBottom: '1px solid var(--border)',
166
- }} />
167
- </div>
168
- )}
169
-
170
- {/* Footer */}
171
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
172
- <span style={{ fontSize: '.58rem', color: 'var(--muted)', fontWeight: 500 }}>{leftLabel || ''}</span>
173
- <span style={{ fontSize: '.78rem', fontWeight: 700, color: greenColor, fontFamily: 'var(--mono)' }}>{uptimePercent}%</span>
174
- <span style={{ fontSize: '.58rem', color: 'var(--muted)', fontWeight: 500 }}>{rightLabel || ''}</span>
175
- </div>
176
- <style>{`
177
- @keyframes hoverCardIn {
178
- from { opacity: 0; transform: translate(-50%, -100%) translateY(4px); }
179
- to { opacity: 1; transform: translate(-50%, -100%) translateY(0); }
180
- }
181
- `}</style>
182
- </div>
183
- );
184
- }
1
+ import { useMemo, useState, useRef } from 'react';
2
+
3
+ const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
4
+
5
+ function LegendDot({ color, label }) {
6
+ return (
7
+ <div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
8
+ <span style={{ width: 7, height: 7, borderRadius: 2, background: color, flexShrink: 0 }} />
9
+ <span style={{ fontSize: '.55rem', color: 'var(--muted)', fontWeight: 500 }}>{label}</span>
10
+ </div>
11
+ );
12
+ }
13
+
14
+ /**
15
+ * ActivityCard — day-block bar with hover tooltip
16
+ */
17
+ export default function ActivityCard({
18
+ title = 'Activity',
19
+ subtitle,
20
+ primary = [],
21
+ additional = [],
22
+ totalSlots = 90,
23
+ greenColor = 'var(--success)',
24
+ redColor = 'var(--danger)',
25
+ emptyColor = 'var(--grey-1)',
26
+ barHeight = 28,
27
+ barRadius = 3,
28
+ leftLabel,
29
+ rightLabel,
30
+ showDot = true,
31
+ dotColor,
32
+ style,
33
+ }) {
34
+ const [hovered, setHovered] = useState(null);
35
+ const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });
36
+ const containerRef = useRef(null);
37
+
38
+ const bars = useMemo(() => {
39
+ const len = Math.max(primary.length, additional.length, totalSlots);
40
+ const result = [];
41
+ const stepS = primary.length / len;
42
+ const stepF = additional.length / len;
43
+ for (let i = 0; i < len; i++) {
44
+ const si = Math.min(Math.floor(i * stepS), primary.length - 1);
45
+ const fi = Math.min(Math.floor(i * stepF), additional.length - 1);
46
+ result.push({ success: primary[si] || 0, failed: additional[fi] || 0 });
47
+ }
48
+ return result;
49
+ }, [primary, additional, totalSlots]);
50
+
51
+ const dates = useMemo(() => {
52
+ const result = [];
53
+ const now = new Date();
54
+ for (let i = 0; i < bars.length; i++) {
55
+ const d = new Date(now);
56
+ d.setDate(d.getDate() - (bars.length - 1 - i));
57
+ result.push(d);
58
+ }
59
+ return result;
60
+ }, [bars.length]);
61
+
62
+ const totalSuccess = bars.reduce((a, b) => a + b.success, 0);
63
+ const totalFailed = bars.reduce((a, b) => a + b.failed, 0);
64
+ const totalAll = totalSuccess + totalFailed;
65
+ const uptimePercent = totalAll > 0 ? Math.round((totalSuccess / totalAll) * 100) : 100;
66
+
67
+ function handleMouseEnter(e, idx) {
68
+ const rect = e.currentTarget.getBoundingClientRect();
69
+ const containerRect = containerRef.current.getBoundingClientRect();
70
+ setTooltipPos({
71
+ x: rect.left - containerRect.left + rect.width / 2,
72
+ y: rect.top - containerRect.top - 8,
73
+ });
74
+ setHovered(idx);
75
+ }
76
+
77
+ const h = hovered !== null ? bars[hovered] : null;
78
+ const hTotal = h ? h.success + h.failed : 0;
79
+
80
+ return (
81
+ <div ref={containerRef} style={{
82
+ background: 'var(--surface,#fff)', border: '1px solid var(--border)', borderRadius: 'var(--rad)',
83
+ boxShadow: 'var(--shadow, 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04))',
84
+ padding: '14px 18px', position: 'relative', ...style,
85
+ }}>
86
+ {/* Header */}
87
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 12 }}>
88
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
89
+ {showDot && (
90
+ <span style={{ width: 8, height: 8, borderRadius: '50%', background: dotColor || greenColor, flexShrink: 0 }} />
91
+ )}
92
+ <span style={{ fontSize: '.78rem', fontWeight: 700, color: 'var(--primary-text)', letterSpacing: '-.01em' }}>{title}</span>
93
+ {subtitle && <span style={{ fontSize: '.65rem', color: 'var(--muted)', fontWeight: 500 }}>{subtitle}</span>}
94
+ </div>
95
+ <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
96
+ <LegendDot color={greenColor} label="Success" />
97
+ <LegendDot color={redColor} label="Failed" />
98
+ <LegendDot color={emptyColor} label="None" />
99
+ </div>
100
+ </div>
101
+
102
+ {/* Bars */}
103
+ <div style={{ display: 'flex', alignItems: 'flex-end', gap: 2, height: barHeight, marginBottom: 6 }}>
104
+ {bars.map((b, i) => {
105
+ const total = b.success + b.failed;
106
+ const hasData = total > 0;
107
+ const successPct = hasData ? (b.success / total) * 100 : 0;
108
+ const failedPct = hasData ? (b.failed / total) * 100 : 0;
109
+
110
+ return (
111
+ <div
112
+ key={i}
113
+ onMouseEnter={(e) => handleMouseEnter(e, i)}
114
+ onMouseLeave={() => setHovered(null)}
115
+ style={{
116
+ flex: 1, height: '100%', borderRadius: barRadius, overflow: 'hidden',
117
+ display: 'flex', flexDirection: 'column',
118
+ background: hasData ? 'transparent' : emptyColor,
119
+ cursor: hasData ? 'pointer' : 'default',
120
+ }}
121
+ >
122
+ {hasData && (
123
+ <>
124
+ {b.failed > 0 && <div style={{ height: `${failedPct}%`, background: redColor, marginTop: 'auto' }} />}
125
+ {b.success > 0 && <div style={{ height: `${successPct}%`, background: greenColor }} />}
126
+ </>
127
+ )}
128
+ </div>
129
+ );
130
+ })}
131
+ </div>
132
+
133
+ {/* Tooltip */}
134
+ {hovered !== null && (
135
+ <div style={{
136
+ position: 'absolute', left: tooltipPos.x, top: tooltipPos.y,
137
+ transform: 'translate(-50%, -100%)', background: 'var(--surface,#fff)',
138
+ border: '1px solid var(--border)', borderRadius: 'var(--rads, 8px)',
139
+ boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))', padding: '10px 14px',
140
+ pointerEvents: 'none', zIndex: 100, whiteSpace: 'nowrap',
141
+ animation: 'hoverCardIn .15s ease',
142
+ }}>
143
+ <div style={{ fontSize: '.65rem', color: 'var(--muted)', fontWeight: 500, marginBottom: 4 }}>
144
+ {dates[hovered]?.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}
145
+ </div>
146
+ {h.success > 0 && (
147
+ <div style={{ fontSize: '.7rem', fontWeight: 700, color: greenColor }}>
148
+ {h.success} success{h.success !== 1 ? 'es' : ''}
149
+ {h.failed > 0 && <span style={{ fontWeight: 500, color: 'var(--muted)' }}> ({Math.round((h.success / hTotal) * 100)}%)</span>}
150
+ </div>
151
+ )}
152
+ {h.failed > 0 && (
153
+ <div style={{ fontSize: '.7rem', fontWeight: 700, color: redColor }}>
154
+ {h.failed} failed{h.failed !== 1 ? 's' : ''}
155
+ {h.success > 0 && <span style={{ fontWeight: 500, color: 'var(--muted)' }}> ({Math.round((h.failed / hTotal) * 100)}%)</span>}
156
+ </div>
157
+ )}
158
+ {!h.success && !h.failed && (
159
+ <div style={{ fontSize: '.7rem', fontWeight: 500, color: 'var(--muted)' }}>No activity</div>
160
+ )}
161
+ <div style={{
162
+ position: 'absolute', left: '50%', bottom: -5,
163
+ transform: 'translateX(-50%) rotate(45deg)',
164
+ width: 8, height: 8, background: 'var(--surface,#fff)',
165
+ borderRight: '1px solid var(--border)', borderBottom: '1px solid var(--border)',
166
+ }} />
167
+ </div>
168
+ )}
169
+
170
+ {/* Footer */}
171
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
172
+ <span style={{ fontSize: '.58rem', color: 'var(--muted)', fontWeight: 500 }}>{leftLabel || ''}</span>
173
+ <span style={{ fontSize: '.78rem', fontWeight: 700, color: greenColor, fontFamily: 'var(--mono)' }}>{uptimePercent}%</span>
174
+ <span style={{ fontSize: '.58rem', color: 'var(--muted)', fontWeight: 500 }}>{rightLabel || ''}</span>
175
+ </div>
176
+ <style>{`
177
+ @keyframes hoverCardIn {
178
+ from { opacity: 0; transform: translate(-50%, -100%) translateY(4px); }
179
+ to { opacity: 1; transform: translate(-50%, -100%) translateY(0); }
180
+ }
181
+ `}</style>
182
+ </div>
183
+ );
184
+ }