fix(site-builder): keep legacy light-surface text readable on dark palettes
Nodes saved before the component-tokens work (9ab0102) store light surface
hexes -- ContactForm inputBg '#ffffff', SubscribeForm style.backgroundColor
'#f8fafc', Testimonials cardBg '#f8fafc' -- while the text on those surfaces
became var(--wsb-text)/var(--wsb-muted). On a dark Site Design palette (light
text token, e.g. Agency #fafafa) that rendered white-on-white.
Text on a STORED light surface (hex #rgb/#rrggbb or rgb()) now keeps the
pre-token dark hex (input #1f2937, subscribe heading #1f2937, testimonial
quote #374151 / name #18181b / title #64748b); absent, token or dark surfaces
keep the token text. Stored props are never rewritten. Applied in both the
editor render and toHtml export.
Generalises Navbar's isLightNavBg into utils/color.ts (isLightColor /
textOnSurface, plus parseColor moved out of publish-checks and re-exported);
Navbar and autoTextColor now share it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7fe47160e9
commit
6afb1c9b22
9 files changed
+339
-43
No files matched your search
@@ -4,6 +4,15 @@ import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { relayFormWiring } from '../../utils/form-relay-wiring';
|
||||
import { escapeHtml, escapeAttr, slugId, cssValue, sanitizeInputType } from '../../utils/escape';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { textOnSurface } from '../../utils/color';
|
||||
|
||||
/* Legacy-surface text (finding 8): nodes saved before the component-tokens
|
||||
work store inputBg '#ffffff'. The typed text on a stored LIGHT input keeps
|
||||
the pre-token dark hex so it stays readable on a dark Site Design palette;
|
||||
absent / token / dark inputs keep the token. Stored props are never
|
||||
rewritten. (Labels need no rule: labelColor has been a stored prop since
|
||||
ContactForm was introduced, so legacy nodes carry their own '#374151'.) */
|
||||
const LEGACY_INPUT_TEXT = '#1f2937';
|
||||
|
||||
// The allowlist enforced at export time lives in `sanitizeInputType`
|
||||
// (utils/escape.ts) -- this union is a superset (it also covers 'textarea'
|
||||
@@ -85,7 +94,7 @@ export const ContactForm: UserComponent<ContactFormProps> = ({
|
||||
border: `1px solid ${inputBorder}`,
|
||||
borderRadius: '6px',
|
||||
backgroundColor: inputBg,
|
||||
color: tokenRef('text'),
|
||||
color: textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text')),
|
||||
boxSizing: 'border-box',
|
||||
outline: 'none',
|
||||
};
|
||||
@@ -216,7 +225,7 @@ ContactForm.craft = {
|
||||
const labelColor = cssValue(props.labelColor) || tokenRef('text');
|
||||
const inputBg = cssValue(props.inputBg) || tokenRef('bg');
|
||||
const inputBorder = cssValue(props.inputBorder) || tokenRef('border');
|
||||
const inputStyleStr = `width:100%;padding:10px 14px;font-size:14px;font-family:Inter,sans-serif;border:1px solid ${inputBorder};border-radius:6px;background-color:${inputBg};color:${tokenRef('text')};box-sizing:border-box;outline:none`;
|
||||
const inputStyleStr = `width:100%;padding:10px 14px;font-size:14px;font-family:Inter,sans-serif;border:1px solid ${inputBorder};border-radius:6px;background-color:${inputBg};color:${textOnSurface(inputBg, LEGACY_INPUT_TEXT, tokenRef('text'))};box-sizing:border-box;outline:none`;
|
||||
|
||||
const fieldsHtml = (props.fields || defaultFields).map((field, i) => {
|
||||
const reqStar = field.required ? `<span style="color:${tokenRef('error')};margin-left:2px">*</span>` : '';
|
||||
|
||||
@@ -4,6 +4,14 @@ import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { relayFormWiring } from '../../utils/form-relay-wiring';
|
||||
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { textOnSurface } from '../../utils/color';
|
||||
|
||||
/* Legacy-surface text (finding 8): nodes saved before the component-tokens
|
||||
work store style.backgroundColor '#f8fafc'. The heading on a stored LIGHT
|
||||
wrapper keeps the pre-token dark hex (readable on a dark Site Design
|
||||
palette); absent / token / dark wrappers keep the token. The email input
|
||||
has its own token surface + token text, so it is unaffected. */
|
||||
const LEGACY_HEADING_TEXT = '#1f2937';
|
||||
|
||||
interface SubscribeFormProps {
|
||||
heading?: string;
|
||||
@@ -56,7 +64,7 @@ export const SubscribeForm: UserComponent<SubscribeFormProps> = ({
|
||||
<h3 style={{
|
||||
fontSize: '22px',
|
||||
fontWeight: '600',
|
||||
color: tokenRef('text'),
|
||||
color: textOnSurface(style.backgroundColor, LEGACY_HEADING_TEXT, tokenRef('text')),
|
||||
marginBottom: '20px',
|
||||
fontFamily: 'Inter, sans-serif',
|
||||
}}>
|
||||
@@ -159,7 +167,7 @@ SubscribeForm.craft = {
|
||||
});
|
||||
|
||||
const headingHtml = heading
|
||||
? `<h3 style="font-size:22px;font-weight:600;color:${tokenRef('text')};margin-bottom:20px;font-family:Inter,sans-serif">${escapeHtml(heading)}</h3>`
|
||||
? `<h3 style="font-size:22px;font-weight:600;color:${textOnSurface(style.backgroundColor, LEGACY_HEADING_TEXT, tokenRef('text'))};margin-bottom:20px;font-family:Inter,sans-serif">${escapeHtml(heading)}</h3>`
|
||||
: '';
|
||||
|
||||
const formStyle = cssPropsToString({
|
||||
|
||||
Reference in new issue
Block a user