AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ui.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import type { ReactNode } from 'react';
  2. import { cn } from '@/lib/utils';
  3. import { useHref } from './context';
  4. /** Page-width wrapper used by every section. */
  5. export function Container({
  6. className,
  7. children,
  8. }: {
  9. className?: string;
  10. children: ReactNode;
  11. }) {
  12. return (
  13. <div className={cn('mx-auto w-full max-w-6xl px-5 sm:px-8', className)}>
  14. {children}
  15. </div>
  16. );
  17. }
  18. export function SfButton({
  19. href,
  20. variant = 'primary',
  21. className,
  22. children,
  23. }: {
  24. href: string;
  25. variant?: 'primary' | 'outline';
  26. className?: string;
  27. children: ReactNode;
  28. }) {
  29. const resolved = useHref(href);
  30. return (
  31. <a
  32. href={resolved}
  33. className={cn(
  34. 'inline-flex items-center justify-center rounded-(--sf-radius) px-5 py-2.5 text-sm font-semibold transition-opacity hover:opacity-85 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--sf-primary)',
  35. variant === 'primary'
  36. ? 'bg-(--sf-primary) text-(--sf-primary-fg)'
  37. : 'border border-(--sf-border) text-(--sf-fg)',
  38. className,
  39. )}
  40. >
  41. {children}
  42. </a>
  43. );
  44. }
  45. /** A plain link whose address is worked out the same way as buttons. */
  46. export function SfLink({
  47. href,
  48. className,
  49. onClick,
  50. children,
  51. }: {
  52. href: string;
  53. className?: string;
  54. onClick?: () => void;
  55. children: ReactNode;
  56. }) {
  57. return (
  58. <a href={useHref(href)} className={className} onClick={onClick}>
  59. {children}
  60. </a>
  61. );
  62. }
  63. /** A minus button, the number, and a plus button. */
  64. export function QuantityStepper({
  65. value,
  66. max,
  67. min = 1,
  68. disabled = false,
  69. onChange,
  70. decreaseLabel,
  71. increaseLabel,
  72. }: {
  73. value: number;
  74. max: number;
  75. min?: number;
  76. disabled?: boolean;
  77. onChange: (value: number) => void;
  78. decreaseLabel: string;
  79. increaseLabel: string;
  80. }) {
  81. const button =
  82. 'flex size-9 items-center justify-center text-lg leading-none transition-colors hover:bg-(--sf-surface) disabled:cursor-not-allowed disabled:opacity-40';
  83. return (
  84. <div className="inline-flex items-center overflow-hidden rounded-(--sf-radius) border border-(--sf-border)">
  85. <button
  86. type="button"
  87. className={button}
  88. aria-label={decreaseLabel}
  89. disabled={disabled || value <= min}
  90. onClick={() => onChange(value - 1)}
  91. >
  92. −
  93. </button>
  94. <span
  95. className="min-w-9 px-1 text-center text-sm tabular-nums"
  96. aria-live="polite"
  97. >
  98. {value}
  99. </span>
  100. <button
  101. type="button"
  102. className={button}
  103. aria-label={increaseLabel}
  104. disabled={disabled || value >= max}
  105. onClick={() => onChange(value + 1)}
  106. >
  107. +
  108. </button>
  109. </div>
  110. );
  111. }
  112. export function Eyebrow({ children }: { children: ReactNode }) {
  113. return (
  114. <p className="text-xs font-semibold tracking-[0.18em] text-(--sf-primary) uppercase">
  115. {children}
  116. </p>
  117. );
  118. }
  119. export function SectionHeading({
  120. heading,
  121. subheading,
  122. align = 'left',
  123. }: {
  124. heading: string;
  125. subheading?: string | null;
  126. align?: 'left' | 'center';
  127. }) {
  128. return (
  129. <div
  130. className={cn(
  131. 'max-w-2xl',
  132. align === 'center' && 'mx-auto text-center',
  133. )}
  134. >
  135. <h2 className="sf-heading text-3xl leading-tight font-semibold sm:text-4xl">
  136. {heading}
  137. </h2>
  138. {subheading && (
  139. <p className="mt-3 text-base text-(--sf-muted)">{subheading}</p>
  140. )}
  141. </div>
  142. );
  143. }
  144. const tilts = ['135deg', '200deg', '45deg', '310deg'];
  145. /**
  146. * Stands in for a photo when there is no real one.
  147. * It is drawn from the theme colours so it always matches the store.
  148. */
  149. export function ImagePlaceholder({
  150. seed = 0,
  151. label,
  152. className,
  153. }: {
  154. seed?: number;
  155. label?: string;
  156. className?: string;
  157. }) {
  158. const tilt = tilts[seed % tilts.length];
  159. // The first letter of the product or headline, set large in the store's heading font,
  160. // so a store without photos still looks designed rather than unfinished.
  161. const letter = label?.trim().charAt(0).toUpperCase() ?? '';
  162. return (
  163. <div
  164. role="img"
  165. aria-label={
  166. label ? `Placeholder image: ${label}` : 'Placeholder image'
  167. }
  168. className={cn(
  169. 'relative grid place-items-center overflow-hidden rounded-(--sf-radius-card) border border-(--sf-border)',
  170. className,
  171. )}
  172. style={{
  173. background: `linear-gradient(${tilt}, color-mix(in srgb, var(--sf-primary) 14%, var(--sf-surface)), color-mix(in srgb, var(--sf-accent) 22%, var(--sf-surface)))`,
  174. }}
  175. >
  176. <div
  177. className="absolute inset-[12%] rounded-(--sf-radius-card) border opacity-40"
  178. style={{ borderColor: 'var(--sf-primary)' }}
  179. />
  180. {letter && (
  181. <span
  182. aria-hidden="true"
  183. className="sf-heading text-[clamp(3rem,12vw,7rem)] leading-none font-semibold opacity-30 select-none"
  184. style={{ color: 'var(--sf-primary)' }}
  185. >
  186. {letter}
  187. </span>
  188. )}
  189. </div>
  190. );
  191. }