cynx-ui 1.2.12 → 1.2.14
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/TabBar.jsx +156 -92
- package/components/Toggle.jsx +21 -37
- package/package.json +1 -1
package/components/TabBar.jsx
CHANGED
|
@@ -1,92 +1,156 @@
|
|
|
1
|
-
import { useRef, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const STYLES = `
|
|
4
|
+
@keyframes cx-tabSlide {
|
|
5
|
+
from { opacity: 0; transform: scaleX(.8); }
|
|
6
|
+
to { opacity: 1; transform: scaleX(1); }
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
let _id = 'cynx-tabbar-styles';
|
|
11
|
+
function ensureStyles() {
|
|
12
|
+
if (typeof document === 'undefined') return;
|
|
13
|
+
if (document.getElementById(_id)) return;
|
|
14
|
+
const tag = document.createElement('style');
|
|
15
|
+
tag.id = _id;
|
|
16
|
+
tag.textContent = STYLES;
|
|
17
|
+
document.head.appendChild(tag);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof document !== 'undefined') ensureStyles();
|
|
21
|
+
|
|
22
|
+
export default function TabBar({ tabs, active, onChange, capitalize = false, padding, variant = 'underline' }) {
|
|
23
|
+
const barRef = useRef(null);
|
|
24
|
+
const indRef = useRef(null);
|
|
25
|
+
const initDone = useRef(false);
|
|
26
|
+
|
|
27
|
+
// Underline indicator positioning
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (variant !== 'underline') return;
|
|
30
|
+
const bar = barRef.current;
|
|
31
|
+
const ind = indRef.current;
|
|
32
|
+
if (!bar || !ind) return;
|
|
33
|
+
|
|
34
|
+
const activeBtn = bar.querySelector(`[data-tabid="${active}"]`);
|
|
35
|
+
if (!activeBtn) return;
|
|
36
|
+
|
|
37
|
+
const barRect = bar.getBoundingClientRect();
|
|
38
|
+
const btnRect = activeBtn.getBoundingClientRect();
|
|
39
|
+
const x = btnRect.left - barRect.left;
|
|
40
|
+
const w = btnRect.width;
|
|
41
|
+
|
|
42
|
+
if (!initDone.current) {
|
|
43
|
+
ind.style.transition = 'none';
|
|
44
|
+
ind.style.width = w + 'px';
|
|
45
|
+
ind.style.transform = `translateX(${x}px)`;
|
|
46
|
+
requestAnimationFrame(() => { ind.style.transition = ''; });
|
|
47
|
+
initDone.current = true;
|
|
48
|
+
} else {
|
|
49
|
+
ind.style.width = w + 'px';
|
|
50
|
+
ind.style.transform = `translateX(${x}px)`;
|
|
51
|
+
}
|
|
52
|
+
}, [active, tabs, variant]);
|
|
53
|
+
|
|
54
|
+
if (variant === 'pill') {
|
|
55
|
+
return (
|
|
56
|
+
<div style={{
|
|
57
|
+
display: 'flex', gap: 4,
|
|
58
|
+
background: 'var(--grey-1, #f5f5f8)',
|
|
59
|
+
borderRadius: 'var(--rads, 8px)',
|
|
60
|
+
padding: '4px',
|
|
61
|
+
border: '1px solid var(--border-light, #ebebf0)',
|
|
62
|
+
}}>
|
|
63
|
+
{tabs.map(t => {
|
|
64
|
+
const isActive = active === t.id;
|
|
65
|
+
return (
|
|
66
|
+
<button
|
|
67
|
+
key={t.id}
|
|
68
|
+
data-tabid={t.id}
|
|
69
|
+
onClick={() => onChange(t.id)}
|
|
70
|
+
style={{
|
|
71
|
+
display: 'flex', alignItems: 'center', gap: 6,
|
|
72
|
+
padding: padding || '8px 16px',
|
|
73
|
+
border: 'none',
|
|
74
|
+
borderRadius: 'var(--radxs, 6px)',
|
|
75
|
+
background: isActive ? '#fff' : 'transparent',
|
|
76
|
+
boxShadow: isActive ? '0 1px 3px rgba(0,0,0,.08)' : 'none',
|
|
77
|
+
fontSize: '.82rem', fontWeight: isActive ? 600 : 500,
|
|
78
|
+
color: isActive ? 'var(--primary-text, #0f111c)' : 'var(--muted, #9b9daa)',
|
|
79
|
+
cursor: 'pointer',
|
|
80
|
+
transition: 'all .18s ease',
|
|
81
|
+
fontFamily: 'inherit',
|
|
82
|
+
whiteSpace: 'nowrap',
|
|
83
|
+
textTransform: capitalize ? 'capitalize' : 'none',
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
{t.icon}{t.label}
|
|
87
|
+
{t.count != null && t.count > 0 && (
|
|
88
|
+
<span style={{
|
|
89
|
+
background: isActive ? 'var(--accent-bg)' : 'var(--grey-2, #d7d8e0)',
|
|
90
|
+
color: isActive ? 'var(--accent)' : 'var(--muted)',
|
|
91
|
+
borderRadius: 10,
|
|
92
|
+
padding: '1px 6px',
|
|
93
|
+
fontSize: '.68rem',
|
|
94
|
+
fontWeight: 600,
|
|
95
|
+
}}>{t.count}</span>
|
|
96
|
+
)}
|
|
97
|
+
</button>
|
|
98
|
+
);
|
|
99
|
+
})}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Default: underline variant
|
|
105
|
+
const defaultPadding = padding || '10px 16px';
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div ref={barRef} style={{ display:'flex', position:'relative' }}>
|
|
109
|
+
<div ref={indRef} style={{
|
|
110
|
+
position:'absolute', bottom:'-1px', left:0,
|
|
111
|
+
height:2, width:0,
|
|
112
|
+
background:'var(--accent)',
|
|
113
|
+
borderRadius:'2px 2px 0 0',
|
|
114
|
+
transition:'transform .22s cubic-bezier(.4,0,.2,1), width .22s cubic-bezier(.4,0,.2,1)',
|
|
115
|
+
pointerEvents:'none', zIndex:2,
|
|
116
|
+
}} />
|
|
117
|
+
|
|
118
|
+
{tabs.map(t => {
|
|
119
|
+
const isActive = active === t.id;
|
|
120
|
+
return (
|
|
121
|
+
<button
|
|
122
|
+
key={t.id}
|
|
123
|
+
data-tabid={t.id}
|
|
124
|
+
onClick={() => onChange(t.id)}
|
|
125
|
+
style={{
|
|
126
|
+
display:'flex', alignItems:'center', gap:6,
|
|
127
|
+
padding: defaultPadding,
|
|
128
|
+
border:'none', background:'none',
|
|
129
|
+
fontSize:'.82rem', fontWeight:500,
|
|
130
|
+
color: isActive ? 'var(--accent)' : 'var(--muted)',
|
|
131
|
+
cursor:'pointer',
|
|
132
|
+
transition:'color .18s',
|
|
133
|
+
marginBottom:'-1px',
|
|
134
|
+
position:'relative', zIndex:1,
|
|
135
|
+
fontFamily:'inherit',
|
|
136
|
+
whiteSpace:'nowrap',
|
|
137
|
+
textTransform: capitalize ? 'capitalize' : 'none',
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{t.icon}{t.label}
|
|
141
|
+
{t.count != null && t.count > 0 && (
|
|
142
|
+
<span style={{
|
|
143
|
+
background: isActive ? 'var(--accent-bg)' : 'var(--grey-1)',
|
|
144
|
+
color: isActive ? 'var(--accent)' : 'var(--muted)',
|
|
145
|
+
borderRadius: 10,
|
|
146
|
+
padding: '1px 6px',
|
|
147
|
+
fontSize: '.68rem',
|
|
148
|
+
transition: 'background .18s, color .18s',
|
|
149
|
+
}}>{t.count}</span>
|
|
150
|
+
)}
|
|
151
|
+
</button>
|
|
152
|
+
);
|
|
153
|
+
})}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
package/components/Toggle.jsx
CHANGED
|
@@ -5,36 +5,13 @@ const SIZES = {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
const COLORS = {
|
|
8
|
-
primary: '
|
|
9
|
-
success: '
|
|
8
|
+
primary: '#f99e2c',
|
|
9
|
+
success: '#27ae60',
|
|
10
10
|
warning: '#f59e0b',
|
|
11
|
-
danger: '
|
|
11
|
+
danger: '#f64747',
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
@keyframes cx-toggle-on {
|
|
16
|
-
0% { transform: translateY(-50%) scale(1); }
|
|
17
|
-
40% { transform: translateY(-50%) scale(1.15); }
|
|
18
|
-
100% { transform: translateY(-50%) scale(1); }
|
|
19
|
-
}
|
|
20
|
-
@keyframes cx-toggle-off {
|
|
21
|
-
0% { transform: translateY(-50%) scale(1); }
|
|
22
|
-
40% { transform: translateY(-50%) scale(1.15); }
|
|
23
|
-
100% { transform: translateY(-50%) scale(1); }
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
let _id = 'cynx-toggle-styles';
|
|
28
|
-
function ensureStyles() {
|
|
29
|
-
if (typeof document === 'undefined') return;
|
|
30
|
-
if (document.getElementById(_id)) return;
|
|
31
|
-
const tag = document.createElement('style');
|
|
32
|
-
tag.id = _id;
|
|
33
|
-
tag.textContent = STYLES;
|
|
34
|
-
document.head.appendChild(tag);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (typeof document !== 'undefined') ensureStyles();
|
|
14
|
+
const OFF_COLOR = '#d7d8e0';
|
|
38
15
|
|
|
39
16
|
export default function Toggle({
|
|
40
17
|
checked = false,
|
|
@@ -48,14 +25,18 @@ export default function Toggle({
|
|
|
48
25
|
className = '',
|
|
49
26
|
style = {},
|
|
50
27
|
}) {
|
|
51
|
-
ensureStyles();
|
|
52
28
|
const s = SIZES[size] || SIZES.md;
|
|
53
|
-
const trackBg = checked ? (COLORS[color] || COLORS.primary) :
|
|
29
|
+
const trackBg = checked ? (COLORS[color] || COLORS.primary) : OFF_COLOR;
|
|
54
30
|
|
|
55
31
|
return (
|
|
56
32
|
<label
|
|
57
33
|
className={className}
|
|
58
|
-
style={{
|
|
34
|
+
style={{
|
|
35
|
+
display:'inline-flex', alignItems:'center', gap:8,
|
|
36
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
37
|
+
userSelect:'none', opacity: disabled ? .4 : 1,
|
|
38
|
+
...style,
|
|
39
|
+
}}
|
|
59
40
|
onClick={onClick}
|
|
60
41
|
>
|
|
61
42
|
<input type="checkbox" checked={checked} disabled={disabled}
|
|
@@ -63,18 +44,21 @@ export default function Toggle({
|
|
|
63
44
|
style={{ position:'absolute', opacity:0, width:0, height:0 }} />
|
|
64
45
|
<span style={{
|
|
65
46
|
position:'relative', width: s.w, height: s.h, borderRadius: s.r,
|
|
66
|
-
background: trackBg, flexShrink:0,
|
|
67
|
-
|
|
47
|
+
background: trackBg, flexShrink: 0,
|
|
48
|
+
transition: 'background .25s ease',
|
|
49
|
+
boxShadow: '0 1px 3px rgba(20,22,41,.1)',
|
|
68
50
|
}}>
|
|
69
51
|
<span style={{
|
|
70
52
|
position:'absolute', top:'50%',
|
|
71
|
-
transform:
|
|
53
|
+
transform: checked
|
|
54
|
+
? 'translateY(-50%) scale(1)'
|
|
55
|
+
: 'translateY(-50%) scale(1)',
|
|
72
56
|
left: checked ? s.on : s.off,
|
|
73
57
|
width: s.dot, height: s.dot,
|
|
74
|
-
background:'#fff', borderRadius:'50%',
|
|
75
|
-
boxShadow:'0 1px 3px rgba(0,0,0,.25)',
|
|
76
|
-
transition:'left .
|
|
77
|
-
|
|
58
|
+
background: '#fff', borderRadius: '50%',
|
|
59
|
+
boxShadow: '0 1px 3px rgba(0,0,0,.25)',
|
|
60
|
+
transition: 'left .3s cubic-bezier(.34,1.56,.64,1), transform .2s ease',
|
|
61
|
+
willChange: 'left',
|
|
78
62
|
}} />
|
|
79
63
|
</span>
|
|
80
64
|
{label && <span style={labelStyle}>{label}</span>}
|