Added Archive element.
This commit is contained in:
parent
11e1f4593a
commit
59845e4e54
4 changed files with 199 additions and 3 deletions
145
frontend/src/lib/components/archive.svelte
Normal file
145
frontend/src/lib/components/archive.svelte
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
<script>
|
||||||
|
import '$lib/css/base.css';
|
||||||
|
import '$lib/css/archive.css';
|
||||||
|
import SvgIcon from '@jamescoyle/svelte-icon';
|
||||||
|
import { mdiChevronRight, mdiHomeVariantOutline } from '@mdi/js';
|
||||||
|
import anime from 'animejs';
|
||||||
|
|
||||||
|
export let fontPost = 1;
|
||||||
|
export let paddingPost = 0.5;
|
||||||
|
const posts = {
|
||||||
|
'Août 2024': [
|
||||||
|
'Est-ce que le lorem est Ipsum ?',
|
||||||
|
"J'aime bien le jeu Minecraft",
|
||||||
|
'Comment Installer Linus Torvalds sur sa tablette',
|
||||||
|
'Pourquoi "Le miam" pourrait être votre groupe de musique préféré ?',
|
||||||
|
"Peut-on vivre dans une maison en pain d'épices ?"
|
||||||
|
],
|
||||||
|
'Juillet 2024': [
|
||||||
|
'Les secrets du café qui ne refroidit jamais',
|
||||||
|
'Comment devenir un ninja en 10 leçons faciles',
|
||||||
|
'La vérité derrière les licornes: Mythe ou réalité ?',
|
||||||
|
"J'ai adopté un dragon, voici ce qui s'est passé"
|
||||||
|
],
|
||||||
|
'Juin 2024': [
|
||||||
|
'Pourquoi "Le miam" pourrait être votre groupe de musique préféré ?',
|
||||||
|
'La recette secrète de la pizza à la glace',
|
||||||
|
'Comment devenir un expert en pirouettes en 5 jours'
|
||||||
|
],
|
||||||
|
'Mai 2024': [
|
||||||
|
'Mon voyage au centre de la Terre en montgolfière',
|
||||||
|
'Pourquoi les pandas devraient être vos nouveaux colocataires',
|
||||||
|
'Les chats dominent-ils vraiment Internet ?'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const size = Object.keys(posts).length;
|
||||||
|
let archiveRefs = Array(size);
|
||||||
|
let archivePostRefs = Array(size);
|
||||||
|
let containerRef;
|
||||||
|
|
||||||
|
let isActive = Array(size).fill(false);
|
||||||
|
let indexArchive = -1;
|
||||||
|
|
||||||
|
function toggleArchive(date, index) {
|
||||||
|
const archive = archiveRefs[index];
|
||||||
|
const archivePost = archivePostRefs[index];
|
||||||
|
const svg = archiveRefs[index].children[1];
|
||||||
|
const rvalue = isActive[index] ? [90, 0] : [0, 90];
|
||||||
|
const ovalue = isActive[index] ? [1, 0] : [0, 1];
|
||||||
|
const shadow = isActive[index] ? '' : '0px 8px 18px -1px rgba(52, 42, 58, 0.2)';
|
||||||
|
const mbvalue = isActive[index] ? [0.5, 0] : [0, 0.5];
|
||||||
|
const hvalue = isActive[index]
|
||||||
|
? [posts[date].length * (2 * paddingPost + fontPost + 0.5), 0]
|
||||||
|
: [0, posts[date].length * (2 * paddingPost + fontPost + 0.5)];
|
||||||
|
|
||||||
|
isActive[index] = isActive[index] ? false : true;
|
||||||
|
|
||||||
|
if (!isActive[index]) {
|
||||||
|
indexArchive = -1;
|
||||||
|
archivePost.style.opacity = '0';
|
||||||
|
} else {
|
||||||
|
indexArchive = index;
|
||||||
|
archivePost.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
anime({
|
||||||
|
targets: { transform: rvalue[0], opacity: ovalue[0], margin: mbvalue[0], height: hvalue[0] },
|
||||||
|
transform: rvalue,
|
||||||
|
opacity: ovalue,
|
||||||
|
margin: mbvalue,
|
||||||
|
height: hvalue,
|
||||||
|
duration: 300,
|
||||||
|
easing: 'easeInOutQuad',
|
||||||
|
update: function (anim) {
|
||||||
|
svg.style.transform = `rotate(${anim.animations[0].currentValue}deg)`;
|
||||||
|
archive.style.background = `linear-gradient(90deg, rgba(65,53,67,${anim.animations[1].currentValue}) 0%, rgba(38,28,44,${anim.animations[1].currentValue}) 100%)`;
|
||||||
|
archive.style.boxShadow = shadow;
|
||||||
|
archive.style.marginBottom = `${anim.animations[2].currentValue}rem`;
|
||||||
|
archivePost.style.height = `${anim.animations[3].currentValue}rem`;
|
||||||
|
},
|
||||||
|
complete: function () {
|
||||||
|
if (!isActive[index]) {
|
||||||
|
archivePost.style.display = 'none';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
anime({
|
||||||
|
targets: archivePost,
|
||||||
|
opacity: ovalue,
|
||||||
|
duration: 300,
|
||||||
|
easing: 'easeOutQuad'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
anime({
|
||||||
|
targets: archive,
|
||||||
|
color: isActive[index] ? '#F8F1F1' : '#261C2C',
|
||||||
|
duration: 200,
|
||||||
|
easing: 'easeInOutQuad'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isActive[index]) {
|
||||||
|
scrollToPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToPosition() {
|
||||||
|
const rect = containerRef.getBoundingClientRect().top + window.scrollY;
|
||||||
|
console.log(rect);
|
||||||
|
window.scrollTo({
|
||||||
|
top: rect,
|
||||||
|
behavior: 'smooth'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="archive-container"
|
||||||
|
style="--font-post: {fontPost}rem; --padding-post: {paddingPost}rem;"
|
||||||
|
bind:this={containerRef}
|
||||||
|
>
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
{#each Object.keys(posts) as date, index}
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<div
|
||||||
|
bind:this={archiveRefs[index]}
|
||||||
|
class="archive"
|
||||||
|
on:click={() => {
|
||||||
|
if (indexArchive != -1 && indexArchive != index) {
|
||||||
|
toggleArchive(date, indexArchive);
|
||||||
|
}
|
||||||
|
toggleArchive(date, index);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span>{date}</span>
|
||||||
|
<SvgIcon type="mdi" path={mdiChevronRight}></SvgIcon>
|
||||||
|
</div>
|
||||||
|
<div bind:this={archivePostRefs[index]} class="archive-post">
|
||||||
|
{#each posts[date] as p}
|
||||||
|
<div>
|
||||||
|
<span>{p}</span>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
|
@ -3,7 +3,7 @@
|
||||||
import '$lib/css/search.css';
|
import '$lib/css/search.css';
|
||||||
|
|
||||||
import SvgIcon from '$lib/components/svg-icon-custom.svelte';
|
import SvgIcon from '$lib/components/svg-icon-custom.svelte';
|
||||||
import { mdiContentSavePlusOutline, mdiMagnify } from '@mdi/js';
|
import { mdiMagnify } from '@mdi/js';
|
||||||
import anime from 'animejs';
|
import anime from 'animejs';
|
||||||
|
|
||||||
let div_search;
|
let div_search;
|
||||||
|
|
48
frontend/src/lib/css/archive.css
Normal file
48
frontend/src/lib/css/archive.css
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
.archive-container {
|
||||||
|
box-shadow: rgba(52, 42, 58, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
|
||||||
|
/* For now */
|
||||||
|
width: 50%;
|
||||||
|
border-radius: 1rem;
|
||||||
|
color: var(--color-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive {
|
||||||
|
font-family: 'JetBrains Mono';
|
||||||
|
font-size: 1.2rem;
|
||||||
|
padding: 1rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-post {
|
||||||
|
font-family: 'JetBrains Mono';
|
||||||
|
font-size: var(--font-post);
|
||||||
|
padding-left: 1rem;
|
||||||
|
color: var(--color-subtext);
|
||||||
|
opacity: 0;
|
||||||
|
height: 0px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-post span {
|
||||||
|
/* Overflow */
|
||||||
|
overflow: hidden;
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-webkit-line-clamp: 1;
|
||||||
|
line-clamp: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-post span:hover {
|
||||||
|
color: var(--palette-pink);
|
||||||
|
text-decoration: underline 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-post div {
|
||||||
|
padding: var(--padding-post);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import Post from '$lib/components/post-min.svelte';
|
import Post from '$lib/components/post-min.svelte';
|
||||||
import Search from '$lib/components/search.svelte';
|
import Search from '$lib/components/search.svelte';
|
||||||
|
import Archive from '$lib/components/archive.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="base">
|
<div class="base">
|
||||||
|
@ -26,9 +27,11 @@
|
||||||
date="26/07/2024"
|
date="26/07/2024"
|
||||||
/>
|
/>
|
||||||
<div class="blank"></div>
|
<div class="blank"></div>
|
||||||
<Post/>
|
|
||||||
<div class="blank"></div>
|
|
||||||
<Search/>
|
<Search/>
|
||||||
<div class="blank"></div>
|
<div class="blank"></div>
|
||||||
<Post/>
|
<Post/>
|
||||||
|
<div class="blank"></div>
|
||||||
|
<Archive/>
|
||||||
|
<div class="blank"></div>
|
||||||
|
<div class="blank"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue