feat(site-builder): tokenise remaining component design colours (Navbar, Menu, Footer, SocialLinks, StickyCallBar, BackgroundSection, ContentSlider, Countdown, HeroSimple)

Refs #44

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-10-07 12:50:47 -07:00
1 parent 2877bc06fa
commit e347a4334d
19 files changed
+190 -68

No files matched your search

@@ -31,3 +31,13 @@ describe('Footer (F4: box-model + animation + visibility props on craft.props)',
expect(craftProps).toHaveProperty('hideOnMobile', false);
});
});
describe('Footer.toHtml design tokens (#44)', () => {
test('default craft props export var(--wsb-*) and none of the old design hex', () => {
const props = { ...((Footer as any).craft.props as object) };
const { html } = (((Footer) as any).toHtml)(props, '', 'node-tok');
const lower = html.toLowerCase();
for (const t of ['text', 'bg']) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
for (const hex of ['#18181b', '#a1a1aa']) expect(lower, `old ${hex}`).not.toContain(hex.toLowerCase());
});
});
+4 -2
View File
@@ -1,6 +1,7 @@
import React, { CSSProperties, useCallback, useRef, useEffect } from 'react';
import { useNode, UserComponent } from '@craftjs/core';
import { cssPropsToString } from '../../utils/style-helpers';
import { tokenRef } from '../../utils/tokens';
import { escapeHtml } from '../../utils/escape';
interface FooterProps {
@@ -92,8 +93,9 @@ Footer.craft = {
props: {
text: '© 2026 MySite. All rights reserved.',
style: {
backgroundColor: '#18181b',
color: '#a1a1aa',
// Dark band: text token as the band, bg token as its (contrast-safe) text.
backgroundColor: tokenRef('text'),
color: tokenRef('bg'),
fontSize: '14px',
padding: '24px 20px',
},
@@ -107,3 +107,13 @@ describe('Menu.toHtml dropdowns (#53)', () => {
expect((Menu as any).craft.props.followPages).toBe(false);
});
});
describe('Menu.toHtml design tokens (#44)', () => {
test('default craft props export var(--wsb-*) and none of the old design hex', () => {
const props = { ...((Menu as any).craft.props as object) };
const { html } = (((Menu) as any).toHtml)(props, '', 'node-tok');
const lower = html.toLowerCase();
for (const t of ['text', 'bg']) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
for (const hex of ['#3f3f46']) expect(lower, `old ${hex}`).not.toContain(hex.toLowerCase());
});
});
+7 -7
View File
@@ -43,10 +43,10 @@ const defaultLinks: MenuLink[] = [
export const Menu: UserComponent<MenuProps> = ({
links = defaultLinks,
alignment = 'right',
linkColor = '#3f3f46',
linkColor = tokenRef('text'),
linkHoverColor = tokenRef('primary'),
ctaBgColor = tokenRef('primary'),
ctaTextColor = '#ffffff',
ctaTextColor = tokenRef('bg'),
gap = '24px',
orientation = 'horizontal',
fontSize = '14px',
@@ -139,7 +139,7 @@ export const Menu: UserComponent<MenuProps> = ({
const SUB_STYLE: CSSProperties = {
position: 'absolute', top: '100%', left: 0, zIndex: 1001, minWidth: 180, margin: 0, padding: '8px 0',
listStyle: 'none', background: 'var(--wsb-bg, #ffffff)', borderRadius: 6, boxShadow: '0 8px 24px rgba(0,0,0,0.12)',
listStyle: 'none', background: tokenRef('bg'), borderRadius: 6, boxShadow: '0 8px 24px rgba(0,0,0,0.12)',
};
const SUB_STATIC_STYLE: CSSProperties = { margin: 0, padding: '4px 0 0 12px', listStyle: 'none' };
@@ -151,10 +151,10 @@ Menu.craft = {
links: defaultLinks,
followPages: false,
alignment: 'right',
linkColor: '#3f3f46',
linkColor: tokenRef('text'),
linkHoverColor: tokenRef('primary'),
ctaBgColor: tokenRef('primary'),
ctaTextColor: '#ffffff',
ctaTextColor: tokenRef('bg'),
gap: '24px',
orientation: 'horizontal',
fontSize: '14px',
@@ -179,10 +179,10 @@ Menu.craft = {
// string-interpolation sinks below (hoverCol goes into a <style> block,
// the worst case: </style> breakout -> arbitrary <script>), see
// task-cssxss-brief.md.
const linkCol = cssValue(props.linkColor) || '#3f3f46';
const linkCol = cssValue(props.linkColor) || tokenRef('text');
const hoverCol = cssValue(props.linkHoverColor) || tokenRef('primary');
const ctaBg = cssValue(props.ctaBgColor) || tokenRef('primary');
const ctaText = cssValue(props.ctaTextColor) || '#ffffff';
const ctaText = cssValue(props.ctaTextColor) || tokenRef('bg');
const gap = cssValue(props.gap) || '24px';
const orientation = props.orientation || 'horizontal';
const alignment = props.alignment || 'right';
@@ -185,3 +185,13 @@ describe('Navbar.toHtml dropdowns (#53)', () => {
expect((Navbar as any).craft.props.followPages).toBe(false);
});
});
describe('Navbar.toHtml design tokens (#44)', () => {
test('default craft props export var(--wsb-*) and none of the old design hex', () => {
const props = { ...((Navbar as any).craft.props as object) };
const { html } = (((Navbar) as any).toHtml)(props, '', 'node-tok');
const lower = html.toLowerCase();
for (const t of ['text', 'bg', 'border']) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
for (const hex of ['#3f3f46', '#e4e4e7']) expect(lower, `old ${hex}`).not.toContain(hex.toLowerCase());
});
});
+21 -12
View File
@@ -53,6 +53,11 @@ const PADDING_PRESETS = [
{ label: 'Spacious', value: '24px 48px' },
];
function isLightNavBg(bg: string): boolean {
const v = (bg || '').trim().toLowerCase();
return v === tokenRef('bg') || v === '#ffffff' || v === '#f8fafc' || v === '#f9fafb';
}
/* ---------- Component ---------- */
export const Navbar: UserComponent<NavbarProps> = ({
@@ -65,11 +70,11 @@ export const Navbar: UserComponent<NavbarProps> = ({
logoFontSize = '20px',
logoColor,
links = defaultLinks,
backgroundColor = '#ffffff',
textColor = '#3f3f46',
backgroundColor = tokenRef('bg'),
textColor = tokenRef('text'),
hoverColor = tokenRef('primary'),
ctaColor = tokenRef('primary'),
ctaTextColor = '#ffffff',
ctaTextColor = tokenRef('bg'),
padding = '16px 24px',
navAlignment = 'space-between',
isSticky = false,
@@ -84,8 +89,12 @@ export const Navbar: UserComponent<NavbarProps> = ({
}));
const { design } = useSiteDesign();
const resolvedLogoColor = logoColor || (backgroundColor === '#ffffff' || backgroundColor === '#f8fafc' || backgroundColor === '#f9fafb' ? design.textColor : '#ffffff');
const resolvedTextColor = textColor || (backgroundColor === '#ffffff' || backgroundColor === '#f8fafc' || backgroundColor === '#f9fafb' ? '#3f3f46' : '#e4e4e7');
// Light-background heuristic: the bg token counts as light (it is the page
// background); legacy stored hex values keep the old hex test. White/zinc on
// an explicitly dark bar is "text on a dark custom colour" -- no token fits.
const lightBg = isLightNavBg(backgroundColor);
const resolvedLogoColor = logoColor || (lightBg ? design.textColor : '#ffffff');
const resolvedTextColor = textColor || (lightBg ? tokenRef('text') : '#e4e4e7');
const [hoveredLink, setHoveredLink] = useState<number | null>(null);
const [openDropdown, setOpenDropdown] = useState<number | null>(null);
@@ -225,17 +234,17 @@ Navbar.craft = {
logoColor: undefined,
links: defaultLinks,
followPages: false,
backgroundColor: '#ffffff',
textColor: '#3f3f46',
backgroundColor: tokenRef('bg'),
textColor: tokenRef('text'),
hoverColor: tokenRef('primary'),
ctaColor: tokenRef('primary'),
ctaTextColor: '#ffffff',
ctaTextColor: tokenRef('bg'),
padding: '16px 24px',
navAlignment: 'space-between',
isSticky: false,
showMobileMenu: false,
style: {
borderBottom: '1px solid #e4e4e7',
borderBottom: `1px solid ${tokenRef('border')}`,
},
hideOnDesktop: false,
hideOnTablet: false,
@@ -256,11 +265,11 @@ Navbar.craft = {
// Sanitized once here -- these are raw string-interpolation sinks below
// (hoverCol/bgColor go into a <style> block, the worst case: </style>
// breakout -> arbitrary <script>), see task-cssxss-brief.md.
const bgColor = cssValue(props.backgroundColor) || '#ffffff';
const textCol = cssValue(props.textColor) || '#3f3f46';
const bgColor = cssValue(props.backgroundColor) || tokenRef('bg');
const textCol = cssValue(props.textColor) || tokenRef('text');
const hoverCol = cssValue(props.hoverColor) || tokenRef('primary');
const ctaCol = cssValue(props.ctaColor) || tokenRef('primary');
const ctaTextCol = cssValue(props.ctaTextColor) || '#ffffff';
const ctaTextCol = cssValue(props.ctaTextColor) || tokenRef('bg');
const pad = cssValue(props.padding) || '16px 24px';
const alignment = props.navAlignment || 'space-between';
const sticky = props.isSticky;
@@ -91,3 +91,13 @@ describe('SocialLinks.craft.props includes the box-model/animation/visibility ro
expect(props).toHaveProperty('hideOnMobile', false);
});
});
describe('SocialLinks.toHtml design tokens (#44)', () => {
test('default craft props export var(--wsb-*) and none of the old design hex', () => {
const props = { ...((SocialLinks as any).craft.props as object) };
const { html } = (((SocialLinks) as any).toHtml)(props, '', 'node-tok');
const lower = html.toLowerCase();
for (const t of ['text', 'bg']) expect(html, `token ${t}`).toContain(`var(--wsb-${t})`);
for (const hex of ['#374151']) expect(lower, `old ${hex}`).not.toContain(hex.toLowerCase());
});
});
+7 -6
View File
@@ -1,6 +1,7 @@
import React, { CSSProperties } from 'react';
import { useNode, UserComponent } from '@craftjs/core';
import { cssPropsToString } from '../../utils/style-helpers';
import { tokenRef } from '../../utils/tokens';
import { escapeAttr, safeUrl, cssValue } from '../../utils/escape';
interface SocialLink {
@@ -87,8 +88,8 @@ const alignMap: Record<string, string> = {
export const SocialLinks: UserComponent<SocialLinksProps> = ({
links = defaultLinks,
iconSize = '20px',
iconColor = '#ffffff',
iconBgColor = '#374151',
iconColor = tokenRef('bg'),
iconBgColor = tokenRef('text'),
iconShape = 'circle',
gap = '10px',
alignment = 'center',
@@ -150,8 +151,8 @@ SocialLinks.craft = {
props: {
links: defaultLinks,
iconSize: '20px',
iconColor: '#ffffff',
iconBgColor: '#374151',
iconColor: tokenRef('bg'),
iconBgColor: tokenRef('text'),
iconShape: 'circle',
gap: '10px',
alignment: 'center',
@@ -175,8 +176,8 @@ SocialLinks.craft = {
const links = props.links || defaultLinks;
// Sanitized -- raw string-interpolation sinks in aStyle/getShapeStr below.
const iconSize = cssValue(props.iconSize) || '20px';
const iconColor = cssValue(props.iconColor) || '#ffffff';
const iconBgColor = cssValue(props.iconBgColor) || '#374151';
const iconColor = cssValue(props.iconColor) || tokenRef('bg');
const iconBgColor = cssValue(props.iconBgColor) || tokenRef('text');
const iconShape = props.iconShape || 'circle';
const gap = props.gap || '10px';
const alignment = props.alignment || 'center';