39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
export interface StatoStyle {
|
|
bg: string;
|
|
color: string;
|
|
border: string;
|
|
}
|
|
|
|
export function statoStyle(idStato: string): StatoStyle {
|
|
if (idStato === 'PU') {
|
|
return { bg: 'var(--color-primary-soft)', color: 'var(--color-primary-text)', border: 'var(--color-primary-soft-border)' };
|
|
}
|
|
if (idStato === 'PR') {
|
|
return { bg: 'var(--color-periodo-bg)', color: 'var(--color-periodo-text)', border: 'var(--color-periodo-border)' };
|
|
}
|
|
return { bg: 'var(--color-neutral-bg)', color: 'var(--color-neutral-text)', border: 'var(--color-neutral-border)' };
|
|
}
|
|
|
|
export function formatData(data: string | undefined): string {
|
|
if (!data) {
|
|
return '';
|
|
}
|
|
return new Intl.DateTimeFormat('it-IT', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(new Date(data));
|
|
}
|
|
|
|
export function parseMarkdown(testo: string): { text: string; weight: string; style: string }[] {
|
|
const parti = (testo || '').split(/(\*\*[^*]+\*\*|\*[^*]+\*)/g).filter((p) => p.length);
|
|
if (!parti.length) {
|
|
return [{ text: '', weight: '400', style: 'normal' }];
|
|
}
|
|
return parti.map((p) => {
|
|
if (p.startsWith('**') && p.endsWith('**')) {
|
|
return { text: p.slice(2, -2), weight: '700', style: 'normal' };
|
|
}
|
|
if (p.startsWith('*') && p.endsWith('*')) {
|
|
return { text: p.slice(1, -1), weight: '400', style: 'italic' };
|
|
}
|
|
return { text: p, weight: '400', style: 'normal' };
|
|
});
|
|
}
|