cynx-ui 1.2.5 → 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,25 +1,26 @@
1
1
  import CircularProgress from './CircularProgress';
2
2
 
3
- const STYLES = `
4
- .scard{display:flex;align-items:center;justify-content:space-between;padding:10px 14px;min-height:68px;border-radius:var(--rad,10px);background:var(--surface,#fff);border:1px solid var(--border);box-shadow:0 1px 3px rgba(0,0,0,.06),0 1px 2px rgba(0,0,0,.04);min-width:0;transition:border-color .15s}
5
- .scard:hover{border-color:var(--border,#d7d8e0)}
6
- .scard-left{display:flex;flex-direction:column;min-width:0;flex:1}
7
- .scard-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
8
- .scard-head-left{display:flex;align-items:center;gap:6px}
9
- .scard-icon{width:24px;height:24px;border-radius:6px;display:inline-flex;align-items:center;justify-content:center;flex-shrink:0}
10
- .scard-icon svg{width:12px;height:12px}
11
- .scard-title{font-size:.58rem;font-weight:600;text-transform:uppercase;letter-spacing:.08em;color:var(--muted,#9b9daa)}
12
- .scard-value{font-size:1.1rem;font-weight:800;letter-spacing:-.02em;color:var(--primary-text,#0f111c);line-height:1.2;min-height:1.32em}
13
- .scard-sub{font-size:.62rem;color:var(--muted,#9b9daa);font-weight:500;margin-top:1px;min-height:1em}
14
- .scard-right{display:flex;align-items:center;gap:8px;flex-shrink:0}
15
- .scard-simple{padding:12px 14px;flex-direction:column;align-items:flex-start;justify-content:flex-start}
16
- .scard-simple .scard-head{width:100%;margin-bottom:8px;display:flex;align-items:center;justify-content:space-between}
17
- .scard-simple .scard-icon-simple{display:inline-flex;align-items:center;justify-content:center;flex-shrink:0}
18
- .scard-simple .scard-icon-simple svg{width:14px;height:14px}
19
- .scard-simple .scard-value{font-size:1.25rem;font-weight:800;letter-spacing:-.03em;line-height:1.1;min-height:1.375em}
20
- `;
3
+ const BASE = {
4
+ display: 'flex',
5
+ alignItems: 'center',
6
+ justifyContent: 'space-between',
7
+ padding: '10px 14px',
8
+ minHeight: 68,
9
+ borderRadius: 'var(--rad,10px)',
10
+ background: 'var(--surface,#fff)',
11
+ border: '1px solid var(--border)',
12
+ boxShadow: '0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04)',
13
+ minWidth: 0,
14
+ transition: 'border-color .15s',
15
+ };
21
16
 
22
- let styleInjected = false;
17
+ const SIMPLE_BASE = {
18
+ ...BASE,
19
+ padding: '12px 14px',
20
+ flexDirection: 'column',
21
+ alignItems: 'flex-start',
22
+ justifyContent: 'flex-start',
23
+ };
23
24
 
24
25
  export default function StatsCard({
25
26
  variant = 'default',
@@ -38,49 +39,122 @@ export default function StatsCard({
38
39
  style = {},
39
40
  children,
40
41
  }) {
41
- if (!styleInjected && typeof document !== 'undefined') {
42
- const tag = document.createElement('style');
43
- tag.textContent = STYLES;
44
- document.head.appendChild(tag);
45
- styleInjected = true;
46
- }
47
-
48
42
  if (variant === 'simple') {
49
43
  return (
50
- <div className={`scard scard-simple${className ? ' ' + className : ''}`} style={style}>
51
- <div className="scard-head">
52
- {title && <div className="scard-title">{title}</div>}
44
+ <div className={className} style={{ ...SIMPLE_BASE, ...style }}>
45
+ <div style={{
46
+ width: '100%',
47
+ marginBottom: 8,
48
+ display: 'flex',
49
+ alignItems: 'center',
50
+ justifyContent: 'space-between',
51
+ }}>
52
+ {title && (
53
+ <div style={{
54
+ fontSize: '.58rem',
55
+ fontWeight: 600,
56
+ textTransform: 'uppercase',
57
+ letterSpacing: '.08em',
58
+ color: 'var(--muted,#9b9daa)',
59
+ }}>{title}</div>
60
+ )}
53
61
  {icon && (
54
- <div className="scard-icon-simple" style={{ color: iconColor }}>
62
+ <div style={{
63
+ display: 'inline-flex',
64
+ alignItems: 'center',
65
+ justifyContent: 'center',
66
+ flexShrink: 0,
67
+ color: iconColor,
68
+ }}>
55
69
  {icon}
56
70
  </div>
57
71
  )}
58
72
  </div>
59
- {value !== undefined && <div className="scard-value">{value}</div>}
73
+ {value !== undefined && (
74
+ <div style={{
75
+ fontSize: '1.25rem',
76
+ fontWeight: 800,
77
+ letterSpacing: '-.03em',
78
+ lineHeight: 1.1,
79
+ minHeight: '1.375em',
80
+ }}>{value}</div>
81
+ )}
60
82
  {children}
61
83
  </div>
62
84
  );
63
85
  }
64
86
 
65
87
  return (
66
- <div className={`scard${className ? ' ' + className : ''}`} style={style}>
67
- <div className="scard-left">
68
- <div className="scard-head">
69
- <div className="scard-head-left">
88
+ <div className={className} style={{ ...BASE, ...style }}>
89
+ <div style={{
90
+ display: 'flex',
91
+ flexDirection: 'column',
92
+ minWidth: 0,
93
+ flex: 1,
94
+ }}>
95
+ <div style={{
96
+ display: 'flex',
97
+ alignItems: 'center',
98
+ justifyContent: 'space-between',
99
+ marginBottom: 8,
100
+ }}>
101
+ <div style={{
102
+ display: 'flex',
103
+ alignItems: 'center',
104
+ gap: 6,
105
+ }}>
70
106
  {icon && (
71
- <div className="scard-icon" style={{ background: iconBg, color: iconColor }}>
107
+ <div style={{
108
+ width: 24,
109
+ height: 24,
110
+ borderRadius: 6,
111
+ display: 'inline-flex',
112
+ alignItems: 'center',
113
+ justifyContent: 'center',
114
+ flexShrink: 0,
115
+ background: iconBg,
116
+ color: iconColor,
117
+ }}>
72
118
  {icon}
73
119
  </div>
74
120
  )}
75
- {title && <div className="scard-title">{title}</div>}
121
+ {title && (
122
+ <div style={{
123
+ fontSize: '.58rem',
124
+ fontWeight: 600,
125
+ textTransform: 'uppercase',
126
+ letterSpacing: '.08em',
127
+ color: 'var(--muted,#9b9daa)',
128
+ }}>{title}</div>
129
+ )}
76
130
  </div>
77
131
  {headRight}
78
132
  </div>
79
- {value !== undefined && <div className="scard-value">{value}</div>}
80
- <div className="scard-sub" style={{ minHeight: 14 }}>{subtitle || '\u00A0'}</div>
133
+ {value !== undefined && (
134
+ <div style={{
135
+ fontSize: '1.1rem',
136
+ fontWeight: 800,
137
+ letterSpacing: '-.02em',
138
+ color: 'var(--primary-text,#0f111c)',
139
+ lineHeight: 1.2,
140
+ minHeight: '1.32em',
141
+ }}>{value}</div>
142
+ )}
143
+ <div style={{
144
+ fontSize: '.62rem',
145
+ color: 'var(--muted,#9b9daa)',
146
+ fontWeight: 500,
147
+ marginTop: 1,
148
+ minHeight: 14,
149
+ }}>{subtitle || '\u00A0'}</div>
81
150
  {children}
82
151
  </div>
83
- <div className="scard-right">
152
+ <div style={{
153
+ display: 'flex',
154
+ alignItems: 'center',
155
+ gap: 8,
156
+ flexShrink: 0,
157
+ }}>
84
158
  {percent !== undefined && (
85
159
  <CircularProgress
86
160
  value={percent}
@@ -1,16 +1,16 @@
1
- export function Tabs({ tabs, value, onChange, style }) {
2
- return (
3
- <div className="xtabs" style={style}>
4
- {tabs.map(t => {
5
- const label = typeof t === 'string' ? t : t.label;
6
- const key = typeof t === 'string' ? t : t.value;
7
- const active = key === value;
8
- return (
9
- <button key={key} className={`xtab${active ? ' active' : ''}`} onClick={() => onChange(key)}>
10
- {label}
11
- </button>
12
- );
13
- })}
14
- </div>
15
- );
16
- }
1
+ export function Tabs({ tabs, value, onChange, style }) {
2
+ return (
3
+ <div className="xtabs" style={style}>
4
+ {tabs.map(t => {
5
+ const label = typeof t === 'string' ? t : t.label;
6
+ const key = typeof t === 'string' ? t : t.value;
7
+ const active = key === value;
8
+ return (
9
+ <button key={key} className={`xtab${active ? ' active' : ''}`} onClick={() => onChange(key)}>
10
+ {label}
11
+ </button>
12
+ );
13
+ })}
14
+ </div>
15
+ );
16
+ }
@@ -1,57 +1,57 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import { createPortal } from 'react-dom';
3
-
4
- // ── Module-level state ────────────────────────────────────────────────────────
5
- let _toasts = [];
6
- let _listeners = new Set();
7
-
8
- function notify() {
9
- const snapshot = [..._toasts];
10
- _listeners.forEach(fn => fn(snapshot));
11
- }
12
-
13
- // Global toast — call from anywhere, no hook needed
14
- export function toast(msg, type = 'ok') {
15
- const id = Date.now() + Math.random();
16
- _toasts = [..._toasts, { id, msg, type }];
17
- notify();
18
- setTimeout(() => {
19
- _toasts = _toasts.filter(t => t.id !== id);
20
- notify();
21
- }, 3500);
22
- }
23
-
24
- // ── Hook — for components that want reactive state ────────────────────────────
25
- export function useToast() {
26
- const [toasts, setToasts] = useState(_toasts);
27
-
28
- useEffect(() => {
29
- _listeners.add(setToasts);
30
- return () => _listeners.delete(setToasts);
31
- }, []);
32
-
33
- const remove = useCallback(id => {
34
- _toasts = _toasts.filter(t => t.id !== id);
35
- notify();
36
- }, []);
37
-
38
- return { toasts, toast, remove };
39
- }
40
-
41
- // ── Render component ──────────────────────────────────────────────────────────
42
- export function Toast({ toasts, remove }) {
43
- return createPortal(
44
- <div id="toast-root">
45
- {toasts.map(t => (
46
- <div key={t.id} className={`toast ${t.type}`} onClick={() => remove(t.id)}>
47
- {t.type === 'ok'
48
- ? <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--success)" strokeWidth="2.5" strokeLinecap="round"><polyline points="20 6 9 17 4 12"/></svg>
49
- : <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--danger)" strokeWidth="2.5" strokeLinecap="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
50
- }
51
- {t.msg}
52
- </div>
53
- ))}
54
- </div>,
55
- document.body
56
- );
57
- }
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+
4
+ // ── Module-level state ────────────────────────────────────────────────────────
5
+ let _toasts = [];
6
+ let _listeners = new Set();
7
+
8
+ function notify() {
9
+ const snapshot = [..._toasts];
10
+ _listeners.forEach(fn => fn(snapshot));
11
+ }
12
+
13
+ // Global toast — call from anywhere, no hook needed
14
+ export function toast(msg, type = 'ok') {
15
+ const id = Date.now() + Math.random();
16
+ _toasts = [..._toasts, { id, msg, type }];
17
+ notify();
18
+ setTimeout(() => {
19
+ _toasts = _toasts.filter(t => t.id !== id);
20
+ notify();
21
+ }, 3500);
22
+ }
23
+
24
+ // ── Hook — for components that want reactive state ────────────────────────────
25
+ export function useToast() {
26
+ const [toasts, setToasts] = useState(_toasts);
27
+
28
+ useEffect(() => {
29
+ _listeners.add(setToasts);
30
+ return () => _listeners.delete(setToasts);
31
+ }, []);
32
+
33
+ const remove = useCallback(id => {
34
+ _toasts = _toasts.filter(t => t.id !== id);
35
+ notify();
36
+ }, []);
37
+
38
+ return { toasts, toast, remove };
39
+ }
40
+
41
+ // ── Render component ──────────────────────────────────────────────────────────
42
+ export function Toast({ toasts, remove }) {
43
+ return createPortal(
44
+ <div id="toast-root">
45
+ {toasts.map(t => (
46
+ <div key={t.id} className={`toast ${t.type}`} onClick={() => remove(t.id)}>
47
+ {t.type === 'ok'
48
+ ? <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--success)" strokeWidth="2.5" strokeLinecap="round"><polyline points="20 6 9 17 4 12"/></svg>
49
+ : <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="var(--danger)" strokeWidth="2.5" strokeLinecap="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
50
+ }
51
+ {t.msg}
52
+ </div>
53
+ ))}
54
+ </div>,
55
+ document.body
56
+ );
57
+ }
@@ -1,58 +1,56 @@
1
- const STYLES = `
2
- .tgl{display:inline-flex;align-items:center;gap:8px;cursor:pointer;user-select:none}
3
- .tgl input{position:absolute;opacity:0;width:0;height:0}
4
- .tgl-tr{position:relative;border-radius:var(--rfull,99px);transition:background .2s ease;flex-shrink:0;box-shadow:var(--shadow,0 1px 3px rgba(20,22,41,.1))}
5
- .tgl-th{position:absolute;top:50%;transform:translateY(-50%);background:#fff;border-radius:50%;box-shadow:0 1px 3px rgba(0,0,0,.25);transition:left .25s cubic-bezier(.34,1.56,.64,1)}
6
- .tgl-sm .tgl-tr{width:28px;height:16px}
7
- .tgl-sm .tgl-th{width:12px;height:12px;left:2px}
8
- .tgl-sm.on .tgl-th{left:14px}
9
- .tgl-md .tgl-tr{width:34px;height:18px}
10
- .tgl-md .tgl-th{width:14px;height:14px;left:2px}
11
- .tgl-md.on .tgl-th{left:18px}
12
- .tgl-lg .tgl-tr{width:44px;height:24px}
13
- .tgl-lg .tgl-th{width:18px;height:18px;left:3px}
14
- .tgl-lg.on .tgl-th{left:23px}
15
- .tgl:disabled{opacity:.4;cursor:not-allowed;pointer-events:none}
16
- `;
17
-
18
- const COLORS = {
19
- primary: 'var(--accent)',
20
- success: 'var(--success)',
21
- warning: '#f59e0b',
22
- danger: 'var(--danger)',
23
- };
24
-
25
- let styleInjected = false;
26
-
27
- export default function Toggle({
28
- checked = false,
29
- onChange,
30
- disabled = false,
31
- size = 'md',
32
- color = 'primary',
33
- label = null,
34
- labelStyle = {},
35
- onClick = null,
36
- className = '',
37
- style = {},
38
- }) {
39
- if (!styleInjected && typeof document !== 'undefined') {
40
- const tag = document.createElement('style');
41
- tag.textContent = STYLES;
42
- document.head.appendChild(tag);
43
- styleInjected = true;
44
- }
45
-
46
- const sizeClass = ` tgl-${size}`;
47
- const classes = `tgl${sizeClass}${checked ? ' on' : ''}${className ? ' ' + className : ''}`;
48
- const trackColor = checked ? (COLORS[color] || COLORS.primary) : 'var(--bd2,#d7d8e0)';
49
-
50
- return (
51
- <label className={classes} style={style} onClick={onClick}>
52
- <input type="checkbox" checked={checked} disabled={disabled}
53
- onChange={e => onChange?.(e.target.checked)} />
54
- <span className="tgl-tr" style={{ background: trackColor }}><span className="tgl-th" /></span>
55
- {label && <span style={labelStyle}>{label}</span>}
56
- </label>
57
- );
58
- }
1
+ const SIZES = {
2
+ sm: { w: 28, h: 16, r: 8, dot: 12, off: 2, on: 14 },
3
+ md: { w: 34, h: 18, r: 9, dot: 14, off: 2, on: 18 },
4
+ lg: { w: 44, h: 24, r: 12, dot: 18, off: 3, on: 23 },
5
+ };
6
+
7
+ const COLORS = {
8
+ primary: 'var(--accent)',
9
+ success: 'var(--success)',
10
+ warning: '#f59e0b',
11
+ danger: 'var(--danger)',
12
+ };
13
+
14
+ export default function Toggle({
15
+ checked = false,
16
+ onChange,
17
+ disabled = false,
18
+ size = 'md',
19
+ color = 'primary',
20
+ label = null,
21
+ labelStyle = {},
22
+ onClick = null,
23
+ className = '',
24
+ style = {},
25
+ }) {
26
+ const s = SIZES[size] || SIZES.md;
27
+ const trackBg = checked ? (COLORS[color] || COLORS.primary) : 'var(--bd2,#d7d8e0)';
28
+
29
+ return (
30
+ <label
31
+ className={className}
32
+ style={{ display:'inline-flex', alignItems:'center', gap:8, cursor: disabled ? 'not-allowed' : 'pointer', userSelect:'none', opacity: disabled ? .4 : 1, ...style }}
33
+ onClick={onClick}
34
+ >
35
+ <input type="checkbox" checked={checked} disabled={disabled}
36
+ onChange={e => onChange?.(e.target.checked)}
37
+ style={{ position:'absolute', opacity:0, width:0, height:0 }} />
38
+ <span style={{
39
+ position:'relative', width: s.w, height: s.h, borderRadius: s.r,
40
+ background: trackBg, flexShrink:0, transition:'background .2s ease',
41
+ boxShadow:'0 1px 3px rgba(20,22,41,.1)',
42
+ }}>
43
+ <span style={{
44
+ position:'absolute', top:'50%',
45
+ transform:'translateY(-50%)',
46
+ left: checked ? s.on : s.off,
47
+ width: s.dot, height: s.dot,
48
+ background:'#fff', borderRadius:'50%',
49
+ boxShadow:'0 1px 3px rgba(0,0,0,.25)',
50
+ transition:'left .25s cubic-bezier(.34,1.56,.64,1)',
51
+ }} />
52
+ </span>
53
+ {label && <span style={labelStyle}>{label}</span>}
54
+ </label>
55
+ );
56
+ }