Skip to content

Commit e0bc2f2

Browse files
committed
feat(form): allow custom CSS styling via @field: css
1 parent 2ab970a commit e0bc2f2

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

changelogs/CHANGELOG-form-css.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Form CSS Customization
2+
3+
## What was changed
4+
Added the ability to apply custom CSS styling to `@Form` blocks using a dedicated `@field : css | "css string"` definition.
5+
6+
## Why it was changed
7+
This allows users to customize the appearance (like background color, text color, borders, etc.) of a specific form without having to write global injected CSS or use external stylesheets, improving the flexibility of the declarative form generation.
8+
9+
## Files modified
10+
- `js/form-docgen.js`: Modified `parseFormBlocks` to extract `@field: css` and applied it as an inline style string to the `.form-dg-card` container. Handles CSS strings with and without pipes `|` properly.

js/form-docgen.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,24 @@
167167
var body = match[1].trim();
168168
var lines = body.split('\n');
169169

170-
// First line = title (may not start with @)
171170
var title = '';
172171
var fields = [];
172+
var customCss = '';
173173
for (var i = 0; i < lines.length; i++) {
174174
var line = lines[i].trim();
175175
if (!line) continue;
176176
var fieldMatch = line.match(/^@field:\s*(.+)/i);
177177
if (fieldMatch) {
178178
var parts = fieldMatch[1].split('|').map(function (s) { return s.trim(); });
179+
var fieldName = parts[0] ? parts[0].toLowerCase() : '';
180+
181+
if (fieldName === 'css') {
182+
customCss = parts.slice(1).join('|') || '';
183+
// Remove surrounding quotes if present
184+
customCss = customCss.replace(/^"|"$/g, '').trim();
185+
continue;
186+
}
187+
179188
fields.push({
180189
name: parts[0] || 'field_' + i,
181190
type: (parts[1] || 'text').toLowerCase(),
@@ -192,6 +201,7 @@
192201
blocks.push({
193202
title: title || 'Form',
194203
fields: fields,
204+
customCss: customCss,
195205
start: match.index,
196206
end: match.index + match[0].length,
197207
fullMatch: match[0]
@@ -231,7 +241,9 @@
231241
}
232242
});
233243

234-
var html = '<div class="form-dg-card" data-form-index="' + blockIndex + '">'
244+
var customCssStyle = block.customCss ? ' style="' + escapeHtml(block.customCss) + '"' : '';
245+
246+
var html = '<div class="form-dg-card" data-form-index="' + blockIndex + '"' + customCssStyle + '>'
235247
+ '<div class="form-dg-header">'
236248
+ '<span class="form-dg-icon">📋</span>'
237249
+ '<span class="form-dg-title">' + escapeHtml(block.title) + '</span>'

0 commit comments

Comments
 (0)