/* global React */
(function () {
const { useState, useRef } = React;
const T = window.SC_T;
const _FS = 13, _LH = 1.55, _PV = 11, _PH = 13;
function Textarea({ value, onChange, placeholder, rows = 7, onKeyDown, lined = false }) {
const [focused, setFocused] = useState(false);
const overlayRef = useRef(null);
const borderStyle = {
border: `1px solid ${focused ? T.accent : T.border}`,
borderRadius: 10,
boxShadow: focused ? `0 0 0 3px ${T.accentSoft}` : 'none',
transition: 'border-color .15s ease, box-shadow .15s ease',
};
const taProps = {
value, placeholder, rows,
spellCheck: false,
onChange: (e) => onChange(e.target.value),
onFocus: () => setFocused(true),
onBlur: () => setFocused(false),
onKeyDown,
};
if (!lined) {
return (
);
}
const lines = value.split('\n');
return (
{/* separator overlay */}
{lines.map((_, i) => (
0 ? { borderTop: '1px solid rgba(0,0,0,0.07)', margin: `0 ${_PH + 4}px` } : {}),
}} />
))}
);
}
function TextInput({ value, onChange, placeholder, type = 'text', rightSlot, style }) {
const [focused, setFocused] = useState(false);
return (
onChange(e.target.value)}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
placeholder={placeholder}
style={{
width: '100%', padding: rightSlot ? '10px 42px 10px 14px' : '10px 14px',
border: `1px solid ${focused ? T.accent : T.border}`,
borderRadius: 10, fontSize: 14, fontFamily: 'inherit',
color: T.ink, outline: 'none', background: T.surface,
boxShadow: focused ? `0 0 0 3px ${T.accentSoft}` : 'none',
transition: 'border-color .15s ease, box-shadow .15s ease', ...style,
}}
/>
{rightSlot && (
{rightSlot}
)}
);
}
function Toggle({ on, onChange }) {
return (
);
}
function ToggleCard({ title, subtitle, on, onChange }) {
return (
onChange(!on)}
role="button" tabIndex={0}
style={{
display: 'flex', alignItems: 'center', gap: 12,
padding: '12px 14px', borderRadius: 10,
border: `1px solid ${on ? T.accent : T.border}`,
background: on ? T.accentSoft : T.surface,
cursor: 'pointer', textAlign: 'left',
transition: 'all .18s ease', width: '100%', userSelect: 'none',
}}
>
);
}
Object.assign(window, { Textarea, TextInput, Toggle, ToggleCard });
})();