feat(site-builder): tokenise colours hard-coded inside components
Component render/toHtml now use var(--wsb-*) instead of hex so Site Design palette changes reach FeaturesGrid, Testimonials, Accordion, PricingTable, CTA/CallToAction, forms, Gallery, Tabs and others. Exemption lists removed. Refs #44 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8227d768e6
commit
2877bc06fa
47 files changed
+473
-195
No files matched your search
@@ -126,3 +126,12 @@ describe('ButtonLink.toHtml palette token default (Refs #44)', () => {
|
||||
expect(html).not.toContain('#3b82f6');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ButtonLink.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({ ...(ButtonLink as any).craft.props }, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["bg", "primary"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#ffffff"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -77,7 +77,7 @@ ButtonLink.craft = {
|
||||
hoverColor: '',
|
||||
style: {
|
||||
backgroundColor: tokenRef('primary'),
|
||||
color: '#ffffff',
|
||||
color: tokenRef('bg'),
|
||||
padding: '12px 24px',
|
||||
borderRadius: '8px',
|
||||
fontWeight: '600',
|
||||
|
||||
@@ -32,3 +32,12 @@ describe('Divider.toHtml XSS hardening (thickness/color into style=)', () => {
|
||||
expect(html).not.toMatch(/"\s+onmouseover="/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Divider.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({}, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["border"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#e4e4e7"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
|
||||
@@ -9,7 +10,7 @@ interface DividerProps {
|
||||
}
|
||||
|
||||
export const Divider: UserComponent<DividerProps> = ({
|
||||
color = '#e4e4e7',
|
||||
color = tokenRef('border'),
|
||||
thickness = '1px',
|
||||
style = {},
|
||||
}) => {
|
||||
@@ -39,7 +40,7 @@ export const Divider: UserComponent<DividerProps> = ({
|
||||
Divider.craft = {
|
||||
displayName: 'Divider',
|
||||
props: {
|
||||
color: '#e4e4e7',
|
||||
color: tokenRef('border'),
|
||||
thickness: '1px',
|
||||
style: {},
|
||||
},
|
||||
@@ -55,7 +56,7 @@ Divider.craft = {
|
||||
(Divider as any).toHtml = (props: DividerProps, _childrenHtml: string) => {
|
||||
const styleStr = cssPropsToString({
|
||||
border: 'none',
|
||||
borderTop: `${props.thickness || '1px'} solid ${props.color || '#e4e4e7'}`,
|
||||
borderTop: `${props.thickness || '1px'} solid ${props.color || tokenRef('border')}`,
|
||||
margin: '16px 0',
|
||||
...props.style,
|
||||
});
|
||||
|
||||
@@ -83,3 +83,12 @@ describe('Logo.toHtml text-logo styling sanitization', () => {
|
||||
expect(html).toContain('MySite');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Logo.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({ text: "Acme" }, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["text"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#1f2937"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { useSiteDesign } from '../../state/SiteDesignContext';
|
||||
@@ -125,7 +126,7 @@ Logo.craft = {
|
||||
fontWeight: props.fontWeight || '700',
|
||||
fontSize: props.fontSize || '20px',
|
||||
fontFamily: props.fontFamily || 'Inter, sans-serif',
|
||||
color: props.color || '#1f2937',
|
||||
color: props.color || tokenRef('text'),
|
||||
});
|
||||
innerHtml = `<span${spanStyle ? ` style="${spanStyle}"` : ''}>${escapeHtml(props.text || 'MySite')}</span>`;
|
||||
}
|
||||
|
||||
@@ -83,3 +83,12 @@ describe('SearchBar.toHtml palette token fallbacks (Refs #44)', () => {
|
||||
expect(html).not.toContain('#1f2937');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SearchBar.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({}, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["bg", "border", "muted", "primary"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#d1d5db", "#9ca3af", "#ffffff"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -57,7 +57,7 @@ export const SearchBar: UserComponent<SearchBarProps> = ({
|
||||
left: '14px',
|
||||
top: '50%',
|
||||
transform: 'translateY(-50%)',
|
||||
color: '#9ca3af',
|
||||
color: tokenRef('muted'),
|
||||
fontSize: '14px',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
@@ -71,9 +71,9 @@ export const SearchBar: UserComponent<SearchBarProps> = ({
|
||||
padding: '12px 16px 12px 40px',
|
||||
fontSize: '15px',
|
||||
fontFamily: 'Inter, sans-serif',
|
||||
border: '1px solid #d1d5db',
|
||||
border: `1px solid ${tokenRef('border')}`,
|
||||
borderRadius: showButton ? '8px 0 0 8px' : '8px',
|
||||
backgroundColor: '#ffffff',
|
||||
backgroundColor: tokenRef('bg'),
|
||||
color: tokenRef('text'),
|
||||
outline: 'none',
|
||||
boxSizing: 'border-box',
|
||||
@@ -88,7 +88,7 @@ export const SearchBar: UserComponent<SearchBarProps> = ({
|
||||
fontSize: '15px',
|
||||
fontWeight: '600',
|
||||
fontFamily: 'Inter, sans-serif',
|
||||
color: '#ffffff',
|
||||
color: tokenRef('bg'),
|
||||
backgroundColor: tokenRef('primary'),
|
||||
border: 'none',
|
||||
borderRadius: '0 8px 8px 0',
|
||||
@@ -148,10 +148,10 @@ SearchBar.craft = {
|
||||
...style,
|
||||
});
|
||||
|
||||
const inputStyleStr = `width:100%;padding:12px 16px 12px 40px;font-size:15px;font-family:Inter,sans-serif;border:1px solid #d1d5db;border-radius:${showButton ? '8px 0 0 8px' : '8px'};background-color:#ffffff;color:${tokenRef('text')};outline:none;box-sizing:border-box`;
|
||||
const inputStyleStr = `width:100%;padding:12px 16px 12px 40px;font-size:15px;font-family:Inter,sans-serif;border:1px solid ${tokenRef('border')};border-radius:${showButton ? '8px 0 0 8px' : '8px'};background-color:${tokenRef('bg')};color:${tokenRef('text')};outline:none;box-sizing:border-box`;
|
||||
|
||||
const btnHtml = showButton
|
||||
? `<button type="submit" style="padding:12px 20px;font-size:15px;font-weight:600;font-family:Inter,sans-serif;color:#ffffff;background-color:${tokenRef('primary')};border:none;border-radius:0 8px 8px 0;cursor:pointer;white-space:nowrap;display:flex;align-items:center;gap:6px"><i class="fa fa-search" style="font-size:13px" aria-hidden="true"></i>${escapeHtml(buttonText)}</button>`
|
||||
? `<button type="submit" style="padding:12px 20px;font-size:15px;font-weight:600;font-family:Inter,sans-serif;color:${tokenRef('bg')};background-color:${tokenRef('primary')};border:none;border-radius:0 8px 8px 0;cursor:pointer;white-space:nowrap;display:flex;align-items:center;gap:6px"><i class="fa fa-search" style="font-size:13px" aria-hidden="true"></i>${escapeHtml(buttonText)}</button>`
|
||||
: '';
|
||||
|
||||
// F2: previously a purely decorative <form> -- no action/method/input
|
||||
@@ -165,7 +165,7 @@ SearchBar.craft = {
|
||||
return {
|
||||
html: `<form role="search" action="${actionAttr}" method="GET"${formStyle ? ` style="${formStyle}"` : ''}>
|
||||
<div style="position:relative;flex:1">
|
||||
<i class="fa fa-search" style="position:absolute;left:14px;top:50%;transform:translateY(-50%);color:#9ca3af;font-size:14px;pointer-events:none" aria-hidden="true"></i>
|
||||
<i class="fa fa-search" style="position:absolute;left:14px;top:50%;transform:translateY(-50%);color:${tokenRef('muted')};font-size:14px;pointer-events:none" aria-hidden="true"></i>
|
||||
<input type="search" name="q" placeholder="${escapeAttr(placeholder)}" style="${inputStyleStr}" />
|
||||
</div>
|
||||
${btnHtml}
|
||||
|
||||
@@ -86,3 +86,12 @@ describe('StarRating.craft.props includes the box-model/animation/visibility rol
|
||||
expect(props).toHaveProperty('hideOnMobile', false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('StarRating.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({}, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["warning", "border"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#f59e0b", "#d1d5db"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { cssValue, escapeAttr } from '../../utils/escape';
|
||||
@@ -21,8 +22,8 @@ export const StarRating: UserComponent<StarRatingProps> = ({
|
||||
rating = 4.5,
|
||||
maxStars = 5,
|
||||
size = '24px',
|
||||
filledColor = '#f59e0b',
|
||||
emptyColor = '#d1d5db',
|
||||
filledColor = tokenRef('warning'),
|
||||
emptyColor = tokenRef('border'),
|
||||
style = {},
|
||||
}) => {
|
||||
const {
|
||||
@@ -89,8 +90,8 @@ StarRating.craft = {
|
||||
rating: 4.5,
|
||||
maxStars: 5,
|
||||
size: '24px',
|
||||
filledColor: '#f59e0b',
|
||||
emptyColor: '#d1d5db',
|
||||
filledColor: tokenRef('warning'),
|
||||
emptyColor: tokenRef('border'),
|
||||
style: {},
|
||||
animation: '',
|
||||
animationDelay: '',
|
||||
@@ -123,8 +124,8 @@ StarRating.craft = {
|
||||
: 5;
|
||||
// Sanitized -- raw string-interpolation sinks in the star glyphs below.
|
||||
const size = cssValue(props.size) || '24px';
|
||||
const filledColor = cssValue(props.filledColor) || '#f59e0b';
|
||||
const emptyColor = cssValue(props.emptyColor) || '#d1d5db';
|
||||
const filledColor = cssValue(props.filledColor) || tokenRef('warning');
|
||||
const emptyColor = cssValue(props.emptyColor) || tokenRef('border');
|
||||
const wrapperStyle = cssPropsToString({
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
|
||||
@@ -108,3 +108,12 @@ describe('TextBlock.toHtml inline rich text (#46)', () => {
|
||||
expect((TextBlock as any).craft.props.html).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('TextBlock.toHtml design tokens (#44)', () => {
|
||||
test('default export references var(--wsb-*) and no longer carries the old hard-coded hex', () => {
|
||||
const { html } = toHtml({ ...(TextBlock as any).craft.props }, '');
|
||||
const lower = html.toLowerCase();
|
||||
for (const t of ["text"]) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
|
||||
for (const hex of ["#3f3f46"]) expect(lower, `old ${hex}`).not.toContain(hex);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { CSSProperties } from 'react';
|
||||
import { tokenRef } from '../../utils/tokens';
|
||||
import { useNode, UserComponent } from '@craftjs/core';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { escapeHtml } from '../../utils/escape';
|
||||
@@ -65,7 +66,7 @@ TextBlock.craft = {
|
||||
style: {
|
||||
fontSize: '16px',
|
||||
lineHeight: '1.6',
|
||||
color: '#3f3f46',
|
||||
color: tokenRef('text'),
|
||||
letterSpacing: '',
|
||||
textTransform: '' as CSSProperties['textTransform'],
|
||||
fontStyle: '' as CSSProperties['fontStyle'],
|
||||
|
||||
Reference in new issue
Block a user