Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/templates/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export { default as productMinimalBadge } from './minimal-badge';
export { default as productDarkPremium } from './dark-premium';
export { default as productShortcutTip } from './shortcut-tip';
export { default as productWaitlist } from './waitlist';
export { default as productYouAsked } from './you-asked';
247 changes: 247 additions & 0 deletions src/templates/product/you-asked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import type { SatoriElement, TemplateDefinition } from '../types';
import { autoFontSize, commonFields, isLightColor, mixColors, truncate } from '../utils';

const template: TemplateDefinition = {
id: 'product-you-asked',
name: 'You Asked',
category: 'product',
description: 'A customer request card announcing the feature your users asked for.',
tags: ['feedback', 'request', 'votes', 'shipped', 'product'],
fields: [
{ ...commonFields.title, defaultValue: 'Dark mode is here' },
{ key: 'request', label: 'Request', type: 'textarea', defaultValue: 'Please add a dark mode for working late', placeholder: 'What did your users ask for?', group: 'Content' },
{ key: 'votes', label: 'Votes', type: 'text', defaultValue: '248', placeholder: '248', group: 'Content' },
{ key: 'voteLabel', label: 'Vote Label', type: 'text', defaultValue: 'votes', placeholder: 'votes', group: 'Content' },
{ key: 'version', label: 'Version', type: 'text', defaultValue: 'v2.4', placeholder: 'v2.4', group: 'Content' },
commonFields.siteName,
commonFields.bgColor,
commonFields.accentColor,
commonFields.textColor,
],
defaults: {
title: 'Dark mode is here',
request: 'Please add a dark mode for working late',
votes: '248',
voteLabel: 'votes',
version: 'v2.4',
siteName: 'notewell.app',
bgColor: '#0a0a0a',
accentColor: '#E07A5F',
textColor: '#FFFFFF',
},
render: (params) => {
const titleValue = String(params.title ?? '').trim();
const request = String(params.request ?? '').trim();
const votes = String(params.votes ?? '').trim();
const voteLabel = String(params.voteLabel ?? '').trim();
const version = String(params.version ?? '').trim();
const siteName = String(params.siteName ?? '').trim();
const bgInput = String(params.bgColor ?? '').trim();
const accentInput = String(params.accentColor ?? '').trim();
const textInput = String(params.textColor ?? '').trim();
const bgColor = bgInput || '#0a0a0a';
const accentColor = accentInput || '#E07A5F';
const textColor = textInput || '#FFFFFF';
const title = truncate(titleValue, 64);
const titleSize = autoFontSize(titleValue, [
{ maxLen: 24, size: 64 },
{ maxLen: 40, size: 54 },
{ maxLen: 56, size: 46 },
{ maxLen: 80, size: 38 },
]);
const voteSize = autoFontSize(votes, [
{ maxLen: 4, size: 40 },
{ maxLen: 6, size: 32 },
{ maxLen: 8, size: 24 },
]);
const voteText = truncate(votes, 9);
const lightBackground = isLightColor(bgColor);
const accentInk = lightBackground ? mixColors(accentColor, '#000000', 0.45) : accentColor;
const voteColor = lightBackground ? accentInk : textColor;
const cardBorder = mixColors(bgColor, lightBackground ? accentInk : textColor, 0.35);
const requestText = truncate(request, 100);
const pillText = version ? `Shipped in ${version}` : 'Shipped';

const requestCard: SatoriElement = {
type: 'div',
props: {
style: {
display: 'flex',
flexDirection: 'row',
alignItems: 'stretch',
width: '100%',
minHeight: '118px',
border: `1px solid ${cardBorder}`,
borderRadius: '16px',
background: mixColors(bgColor, textColor, 0.06),
overflow: 'hidden',
},
children: [
...(votes
? [{
type: 'div',
props: {
style: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
flexShrink: 0,
width: '170px',
padding: '22px 18px',
borderRight: `1px solid ${cardBorder}`,
overflow: 'hidden',
},
children: [
{
type: 'span',
props: {
style: {
display: 'flex',
maxWidth: '134px',
overflow: 'hidden',
fontFamily: 'JetBrains Mono, monospace',
fontSize: `${voteSize}px`,
fontWeight: 700,
lineHeight: 1,
color: voteColor,
},
children: voteText,
},
},
...(voteLabel
? [{
type: 'span',
props: {
style: {
display: 'flex',
marginTop: '8px',
maxWidth: '134px',
overflow: 'hidden',
fontSize: '17px',
lineHeight: 1.1,
color: `${textColor}99`,
},
children: truncate(voteLabel, 18),
},
}]
: []),
],
},
}]
: []),
{
type: 'div',
props: {
style: {
display: 'flex',
flex: 1,
alignItems: 'center',
minWidth: 0,
padding: '24px 30px',
overflow: 'hidden',
},
children: {
type: 'p',
props: {
style: {
display: 'flex',
maxHeight: '76px',
margin: 0,
overflow: 'hidden',
fontSize: '28px',
lineHeight: 1.35,
color: `${textColor}aa`,
},
children: `“${requestText}”`,
},
},
},
},
],
},
};

return {
type: 'div',
props: {
style: {
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
justifyContent: 'center',
width: '1200px',
height: '630px',
padding: '64px 72px',
background: bgColor,
fontFamily: 'Inter, sans-serif',
overflow: 'hidden',
},
children: [
...(request ? [requestCard] : []),
{
type: 'div',
props: {
style: {
display: 'flex',
alignItems: 'center',
marginTop: request ? '20px' : 0,
padding: '8px 18px',
borderRadius: '999px',
background: mixColors(bgColor, accentColor, 0.14),
border: `1px solid ${cardBorder}`,
overflow: 'hidden',
},
children: {
type: 'span',
props: {
style: {
display: 'flex',
maxWidth: '1000px',
overflow: 'hidden',
fontSize: '18px',
fontWeight: 600,
color: accentInk,
},
children: pillText,
},
},
},
},
{
type: 'h1',
props: {
style: {
display: 'flex',
maxWidth: '1056px',
margin: '30px 0 0',
overflow: 'hidden',
fontSize: `${titleSize}px`,
fontWeight: 700,
lineHeight: 1.08,
color: textColor,
},
children: title,
},
},
...(siteName
? [{
type: 'span',
props: {
style: {
display: 'flex',
marginTop: '22px',
fontSize: '18px',
color: `${textColor}88`,
},
children: siteName,
},
}]
: []),
],
},
};
},
};

export default template;
3 changes: 2 additions & 1 deletion src/templates/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ import productMinimalBadge from './product/minimal-badge';
import productDarkPremium from './product/dark-premium';
import productShortcutTip from './product/shortcut-tip';
import productWaitlist from './product/waitlist';
import productYouAsked from './product/you-asked';

[
productCenteredHero, productSplitScreen, productGradientWave, productNeonGlow,
productGlassmorphism, productAppShowcase, productFeatureGrid, productAnnouncement,
productMinimalBadge, productDarkPremium,
productShortcutTip, productWaitlist,
productShortcutTip, productWaitlist,productYouAsked,
].forEach(registerTemplate);

// SaaS
Expand Down
93 changes: 93 additions & 0 deletions tests/templates/you-asked.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { describe, it, expect } from 'vitest';
import youAsked from '@/templates/product/you-asked';
import { productYouAsked } from '@/templates/product';
import { getTemplate } from '@/templates/registry';
import type { SatoriElement } from '@/templates/types';

function textContent(node: unknown): string[] {
if (typeof node === 'string') return [node];
if (Array.isArray(node)) return node.flatMap(textContent);
if (node && typeof node === 'object' && 'props' in node) {
return textContent((node as SatoriElement).props.children);
}
return [];
}

const render = (overrides: Record<string, unknown> = {}) =>
youAsked.render({ ...youAsked.defaults, ...overrides });

function elements(node: unknown): SatoriElement[] {
if (Array.isArray(node)) return node.flatMap(elements);
if (node && typeof node === 'object' && 'type' in node) {
const element = node as SatoriElement;
return [element, ...elements(element.props.children)];
}
return [];
}

describe('product-you-asked', () => {
it('is registered and re-exported', () => {
expect(getTemplate('product-you-asked')).toBe(youAsked);
expect(productYouAsked).toBe(youAsked);
});

it('renders the request card, pill, title, and site name', () => {
expect(textContent(render())).toEqual(expect.arrayContaining([
'“Please add a dark mode for working late”',
'Shipped in v2.4',
'Dark mode is here',
'notewell.app',
]));
});

it('hides the card for blank requests while keeping the pill and title', () => {
const empty = render({ request: ' ' });
const content = textContent(empty);
expect(content).toEqual(expect.arrayContaining(['Shipped in v2.4', 'Dark mode is here', 'notewell.app']));
expect(elements(empty).some((element) => element.props.children === '“”')).toBe(false);
});

it('hides the vote box and vote label without a count', () => {
const content = textContent(render({ votes: ' ' }));
expect(content).not.toContain('248');
expect(content).not.toContain('votes');
});

it('only renders the vote label when a count exists', () => {
expect(textContent(render())).toContain('votes');
expect(textContent(render({ voteLabel: ' ' }))).not.toContain('votes');
});

it('uses Shipped when the version is blank', () => {
expect(textContent(render({ version: ' ' }))).toContain('Shipped');
expect(textContent(render({ version: ' ' }))).not.toContain('Shipped in');
});

it('shrinks and truncates long titles', () => {
const element = render({ title: 'A very long title that keeps going beyond the available width for this announcement' });
const title = elements(element).find((item) => item.type === 'h1');
expect(title?.props.style.fontSize).toBe('38px');
expect(textContent(title)[0]).toMatch(/^A very long title that keeps going beyond/);
expect(textContent(title)[0]).toMatch(/…$/);
});

it('truncates long requests and vote counts', () => {
const element = render({
request: 'This is an exceptionally long customer request that should be capped so the card remains within two lines and never pushes the title out of place.',
votes: '123456789012345',
});
const content = textContent(element);
const request = content.find((text) => text.startsWith('“')) ?? '';
expect(request.length).toBeLessThan(132);
expect(request).toMatch(/…”$/);
const voteCount = content.find((text) => text.endsWith('…')) ?? '';
expect(voteCount).toMatch(/…$/);
expect(voteCount.length).toBeLessThanOrEqual(9);
});

it('uses darkened accent ink on a light background', () => {
const element = render({ bgColor: '#ffffff', accentColor: '#E07A5F' });
expect(() => JSON.stringify(element)).not.toThrow();
expect(JSON.stringify(element)).toContain('#7b4334');
});
});
Loading