Simplify and fix cards

This commit is contained in:
Andras Schmelczer 2022-09-21 13:30:54 +02:00
parent f9540abdef
commit fcf7f64acd
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
3 changed files with 19 additions and 20 deletions

View file

@ -0,0 +1,2 @@
export const titleToFragment = (title: string): string =>
encodeURIComponent(title.toLocaleLowerCase().replace(/\W+/g, '-'));

View file

@ -2,14 +2,13 @@ import info from '../../../../static/icons/info.svg';
import './timeline-element.scss';
import { html } from '../../../types/html';
import { TimelineElementParameters } from './timeline-element';
import { titleToFragment } from '../../../helper/title-to-fragment';
export const generate = (
{ date, title, more }: TimelineElementParameters,
{ date, title, description, more }: TimelineElementParameters,
showMore: string
): html => {
const id = titleToFragment(title);
return `
<section id="${id}" class="timeline-element">
): html => `
<section id="${titleToFragment(title)}" class="timeline-element">
<div class="line-container">
<div class="line"></div>
<p class="date">${date}</p>
@ -17,25 +16,24 @@ export const generate = (
<div class="card">
<div class="figure"></div>
<div class="lower">
<h2><a href="#${id}">${title}</a></h2>
<p class="description"></p>
<h2>
<a href="#${titleToFragment(title)}">${title}</a>
</h2>
<p class="description">${description}</p>
${more ? '<div class="more"></div>' : ''}
<div class="buttons">
${
more
? `
<div tabindex=0 class="info-button">
more &&
`<div tabindex=0 class="info-button">
<div class="svgContainer">${info}</div>
<p>${showMore}</p>
</div>`
: ''
}
</div>
</div>
</div>
</section>
`;
};
const titleToFragment = (title: string): string =>
encodeURIComponent(title.toLocaleLowerCase().replace(/\W+/g, '-'));

View file

@ -34,7 +34,6 @@ export class PageTimelineElement extends PageElement {
this.query('.info-button').addEventListener('click', this.toggleOpen.bind(this));
this.attachElementByReplacing('.figure', timelineElement.figure);
this.query('.description').innerText = timelineElement.description;
timelineElement.links.forEach((l) => this.attachElementAsChildOf('.buttons', l));
this.isOpen = false;
@ -53,17 +52,17 @@ export class PageTimelineElement extends PageElement {
}
private openMore() {
const deltaHeight = this.more!.scrollHeight;
this.more!.style.height = `${deltaHeight.toString()}px`;
const deltaHeight = this.more.scrollHeight;
this.more.style.height = `${deltaHeight.toString()}px`;
}
private closeMore() {
this.more!.style.height = '0';
this.more.style.height = '0';
}
private handleResize() {
if (this.isOpen) {
this.more!.style.height = 'auto';
this.more.style.height = 'auto';
this.openMore.bind(this);
}
}