cynx-ui 1.0.0

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.
@@ -0,0 +1,145 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { Pencil, Trash2, Upload } from 'lucide-react';
3
+ import { Modal } from './Modal';
4
+ import Input from './Input';
5
+ import Button from './Button';
6
+
7
+ export function BrandingCard({ label, hint, value, onUpload, onRemove, saving, option, cardStyle }) {
8
+ const [editOpen, setEditOpen] = useState(false);
9
+ const [pendingFile, setPendingFile] = useState(null);
10
+ const [pendingUrl, setPendingUrl] = useState('');
11
+ const [uploading, setUploading] = useState(false);
12
+ const [previewOpen, setPreviewOpen] = useState(false);
13
+
14
+ const fullview = option === 'fullview';
15
+
16
+ // Pre-fill URL when modal opens
17
+ useEffect(() => {
18
+ if (editOpen && value && !pendingFile) setPendingUrl(value);
19
+ }, [editOpen]);
20
+
21
+ const hasExisting = !!value;
22
+ const filename = pendingFile ? pendingFile.name : value?.split('/').pop() || null;
23
+ const previewUrl = pendingFile ? URL.createObjectURL(pendingFile) : value;
24
+
25
+ function handleFileDrop(file) {
26
+ setPendingFile(file);
27
+ setPendingUrl('');
28
+ }
29
+
30
+ async function handleSave() {
31
+ setUploading(true);
32
+ try {
33
+ if (pendingFile) {
34
+ await onUpload(pendingFile);
35
+ } else if (pendingUrl) {
36
+ await onUpload(pendingUrl);
37
+ }
38
+ setEditOpen(false);
39
+ setPendingFile(null);
40
+ setPendingUrl('');
41
+ } catch (e) {
42
+ // error handled by parent toast
43
+ } finally {
44
+ setUploading(false);
45
+ }
46
+ }
47
+
48
+ function handleRemove() {
49
+ setPendingFile(null);
50
+ setPendingUrl('');
51
+ onRemove();
52
+ }
53
+
54
+ return (
55
+ <div>
56
+ <div style={{
57
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between',
58
+ padding: '10px 12px', borderRadius: 'var(--rads)',
59
+ border: '1px solid var(--border-light)', background: 'var(--surface)',
60
+ boxShadow: '0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06)',
61
+ ...cardStyle,
62
+ }}>
63
+ {(hasExisting || previewUrl) ? (
64
+ <img src={previewUrl} alt={label} onClick={() => fullview && setPreviewOpen(true)}
65
+ style={{ height: fullview ? 24 : 32, width: fullview ? 'auto' : 32, objectFit: 'contain', borderRadius: 4, flexShrink: 0, cursor: fullview ? 'pointer' : 'default' }} />
66
+ ) : (
67
+ <div style={{ width: fullview ? 24 : 32, height: fullview ? 24 : 32, borderRadius: 4, background: 'var(--grey-2)', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
68
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--muted)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
69
+ <rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>
70
+ </svg>
71
+ </div>
72
+ )}
73
+ {!fullview && (
74
+ <div style={{ flex: 1, fontSize: '.78rem', color: filename ? 'var(--primary-text)' : 'var(--muted)', fontFamily: filename ? 'var(--mono)' : 'inherit', wordBreak: 'break-all', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
75
+ {filename || 'Not set'}
76
+ </div>
77
+ )}
78
+ <div style={{ display: 'flex', gap: 4, flexShrink: 0 }}>
79
+ <Button variant="ghost" size="xs" type="button" icon={<Pencil size={11} />} onClick={() => setEditOpen(true)} style={cardStyle ? { background: '#fff', color: '#333' } : undefined}>Edit</Button>
80
+ {hasExisting && (
81
+ <Button variant="ghost" size="xs" type="button" icon={<Trash2 size={11} />} style={cardStyle ? { background: '#fff', color: 'var(--danger)' } : { color: 'var(--danger)' }}
82
+ onClick={handleRemove} disabled={saving}>Remove</Button>
83
+ )}
84
+ </div>
85
+ </div>
86
+ <div style={{ fontSize: '.68rem', color: 'var(--muted)', marginTop: 4 }}>{hint}</div>
87
+
88
+ {previewOpen && (
89
+ <Modal title={label} open={previewOpen} onClose={() => setPreviewOpen(false)}
90
+ footer={<Button variant="ghost" size="sm" onClick={() => setPreviewOpen(false)}>Close</Button>}>
91
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px 0' }}>
92
+ <img src={previewUrl} alt={label} style={{ maxWidth: '100%', maxHeight: 400, objectFit: 'contain', borderRadius: 6 }} />
93
+ </div>
94
+ </Modal>
95
+ )}
96
+
97
+ {editOpen && (
98
+ <Modal title={`Edit ${label}`} open={editOpen} onClose={() => { setEditOpen(false); setPendingFile(null); setPendingUrl(''); }}
99
+ footer={
100
+ <>
101
+ <Button variant="ghost" size="sm" onClick={() => { setEditOpen(false); setPendingFile(null); setPendingUrl(''); }}>Cancel</Button>
102
+ <Button variant="primary" size="sm" disabled={saving || uploading} onClick={handleSave}>
103
+ {uploading ? 'Uploading...' : saving ? 'Saving...' : 'Save'}
104
+ </Button>
105
+ </>
106
+ }>
107
+ <label
108
+ onDragOver={e => { e.preventDefault(); e.currentTarget.style.borderColor = 'var(--accent)'; }}
109
+ onDragLeave={e => { e.currentTarget.style.borderColor = pendingFile ? 'var(--accent)' : 'var(--border)'; }}
110
+ onDrop={e => { e.preventDefault(); const f = e.dataTransfer.files[0]; if (f) handleFileDrop(f); }}
111
+ style={{
112
+ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
113
+ gap: 8, padding: '24px 16px', borderRadius: 'var(--rads)',
114
+ border: `1.5px dashed ${pendingFile ? 'var(--accent)' : 'var(--border)'}`,
115
+ background: 'var(--grey-1)', cursor: 'pointer', transition: 'all .15s', textAlign: 'center',
116
+ }}>
117
+ <input type="file" accept="image/*,.ico" style={{ display: 'none' }}
118
+ onChange={e => { const f = e.target.files[0]; if (f) handleFileDrop(f); }} />
119
+ {pendingFile ? (
120
+ <>
121
+ <img src={URL.createObjectURL(pendingFile)} alt="preview" style={{ height: 48, maxWidth: 160, objectFit: 'contain', borderRadius: 4 }} />
122
+ <div style={{ fontSize: '.76rem', fontWeight: 600, color: 'var(--accent)' }}>{pendingFile.name}</div>
123
+ <div style={{ fontSize: '.68rem', color: 'var(--muted)' }}>{(pendingFile.size / 1024).toFixed(1)} KB — click to change</div>
124
+ </>
125
+ ) : (
126
+ <>
127
+ <Upload size={20} style={{ color: 'var(--muted)' }} />
128
+ <div style={{ fontSize: '.82rem', fontWeight: 600 }}>Click or drag to upload</div>
129
+ <div style={{ fontSize: '.72rem', color: 'var(--muted)' }}>PNG, JPG, SVG, ICO up to 2MB</div>
130
+ </>
131
+ )}
132
+ </label>
133
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8, margin: '12px 0 4px' }}>
134
+ <div style={{ flex: 1, height: 1, background: 'var(--border)' }} />
135
+ <span style={{ fontSize: '.72rem', color: 'var(--muted)' }}>or enter URL directly</span>
136
+ <div style={{ flex: 1, height: 1, background: 'var(--border)' }} />
137
+ </div>
138
+ <Input type="url" placeholder="https://example.com/logo.png" value={pendingUrl}
139
+ onChange={e => { setPendingUrl(e.target.value); setPendingFile(null); }}
140
+ style={{ width: '100%', fontSize: '.82rem' }} />
141
+ </Modal>
142
+ )}
143
+ </div>
144
+ );
145
+ }
package/Button.jsx ADDED
@@ -0,0 +1,76 @@
1
+ import { Spinner } from './Spinner';
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){ }
7
+
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}
14
+
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;
39
+
40
+ export default function Button({
41
+ children,
42
+ variant = 'default',
43
+ size = 'md',
44
+ icon = null,
45
+ iconRight = null,
46
+ disabled = false,
47
+ loading = false,
48
+ onClick = null,
49
+ style = {},
50
+ className = '',
51
+ ...props
52
+ }) {
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
+ }
59
+
60
+ const classes = `cbtn cbtn-${variant} cbtn-${size}${loading ? ' cbtn-loading' : ''}${className ? ' ' + className : ''}`;
61
+
62
+ return (
63
+ <button
64
+ className={classes}
65
+ disabled={disabled || loading}
66
+ onClick={onClick}
67
+ style={style}
68
+ {...props}
69
+ >
70
+ {loading && <Spinner size={14} inline color="currentColor" />}
71
+ {!loading && icon && icon}
72
+ {!loading && children}
73
+ {!loading && iconRight && iconRight}
74
+ </button>
75
+ );
76
+ }
package/Card.jsx ADDED
@@ -0,0 +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
+ }
package/Checkbox.jsx ADDED
@@ -0,0 +1,59 @@
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ /**
4
+ * Checkbox — custom styled checkbox component
5
+ * Props:
6
+ * checked: bool
7
+ * indeterminate: bool — shows dash instead of check
8
+ * onChange: fn(checked)
9
+ * disabled: bool
10
+ * size: 'sm' | 'md' (default 'md')
11
+ * label: string — optional label text
12
+ * style: object — optional extra styles on wrapper
13
+ */
14
+ export default function Checkbox({ checked, indeterminate, onChange, disabled = false, size = 'md', label, style }) {
15
+ const inputRef = useRef(null);
16
+ useEffect(() => { if (inputRef.current) inputRef.current.indeterminate = !!indeterminate; }, [indeterminate]);
17
+
18
+ const dims = size === 'sm' ? { w: 14, h: 14, icon: 8 } : { w: 16, h: 16, icon: 10 };
19
+
20
+ return (
21
+ <label style={{
22
+ display: 'inline-flex', alignItems: 'center', gap: 6,
23
+ cursor: disabled ? 'not-allowed' : 'pointer',
24
+ userSelect: 'none', margin: 0, padding: 0, lineHeight: 1,
25
+ opacity: disabled ? 0.45 : 1,
26
+ ...style,
27
+ }}>
28
+ <span style={{
29
+ position: 'relative', width: dims.w, height: dims.h, flexShrink: 0,
30
+ border: `1.5px solid ${checked || indeterminate ? 'var(--accent)' : 'var(--border)'}`,
31
+ borderRadius: size === 'sm' ? 3 : 4,
32
+ background: checked || indeterminate ? 'var(--accent)' : 'var(--input-bg)',
33
+ transition: 'all .14s',
34
+ cursor: disabled ? 'not-allowed' : 'pointer',
35
+ }}>
36
+ {indeterminate ? (
37
+ <svg style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}
38
+ width={dims.icon} height={dims.icon} viewBox="0 0 10 10" fill="none">
39
+ <line x1="2" y1="5" x2="8" y2="5" stroke="white" strokeWidth="1.6" strokeLinecap="round" />
40
+ </svg>
41
+ ) : checked ? (
42
+ <svg style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}
43
+ width={dims.icon} height={dims.icon} viewBox="0 0 10 10" fill="none">
44
+ <polyline points="1.5,5 4,7.5 8.5,2.5" stroke="white" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
45
+ </svg>
46
+ ) : null}
47
+ </span>
48
+ {label && <span style={{ fontSize: size === 'sm' ? '.72rem' : '.78rem' }}>{label}</span>}
49
+ <input
50
+ ref={inputRef}
51
+ type="checkbox"
52
+ checked={!!checked}
53
+ disabled={disabled}
54
+ onChange={e => onChange?.(e.target.checked)}
55
+ style={{ position: 'absolute', opacity: 0, width: 0, height: 0, pointerEvents: 'none' }}
56
+ />
57
+ </label>
58
+ );
59
+ }
package/ChipSelect.jsx ADDED
@@ -0,0 +1,54 @@
1
+ import { useRef, useEffect } from 'react';
2
+
3
+ /**
4
+ * ChipSelect — reusable multi-select chip/toggle group
5
+ * Props:
6
+ * options: [{ value, label }]
7
+ * value: string[] — selected values
8
+ * onChange: fn(string[]) — called with updated selection
9
+ * size: 'sm' | 'md' (default 'md')
10
+ */
11
+ export default function ChipSelect({ options, value = [], onChange, size = 'md' }) {
12
+ const dims = size === 'sm' ? { h: 14, icon: 8, px: 10, py: 5, gap: 6, font: '.72rem' } : { h: 16, icon: 10, px: 14, py: 7, gap: 7, font: '.78rem' };
13
+
14
+ function toggle(val) {
15
+ const next = value.includes(val) ? value.filter(v => v !== val) : [...value, val];
16
+ onChange?.(next);
17
+ }
18
+
19
+ return (
20
+ <div style={{ display:'flex', gap:10, flexWrap:'wrap' }}>
21
+ {options.map(opt => {
22
+ const active = value.includes(opt.value);
23
+ return (
24
+ <div key={opt.value}
25
+ onClick={() => toggle(opt.value)}
26
+ style={{
27
+ display:'flex', alignItems:'center', gap: dims.gap,
28
+ padding:`${dims.py}px ${dims.px}px`, cursor:'pointer',
29
+ borderRadius: 8,
30
+ background: 'var(--grey-1)',
31
+ transition: 'all .14s',
32
+ userSelect: 'none',
33
+ }}>
34
+ <span style={{
35
+ position:'relative', width: dims.h, height: dims.h, flexShrink:0,
36
+ borderRadius: 4,
37
+ background: active ? 'var(--accent)' : 'var(--input-bg)',
38
+ border: `1.5px solid ${active ? 'var(--accent)' : 'var(--border)'}`,
39
+ transition: 'all .14s',
40
+ display:'flex', alignItems:'center', justifyContent:'center',
41
+ }}>
42
+ {active && (
43
+ <svg width={dims.icon} height={dims.icon} viewBox="0 0 10 10" fill="none">
44
+ <polyline points="1.5,5 4,7.5 8.5,2.5" stroke="white" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
45
+ </svg>
46
+ )}
47
+ </span>
48
+ <span style={{ fontSize: dims.font, fontWeight:600, textTransform:'uppercase', letterSpacing:'.04em', color: 'var(--muted)' }}>{opt.label}</span>
49
+ </div>
50
+ );
51
+ })}
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +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
+ }
package/Confirm.jsx ADDED
@@ -0,0 +1,79 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { AlertTriangle } from 'lucide-react';
3
+ import Button from './Button.jsx';
4
+
5
+ let _show = null;
6
+
7
+ export function ConfirmRoot() {
8
+ const [state, setState] = useState(null);
9
+ const [closing, setClosing] = useState(false);
10
+
11
+ useEffect(() => {
12
+ _show = (opts) => new Promise(resolve => {
13
+ setClosing(false);
14
+ setState({ ...opts, resolve });
15
+ });
16
+ return () => { _show = null; };
17
+ }, []);
18
+
19
+ if (!state) return null;
20
+
21
+ function answer(val) {
22
+ setClosing(true);
23
+ setTimeout(() => { state.resolve(val); setState(null); }, 250);
24
+ }
25
+
26
+ return (
27
+ <div
28
+ style={{
29
+ position: 'fixed', inset: 0,
30
+ background: 'rgba(20,22,41,.5)',
31
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
32
+ zIndex: 99999, padding: 20,
33
+ animation: `${closing ? 'backdropClose' : 'backdropFade'} .25s ease forwards`,
34
+ }}
35
+ onClick={e => e.target === e.currentTarget && answer(false)}
36
+ >
37
+ <div style={{
38
+ background: 'var(--surface)', border: '1px solid var(--border)',
39
+ borderRadius: 14, width: '100%', maxWidth: 400,
40
+ boxShadow: '0 20px 60px rgba(0,0,0,.4)',
41
+ animation: `${closing ? 'modalClose' : 'modalPop'} .25s cubic-bezier(.4,0,.2,1) forwards`,
42
+ }}>
43
+ <div style={{ padding: '20px 20px 0', display: 'flex', gap: 14, alignItems: 'flex-start' }}>
44
+ <div style={{
45
+ width: 36, height: 36, borderRadius: '50%', flexShrink: 0,
46
+ background: state.danger ? 'rgba(246,71,71,.1)' : 'rgba(249,158,44,.1)',
47
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
48
+ }}>
49
+ <AlertTriangle size={17} color={state.danger ? 'var(--danger)' : 'var(--warning)'} />
50
+ </div>
51
+ <div>
52
+ <div style={{ fontWeight: 700, fontSize: '.9rem', marginBottom: 6 }}>
53
+ {state.title || 'Are you sure?'}
54
+ </div>
55
+ <div style={{ fontSize: '.8rem', color: 'var(--muted)', lineHeight: 1.6 }}>
56
+ {state.message}
57
+ </div>
58
+ </div>
59
+ </div>
60
+ <div style={{
61
+ display: 'flex', justifyContent: 'flex-end', gap: 8,
62
+ padding: '16px 20px', marginTop: 18,
63
+ borderTop: '1px solid var(--border-light)',
64
+ background: 'var(--grey-1)', borderRadius: '0 0 14px 14px',
65
+ }}>
66
+ <Button variant="ghost" size="sm" onClick={() => answer(false)}>Cancel</Button>
67
+ <Button variant={state.danger ? 'ghost' : 'primary'} size="sm" style={state.danger ? { background: 'var(--danger)', color: '#fff', border: 'none' } : {}} onClick={() => answer(true)}>
68
+ {state.confirmLabel || 'Confirm'}
69
+ </Button>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ );
74
+ }
75
+
76
+ export function confirm(opts) {
77
+ if (!_show) return Promise.resolve(false);
78
+ return _show(typeof opts === 'string' ? { message: opts } : opts);
79
+ }