All files / src/lib/email/templates/shared emailComponents.ts

100% Statements 23/23
100% Branches 7/7
100% Functions 12/12
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148                    3x                                               3x                         2x                     3x                                       3x                               8x                 3x                     3x                 2x             2x     3x                 2x   6x      
import {
  EMAIL_COLORS,
  EMAIL_FONTS,
  EMAIL_RADIUS,
  EMAIL_SPACING,
} from './emailStyles';
 
/**
 * Email layout wrapper with responsive container
 */
export const emailLayout = (content: string) => `
  <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
  <body style="margin: 0; padding: 0; font-family: ${EMAIL_FONTS.primary}; background-color: ${EMAIL_COLORS.background};">
    <table role="presentation" style="width: 100%; border-collapse: collapse;">
      <tr>
        <td style="padding: ${EMAIL_SPACING.lg} ${EMAIL_SPACING.sm};">
          <table role="presentation" style="max-width: 600px; margin: 0 auto; background-color: ${EMAIL_COLORS.white}; border-radius: ${EMAIL_RADIUS.lg}; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
            ${content}
          </table>
        </td>
      </tr>
    </table>
  </body>
  </html>
`;
 
/**
 * Email header component
 */
export const emailHeader = (title: string) => `
  <tr>
    <td style="padding: ${EMAIL_SPACING.lg} ${EMAIL_SPACING.lg} ${EMAIL_SPACING.md}; text-align: center; background-color: ${EMAIL_COLORS.primary}; border-radius: ${EMAIL_RADIUS.lg} ${EMAIL_RADIUS.lg} 0 0;">
      <h1 style="margin: 0; color: ${EMAIL_COLORS.white}; font-size: 28px; font-weight: 600;">
        ${title}
      </h1>
    </td>
  </tr>
`;
 
/**
 * Email content wrapper
 */
export const emailContent = (content: string) => `
  <tr>
    <td style="padding: ${EMAIL_SPACING.lg};">
      ${content}
    </td>
  </tr>
`;
 
/**
 * Email footer component
 */
export const emailFooter = (message: string, disclaimer?: string) => `
  <tr>
    <td style="padding: ${EMAIL_SPACING.md} ${EMAIL_SPACING.lg}; background-color: ${EMAIL_COLORS.gray.light}; border-radius: 0 0 ${EMAIL_RADIUS.lg} ${EMAIL_RADIUS.lg}; text-align: center;">
      <p style="margin: 0 0 ${EMAIL_SPACING.xs}; color: ${EMAIL_COLORS.gray.medium}; font-size: 14px; line-height: 1.5;">
        ${message}
      </p>
      ${
        disclaimer
          ? `<p style="margin: 0; color: ${EMAIL_COLORS.gray.dark}; font-size: 12px; line-height: 1.5;">
        ${disclaimer}
      </p>`
          : ''
      }
    </td>
  </tr>
`;
 
/**
 * Primary CTA button component
 */
export const emailButton = (text: string, href: string) => `
  <table role="presentation" style="margin: 0 auto;">
    <tr>
      <td style="border-radius: ${EMAIL_RADIUS.md}; background-color: ${EMAIL_COLORS.primary};">
        <a href="${href}" 
           style="display: inline-block; padding: 14px 32px; color: ${EMAIL_COLORS.white}; text-decoration: none; font-size: 16px; font-weight: 600; border-radius: ${EMAIL_RADIUS.md};">
          ${text}
        </a>
      </td>
    </tr>
  </table>
`;
 
/**
 * Paragraph component
 */
export const emailParagraph = (text: string, marginBottom = '20px') => `
  <p style="margin: 0 0 ${marginBottom}; color: ${EMAIL_COLORS.black}; font-size: 16px; line-height: 1.6;">
    ${text}
  </p>
`;
 
/**
 * Warning/info box component
 */
export const emailWarningBox = (content: string, icon = '⚠️') => `
  <div style="background: ${EMAIL_COLORS.warning.background}; border-left: 4px solid ${EMAIL_COLORS.warning.border}; padding: 15px; margin: ${EMAIL_SPACING.sm} 0; border-radius: ${EMAIL_RADIUS.sm};">
    <p style="margin: 0; font-size: 14px; color: ${EMAIL_COLORS.warning.text};">
      ${icon} <strong>Important:</strong> ${content}
    </p>
  </div>
`;
 
/**
 * Link display component (for fallback URLs)
 */
export const emailLink = (url: string, label?: string) => `
  <p style="font-size: 14px; color: ${EMAIL_COLORS.primary}; word-break: break-all;">
    ${label || url}
  </p>
`;
 
/**
 * Divider/separator line
 */
export const emailDivider = () => `
  <hr style="border: none; border-top: 1px solid #ddd; margin: ${EMAIL_SPACING.md} 0;">
`;
 
/**
 * Small text component (for disclaimers, etc.)
 */
export const emailSmallText = (
  text: string,
  color = EMAIL_COLORS.gray.medium,
) => `
  <p style="font-size: 14px; color: ${color};">
    ${text}
  </p>
`;
 
/**
 * List component
 */
export const emailList = (items: string[]) => `
  <ul style="margin: 0 0 ${EMAIL_SPACING.md}; padding-left: ${EMAIL_SPACING.sm}; color: ${EMAIL_COLORS.black}; font-size: 16px; line-height: 1.8;">
    ${items.map((item) => `<li>${item}</li>`).join('')}
  </ul>
`;