cynx-ui 1.2.6 → 1.2.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,41 +1,101 @@
1
1
  import { Spinner } from './Spinner';
2
2
 
3
- const STYLES = `
4
- .cbtn{display:inline-flex;align-items:center;justify-content:center;gap:6px;border-radius:var(--rads,8px);font-family:var(--f,var(--sans,inherit));font-weight:500;cursor:pointer;border:1px solid transparent;white-space:nowrap;transition:all .14s;letter-spacing:-.01em;outline:none;box-shadow:var(--shadow,0 1px 3px rgba(20,22,41,.1))}
5
- .cbtn:disabled{opacity:.45;cursor:not-allowed;pointer-events:none}
6
- .cbtn:active:not(:disabled){ }
3
+ const VARIANTS = {
4
+ default: {
5
+ background: '#fff',
6
+ color: 'var(--def-btn-text,#0f111c)',
7
+ border: '1px solid var(--bd,#d7d8e0)',
8
+ hoverBg: 'var(--grey-1,#f5f5f8)',
9
+ hoverBorder: 'var(--grey-2,#ebebee)',
10
+ },
11
+ primary: {
12
+ background: 'var(--accent,#f99e2c)',
13
+ color: '#fff',
14
+ border: '1px solid transparent',
15
+ hoverBg: 'var(--accent-hover,#e68d1f)',
16
+ hoverShadow: '0 2px 8px rgba(249,158,44,.35)',
17
+ },
18
+ secondary: {
19
+ background: 'var(--blue-bg,rgba(39,130,228,.1))',
20
+ color: 'var(--blue,#2782e4)',
21
+ border: '1px solid rgba(39,130,228,.2)',
22
+ hoverBg: 'rgba(39,130,228,.18)',
23
+ hoverShadow: '0 2px 8px rgba(39,130,228,.25)',
24
+ },
25
+ danger: {
26
+ background: 'var(--danger-bg,rgba(246,71,71,.1))',
27
+ color: 'var(--danger,#f64747)',
28
+ border: '1px solid rgba(246,71,71,.2)',
29
+ hoverBg: 'rgba(246,71,71,.18)',
30
+ hoverShadow: '0 2px 8px rgba(246,71,71,.25)',
31
+ },
32
+ success: {
33
+ background: 'var(--success-bg,rgba(39,174,96,.1))',
34
+ color: 'var(--success,#27ae60)',
35
+ border: '1px solid rgba(39,174,96,.2)',
36
+ hoverBg: 'rgba(39,174,96,.18)',
37
+ hoverShadow: '0 2px 8px rgba(39,174,96,.25)',
38
+ },
39
+ warning: {
40
+ background: 'var(--accent-bg,rgba(249,158,44,.1))',
41
+ color: 'var(--accent,#f99e2c)',
42
+ border: '1px solid var(--accent-border,rgba(249,158,44,.25))',
43
+ hoverBg: 'rgba(249,158,44,.18)',
44
+ hoverShadow: '0 2px 8px rgba(249,158,44,.25)',
45
+ },
46
+ ghost: {
47
+ background: 'transparent',
48
+ color: 'var(--t2,#797b8d)',
49
+ border: '1px solid var(--bd,#d7d8e0)',
50
+ hoverColor: 'var(--t1,#1a1a2e)',
51
+ hoverBg: 'var(--grey-1,#f5f5f8)',
52
+ hoverBorder: 'var(--grey-2,#ebebee)',
53
+ },
54
+ outline: {
55
+ background: 'transparent',
56
+ color: 'var(--accent,#f99e2c)',
57
+ border: '1px solid var(--accent,#f99e2c)',
58
+ hoverBg: 'var(--accent-bg,rgba(249,158,44,.1))',
59
+ },
60
+ link: {
61
+ background: 'transparent',
62
+ color: 'var(--accent,#f99e2c)',
63
+ border: '1px solid transparent',
64
+ paddingLeft: 4,
65
+ paddingRight: 4,
66
+ boxShadow: 'none',
67
+ hoverTextDec: 'underline',
68
+ },
69
+ 'no-line': {
70
+ background: 'none',
71
+ border: 'none',
72
+ boxShadow: 'none',
73
+ color: 'var(--t3,#8a96b0)',
74
+ paddingLeft: 14,
75
+ paddingRight: 14,
76
+ borderRadius: 'var(--rmd,8px)',
77
+ hoverColor: 'var(--p,var(--accent,#f99e2c))',
78
+ hoverBg: 'var(--pd,var(--accent-bg,rgba(249,158,44,.1)))',
79
+ },
80
+ };
7
81
 
8
- .cbtn-xs{padding:4px 8px;font-size:12px;height:28px}
9
- .cbtn-sm{padding:4px 8px;font-size:12px;height:32px}
10
- .cbtn-md{padding:8px 16px;font-size:13px;height:38px}
11
- .cbtn-lg{padding:10px 20px;font-size:14px;height:44px}
12
- .cbtn-icon{padding:0;width:30px;height:30px;border-radius:var(--rads,8px);display:inline-flex;align-items:center;justify-content:center;line-height:0}
13
- .cbtn-icon svg{margin:-1px 0 0 -1px}
82
+ const SIZES = {
83
+ xs: { padding: '4px 8px', fontSize: 12, height: 28 },
84
+ sm: { padding: '4px 8px', fontSize: 12, height: 32 },
85
+ md: { padding: '8px 16px', fontSize: 13, height: 38 },
86
+ lg: { padding: '10px 20px', fontSize: 14, height: 44 },
87
+ };
14
88
 
15
- .cbtn-default{background:#fff;color:var(--def-btn-text,#0f111c);border-color:var(--bd,#d7d8e0)}
16
- .cbtn-default:hover:not(:disabled){background:var(--grey-1,#f5f5f8);color:var(--def-btn-text,#0f111c);border-color:var(--grey-2,#ebebee)}
17
- .cbtn-default:active:not(:disabled){background:var(--grey-1,#f5f5f8);color:var(--def-btn-text,#0f111c);border-color:var(--grey-2,#ebebee)}
18
- .cbtn-primary{background:var(--accent,#f99e2c);color:#fff;border-color:transparent}
19
- .cbtn-primary:hover:not(:disabled){background:var(--accent-hover,#e68d1f);box-shadow:0 2px 8px rgba(249,158,44,.35)}
20
- .cbtn-secondary{background:var(--blue-bg,rgba(39,130,228,.1));color:var(--blue,#2782e4);border-color:rgba(39,130,228,.2)}
21
- .cbtn-secondary:hover:not(:disabled){background:rgba(39,130,228,.18);box-shadow:0 2px 8px rgba(39,130,228,.25)}
22
- .cbtn-danger{background:var(--danger-bg,rgba(246,71,71,.1));color:var(--danger,#f64747);border-color:rgba(246,71,71,.2)}
23
- .cbtn-danger:hover:not(:disabled){background:rgba(246,71,71,.18);box-shadow:0 2px 8px rgba(246,71,71,.25)}
24
- .cbtn-success{background:var(--success-bg,rgba(39,174,96,.1));color:var(--success,#27ae60);border-color:rgba(39,174,96,.2)}
25
- .cbtn-success:hover:not(:disabled){background:rgba(39,174,96,.18);box-shadow:0 2px 8px rgba(39,174,96,.25)}
26
- .cbtn-warning{background:var(--accent-bg,rgba(249,158,44,.1));color:var(--accent,#f99e2c);border-color:var(--accent-border,rgba(249,158,44,.25))}
27
- .cbtn-warning:hover:not(:disabled){background:rgba(249,158,44,.18);box-shadow:0 2px 8px rgba(249,158,44,.25)}
28
- .cbtn-ghost{background:transparent;color:var(--t2,#797b8d);border-color:var(--bd,#d7d8e0)}
29
- .cbtn-ghost:hover:not(:disabled){color:var(--t1,#1a1a2e);background:var(--grey-1,#f5f5f8);border-color:var(--grey-2,#ebebee)}
30
- .cbtn-outline{background:transparent;color:var(--accent,#f99e2c);border-color:var(--accent,#f99e2c)}
31
- .cbtn-outline:hover:not(:disabled){background:var(--accent-bg,rgba(249,158,44,.1))}
32
- .cbtn-link{background:transparent;color:var(--accent,#f99e2c);border-color:transparent;padding-left:4px;padding-right:4px;box-shadow:none}
33
- .cbtn-link:hover:not(:disabled){text-decoration:underline}
34
- .cbtn-no-line{background:none;border:none!important;box-shadow:none!important;color:var(--t3,#8a96b0);padding:6px 14px;border-radius:var(--rmd,8px);transition:color var(--tr,150ms),background var(--tr,150ms)}
35
- .cbtn-no-line:hover:not(:disabled){color:var(--p,var(--accent,#f99e2c));background:var(--pd,var(--accent-bg,rgba(249,158,44,.1)))}
36
- `;
37
-
38
- let styleInjected = false;
89
+ const ICON_STYLE = {
90
+ padding: 0,
91
+ width: 30,
92
+ height: 30,
93
+ borderRadius: 'var(--rads,8px)',
94
+ display: 'inline-flex',
95
+ alignItems: 'center',
96
+ justifyContent: 'center',
97
+ lineHeight: 0,
98
+ };
39
99
 
40
100
  export default function Button({
41
101
  children,
@@ -50,21 +110,44 @@ export default function Button({
50
110
  className = '',
51
111
  ...props
52
112
  }) {
53
- if (!styleInjected && typeof document !== 'undefined') {
54
- const tag = document.createElement('style');
55
- tag.textContent = STYLES;
56
- document.head.appendChild(tag);
57
- styleInjected = true;
58
- }
113
+ const v = VARIANTS[variant] || VARIANTS.default;
114
+ const s = SIZES[size] || SIZES.md;
59
115
 
60
- const classes = `cbtn cbtn-${variant} cbtn-${size}${loading ? ' cbtn-loading' : ''}${className ? ' ' + className : ''}`;
116
+ const isIconOnly = variant === 'icon';
61
117
 
62
118
  return (
63
119
  <button
64
- className={classes}
120
+ className={className}
65
121
  disabled={disabled || loading}
66
122
  onClick={onClick}
67
- style={style}
123
+ style={{
124
+ display: 'inline-flex',
125
+ alignItems: 'center',
126
+ justifyContent: 'center',
127
+ gap: 6,
128
+ borderRadius: 'var(--rads,8px)',
129
+ fontFamily: 'var(--f,var(--sans,inherit))',
130
+ fontWeight: 500,
131
+ cursor: disabled ? 'not-allowed' : 'pointer',
132
+ whiteSpace: 'nowrap',
133
+ transition: 'all .14s',
134
+ letterSpacing: '-.01em',
135
+ outline: 'none',
136
+ boxShadow: 'var(--shadow,0 1px 3px rgba(20,22,41,.1))',
137
+ opacity: disabled ? 0.45 : 1,
138
+ pointerEvents: disabled ? 'none' : undefined,
139
+ background: v.background,
140
+ color: v.color,
141
+ border: v.border,
142
+ padding: isIconOnly ? 0 : s.padding,
143
+ fontSize: s.fontSize,
144
+ height: isIconOnly ? 30 : s.height,
145
+ width: isIconOnly ? 30 : undefined,
146
+ ...(v.paddingLeft !== undefined && { paddingLeft: v.paddingLeft }),
147
+ ...(v.paddingRight !== undefined && { paddingRight: v.paddingRight }),
148
+ ...(v.boxShadow !== undefined && { boxShadow: v.boxShadow }),
149
+ ...style,
150
+ }}
68
151
  {...props}
69
152
  >
70
153
  {loading && <Spinner size={14} inline color="currentColor" />}
@@ -1,62 +1,62 @@
1
- import { Pagination } from './Pagination';
2
-
3
- export function PageShell({ title, children }) {
4
- return (
5
- <div className="page-shell" style={{ padding: '20px 24px' }}>
6
- {children}
7
- </div>
8
- );
9
- }
10
-
11
- export function TableCard({ children }) {
12
- return <div className="table-card">{children}</div>;
13
- }
14
- export function TableCardFilters({ children }) {
15
- return <div className="table-card-filters">{children}</div>;
16
- }
17
- export function TableCardBody({ children }) {
18
- return <div className="table-card-body">{children}</div>;
19
- }
20
- export function TableCardFooter({ total, page, limit, pages, onChange }) {
21
- const from = total === 0 ? 0 : (page - 1) * limit + 1;
22
- const to = Math.min(page * limit, total);
23
- return (
24
- <div className="table-card-footer">
25
- <span className="table-card-footer-count">
26
- {total === 0 ? 'No records' : `${from}–${to} of ${total}`}
27
- </span>
28
- <Pagination page={page} pages={pages} onChange={onChange} />
29
- </div>
30
- );
31
- }
32
-
33
- export function CardHdr({ title, icon: Icon, tabs, children }) {
34
- return (
35
- <div className="card-hdr">
36
- <div className="card-title">
37
- {Icon && <Icon size={14} />}
38
- {title}
39
- {tabs && <span style={{ marginLeft: 12 }}>{tabs}</span>}
40
- </div>
41
- {children && <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>{children}</div>}
42
- </div>
43
- );
44
- }
45
-
46
- export function StatCard({ label, value, sub }) {
47
- return (
48
- <div className="stat">
49
- <div className="stat-label">{label}</div>
50
- <div className="stat-val">{value ?? '—'}</div>
51
- {sub && <div className="stat-sub">{sub}</div>}
52
- </div>
53
- );
54
- }
55
- export function StatCardSkeleton() {
56
- return (
57
- <div className="stat-skeleton">
58
- <div className="skeleton skeleton-text short" style={{ marginBottom: 10 }} />
59
- <div className="skeleton skeleton-text mid" style={{ height: 28, marginBottom: 6 }} />
60
- </div>
61
- );
62
- }
1
+ import { Pagination } from './Pagination';
2
+
3
+ export function PageShell({ title, children }) {
4
+ return (
5
+ <div className="page-shell" style={{ padding: '20px 24px' }}>
6
+ {children}
7
+ </div>
8
+ );
9
+ }
10
+
11
+ export function TableCard({ children }) {
12
+ return <div className="table-card">{children}</div>;
13
+ }
14
+ export function TableCardFilters({ children }) {
15
+ return <div className="table-card-filters">{children}</div>;
16
+ }
17
+ export function TableCardBody({ children }) {
18
+ return <div className="table-card-body">{children}</div>;
19
+ }
20
+ export function TableCardFooter({ total, page, limit, pages, onChange }) {
21
+ const from = total === 0 ? 0 : (page - 1) * limit + 1;
22
+ const to = Math.min(page * limit, total);
23
+ return (
24
+ <div className="table-card-footer">
25
+ <span className="table-card-footer-count">
26
+ {total === 0 ? 'No records' : `${from}–${to} of ${total}`}
27
+ </span>
28
+ <Pagination page={page} pages={pages} onChange={onChange} />
29
+ </div>
30
+ );
31
+ }
32
+
33
+ export function CardHdr({ title, icon: Icon, tabs, children }) {
34
+ return (
35
+ <div className="card-hdr">
36
+ <div className="card-title">
37
+ {Icon && <Icon size={14} />}
38
+ {title}
39
+ {tabs && <span style={{ marginLeft: 12 }}>{tabs}</span>}
40
+ </div>
41
+ {children && <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>{children}</div>}
42
+ </div>
43
+ );
44
+ }
45
+
46
+ export function StatCard({ label, value, sub }) {
47
+ return (
48
+ <div className="stat">
49
+ <div className="stat-label">{label}</div>
50
+ <div className="stat-val">{value ?? '—'}</div>
51
+ {sub && <div className="stat-sub">{sub}</div>}
52
+ </div>
53
+ );
54
+ }
55
+ export function StatCardSkeleton() {
56
+ return (
57
+ <div className="stat-skeleton">
58
+ <div className="skeleton skeleton-text short" style={{ marginBottom: 10 }} />
59
+ <div className="skeleton skeleton-text mid" style={{ height: 28, marginBottom: 6 }} />
60
+ </div>
61
+ );
62
+ }
@@ -1,163 +1,163 @@
1
- import { useEffect, useRef } from 'react';
2
-
3
- const SIZES = {
4
- xs: { svg: 48, stroke: 4, fontSize: '.7rem' },
5
- sm: { svg: 64, stroke: 5, fontSize: '.85rem' },
6
- md: { svg: 80, stroke: 6, fontSize: '1rem' },
7
- lg: { svg: 100, stroke: 7, fontSize: '1.15rem' },
8
- xl: { svg: 120, stroke: 8, fontSize: '1.3rem' },
9
- };
10
-
11
- export default function CircularProgress({
12
- value = 0,
13
- size = 'md',
14
- customSize,
15
- color = 'var(--blue)',
16
- trackColor = '#e0e0e4',
17
- label = '',
18
- showPercent = true,
19
- animated = true,
20
- rounded = false,
21
- indeterminate = false,
22
- speed = 1,
23
- strokeWidth,
24
- gap = 4,
25
- className = '',
26
- style = {},
27
- }) {
28
- const base = SIZES[size] || SIZES.md;
29
- const svg = customSize || base.svg;
30
- const stroke = strokeWidth ?? (customSize ? Math.max(3, svg * 0.06) : base.stroke);
31
- const fontSize = customSize ? `${Math.max(11, svg * 0.13)}px` : base.fontSize;
32
- const cx = svg / 2;
33
- const cy = svg / 2;
34
- const r = (svg - stroke) / 2;
35
- const c = 2 * Math.PI * r;
36
- const pct = Math.min(100, Math.max(0, value));
37
- const BIG = c * 4;
38
- const cap = rounded ? 'round' : 'butt';
39
-
40
- const userGap = gap !== undefined ? gap : (rounded ? c * 0.05 : c * 0.03);
41
- const capOverrun = rounded ? stroke : 0;
42
- const gapSize = userGap + capOverrun;
43
- const total = c - 2 * gapSize;
44
-
45
- const isFull = pct >= 100;
46
- const isEmpty = pct <= 0;
47
-
48
- let indDash, indOffset, trackDash, trackOffset, indOpacity;
49
- let indStartDeg, indEndDeg, trackStartDeg, trackEndDeg;
50
-
51
- if (isEmpty) {
52
- indDash = `0,${BIG}`; indOffset = 0;
53
- trackDash = `${c},${BIG}`; trackOffset = 0;
54
- indOpacity = 0;
55
- indStartDeg = indEndDeg = trackStartDeg = trackEndDeg = 0;
56
- } else if (isFull) {
57
- indDash = `${c + stroke * 2},${BIG}`; indOffset = 0;
58
- trackDash = `0,${BIG}`; trackOffset = 0;
59
- indOpacity = 1;
60
- indStartDeg = 0; indEndDeg = 360;
61
- trackStartDeg = trackEndDeg = 0;
62
- } else {
63
- const activeLen = (pct / 100) * total;
64
- const inactiveLen = total - activeLen;
65
- indDash = `${activeLen},${BIG}`; indOffset = 0;
66
- trackDash = `${inactiveLen},${BIG}`; trackOffset = -(activeLen + gapSize);
67
- indOpacity = 1;
68
- indStartDeg = 0; indEndDeg = (pct / 100) * 360;
69
- trackStartDeg = (pct / 100) * 360; trackEndDeg = 360;
70
- }
71
-
72
- const gRef = useRef(null);
73
- const indRef = useRef(null);
74
- const trackRef = useRef(null);
75
-
76
- useEffect(() => {
77
- if (!indeterminate) return;
78
- const capRad = (180 / Math.PI) * (stroke / r) / 2;
79
- const gapRad = (180 / Math.PI) * (gapSize / r);
80
- const gapArcLen = (capRad + gapRad) / 360 * c;
81
- let angle = -90, arcFrac = 0.45, arcDir = 1, raf;
82
- let lastTime = performance.now();
83
- function tick(now) {
84
- const dt = (now - lastTime) / 16.67;
85
- lastTime = now;
86
- angle = (angle + 3.6 * speed * dt) % 360;
87
- arcFrac += 0.006 * arcDir * speed * dt;
88
- if (arcFrac >= 0.72) { arcFrac = 0.72; arcDir = -1; }
89
- if (arcFrac <= 0.18) { arcFrac = 0.18; arcDir = 1; }
90
- const indLen = c * arcFrac;
91
- const trackLen = Math.max(0, c - indLen - gapArcLen * 2);
92
- if (gRef.current) gRef.current.style.transform = `rotate(${angle}deg)`;
93
- if (indRef.current) indRef.current.setAttribute('stroke-dasharray', `${indLen.toFixed(2)},9999`);
94
- if (trackRef.current) {
95
- trackRef.current.setAttribute('stroke-dasharray', `${trackLen.toFixed(2)},9999`);
96
- trackRef.current.setAttribute('stroke-dashoffset', `${(-(indLen + gapArcLen)).toFixed(2)}`);
97
- }
98
- raf = requestAnimationFrame(tick);
99
- }
100
- raf = requestAnimationFrame(tick);
101
- return () => cancelAnimationFrame(raf);
102
- }, [indeterminate, c, stroke, r, gapSize, speed]);
103
-
104
- return (
105
- <div className={className} style={{ display: 'inline-flex', flexDirection: 'column', alignItems: 'center', gap: 4, ...style }}>
106
- <div style={{ position: 'relative', width: svg, height: svg }}>
107
- <svg width={svg} height={svg} viewBox={`0 0 ${svg} ${svg}`}>
108
- {indeterminate ? (
109
- <g ref={gRef} style={{ transformOrigin: `${cx}px ${cy}px` }}>
110
- <circle
111
- ref={trackRef}
112
- cx={cx} cy={cy} r={r}
113
- fill="none" stroke={trackColor} strokeWidth={stroke} strokeLinecap={cap}
114
- />
115
- <circle
116
- ref={indRef}
117
- cx={cx} cy={cy} r={r}
118
- fill="none" stroke={color} strokeWidth={stroke} strokeLinecap={cap}
119
- />
120
- </g>
121
- ) : (
122
- <>
123
- <circle
124
- cx={cx} cy={cy} r={r}
125
- fill="none" stroke={trackColor} strokeWidth={stroke}
126
- strokeLinecap={cap}
127
- strokeDasharray={trackDash} strokeDashoffset={trackOffset}
128
- style={{
129
- transform: 'rotate(-90deg)', transformOrigin: '50% 50%',
130
- transition: animated ? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)' : 'none',
131
- }}
132
- />
133
- <circle
134
- cx={cx} cy={cy} r={r}
135
- fill="none" stroke={color} strokeWidth={stroke}
136
- strokeLinecap={cap}
137
- strokeDasharray={indDash} strokeDashoffset={indOffset}
138
- style={{
139
- transform: 'rotate(-90deg)', transformOrigin: '50% 50%',
140
- opacity: indOpacity,
141
- transition: animated ? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), opacity .2s' : 'none',
142
- }}
143
- />
144
- </>
145
- )}
146
- </svg>
147
- {showPercent && !indeterminate && (
148
- <div style={{
149
- position: 'absolute', inset: 0,
150
- display: 'flex', alignItems: 'center', justifyContent: 'center',
151
- fontSize, fontWeight: 600, color: 'var(--primary-text)',
152
- fontVariantNumeric: 'tabular-nums',
153
- }}>
154
- {Math.round(pct)}%
155
- </div>
156
- )}
157
- </div>
158
- {label && (
159
- <span style={{ fontSize: '.6rem', color: 'var(--muted)', fontWeight: 500 }}>{label}</span>
160
- )}
161
- </div>
162
- );
163
- }
1
+ import { useEffect, useRef } from 'react';
2
+
3
+ const SIZES = {
4
+ xs: { svg: 48, stroke: 4, fontSize: '.7rem' },
5
+ sm: { svg: 64, stroke: 5, fontSize: '.85rem' },
6
+ md: { svg: 80, stroke: 6, fontSize: '1rem' },
7
+ lg: { svg: 100, stroke: 7, fontSize: '1.15rem' },
8
+ xl: { svg: 120, stroke: 8, fontSize: '1.3rem' },
9
+ };
10
+
11
+ export default function CircularProgress({
12
+ value = 0,
13
+ size = 'md',
14
+ customSize,
15
+ color = 'var(--blue)',
16
+ trackColor = '#e0e0e4',
17
+ label = '',
18
+ showPercent = true,
19
+ animated = true,
20
+ rounded = false,
21
+ indeterminate = false,
22
+ speed = 1,
23
+ strokeWidth,
24
+ gap = 4,
25
+ className = '',
26
+ style = {},
27
+ }) {
28
+ const base = SIZES[size] || SIZES.md;
29
+ const svg = customSize || base.svg;
30
+ const stroke = strokeWidth ?? (customSize ? Math.max(3, svg * 0.06) : base.stroke);
31
+ const fontSize = customSize ? `${Math.max(11, svg * 0.13)}px` : base.fontSize;
32
+ const cx = svg / 2;
33
+ const cy = svg / 2;
34
+ const r = (svg - stroke) / 2;
35
+ const c = 2 * Math.PI * r;
36
+ const pct = Math.min(100, Math.max(0, value));
37
+ const BIG = c * 4;
38
+ const cap = rounded ? 'round' : 'butt';
39
+
40
+ const userGap = gap !== undefined ? gap : (rounded ? c * 0.05 : c * 0.03);
41
+ const capOverrun = rounded ? stroke : 0;
42
+ const gapSize = userGap + capOverrun;
43
+ const total = c - 2 * gapSize;
44
+
45
+ const isFull = pct >= 100;
46
+ const isEmpty = pct <= 0;
47
+
48
+ let indDash, indOffset, trackDash, trackOffset, indOpacity;
49
+ let indStartDeg, indEndDeg, trackStartDeg, trackEndDeg;
50
+
51
+ if (isEmpty) {
52
+ indDash = `0,${BIG}`; indOffset = 0;
53
+ trackDash = `${c},${BIG}`; trackOffset = 0;
54
+ indOpacity = 0;
55
+ indStartDeg = indEndDeg = trackStartDeg = trackEndDeg = 0;
56
+ } else if (isFull) {
57
+ indDash = `${c + stroke * 2},${BIG}`; indOffset = 0;
58
+ trackDash = `0,${BIG}`; trackOffset = 0;
59
+ indOpacity = 1;
60
+ indStartDeg = 0; indEndDeg = 360;
61
+ trackStartDeg = trackEndDeg = 0;
62
+ } else {
63
+ const activeLen = (pct / 100) * total;
64
+ const inactiveLen = total - activeLen;
65
+ indDash = `${activeLen},${BIG}`; indOffset = 0;
66
+ trackDash = `${inactiveLen},${BIG}`; trackOffset = -(activeLen + gapSize);
67
+ indOpacity = 1;
68
+ indStartDeg = 0; indEndDeg = (pct / 100) * 360;
69
+ trackStartDeg = (pct / 100) * 360; trackEndDeg = 360;
70
+ }
71
+
72
+ const gRef = useRef(null);
73
+ const indRef = useRef(null);
74
+ const trackRef = useRef(null);
75
+
76
+ useEffect(() => {
77
+ if (!indeterminate) return;
78
+ const capRad = (180 / Math.PI) * (stroke / r) / 2;
79
+ const gapRad = (180 / Math.PI) * (gapSize / r);
80
+ const gapArcLen = (capRad + gapRad) / 360 * c;
81
+ let angle = -90, arcFrac = 0.45, arcDir = 1, raf;
82
+ let lastTime = performance.now();
83
+ function tick(now) {
84
+ const dt = (now - lastTime) / 16.67;
85
+ lastTime = now;
86
+ angle = (angle + 3.6 * speed * dt) % 360;
87
+ arcFrac += 0.006 * arcDir * speed * dt;
88
+ if (arcFrac >= 0.72) { arcFrac = 0.72; arcDir = -1; }
89
+ if (arcFrac <= 0.18) { arcFrac = 0.18; arcDir = 1; }
90
+ const indLen = c * arcFrac;
91
+ const trackLen = Math.max(0, c - indLen - gapArcLen * 2);
92
+ if (gRef.current) gRef.current.style.transform = `rotate(${angle}deg)`;
93
+ if (indRef.current) indRef.current.setAttribute('stroke-dasharray', `${indLen.toFixed(2)},9999`);
94
+ if (trackRef.current) {
95
+ trackRef.current.setAttribute('stroke-dasharray', `${trackLen.toFixed(2)},9999`);
96
+ trackRef.current.setAttribute('stroke-dashoffset', `${(-(indLen + gapArcLen)).toFixed(2)}`);
97
+ }
98
+ raf = requestAnimationFrame(tick);
99
+ }
100
+ raf = requestAnimationFrame(tick);
101
+ return () => cancelAnimationFrame(raf);
102
+ }, [indeterminate, c, stroke, r, gapSize, speed]);
103
+
104
+ return (
105
+ <div className={className} style={{ display: 'inline-flex', flexDirection: 'column', alignItems: 'center', gap: 4, ...style }}>
106
+ <div style={{ position: 'relative', width: svg, height: svg }}>
107
+ <svg width={svg} height={svg} viewBox={`0 0 ${svg} ${svg}`}>
108
+ {indeterminate ? (
109
+ <g ref={gRef} style={{ transformOrigin: `${cx}px ${cy}px` }}>
110
+ <circle
111
+ ref={trackRef}
112
+ cx={cx} cy={cy} r={r}
113
+ fill="none" stroke={trackColor} strokeWidth={stroke} strokeLinecap={cap}
114
+ />
115
+ <circle
116
+ ref={indRef}
117
+ cx={cx} cy={cy} r={r}
118
+ fill="none" stroke={color} strokeWidth={stroke} strokeLinecap={cap}
119
+ />
120
+ </g>
121
+ ) : (
122
+ <>
123
+ <circle
124
+ cx={cx} cy={cy} r={r}
125
+ fill="none" stroke={trackColor} strokeWidth={stroke}
126
+ strokeLinecap={cap}
127
+ strokeDasharray={trackDash} strokeDashoffset={trackOffset}
128
+ style={{
129
+ transform: 'rotate(-90deg)', transformOrigin: '50% 50%',
130
+ transition: animated ? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)' : 'none',
131
+ }}
132
+ />
133
+ <circle
134
+ cx={cx} cy={cy} r={r}
135
+ fill="none" stroke={color} strokeWidth={stroke}
136
+ strokeLinecap={cap}
137
+ strokeDasharray={indDash} strokeDashoffset={indOffset}
138
+ style={{
139
+ transform: 'rotate(-90deg)', transformOrigin: '50% 50%',
140
+ opacity: indOpacity,
141
+ transition: animated ? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), opacity .2s' : 'none',
142
+ }}
143
+ />
144
+ </>
145
+ )}
146
+ </svg>
147
+ {showPercent && !indeterminate && (
148
+ <div style={{
149
+ position: 'absolute', inset: 0,
150
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
151
+ fontSize, fontWeight: 600, color: 'var(--primary-text)',
152
+ fontVariantNumeric: 'tabular-nums',
153
+ }}>
154
+ {Math.round(pct)}%
155
+ </div>
156
+ )}
157
+ </div>
158
+ {label && (
159
+ <span style={{ fontSize: '.6rem', color: 'var(--muted)', fontWeight: 500 }}>{label}</span>
160
+ )}
161
+ </div>
162
+ );
163
+ }