import { cn } from '@/lib/utils'; import type { LogoDesignKey, StoreLogoData } from './types'; /** Keep in step with StoreLogos::DESIGNS. */ export const LOGO_DESIGNS: LogoDesignKey[] = [ 'wordmark', 'spaced', 'monogram-circle', 'monogram-square', 'two-tone', 'underline', 'badge', 'dot', ]; /** Up to two letters for a badge: the first letters of the first two words. */ export function initials(name: string): string { const words = name .replace(/[^\p{L}\p{N}\s]/gu, ' ') .split(/\s+/) .filter(Boolean); return ( words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? '?').slice(0, 2) ).toUpperCase(); } /** * A store's logo. Reads the store's colours and fonts from the storefront's CSS variables, * so ready designs follow the store's look when it changes. */ export function StoreLogo({ logo, name, className, }: { logo: StoreLogoData; name: string; className?: string; }) { if (logo.type === 'upload') { return ( {name} ); } if (logo.type === 'drawn') { return ( svg]:h-full [&>svg]:w-auto [&>svg]:max-w-[260px]', className, )} // Cleaned on the server by LogoSvg: simple shapes and text only. dangerouslySetInnerHTML={{ __html: logo.svg }} data-test="store-logo" /> ); } return ; } /** One of the ready designs, drawn from the store's name, fonts and colours. */ export function LogoDesign({ design, name, className, }: { design: LogoDesignKey; name: string; className?: string; }) { const heading = 'font-(family-name:--sf-font-heading) text-(--sf-fg)'; const mark = (shape: 'circle' | 'square') => ( ); const [first, ...rest] = name.split(' '); const body = (() => { switch (design) { case 'spaced': return ( {name} ); case 'monogram-circle': case 'monogram-square': return ( {mark( design === 'monogram-circle' ? 'circle' : 'square', )} {name} ); case 'two-tone': return ( {first} {rest.length > 0 && ` ${rest.join(' ')}`} ); case 'underline': return ( {name} ); case 'badge': return ( {name} ); case 'dot': return ( {name} ); default: return ( {name} ); } })(); return ( {body} ); }