import React from 'react'; import type { ComponentConfig } from '@measured/puck'; import { MapPin, Phone, Mail, Building2 } from 'lucide-react'; export interface AddressBlockProps { businessName?: string; address?: string; address2?: string; city?: string; state?: string; zip?: string; phone?: string; email?: string; showIcons: boolean; layout: 'vertical' | 'horizontal'; alignment: 'left' | 'center' | 'right'; } const formatPhone = (phone: string): string => { // Remove all non-digits const digits = phone.replace(/\D/g, ''); // Format as (XXX) XXX-XXXX if 10 digits if (digits.length === 10) { return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`; } // Return original if not 10 digits return phone; }; const AddressBlockRender: React.FC = ({ businessName, address, address2, city, state, zip, phone, email, showIcons = true, layout = 'vertical', alignment = 'left', }) => { const alignmentClasses = { left: 'text-left', center: 'text-center', right: 'text-right', }; const justifyClasses = { left: 'justify-start', center: 'justify-center', right: 'justify-end', }; // Build full address string const addressParts = []; if (address) addressParts.push(address); if (address2) addressParts.push(address2); const cityStateZip = [city, state].filter(Boolean).join(', '); const fullCityLine = [cityStateZip, zip].filter(Boolean).join(' '); if (fullCityLine) addressParts.push(fullCityLine); const fullAddress = addressParts.join(', '); const items = [ { icon: Building2, value: businessName, href: null }, { icon: MapPin, value: fullAddress, href: fullAddress ? `https://maps.google.com/?q=${encodeURIComponent(fullAddress)}` : null }, { icon: Phone, value: phone ? formatPhone(phone) : null, href: phone ? `tel:${phone.replace(/\D/g, '')}` : null }, { icon: Mail, value: email, href: email ? `mailto:${email}` : null }, ].filter(item => item.value); if (items.length === 0) { return (
Add your business contact information
); } if (layout === 'horizontal') { return (
{items.map(({ icon: Icon, value, href }, index) => (
{showIcons && ( )} {href ? ( {value} ) : ( {value} )}
))}
); } return (
{items.map(({ icon: Icon, value, href }, index) => (
{showIcons && ( )} {href ? ( {value} ) : ( {value} )}
))}
); }; export const AddressBlock: ComponentConfig = { label: 'Address Block', fields: { businessName: { type: 'text', label: 'Business Name', }, address: { type: 'text', label: 'Street Address', }, address2: { type: 'text', label: 'Address Line 2 (Suite, Unit, etc.)', }, city: { type: 'text', label: 'City', }, state: { type: 'text', label: 'State', }, zip: { type: 'text', label: 'ZIP Code', }, phone: { type: 'text', label: 'Phone Number', }, email: { type: 'text', label: 'Email Address', }, showIcons: { type: 'radio', label: 'Show Icons', options: [ { label: 'Yes', value: true }, { label: 'No', value: false }, ], }, layout: { type: 'select', label: 'Layout', options: [ { label: 'Vertical (Stacked)', value: 'vertical' }, { label: 'Horizontal (Inline)', value: 'horizontal' }, ], }, alignment: { type: 'select', label: 'Alignment', options: [ { label: 'Left', value: 'left' }, { label: 'Center', value: 'center' }, { label: 'Right', value: 'right' }, ], }, }, defaultProps: { businessName: '', address: '', address2: '', city: '', state: '', zip: '', phone: '', email: '', showIcons: true, layout: 'vertical', alignment: 'left', }, render: AddressBlockRender, }; export default AddressBlock;