dees-document/ts_web/elements/letterheader.ts

127 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-10-16 16:28:12 +00:00
import {
DeesElement,
property,
html,
customElement,
type TemplateResult,
css,
cssManager,
unsafeCSS,
domtools,
2023-10-16 16:28:12 +00:00
} from '@design.estate/dees-element';
import * as plugins from '../plugins.js';
import { dedocumentSharedStyle } from '../style.js';
2023-10-16 16:28:12 +00:00
declare global {
interface HTMLElementTagNameMap {
'dedocument-letterheader': DeLetterHeader;
}
}
@customElement('dedocument-letterheader')
export class DeLetterHeader extends DeesElement {
public static demo = () => html`
<dedocument-letterheader .format="${'a4'}" .letterData=${plugins.shared.demoLetter}></dedocument-letterheader>
2023-10-16 16:28:12 +00:00
`;
@property({
type: Object,
reflect: true
})
public letterData: plugins.tsclass.business.ILetter;
2023-10-16 16:28:12 +00:00
@property({
type: Number,
reflect: true,
})
public pageNumber: number = 1;
@property({
type: Number,
reflect: true,
})
public pageTotalNumber: number = 1;
constructor() {
super();
domtools.DomTools.setupDomTools();
}
public static styles = [
domtools.elementBasic.staticStyles,
dedocumentSharedStyle,
2023-10-16 16:28:12 +00:00
css`
:host {
color: #333;
}
.recepientInfo {
position: absolute;
display: block;
overflow: hidden;
top: 200px;
right: ${unsafeCSS(plugins.shared.rightMargin + 'px')};
2023-10-16 16:28:12 +00:00
width: 200px;
text-align: right;
}
.recepientInfo .label {
margin-top: 10px;
margin-bottom: 3px;
font-size: 10px;
font-weight: bold;
}
.date {
position: absolute;
top: 180px;
right: ${unsafeCSS(plugins.shared.rightMargin + 'px')};
2023-10-16 16:28:12 +00:00
text-align: right;
}
.address {
position: absolute;
top: 180px;
left: ${unsafeCSS(plugins.shared.leftMargin + 'px')};
2023-10-16 16:28:12 +00:00
}
.address .from {
font-size: 10px;
}
.address .to {
margin-top: 10px;
}
`,
];
public render(): TemplateResult {
return html`
<div class="date">
${new Date(this.letterData.date).getDate()}. ${new Date(this.letterData.date).toLocaleString('default', { month: 'long' })}
${new Date(this.letterData.date).getFullYear()}
</div>
<div class="address">
<div class="from">
${this.letterData.from.name}, ${this.letterData.from.address.streetName}
${this.letterData.from.address.houseNumber}, ${this.letterData.from.address.postalCode}
${this.letterData.from.address.city}, ${this.letterData.from.address.country}
</div>
<div class="to">
${this.letterData.to.name}<br />
${this.letterData.to.address.streetName} ${this.letterData.to.address.houseNumber}<br />
${this.letterData.to.address.postalCode} ${this.letterData.to.address.city}<br />
${this.letterData.from.address.country}
</div>
</div>
<div class="recepientInfo">
<div class="label">your customer id:</div>
${this.letterData.to.customerNumber || 'not registered'}
<div class="label">your vat id on file:</div>
${this.letterData.to.vatId || 'not provided'}
</div>
`;
}
}