AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ui.tsx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. children,
  50. }: {
  51. href: string;
  52. className?: string;
  53. children: ReactNode;
  54. }) {
  55. return (
  56. <a href={useHref(href)} className={className}>
  57. {children}
  58. </a>
  59. );
  60. }
  61. /** A minus button, the number, and a plus button. */
  62. export function QuantityStepper({
  63. value,
  64. max,
  65. min = 1,
  66. disabled = false,
  67. onChange,
  68. decreaseLabel,
  69. increaseLabel,
  70. }: {
  71. value: number;
  72. max: number;
  73. min?: number;
  74. disabled?: boolean;
  75. onChange: (value: number) => void;
  76. decreaseLabel: string;
  77. increaseLabel: string;
  78. }) {
  79. const button =
  80. 'flex size-9 items-center justify-center text-lg leading-none transition-colors hover:bg-(--sf-surface) disabled:cursor-not-allowed disabled:opacity-40';
  81. return (
  82. <div className="inline-flex items-center overflow-hidden rounded-(--sf-radius) border border-(--sf-border)">
  83. <button
  84. type="button"
  85. className={button}
  86. aria-label={decreaseLabel}
  87. disabled={disabled || value <= min}
  88. onClick={() => onChange(value - 1)}
  89. >
  90. −
  91. </button>
  92. <span
  93. className="min-w-9 px-1 text-center text-sm tabular-nums"
  94. aria-live="polite"
  95. >
  96. {value}
  97. </span>
  98. <button
  99. type="button"
  100. className={button}
  101. aria-label={increaseLabel}
  102. disabled={disabled || value >= max}
  103. onClick={() => onChange(value + 1)}
  104. >
  105. +
  106. </button>
  107. </div>
  108. );
  109. }
  110. export function Eyebrow({ children }: { children: ReactNode }) {
  111. return (
  112. <p className="text-xs font-semibold tracking-[0.18em] text-(--sf-primary) uppercase">
  113. {children}
  114. </p>
  115. );
  116. }
  117. export function SectionHeading({
  118. heading,
  119. subheading,
  120. align = 'left',
  121. }: {
  122. heading: string;
  123. subheading?: string | null;
  124. align?: 'left' | 'center';
  125. }) {
  126. return (
  127. <div
  128. className={cn(
  129. 'max-w-2xl',
  130. align === 'center' && 'mx-auto text-center',
  131. )}
  132. >
  133. <h2 className="sf-heading text-3xl leading-tight font-semibold sm:text-4xl">
  134. {heading}
  135. </h2>
  136. {subheading && (
  137. <p className="mt-3 text-base text-(--sf-muted)">{subheading}</p>
  138. )}
  139. </div>
  140. );
  141. }
  142. const tilts = ['135deg', '200deg', '45deg', '310deg'];
  143. /**
  144. * Stands in for a photo when there is no real one.
  145. * It is drawn from the theme colours so it always matches the store.
  146. */
  147. export function ImagePlaceholder({
  148. seed = 0,
  149. label,
  150. className,
  151. }: {
  152. seed?: number;
  153. label?: string;
  154. className?: string;
  155. }) {
  156. const tilt = tilts[seed % tilts.length];
  157. return (
  158. <div
  159. role="img"
  160. aria-label={
  161. label ? `Placeholder image: ${label}` : 'Placeholder image'
  162. }
  163. className={cn(
  164. 'relative overflow-hidden rounded-(--sf-radius-card) border border-(--sf-border)',
  165. className,
  166. )}
  167. style={{
  168. background: `linear-gradient(${tilt}, color-mix(in srgb, var(--sf-primary) 28%, var(--sf-surface)), color-mix(in srgb, var(--sf-accent) 38%, var(--sf-surface)))`,
  169. }}
  170. >
  171. <div
  172. className="absolute -right-[15%] -bottom-[25%] aspect-square w-[70%] rounded-full opacity-40"
  173. style={{ background: 'var(--sf-accent)' }}
  174. />
  175. <div
  176. className="absolute -top-[20%] -left-[10%] aspect-square w-[45%] rounded-full opacity-25"
  177. style={{ background: 'var(--sf-primary)' }}
  178. />
  179. </div>
  180. );
  181. }