import React, { useCallback, useRef } from 'react'; import { useEditor } from '@craftjs/core'; import { BG_COLORS, SPACING_PRESETS, } from '../../../constants/presets'; import { StylePanelProps, SectionLabel, ColorSwatchGrid, GradientSwatchGrid, PresetButtonGrid, CollapsibleSection, ColorPickerField, uploadToWhp, labelStyle, inputStyle, smallInputStyle, btnActiveStyle, sectionGap, } from './shared'; /* ---------- BACKGROUND SECTION ---------- */ export const BackgroundSectionStylePanel: React.FC = ({ selectedId, nodeProps }) => { const { actions } = useEditor(); const fileInputRef = useRef(null); const setProp = useCallback((key: string, value: any) => { actions.setProp(selectedId, (props: any) => { props[key] = value; }); }, [actions, selectedId]); const setPropStyle = useCallback((key: string, value: string) => { actions.setProp(selectedId, (props: any) => { props.style = { ...props.style, [key]: value }; }); }, [actions, selectedId]); const handleUpload = useCallback(async (file: File) => { const url = await uploadToWhp(file); if (url) setProp('bgImage', url); }, [setProp]); const style = nodeProps.style || {}; return ( <> {/* Background Image */} {nodeProps.bgImage && (
)}
{ const f = e.target.files?.[0]; if (f) handleUpload(f); e.target.value = ''; }} /> setProp('bgImage', e.target.value)} style={{ ...smallInputStyle, width: '100%', marginTop: 4 }} />
{/* Background Color */} setProp('bgColor', v)} /> {/* Overlay */} setProp('overlayColor', v)} />
setProp('overlayOpacity', parseInt(e.target.value) / 100)} style={{ width: '100%' }} />
{/* Layout */}
setProp('innerMaxWidth', e.target.value)} style={inputStyle} />
Padding setPropStyle('padding', v)} />
); };