cynx-ui 1.2.6 → 1.2.8

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,6 +1,31 @@
1
1
  import { useState, useEffect, useCallback } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
 
4
+ const STYLES = `
5
+ #toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 99999; }
6
+ .toast {
7
+ background: var(--surface, #fff); border: 1px solid var(--border, #d7d8e0);
8
+ border-radius: var(--rads, 8px); padding: 10px 14px;
9
+ font-size: .78rem; display: flex; align-items: center; gap: 8px;
10
+ box-shadow: 0px 40px 100px 0px rgba(0,0,0,.15); max-width: 300px;
11
+ color: var(--primary-text, #0f111c); font-weight: 500;
12
+ animation: cx-toastSlide .18s ease;
13
+ cursor: pointer;
14
+ }
15
+ .toast.ok { border-left: 3px solid var(--success, #27ae60); }
16
+ .toast.err { border-left: 3px solid var(--danger, #f64747); }
17
+ @keyframes cx-toastSlide { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
18
+ `;
19
+
20
+ let injected = false;
21
+ function ensureStyles() {
22
+ if (injected || typeof document === 'undefined') return;
23
+ const tag = document.createElement('style');
24
+ tag.textContent = STYLES;
25
+ document.head.appendChild(tag);
26
+ injected = true;
27
+ }
28
+
4
29
  // ── Module-level state ────────────────────────────────────────────────────────
5
30
  let _toasts = [];
6
31
  let _listeners = new Set();
@@ -12,6 +37,7 @@ function notify() {
12
37
 
13
38
  // Global toast — call from anywhere, no hook needed
14
39
  export function toast(msg, type = 'ok') {
40
+ ensureStyles();
15
41
  const id = Date.now() + Math.random();
16
42
  _toasts = [..._toasts, { id, msg, type }];
17
43
  notify();
@@ -40,6 +66,7 @@ export function useToast() {
40
66
 
41
67
  // ── Render component ──────────────────────────────────────────────────────────
42
68
  export function Toast({ toasts, remove }) {
69
+ ensureStyles();
43
70
  return createPortal(
44
71
  <div id="toast-root">
45
72
  {toasts.map(t => (
@@ -1,56 +1,56 @@
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
- }
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
+ }