cynx-ui 1.3.23 → 1.3.25
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.
- package/components/Badge.jsx +93 -68
- package/components/Select.jsx +39 -28
- package/package.json +1 -1
package/components/Badge.jsx
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
const VARIANTS = {
|
|
2
|
-
ok:
|
|
3
|
-
err:
|
|
4
|
-
warn:
|
|
5
|
-
blue:
|
|
6
|
-
dim:
|
|
7
|
-
purple:
|
|
8
|
-
teal:
|
|
9
|
-
pink:
|
|
10
|
-
ghost:
|
|
11
|
-
paid: { bg: 'var(--pd, rgba(30,41,59,.08))', color: 'var(--t, #1e293b)', border: 'var(--accent-border, rgba(30,41,59,.15))', dot: 'var(--t, #1e293b)' },
|
|
12
|
-
invoiced: { bg: 'rgba(120,120,130,.08)', color: 'var(--t2, #787882)', border: 'rgba(120,120,130,.15)', dot: 'var(--t2, #787882)' },
|
|
13
|
-
verified: { bg: 'var(--sd, rgba(34,197,94,.08))', color: 'var(--s, #22c55e)', border: 'var(--sd, rgba(34,197,94,.15))', dot: 'var(--s, #22c55e)' },
|
|
14
|
-
partial: { bg: 'rgba(100,100,110,.08)', color: '#64646e', border: 'rgba(100,100,110,.15)', dot: '#64646e' },
|
|
15
|
-
deleted: { bg: 'var(--dd, rgba(239,68,68,.08))', color: 'var(--d, #ef4444)', border: 'var(--dd, rgba(239,68,68,.15))', dot: 'var(--d, #ef4444)' },
|
|
16
|
-
update: { bg: 'var(--wd, rgba(249,115,22,.08))', color: 'var(--w, #f97316)', border: 'var(--wd, rgba(249,115,22,.15))', dot: 'var(--w, #f97316)' },
|
|
17
|
-
ready: { bg: 'var(--wd, rgba(234,179,8,.08))', color: 'var(--w, #eab308)', border: 'var(--wd, rgba(234,179,8,.15))', dot: 'var(--w, #eab308)' },
|
|
18
|
-
new: { bg: 'var(--infd, rgba(59,130,246,.08))', color: 'var(--inf, #3b82f6)', border: 'var(--infd, rgba(59,130,246,.15))', dot: 'var(--inf, #3b82f6)' },
|
|
19
|
-
active: { bg: 'transparent', color: 'var(--s, #22c55e)', border: 'none', dot: 'var(--s, #22c55e)', noPad: true },
|
|
20
|
-
inactive: { bg: 'transparent', color: 'var(--d, #ef4444)', border: 'none', dot: 'var(--d, #ef4444)', noPad: true },
|
|
21
|
-
pending: { bg: 'transparent', color: 'var(--w, #d97706)', border: 'none', dot: 'var(--w, #d97706)', noPad: true, pulse: true },
|
|
4
|
+
ok: { bg: 'var(--success-bg,rgba(39,174,96,.1))', color: 'var(--success,#27ae60)', border: 'var(--sd, rgba(39,174,96,.2))', dot: 'var(--success,#27ae60)' },
|
|
5
|
+
err: { bg: 'var(--danger-bg,rgba(246,71,71,.1))', color: 'var(--danger,#f64747)', border: 'var(--dd, rgba(246,71,71,.2))', dot: 'var(--danger,#f64747)' },
|
|
6
|
+
warn: { bg: 'var(--accent-bg,rgba(249,158,44,.1))', color: 'var(--accent,#f99e2c)', border: 'var(--accent-border,rgba(249,158,44,.25))', dot: 'var(--accent,#f99e2c)' },
|
|
7
|
+
blue: { bg: 'var(--blue-bg,rgba(39,130,228,.1))', color: 'var(--blue,#2782e4)', border: 'var(--infd, rgba(39,130,228,.2))', dot: 'var(--blue,#2782e4)' },
|
|
8
|
+
dim: { bg: 'var(--grey-1,#f5f5f8)', color: 'var(--grey-4,#797b8d)', border: 'var(--border,#d7d8e0)', dot: 'var(--grey-4,#797b8d)' },
|
|
9
|
+
purple: { bg: 'rgba(139,92,246,.1)', color: '#8b5cf6', border: 'rgba(139,92,246,.2)', dot: '#8b5cf6' },
|
|
10
|
+
teal: { bg: 'rgba(20,184,166,.1)', color: '#14b8a6', border: 'rgba(20,184,166,.2)', dot: '#14b8a6' },
|
|
11
|
+
pink: { bg: 'rgba(236,72,153,.1)', color: '#ec4899', border: 'rgba(236,72,153,.2)', dot: '#ec4899' },
|
|
12
|
+
ghost: { bg: 'transparent', color: 'var(--t2,var(--grey-4,#797b8d))', border: 'var(--bd,var(--border,#d7d8e0))', dot: 'var(--t3,var(--grey-4,#797b8d))' },
|
|
22
13
|
};
|
|
23
14
|
|
|
24
15
|
const SHAPES = {
|
|
25
16
|
ok: 'circle', err: 'circle', warn: 'circle', blue: 'circle', dim: 'circle',
|
|
26
17
|
purple: 'circle', teal: 'circle', pink: 'circle', ghost: 'circle',
|
|
27
|
-
paid: 'circle', invoiced: 'circle', verified: 'circle', partial: 'semicircle',
|
|
28
|
-
deleted: 'circle', update: 'triangle', ready: 'diamond', new: 'circle',
|
|
29
18
|
};
|
|
30
19
|
|
|
31
|
-
const KEYFRAMES = `@keyframes badge-pulse{0%,100%{opacity:1}50%{opacity:.4}}`;
|
|
20
|
+
const KEYFRAMES = `@keyframes badge-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.4;transform:scale(0.85)}}`;
|
|
32
21
|
let _id = 'cynx-badge-styles';
|
|
33
22
|
|
|
34
23
|
function ensureStyles() {
|
|
@@ -41,28 +30,26 @@ function ensureStyles() {
|
|
|
41
30
|
}
|
|
42
31
|
|
|
43
32
|
const SIZE_MAP = {
|
|
44
|
-
xs: { padding: '1.5px 6px', fontSize: '
|
|
45
|
-
sm: { padding: '2px
|
|
46
|
-
md: { padding: '3px 9px', fontSize: '
|
|
47
|
-
lg: { padding: '4px 12px', fontSize: '
|
|
33
|
+
xs: { padding: '1.5px 6px', plainPadding: '1px 0', fontSize: '9.5px', dotSize: 5, iconSize: 11, gap: 4 },
|
|
34
|
+
sm: { padding: '2px 8px', plainPadding: '2px 0', fontSize: '11px', dotSize: 6, iconSize: 12, gap: 5 },
|
|
35
|
+
md: { padding: '3px 9px', plainPadding: '2px 0', fontSize: '12px', dotSize: 6.5, iconSize: 13, gap: 6 },
|
|
36
|
+
lg: { padding: '4px 12px', plainPadding: '3px 0', fontSize: '13px', dotSize: 8, iconSize: 15, gap: 7 },
|
|
48
37
|
};
|
|
49
38
|
|
|
50
39
|
const SHAPE_STYLE = {
|
|
51
|
-
circle:
|
|
52
|
-
triangle:
|
|
53
|
-
diamond:
|
|
40
|
+
circle: (c) => ({ width: 7, height: 7, borderRadius: '50%', background: c, border: 'none' }),
|
|
41
|
+
triangle: (c) => ({ width: 0, height: 0, borderLeft: '4px solid transparent', borderRight: '4px solid transparent', borderBottom: `7px solid ${c}`, background: 'none', borderTop: 'none' }),
|
|
42
|
+
diamond: (c) => ({ width: 7, height: 7, borderRadius: 1, transform: 'rotate(45deg)', background: c, border: 'none' }),
|
|
54
43
|
semicircle:(c) => ({ width: 7, height: 7, borderRadius: '50%', border: 'none', borderTop: '2px solid var(--bg,#fff)', background: c }),
|
|
55
44
|
};
|
|
56
45
|
|
|
57
46
|
const COLOR_MAP = {
|
|
58
|
-
green: '#10b981',
|
|
59
|
-
yellow: '#f59e0b',
|
|
60
|
-
red: '#ef4444',
|
|
61
|
-
blue: '#3b82f6',
|
|
62
|
-
purple: '#8b5cf6', violet: '#8b5cf6',
|
|
63
|
-
|
|
64
|
-
cyan: '#06b6d4',
|
|
65
|
-
teal: '#14b8a6',
|
|
47
|
+
green: '#10b981', ok: '#10b981', success: '#10b981', emerald: '#10b981',
|
|
48
|
+
yellow: '#f59e0b', warn: '#f97316', warning: '#f97316', amber: '#f59e0b', orange: '#f97316',
|
|
49
|
+
red: '#ef4444', err: '#ef4444', danger: '#ef4444', error: '#ef4444', critical: '#ef4444',
|
|
50
|
+
blue: '#3b82f6', info: '#3b82f6', sky: '#0284c7',
|
|
51
|
+
purple: '#8b5cf6', violet: '#8b5cf6', indigo: '#6366f1',
|
|
52
|
+
cyan: '#06b6d4', teal: '#14b8a6',
|
|
66
53
|
pink: '#ec4899', rose: '#f43f5e',
|
|
67
54
|
grey: '#6b7280', gray: '#6b7280', dim: '#6b7280',
|
|
68
55
|
};
|
|
@@ -83,6 +70,11 @@ export default function Badge({
|
|
|
83
70
|
dot = false,
|
|
84
71
|
shape = null,
|
|
85
72
|
icon = null,
|
|
73
|
+
iconPosition = 'left',
|
|
74
|
+
iconSize = null,
|
|
75
|
+
pulse = false,
|
|
76
|
+
plain = false,
|
|
77
|
+
minimal = false,
|
|
86
78
|
onClick = null,
|
|
87
79
|
style = {},
|
|
88
80
|
className = '',
|
|
@@ -91,15 +83,59 @@ export default function Badge({
|
|
|
91
83
|
|
|
92
84
|
const v = VARIANTS[variant] || VARIANTS.dim;
|
|
93
85
|
const sz = SIZE_MAP[size] || SIZE_MAP.md;
|
|
86
|
+
const isPlain = plain || minimal;
|
|
94
87
|
const shapeType = (shape === 'none' || shape === false) ? null : (shape || SHAPES[variant] || null);
|
|
95
88
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
const customColor = resolveBadgeColor(color);
|
|
90
|
+
let colorStyle = {};
|
|
91
|
+
|
|
92
|
+
if (customColor) {
|
|
93
|
+
if (isPlain) {
|
|
94
|
+
colorStyle = { color: customColor, background: 'transparent', border: 'none' };
|
|
95
|
+
} else if (customColor.startsWith('#')) {
|
|
96
|
+
colorStyle = {
|
|
97
|
+
color: customColor,
|
|
98
|
+
background: `${customColor}18`,
|
|
99
|
+
border: `1px solid ${customColor}33`,
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
colorStyle = {
|
|
103
|
+
color: customColor,
|
|
104
|
+
background: `color-mix(in srgb, ${customColor} 12%, transparent)`,
|
|
105
|
+
border: `1px solid color-mix(in srgb, ${customColor} 25%, transparent)`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
} else if (isPlain) {
|
|
109
|
+
colorStyle = {
|
|
110
|
+
color: v.color,
|
|
111
|
+
background: 'transparent',
|
|
112
|
+
border: 'none',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const dotColor = customColor || v.dot || v.color;
|
|
117
|
+
const actualDotSize = sz.dotSize || 6;
|
|
118
|
+
const actualIconSize = iconSize || sz.iconSize || 13;
|
|
119
|
+
|
|
120
|
+
const renderIcon = () => {
|
|
121
|
+
if (!icon) return null;
|
|
122
|
+
return (
|
|
123
|
+
<span style={{
|
|
124
|
+
display: 'inline-flex',
|
|
125
|
+
alignItems: 'center',
|
|
126
|
+
justifyContent: 'center',
|
|
127
|
+
flexShrink: 0,
|
|
128
|
+
color: dotColor,
|
|
129
|
+
}}>
|
|
130
|
+
{React.isValidElement(icon)
|
|
131
|
+
? React.cloneElement(icon, {
|
|
132
|
+
size: icon.props?.size || actualIconSize,
|
|
133
|
+
color: icon.props?.color || dotColor,
|
|
134
|
+
})
|
|
135
|
+
: icon}
|
|
136
|
+
</span>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
103
139
|
|
|
104
140
|
return (
|
|
105
141
|
<span
|
|
@@ -107,31 +143,32 @@ export default function Badge({
|
|
|
107
143
|
style={{
|
|
108
144
|
display: 'inline-flex',
|
|
109
145
|
alignItems: 'center',
|
|
110
|
-
gap: 5,
|
|
111
|
-
padding:
|
|
112
|
-
borderRadius: 'var(--rfull,99px)',
|
|
146
|
+
gap: sz.gap || 5,
|
|
147
|
+
padding: isPlain ? sz.plainPadding : sz.padding,
|
|
148
|
+
borderRadius: isPlain ? 0 : 'var(--rfull,99px)',
|
|
113
149
|
fontSize: sz.fontSize,
|
|
114
|
-
fontWeight: 600,
|
|
115
|
-
border: `1px solid ${v.border}`,
|
|
116
|
-
background: v.bg,
|
|
150
|
+
fontWeight: isPlain ? 500 : 600,
|
|
151
|
+
border: isPlain ? 'none' : `1px solid ${v.border}`,
|
|
152
|
+
background: isPlain ? 'transparent' : v.bg,
|
|
117
153
|
color: v.color,
|
|
118
154
|
whiteSpace: 'nowrap',
|
|
119
155
|
transition: 'all .15s',
|
|
120
156
|
cursor: onClick ? 'pointer' : undefined,
|
|
157
|
+
lineHeight: 1.2,
|
|
121
158
|
...colorStyle,
|
|
122
159
|
...style,
|
|
123
160
|
}}
|
|
124
161
|
onClick={onClick}
|
|
125
162
|
>
|
|
163
|
+
{icon && iconPosition === 'left' && renderIcon()}
|
|
126
164
|
{dot && (
|
|
127
165
|
<span style={{
|
|
128
|
-
width:
|
|
129
|
-
height:
|
|
166
|
+
width: actualDotSize,
|
|
167
|
+
height: actualDotSize,
|
|
130
168
|
borderRadius: '50%',
|
|
131
169
|
flexShrink: 0,
|
|
132
|
-
marginTop: -2,
|
|
133
170
|
background: dotColor,
|
|
134
|
-
animation:
|
|
171
|
+
animation: pulse ? 'badge-pulse 1.5s ease-in-out infinite' : undefined,
|
|
135
172
|
}} />
|
|
136
173
|
)}
|
|
137
174
|
{shapeType && !dot && (
|
|
@@ -142,20 +179,8 @@ export default function Badge({
|
|
|
142
179
|
...(SHAPE_STYLE[shapeType] ? SHAPE_STYLE[shapeType](dotColor) : {}),
|
|
143
180
|
}} />
|
|
144
181
|
)}
|
|
145
|
-
{icon && (
|
|
146
|
-
<span style={{
|
|
147
|
-
display: 'inline-flex',
|
|
148
|
-
alignItems: 'center',
|
|
149
|
-
justifyContent: 'center',
|
|
150
|
-
width: 14,
|
|
151
|
-
height: 14,
|
|
152
|
-
flexShrink: 0,
|
|
153
|
-
color: dotColor,
|
|
154
|
-
}}>
|
|
155
|
-
{icon}
|
|
156
|
-
</span>
|
|
157
|
-
)}
|
|
158
182
|
{children}
|
|
183
|
+
{icon && iconPosition === 'right' && renderIcon()}
|
|
159
184
|
</span>
|
|
160
185
|
);
|
|
161
186
|
}
|
package/components/Select.jsx
CHANGED
|
@@ -37,6 +37,7 @@ export default function Select({
|
|
|
37
37
|
size = 'md',
|
|
38
38
|
style = {},
|
|
39
39
|
rounded = false,
|
|
40
|
+
showCount = false,
|
|
40
41
|
}) {
|
|
41
42
|
const [open, setOpen] = useState(false);
|
|
42
43
|
const [query, setQuery] = useState('');
|
|
@@ -217,32 +218,42 @@ export default function Select({
|
|
|
217
218
|
>
|
|
218
219
|
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center' }}>
|
|
219
220
|
{multi && selectedValues.length > 0 ? (
|
|
220
|
-
|
|
221
|
-
{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
221
|
+
showCount ? (
|
|
222
|
+
<span style={{ fontWeight: 500, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', color: 'var(--t,var(--primary-text, #0f172a))' }}>
|
|
223
|
+
{typeof showCount === 'function'
|
|
224
|
+
? showCount(selectedValues.length)
|
|
225
|
+
: selectedValues.length === 1
|
|
226
|
+
? getLabel(selectedValues[0])
|
|
227
|
+
: `Выбрано: ${selectedValues.length}`}
|
|
228
|
+
</span>
|
|
229
|
+
) : (
|
|
230
|
+
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4, flex: 1, minWidth: 0 }}>
|
|
231
|
+
{selectedValues.map(v => (
|
|
232
|
+
<span key={v} style={{
|
|
233
|
+
display: 'inline-flex',
|
|
234
|
+
alignItems: 'center',
|
|
235
|
+
gap: 4,
|
|
236
|
+
padding: '2px 6px',
|
|
237
|
+
background: 'var(--pd,var(--accent-bg, rgba(249,158,44,.1)))',
|
|
238
|
+
border: '1px solid var(--accent, #f99e2c)',
|
|
239
|
+
borderRadius: 4,
|
|
240
|
+
fontSize: 11,
|
|
241
|
+
fontWeight: 600,
|
|
242
|
+
color: 'var(--accent, #f99e2c)',
|
|
243
|
+
whiteSpace: 'nowrap',
|
|
244
|
+
maxWidth: 140,
|
|
245
|
+
opacity: 0.85,
|
|
246
|
+
}}>
|
|
247
|
+
{getLabel(v)}
|
|
248
|
+
<X
|
|
249
|
+
size={11}
|
|
250
|
+
style={{ cursor: 'pointer', flexShrink: 0, opacity: 0.5 }}
|
|
251
|
+
onMouseDown={(e) => removeTag(e, v)}
|
|
252
|
+
/>
|
|
253
|
+
</span>
|
|
254
|
+
))}
|
|
255
|
+
</div>
|
|
256
|
+
)
|
|
246
257
|
) : !multi && selectedValues.length > 0 ? (
|
|
247
258
|
<span style={{ fontWeight: 400, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
248
259
|
{getLabel(selectedValues[0]) || '\u00A0'}
|
|
@@ -251,12 +262,12 @@ export default function Select({
|
|
|
251
262
|
<span style={{ color: 'var(--t3,var(--grey-3, #cbd5e1))', fontWeight: 400 }}>{placeholder}</span>
|
|
252
263
|
)}
|
|
253
264
|
</div>
|
|
254
|
-
{
|
|
265
|
+
{selectedValues.length > 0 && selectedValues[0] !== '' && selectedValues[0] !== null && (clearable || !!onClear) ? (
|
|
255
266
|
<span
|
|
256
267
|
onClick={(e) => {
|
|
257
268
|
e.stopPropagation();
|
|
258
269
|
if (onClear) onClear();
|
|
259
|
-
else onChange?.('');
|
|
270
|
+
else onChange?.(multi ? [] : '');
|
|
260
271
|
}}
|
|
261
272
|
title="Сбросить выбор"
|
|
262
273
|
style={{
|