Simplify and fix cards
This commit is contained in:
parent
f9540abdef
commit
fcf7f64acd
3 changed files with 19 additions and 20 deletions
2
src/helper/title-to-fragment.ts
Normal file
2
src/helper/title-to-fragment.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const titleToFragment = (title: string): string =>
|
||||||
|
encodeURIComponent(title.toLocaleLowerCase().replace(/\W+/g, '-'));
|
||||||
|
|
@ -2,14 +2,13 @@ import info from '../../../../static/icons/info.svg';
|
||||||
import './timeline-element.scss';
|
import './timeline-element.scss';
|
||||||
import { html } from '../../../types/html';
|
import { html } from '../../../types/html';
|
||||||
import { TimelineElementParameters } from './timeline-element';
|
import { TimelineElementParameters } from './timeline-element';
|
||||||
|
import { titleToFragment } from '../../../helper/title-to-fragment';
|
||||||
|
|
||||||
export const generate = (
|
export const generate = (
|
||||||
{ date, title, more }: TimelineElementParameters,
|
{ date, title, description, more }: TimelineElementParameters,
|
||||||
showMore: string
|
showMore: string
|
||||||
): html => {
|
): html => `
|
||||||
const id = titleToFragment(title);
|
<section id="${titleToFragment(title)}" class="timeline-element">
|
||||||
return `
|
|
||||||
<section id="${id}" class="timeline-element">
|
|
||||||
<div class="line-container">
|
<div class="line-container">
|
||||||
<div class="line"></div>
|
<div class="line"></div>
|
||||||
<p class="date">${date}</p>
|
<p class="date">${date}</p>
|
||||||
|
|
@ -17,25 +16,24 @@ export const generate = (
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="figure"></div>
|
<div class="figure"></div>
|
||||||
<div class="lower">
|
<div class="lower">
|
||||||
<h2><a href="#${id}">${title}</a></h2>
|
<h2>
|
||||||
<p class="description"></p>
|
<a href="#${titleToFragment(title)}">${title}</a>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p class="description">${description}</p>
|
||||||
|
|
||||||
${more ? '<div class="more"></div>' : ''}
|
${more ? '<div class="more"></div>' : ''}
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
${
|
${
|
||||||
more
|
more &&
|
||||||
? `
|
`<div tabindex=0 class="info-button">
|
||||||
<div tabindex=0 class="info-button">
|
|
||||||
<div class="svgContainer">${info}</div>
|
<div class="svgContainer">${info}</div>
|
||||||
<p>${showMore}</p>
|
<p>${showMore}</p>
|
||||||
</div>`
|
</div>`
|
||||||
: ''
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
`;
|
`;
|
||||||
};
|
|
||||||
|
|
||||||
const titleToFragment = (title: string): string =>
|
|
||||||
encodeURIComponent(title.toLocaleLowerCase().replace(/\W+/g, '-'));
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ export class PageTimelineElement extends PageElement {
|
||||||
|
|
||||||
this.query('.info-button').addEventListener('click', this.toggleOpen.bind(this));
|
this.query('.info-button').addEventListener('click', this.toggleOpen.bind(this));
|
||||||
this.attachElementByReplacing('.figure', timelineElement.figure);
|
this.attachElementByReplacing('.figure', timelineElement.figure);
|
||||||
this.query('.description').innerText = timelineElement.description;
|
|
||||||
timelineElement.links.forEach((l) => this.attachElementAsChildOf('.buttons', l));
|
timelineElement.links.forEach((l) => this.attachElementAsChildOf('.buttons', l));
|
||||||
|
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
|
|
@ -53,17 +52,17 @@ export class PageTimelineElement extends PageElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
private openMore() {
|
private openMore() {
|
||||||
const deltaHeight = this.more!.scrollHeight;
|
const deltaHeight = this.more.scrollHeight;
|
||||||
this.more!.style.height = `${deltaHeight.toString()}px`;
|
this.more.style.height = `${deltaHeight.toString()}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeMore() {
|
private closeMore() {
|
||||||
this.more!.style.height = '0';
|
this.more.style.height = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleResize() {
|
private handleResize() {
|
||||||
if (this.isOpen) {
|
if (this.isOpen) {
|
||||||
this.more!.style.height = 'auto';
|
this.more.style.height = 'auto';
|
||||||
this.openMore.bind(this);
|
this.openMore.bind(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue