feat(site-builder): HTML blocks get a code-only style panel

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-08 18:42:28 -07:00
co-authored by Claude Opus 5
parent 0d0d722dd7
commit 4ac57e1c4c
4 changed files with 79 additions and 3 deletions
@@ -0,0 +1,38 @@
import { describe, test, expect, vi } from 'vitest';
import React from 'react';
import { createRoot, Root } from 'react-dom/client';
import { act } from 'react-dom/test-utils';
vi.mock('@craftjs/core', () => ({
useEditor: () => ({ actions: { setProp: vi.fn() }, query: {} }),
}));
import { HtmlStylePanel } from './HtmlStylePanel';
let container: HTMLDivElement;
let root: Root;
function render(ui: React.ReactElement) {
container = document.createElement('div');
document.body.appendChild(container);
act(() => {
root = createRoot(container);
root.render(ui);
});
}
describe('HtmlStylePanel', () => {
test('renders the Edit HTML control', () => {
render(<HtmlStylePanel selectedId="n1" nodeProps={{ code: '<p>x</p>', style: {} }} />);
expect(container.textContent).toContain('Edit HTML');
});
test('renders NO colour or style controls (they never reach the live page)', () => {
render(<HtmlStylePanel selectedId="n1" nodeProps={{ code: '<p>x</p>', style: {} }} />);
expect(container.querySelector('input[type="color"]')).toBeNull();
expect(container.textContent).not.toContain('Background');
expect(container.textContent).not.toContain('Text Color');
expect(container.textContent).not.toContain('Padding');
expect(container.textContent).not.toContain('Border Radius');
});
});
@@ -0,0 +1,30 @@
import React from 'react';
import { useNodeProp } from './shared';
import { HtmlCodeField } from './HtmlCodeField';
/**
* The HTML block's entire style panel.
*
* Deliberately ONLY the code editor. `HtmlBlock.toHtml()` emits nothing but
* the purified `code`, so every colour/padding/alignment control the generic
* editor used to offer here was dead on the published page. Styling an HTML
* block is done inside the user's own markup.
*/
export const HtmlStylePanel: React.FC<{ selectedId: string; nodeProps: Record<string, any> }> = ({
selectedId,
nodeProps,
}) => {
const { setProp: setPropValue } = useNodeProp(selectedId);
return (
<>
<HtmlCodeField
value={typeof nodeProps.code === 'string' ? nodeProps.code : ''}
onChange={(v) => setPropValue('code', v)}
/>
<p style={{ fontSize: 10, color: 'var(--color-text-dim)', lineHeight: 1.4, padding: '0 2px' }}>
Style this block inside your own markup — a wrapper set here would show
in the editor but not on the published page.
</p>
</>
);
};
+1
View File
@@ -11,3 +11,4 @@ export { SectionTypePanel } from './SectionTypePanel';
export { PricingStylePanel } from './PricingStylePanel';
export { BackgroundSectionStylePanel } from './BackgroundSectionStylePanel';
export { GenericPropsEditor } from './GenericPropsEditor';
export { HtmlStylePanel } from './HtmlStylePanel';