import React, { useState } from 'react'; import { CSSProperties } from 'react'; interface BorderControlProps { style: CSSProperties; onChange: (updates: CSSProperties) => void; } const BORDER_STYLES = ['none', 'solid', 'dashed', 'dotted'] as const; const labelStyle: React.CSSProperties = { fontSize: 11, fontWeight: 600, color: '#a1a1aa', display: 'block', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.3px', }; const inputStyle: React.CSSProperties = { width: '100%', padding: '4px 6px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 11, textAlign: 'center', }; const btnStyle = (active: boolean): React.CSSProperties => ({ padding: '4px 8px', fontSize: 11, borderRadius: 4, cursor: 'pointer', border: '1px solid #3f3f46', background: active ? '#3b82f6' : '#27272a', color: active ? '#fff' : '#a1a1aa', flex: 1, textTransform: 'capitalize', }); const sideLabel: React.CSSProperties = { fontSize: 9, color: '#71717a', textAlign: 'center', marginTop: 2, textTransform: 'uppercase', letterSpacing: '0.5px', }; interface FourSidedValue { top: string; right: string; bottom: string; left: string; } function parseFourSided(val: string | undefined): FourSidedValue { if (!val) return { top: '0', right: '0', bottom: '0', left: '0' }; const parts = val.trim().split(/\s+/); if (parts.length === 1) return { top: parts[0], right: parts[0], bottom: parts[0], left: parts[0] }; if (parts.length === 2) return { top: parts[0], right: parts[1], bottom: parts[0], left: parts[1] }; if (parts.length === 3) return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[1] }; return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[3] }; } function fourSidedToString(val: FourSidedValue): string { const { top, right, bottom, left } = val; if (top === right && right === bottom && bottom === left) return top || '0'; if (top === bottom && right === left) return `${top} ${right}`; if (right === left) return `${top} ${right} ${bottom}`; return `${top} ${right} ${bottom} ${left}`; } function getNumeric(val: string): string { return val.replace(/[^0-9.]/g, '') || '0'; } export const BorderControl: React.FC = ({ style, onChange }) => { const [widthLinked, setWidthLinked] = useState(true); const [radiusLinked, setRadiusLinked] = useState(true); const currentBorderStyle = (style.borderStyle as string) || 'none'; const currentBorderColor = (style.borderColor as string) || '#3f3f46'; // Border width as 4-sided const borderWidth = parseFourSided(style.borderWidth as string); // Border radius as 4 corners (TL, TR, BR, BL) const borderRadius = parseFourSided(style.borderRadius as string); const handleWidthChange = (side: keyof FourSidedValue, raw: string) => { const num = raw.replace(/[^0-9.]/g, ''); const newVal = num ? `${num}px` : '0'; let updated: FourSidedValue; if (widthLinked) { updated = { top: newVal, right: newVal, bottom: newVal, left: newVal }; } else { updated = { ...borderWidth, [side]: newVal }; } onChange({ borderWidth: fourSidedToString(updated) }); }; const handleRadiusChange = (corner: keyof FourSidedValue, raw: string) => { const num = raw.replace(/[^0-9.]/g, ''); const newVal = num ? `${num}px` : '0'; let updated: FourSidedValue; if (radiusLinked) { updated = { top: newVal, right: newVal, bottom: newVal, left: newVal }; } else { updated = { ...borderRadius, [corner]: newVal }; } onChange({ borderRadius: fourSidedToString(updated) }); }; const widthSides: { key: keyof FourSidedValue; label: string }[] = [ { key: 'top', label: 'T' }, { key: 'right', label: 'R' }, { key: 'bottom', label: 'B' }, { key: 'left', label: 'L' }, ]; const radiusCorners: { key: keyof FourSidedValue; label: string }[] = [ { key: 'top', label: 'TL' }, { key: 'right', label: 'TR' }, { key: 'bottom', label: 'BR' }, { key: 'left', label: 'BL' }, ]; return (
{/* Border Style */}
{BORDER_STYLES.map((bs) => ( ))}
{/* Border Width (4-sided) */} {currentBorderStyle !== 'none' && (
{widthSides.map((s) => (
handleWidthChange(s.key, e.target.value)} style={inputStyle} />
{s.label}
))}
)} {/* Border Color */} {currentBorderStyle !== 'none' && (
onChange({ borderColor: e.target.value })} style={{ width: 32, height: 28, border: '1px solid #3f3f46', borderRadius: 4, background: 'none', cursor: 'pointer', padding: 0 }} /> onChange({ borderColor: e.target.value })} style={{ ...inputStyle, flex: 1, textAlign: 'left' }} placeholder="#000000" />
)} {/* Border Radius (4 corners) */}
{radiusCorners.map((c) => (
handleRadiusChange(c.key, e.target.value)} style={inputStyle} />
{c.label}
))}
); };