AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

theme.ts 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { CSSProperties } from 'react';
  2. import type { FontMap, Theme, ThemeRadius } from './types';
  3. const buttonRadius: Record<ThemeRadius, string> = {
  4. none: '0px',
  5. small: '4px',
  6. medium: '10px',
  7. large: '16px',
  8. full: '9999px',
  9. };
  10. const cardRadius: Record<ThemeRadius, string> = {
  11. none: '0px',
  12. small: '6px',
  13. medium: '14px',
  14. large: '22px',
  15. full: '28px',
  16. };
  17. const fallbackFont = 'ui-sans-serif, system-ui, sans-serif';
  18. function family(key: string, fonts: FontMap): string {
  19. const name = fonts[key];
  20. return name ? `'${name}', ${fallbackFont}` : fallbackFont;
  21. }
  22. /** Turn a plan theme into the CSS variables every section reads. */
  23. export function themeStyle(theme: Theme, fonts: FontMap): CSSProperties {
  24. return {
  25. '--sf-bg': theme.colors.background,
  26. '--sf-surface': theme.colors.surface,
  27. '--sf-fg': theme.colors.foreground,
  28. '--sf-muted': theme.colors.muted,
  29. '--sf-primary': theme.colors.primary,
  30. '--sf-primary-fg': theme.colors.primaryForeground,
  31. '--sf-accent': theme.colors.accent,
  32. '--sf-border': theme.colors.border,
  33. '--sf-radius': buttonRadius[theme.radius] ?? buttonRadius.medium,
  34. '--sf-radius-card': cardRadius[theme.radius] ?? cardRadius.medium,
  35. '--sf-font-heading': family(theme.fonts.heading, fonts),
  36. '--sf-font-body': family(theme.fonts.body, fonts),
  37. } as CSSProperties;
  38. }
  39. /** Web address that loads the theme's fonts. */
  40. export function fontStylesheetUrl(theme: Theme, fonts: FontMap): string | null {
  41. const keys = [...new Set([theme.fonts.heading, theme.fonts.body])].filter(
  42. (key) => key in fonts,
  43. );
  44. if (keys.length === 0) {
  45. return null;
  46. }
  47. const families = keys.map((key) => `${key}:400,500,600,700`).join('|');
  48. return `https://fonts.bunny.net/css?family=${families}&display=swap`;
  49. }
  50. const ringgit = new Intl.NumberFormat('en-MY', {
  51. style: 'currency',
  52. currency: 'MYR',
  53. });
  54. export function formatPrice(amount: number): string {
  55. return ringgit.format(amount);
  56. }
  57. /**
  58. * Put in front of a page title to say "this is a store's own page".
  59. * app.tsx removes it and leaves out our app name.
  60. */
  61. export const storefrontTitlePrefix = 'storefront::';