PluginProbe
Ultimate Store Kit / 3.1.2
Ultimate Store Kit v3.1.2
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / src / admin / components / Toggle.js

Toggle.js in Ultimate Store Kit 3.1.2, at src/admin/components/Toggle.js

80 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Smooth Toggle switch component.
3 * Uses inline styles exclusively so WordPress admin CSS cannot
4 * override transform/transition via stylesheet specificity.
5 */
6 const BRAND = '#00216A';
7 const OFF_BG = '#cbd5e1';
8
9 // Spring-like easing: fast start, gentle settle
10 const EASE = 'cubic-bezier(0.34, 1.56, 0.64, 1)';
11 const EASE_BG = 'cubic-bezier(0.4, 0, 0.2, 1)';
12
13 const Toggle = ({ checked, onChange, disabled }) => {
14 const trackStyle = {
15 position: 'absolute',
16 inset: 0,
17 borderRadius: '9999px',
18 background: checked ? BRAND : OFF_BG,
19 transition: `background 0.25s ${EASE_BG}`,
20 opacity: disabled ? 0.45 : 1,
21 pointerEvents: 'none',
22 willChange: 'background',
23 };
24
25 const knobStyle = {
26 position: 'absolute',
27 top: '50%',
28 left: 3,
29 width: 16,
30 height: 16,
31 borderRadius: '9999px',
32 background: '#fff',
33 boxShadow: '0 1px 4px rgba(0,0,0,0.25)',
34 transform: checked
35 ? 'translate(18px, -50%)'
36 : 'translate(0px, -50%)',
37 transition: `transform 0.3s ${EASE}, box-shadow 0.2s ease`,
38 pointerEvents: 'none',
39 zIndex: 1,
40 willChange: 'transform',
41 };
42
43 const labelStyle = {
44 position: 'relative',
45 display: 'inline-flex',
46 alignItems: 'center',
47 width: 40,
48 height: 22,
49 cursor: disabled ? 'not-allowed' : 'pointer',
50 flexShrink: 0,
51 userSelect: 'none',
52 };
53
54 const inputStyle = {
55 position: 'absolute',
56 opacity: 0,
57 width: 0,
58 height: 0,
59 margin: 0,
60 padding: 0,
61 pointerEvents: 'none',
62 };
63
64 return (
65 <label style={labelStyle}>
66 <input
67 type="checkbox"
68 checked={checked}
69 disabled={disabled}
70 onChange={onChange}
71 style={inputStyle}
72 />
73 <span style={trackStyle} />
74 <span style={knobStyle} />
75 </label>
76 );
77 };
78
79 export default Toggle;
80