AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

logo.tsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { cn } from '@/lib/utils';
  2. import type { LogoDesignKey, StoreLogoData } from './types';
  3. /** Keep in step with StoreLogos::DESIGNS. */
  4. export const LOGO_DESIGNS: LogoDesignKey[] = [
  5. 'wordmark',
  6. 'spaced',
  7. 'monogram-circle',
  8. 'monogram-square',
  9. 'two-tone',
  10. 'underline',
  11. 'badge',
  12. 'dot',
  13. ];
  14. /** Up to two letters for a badge: the first letters of the first two words. */
  15. export function initials(name: string): string {
  16. const words = name
  17. .replace(/[^\p{L}\p{N}\s]/gu, ' ')
  18. .split(/\s+/)
  19. .filter(Boolean);
  20. return (
  21. words.length > 1
  22. ? words[0][0] + words[1][0]
  23. : (words[0] ?? '?').slice(0, 2)
  24. ).toUpperCase();
  25. }
  26. /**
  27. * A store's logo. Reads the store's colours and fonts from the storefront's CSS variables,
  28. * so ready designs follow the store's look when it changes.
  29. */
  30. export function StoreLogo({
  31. logo,
  32. name,
  33. className,
  34. }: {
  35. logo: StoreLogoData;
  36. name: string;
  37. className?: string;
  38. }) {
  39. if (logo.type === 'upload') {
  40. return (
  41. <img
  42. src={logo.url}
  43. width={logo.width}
  44. height={logo.height}
  45. alt={name}
  46. className={cn(
  47. 'h-10 w-auto max-w-[200px] object-contain md:h-12',
  48. className,
  49. )}
  50. data-test="store-logo"
  51. />
  52. );
  53. }
  54. if (logo.type === 'drawn') {
  55. return (
  56. <span
  57. role="img"
  58. aria-label={name}
  59. className={cn(
  60. 'block h-10 md:h-12 [&>svg]:h-full [&>svg]:w-auto [&>svg]:max-w-[260px]',
  61. className,
  62. )}
  63. // Cleaned on the server by LogoSvg: simple shapes and text only.
  64. dangerouslySetInnerHTML={{ __html: logo.svg }}
  65. data-test="store-logo"
  66. />
  67. );
  68. }
  69. return <LogoDesign design={logo.key} name={name} className={className} />;
  70. }
  71. /** One of the ready designs, drawn from the store's name, fonts and colours. */
  72. export function LogoDesign({
  73. design,
  74. name,
  75. className,
  76. }: {
  77. design: LogoDesignKey;
  78. name: string;
  79. className?: string;
  80. }) {
  81. const heading = 'font-(family-name:--sf-font-heading) text-(--sf-fg)';
  82. const mark = (shape: 'circle' | 'square') => (
  83. <span
  84. aria-hidden="true"
  85. className={cn(
  86. 'flex size-9 shrink-0 items-center justify-center bg-(--sf-primary) text-sm font-bold tracking-wide text-(--sf-primary-fg)',
  87. shape === 'circle' ? 'rounded-full' : 'rounded-(--sf-radius)',
  88. )}
  89. >
  90. {initials(name)}
  91. </span>
  92. );
  93. const [first, ...rest] = name.split(' ');
  94. const body = (() => {
  95. switch (design) {
  96. case 'spaced':
  97. return (
  98. <span
  99. className={cn(
  100. heading,
  101. 'text-lg font-semibold tracking-[0.22em] uppercase',
  102. )}
  103. >
  104. {name}
  105. </span>
  106. );
  107. case 'monogram-circle':
  108. case 'monogram-square':
  109. return (
  110. <span className="inline-flex items-center gap-2.5">
  111. {mark(
  112. design === 'monogram-circle' ? 'circle' : 'square',
  113. )}
  114. <span className={cn(heading, 'text-xl font-semibold')}>
  115. {name}
  116. </span>
  117. </span>
  118. );
  119. case 'two-tone':
  120. return (
  121. <span
  122. className={cn(
  123. heading,
  124. 'text-xl font-bold tracking-tight',
  125. )}
  126. >
  127. <span className="text-(--sf-primary)">{first}</span>
  128. {rest.length > 0 && ` ${rest.join(' ')}`}
  129. </span>
  130. );
  131. case 'underline':
  132. return (
  133. <span className="inline-flex flex-col items-start gap-1">
  134. <span
  135. className={cn(
  136. heading,
  137. 'text-xl leading-none font-bold',
  138. )}
  139. >
  140. {name}
  141. </span>
  142. <span
  143. aria-hidden="true"
  144. className="h-[3px] w-2/5 rounded-full bg-(--sf-accent)"
  145. />
  146. </span>
  147. );
  148. case 'badge':
  149. return (
  150. <span
  151. className={cn(
  152. heading,
  153. 'rounded-(--sf-radius) border-2 border-(--sf-fg) px-3 py-1 text-sm font-bold tracking-[0.16em] uppercase',
  154. )}
  155. >
  156. {name}
  157. </span>
  158. );
  159. case 'dot':
  160. return (
  161. <span
  162. className={cn(
  163. heading,
  164. 'text-xl font-bold tracking-tight',
  165. )}
  166. >
  167. {name}
  168. <span aria-hidden="true" className="text-(--sf-accent)">
  169. .
  170. </span>
  171. </span>
  172. );
  173. default:
  174. return (
  175. <span className={cn(heading, 'text-xl font-semibold')}>
  176. {name}
  177. </span>
  178. );
  179. }
  180. })();
  181. return (
  182. <span
  183. className={cn(
  184. 'inline-flex items-center whitespace-nowrap',
  185. className,
  186. )}
  187. aria-label={name}
  188. role="img"
  189. data-test="store-logo"
  190. >
  191. {body}
  192. </span>
  193. );
  194. }