pagamio-frontend-commons-lib
Version:
Pagamio library for Frontend reusable components like the form engine and table container
114 lines (113 loc) • 3.84 kB
JavaScript
// Utility functions for PDF export configuration
/**
* Creates PDF export options from client configuration
* @param config - The client configuration object
* @param title - Optional custom title for the PDF
* @returns PdfExportOptions object configured with app theme and branding
*/
export const createPdfExportOptions = (config, title) => {
return {
title: title || `${config.branding.name} Report`,
subtitle: `Generated on ${new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})}`,
colors: {
primary: config.theme.colors.primary,
core: config.theme.colors.core,
},
logo: {
url: config.branding.navbarLogo?.path || config.branding.logo.path,
width: config.branding.navbarLogo?.width || config.branding.logo.width,
height: config.branding.navbarLogo?.height || config.branding.logo.height,
},
};
};
/**
* Creates Excel export options from client configuration
* @param config - The client configuration object
* @param title - Optional custom title for the Excel file
* @param sheetName - Optional custom sheet name
* @returns XlsxExportOptions object configured with app theme and branding
*/
export const createXlsxExportOptions = (config, title, sheetName) => {
return {
title: title || `${config.branding.name} Report`,
subtitle: `Generated on ${new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})}`,
colors: {
primary: config.theme.colors.primary,
core: config.theme.colors.core,
},
sheetName: sheetName || 'Data',
includeTimestamp: true,
autoFitColumns: true,
};
};
/**
* Creates Excel export options with fallback values when no config is available
* @param title - Optional custom title for the Excel file
* @param sheetName - Optional custom sheet name
* @returns XlsxExportOptions object with default styling
*/
export const createDefaultXlsxExportOptions = (title, sheetName) => {
return {
title: title || 'Data Export',
subtitle: `Generated on ${new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})}`,
colors: {
primary: {
500: '#b45dae',
600: '#a14d9e',
700: '#8e3d8e',
},
core: {
primary: '#b45dae',
secondary: '#170e31',
},
},
sheetName: sheetName || 'Data',
includeTimestamp: true,
autoFitColumns: true,
};
};
/**
* Creates CSV export options from client configuration
* @param config - The client configuration object
* @param title - Optional custom title for the CSV file
* @returns CsvExportOptions object configured with app branding
*/
export const createCsvExportOptions = (config, title) => {
return {
title: title || `${config.branding.name} Report`,
includeTimestamp: true,
includeHeaders: true,
delimiter: ',',
};
};
/**
* Creates CSV export options with fallback values when no config is available
* @param title - Optional custom title for the CSV file
* @returns CsvExportOptions object with default settings
*/
export const createDefaultCsvExportOptions = (title) => {
return {
title: title || 'Data Export',
includeTimestamp: true,
includeHeaders: true,
delimiter: ',',
};
};