cynx-ui 1.2.17 → 1.2.18

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,118 +1,118 @@
1
- import { useState, useRef, useEffect } from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { ChevronDown, Search, Check } from 'lucide-react';
4
-
5
- export function SearchableDropdown({ value, onChange, options = [], placeholder = 'Select...' }) {
6
- const [open, setOpen] = useState(false);
7
- const [query, setQuery] = useState('');
8
- const ref = useRef(null);
9
- const inputRef = useRef(null);
10
- const btnRef = useRef(null);
11
- const menuRef = useRef(null);
12
- const [menuStyle, setMenuStyle] = useState({});
13
-
14
- const selected = options.find(o => o.value === value);
15
-
16
- const filtered = query
17
- ? options.filter(o => o.label.toLowerCase().includes(query.toLowerCase()))
18
- : options;
19
-
20
- useEffect(() => {
21
- if (!open) return;
22
- function close(e) {
23
- if (!ref.current?.contains(e.target) && !menuRef.current?.contains(e.target)) {
24
- setOpen(false);
25
- setQuery('');
26
- }
27
- }
28
- const timer = setTimeout(() => {
29
- document.addEventListener('mousedown', close, true);
30
- }, 0);
31
- return () => {
32
- clearTimeout(timer);
33
- document.removeEventListener('mousedown', close, true);
34
- };
35
- }, [open]);
36
-
37
- useEffect(() => {
38
- if (!open) return;
39
- const btn = btnRef.current;
40
- if (!btn) return;
41
- const rect = btn.getBoundingClientRect();
42
- setMenuStyle({
43
- position: 'fixed',
44
- top: rect.bottom + 4,
45
- left: rect.left,
46
- width: rect.width,
47
- zIndex: 999999,
48
- });
49
- setTimeout(() => inputRef.current?.focus(), 50);
50
- }, [open]);
51
-
52
- function select(val) {
53
- onChange(val);
54
- setOpen(false);
55
- setQuery('');
56
- }
57
-
58
- return (
59
- <div ref={ref} style={{ position: 'relative' }}>
60
- <button type="button" ref={btnRef} onClick={() => setOpen(o => !o)} style={{
61
- display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 6,
62
- width: '100%', padding: '6px 10px', height: 32,
63
- border: `1px solid ${open ? 'var(--accent)' : 'var(--border)'}`, borderRadius: 'var(--rads)',
64
- background: 'var(--surface)', color: selected ? 'var(--primary-text)' : 'var(--muted)',
65
- cursor: 'pointer', fontSize: '.8rem', fontFamily: 'var(--sans)',
66
- transition: 'border-color .15s', boxShadow: open ? '0 0 0 3px rgba(249,158,44,.12)' : 'var(--shadow)',
67
- }}
68
- onMouseEnter={e => { if (!open) e.currentTarget.style.borderColor = 'var(--accent)'; }}
69
- onMouseLeave={e => { if (!open) e.currentTarget.style.borderColor = 'var(--border)'; }}>
70
- <span style={{ flex: 1, textAlign: 'left', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
71
- {selected?.label || placeholder}
72
- </span>
73
- <ChevronDown size={13} style={{ color: 'var(--muted)', flexShrink: 0 }} />
74
- </button>
75
-
76
- {open && createPortal(
77
- <div ref={menuRef} style={{
78
- ...menuStyle,
79
- background: 'var(--surface)', border: '1px solid var(--border)',
80
- borderRadius: 'var(--rads)', boxShadow: 'var(--shadow-lg)',
81
- overflow: 'hidden', animation: 'dropdownOpen .12s ease',
82
- }}>
83
- <div style={{ padding: '6px 8px', borderBottom: '1px solid var(--border-light)', display: 'flex', alignItems: 'center', gap: 6 }}>
84
- <Search size={12} style={{ color: 'var(--muted)', flexShrink: 0 }} />
85
- <input
86
- ref={inputRef}
87
- value={query}
88
- onChange={e => setQuery(e.target.value)}
89
- placeholder="Search..."
90
- style={{ border: 'none', background: 'transparent', outline: 'none', fontSize: '.78rem', color: 'var(--primary-text)', width: '100%', fontFamily: 'var(--sans)' }}
91
- />
92
- </div>
93
- <div style={{ maxHeight: 200, overflowY: 'auto', scrollbarWidth: 'thin' }}>
94
- {filtered.length === 0 ? (
95
- <div style={{ padding: '10px 12px', fontSize: '.78rem', color: 'var(--muted)', textAlign: 'center' }}>No results</div>
96
- ) : filtered.map(o => (
97
- <div key={o.value}
98
- onMouseDown={e => e.stopPropagation()}
99
- onClick={() => select(o.value)} style={{
100
- display: 'flex', alignItems: 'center', justifyContent: 'space-between',
101
- padding: '8px 12px', fontSize: '.8rem', cursor: 'pointer',
102
- background: o.value === value ? 'var(--accent-bg)' : 'transparent',
103
- color: o.value === value ? 'var(--accent)' : 'var(--primary-text)',
104
- transition: 'background .1s',
105
- }}
106
- onMouseEnter={e => { if (o.value !== value) e.currentTarget.style.background = 'var(--grey-1)'; }}
107
- onMouseLeave={e => { if (o.value !== value) e.currentTarget.style.background = 'transparent'; }}>
108
- <span>{o.label}</span>
109
- {o.value === value && <Check size={12} />}
110
- </div>
111
- ))}
112
- </div>
113
- </div>,
114
- document.body
115
- )}
116
- </div>
117
- );
118
- }
1
+ import { useState, useRef, useEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { ChevronDown, Search, Check } from 'lucide-react';
4
+
5
+ export function SearchableDropdown({ value, onChange, options = [], placeholder = 'Select...' }) {
6
+ const [open, setOpen] = useState(false);
7
+ const [query, setQuery] = useState('');
8
+ const ref = useRef(null);
9
+ const inputRef = useRef(null);
10
+ const btnRef = useRef(null);
11
+ const menuRef = useRef(null);
12
+ const [menuStyle, setMenuStyle] = useState({});
13
+
14
+ const selected = options.find(o => o.value === value);
15
+
16
+ const filtered = query
17
+ ? options.filter(o => o.label.toLowerCase().includes(query.toLowerCase()))
18
+ : options;
19
+
20
+ useEffect(() => {
21
+ if (!open) return;
22
+ function close(e) {
23
+ if (!ref.current?.contains(e.target) && !menuRef.current?.contains(e.target)) {
24
+ setOpen(false);
25
+ setQuery('');
26
+ }
27
+ }
28
+ const timer = setTimeout(() => {
29
+ document.addEventListener('mousedown', close, true);
30
+ }, 0);
31
+ return () => {
32
+ clearTimeout(timer);
33
+ document.removeEventListener('mousedown', close, true);
34
+ };
35
+ }, [open]);
36
+
37
+ useEffect(() => {
38
+ if (!open) return;
39
+ const btn = btnRef.current;
40
+ if (!btn) return;
41
+ const rect = btn.getBoundingClientRect();
42
+ setMenuStyle({
43
+ position: 'fixed',
44
+ top: rect.bottom + 4,
45
+ left: rect.left,
46
+ width: rect.width,
47
+ zIndex: 999999,
48
+ });
49
+ setTimeout(() => inputRef.current?.focus(), 50);
50
+ }, [open]);
51
+
52
+ function select(val) {
53
+ onChange(val);
54
+ setOpen(false);
55
+ setQuery('');
56
+ }
57
+
58
+ return (
59
+ <div ref={ref} style={{ position: 'relative' }}>
60
+ <button type="button" ref={btnRef} onClick={() => setOpen(o => !o)} style={{
61
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 6,
62
+ width: '100%', padding: '6px 10px', height: 32,
63
+ border: `1px solid ${open ? 'var(--accent)' : 'var(--border)'}`, borderRadius: 'var(--rads)',
64
+ background: 'var(--surface)', color: selected ? 'var(--primary-text)' : 'var(--muted)',
65
+ cursor: 'pointer', fontSize: '.8rem', fontFamily: 'var(--sans)',
66
+ transition: 'border-color .15s', boxShadow: open ? '0 0 0 3px rgba(249,158,44,.12)' : 'var(--shadow)',
67
+ }}
68
+ onMouseEnter={e => { if (!open) e.currentTarget.style.borderColor = 'var(--accent)'; }}
69
+ onMouseLeave={e => { if (!open) e.currentTarget.style.borderColor = 'var(--border)'; }}>
70
+ <span style={{ flex: 1, textAlign: 'left', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
71
+ {selected?.label || placeholder}
72
+ </span>
73
+ <ChevronDown size={13} style={{ color: 'var(--muted)', flexShrink: 0 }} />
74
+ </button>
75
+
76
+ {open && createPortal(
77
+ <div ref={menuRef} style={{
78
+ ...menuStyle,
79
+ background: 'var(--surface)', border: '1px solid var(--border)',
80
+ borderRadius: 'var(--rads)', boxShadow: 'var(--shadow-lg)',
81
+ overflow: 'hidden', animation: 'dropdownOpen .12s ease',
82
+ }}>
83
+ <div style={{ padding: '6px 8px', borderBottom: '1px solid var(--border-light)', display: 'flex', alignItems: 'center', gap: 6 }}>
84
+ <Search size={12} style={{ color: 'var(--muted)', flexShrink: 0 }} />
85
+ <input
86
+ ref={inputRef}
87
+ value={query}
88
+ onChange={e => setQuery(e.target.value)}
89
+ placeholder="Search..."
90
+ style={{ border: 'none', background: 'transparent', outline: 'none', fontSize: '.78rem', color: 'var(--primary-text)', width: '100%', fontFamily: 'var(--sans)' }}
91
+ />
92
+ </div>
93
+ <div style={{ maxHeight: 200, overflowY: 'auto', scrollbarWidth: 'thin' }}>
94
+ {filtered.length === 0 ? (
95
+ <div style={{ padding: '10px 12px', fontSize: '.78rem', color: 'var(--muted)', textAlign: 'center' }}>No results</div>
96
+ ) : filtered.map(o => (
97
+ <div key={o.value}
98
+ onMouseDown={e => e.stopPropagation()}
99
+ onClick={() => select(o.value)} style={{
100
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between',
101
+ padding: '8px 12px', fontSize: '.8rem', cursor: 'pointer',
102
+ background: o.value === value ? 'var(--accent-bg)' : 'transparent',
103
+ color: o.value === value ? 'var(--accent)' : 'var(--primary-text)',
104
+ transition: 'background .1s',
105
+ }}
106
+ onMouseEnter={e => { if (o.value !== value) e.currentTarget.style.background = 'var(--grey-1)'; }}
107
+ onMouseLeave={e => { if (o.value !== value) e.currentTarget.style.background = 'transparent'; }}>
108
+ <span>{o.label}</span>
109
+ {o.value === value && <Check size={12} />}
110
+ </div>
111
+ ))}
112
+ </div>
113
+ </div>,
114
+ document.body
115
+ )}
116
+ </div>
117
+ );
118
+ }
@@ -1,52 +1,52 @@
1
- const STYLES = `.spin{animation:cx-spin .7s linear infinite}@keyframes cx-spin{to{transform:rotate(360deg)}}`;
2
-
3
- let _id = 'cynx-spinner-styles';
4
- function ensureStyles() {
5
- if (typeof document === 'undefined') return;
6
- if (document.getElementById(_id)) return;
7
- const tag = document.createElement('style');
8
- tag.id = _id;
9
- tag.textContent = STYLES;
10
- document.head.appendChild(tag);
11
- }
12
-
13
- // Auto-inject on module load
14
- if (typeof document !== 'undefined') ensureStyles();
15
-
16
- export function Spinner({ size = 20, inline = false, color = 'currentColor', fullPage = false }) {
17
- ensureStyles();
18
- const s = inline ? 14 : size;
19
- const svg = (
20
- <svg className="spin" width={s} height={s} viewBox="0 0 24 24" fill="none"
21
- stroke={color} strokeWidth="2.5" strokeLinecap="round">
22
- <path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/>
23
- </svg>
24
- );
25
-
26
- if (fullPage) {
27
- return (
28
- <div style={{
29
- position: 'fixed', inset: 0,
30
- background: 'var(--bg)',
31
- display: 'flex', flexDirection: 'column',
32
- alignItems: 'center', justifyContent: 'center', gap: 16,
33
- zIndex: 9999,
34
- }}>
35
- {svg}
36
- <div style={{ fontSize: '.75rem', fontFamily: 'var(--mono)', color: 'var(--muted)' }}>
37
- Loading...
38
- </div>
39
- </div>
40
- );
41
- }
42
-
43
- if (inline) return svg;
44
-
45
- return (
46
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '48px 0' }}>
47
- {svg}
48
- </div>
49
- );
50
- }
51
-
52
- export default Spinner;
1
+ const STYLES = `.spin{animation:cx-spin .7s linear infinite}@keyframes cx-spin{to{transform:rotate(360deg)}}`;
2
+
3
+ let _id = 'cynx-spinner-styles';
4
+ function ensureStyles() {
5
+ if (typeof document === 'undefined') return;
6
+ if (document.getElementById(_id)) return;
7
+ const tag = document.createElement('style');
8
+ tag.id = _id;
9
+ tag.textContent = STYLES;
10
+ document.head.appendChild(tag);
11
+ }
12
+
13
+ // Auto-inject on module load
14
+ if (typeof document !== 'undefined') ensureStyles();
15
+
16
+ export function Spinner({ size = 20, inline = false, color = 'currentColor', fullPage = false }) {
17
+ ensureStyles();
18
+ const s = inline ? 14 : size;
19
+ const svg = (
20
+ <svg className="spin" width={s} height={s} viewBox="0 0 24 24" fill="none"
21
+ stroke={color} strokeWidth="2.5" strokeLinecap="round">
22
+ <path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/>
23
+ </svg>
24
+ );
25
+
26
+ if (fullPage) {
27
+ return (
28
+ <div style={{
29
+ position: 'fixed', inset: 0,
30
+ background: 'var(--bg)',
31
+ display: 'flex', flexDirection: 'column',
32
+ alignItems: 'center', justifyContent: 'center', gap: 16,
33
+ zIndex: 9999,
34
+ }}>
35
+ {svg}
36
+ <div style={{ fontSize: '.75rem', fontFamily: 'var(--mono)', color: 'var(--muted)' }}>
37
+ Loading...
38
+ </div>
39
+ </div>
40
+ );
41
+ }
42
+
43
+ if (inline) return svg;
44
+
45
+ return (
46
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '48px 0' }}>
47
+ {svg}
48
+ </div>
49
+ );
50
+ }
51
+
52
+ export default Spinner;
@@ -1,25 +1,25 @@
1
- import LineProgress from './LineProgress';
2
-
3
- export default function StatBarCard({ title, icon, items, style }) {
4
- const total = items.reduce((s, i) => s + (i.value || 0), 0);
5
-
6
- return (
7
- <div style={{
8
- background: '#fff', border: '1px solid var(--border)', borderRadius: 'var(--rad)',
9
- boxShadow: '0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04)',
10
- padding: '12px 14px', minWidth: 220, ...style,
11
- }}>
12
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
13
- <div style={{ fontSize: '.58rem', fontWeight: 700, color: 'var(--muted, #9ca3af)', textTransform: 'uppercase', letterSpacing: '.08em' }}>
14
- {title}{total ? ` (${total})` : ''}
15
- </div>
16
- {icon && <span style={{ color: 'var(--muted, #9ca3af)' }}>{icon}</span>}
17
- </div>
18
- <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
19
- {items.map((item, i) => (
20
- <LineProgress key={i} value={item.value} total={total} color={item.color} label={item.label} size="sm" />
21
- ))}
22
- </div>
23
- </div>
24
- );
25
- }
1
+ import LineProgress from './LineProgress';
2
+
3
+ export default function StatBarCard({ title, icon, items, style }) {
4
+ const total = items.reduce((s, i) => s + (i.value || 0), 0);
5
+
6
+ return (
7
+ <div style={{
8
+ background: '#fff', border: '1px solid var(--border)', borderRadius: 'var(--rad)',
9
+ boxShadow: '0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04)',
10
+ padding: '12px 14px', minWidth: 220, ...style,
11
+ }}>
12
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
13
+ <div style={{ fontSize: '.58rem', fontWeight: 700, color: 'var(--muted, #9ca3af)', textTransform: 'uppercase', letterSpacing: '.08em' }}>
14
+ {title}{total ? ` (${total})` : ''}
15
+ </div>
16
+ {icon && <span style={{ color: 'var(--muted, #9ca3af)' }}>{icon}</span>}
17
+ </div>
18
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
19
+ {items.map((item, i) => (
20
+ <LineProgress key={i} value={item.value} total={total} color={item.color} label={item.label} size="sm" />
21
+ ))}
22
+ </div>
23
+ </div>
24
+ );
25
+ }