cynx-ui 1.2.5 → 1.2.6

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,19 +1,8 @@
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
- `;
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
+ };
17
6
 
18
7
  const COLORS = {
19
8
  primary: 'var(--accent)',
@@ -22,8 +11,6 @@ const COLORS = {
22
11
  danger: 'var(--danger)',
23
12
  };
24
13
 
25
- let styleInjected = false;
26
-
27
14
  export default function Toggle({
28
15
  checked = false,
29
16
  onChange,
@@ -36,22 +23,33 @@ export default function Toggle({
36
23
  className = '',
37
24
  style = {},
38
25
  }) {
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)';
26
+ const s = SIZES[size] || SIZES.md;
27
+ const trackBg = checked ? (COLORS[color] || COLORS.primary) : 'var(--bd2,#d7d8e0)';
49
28
 
50
29
  return (
51
- <label className={classes} style={style} onClick={onClick}>
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
+ >
52
35
  <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>
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>
55
53
  {label && <span style={labelStyle}>{label}</span>}
56
54
  </label>
57
55
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cynx-ui",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js"