diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-29 18:11:51 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-29 18:11:51 +0100 |
| commit | 7038c517ee9fe4415f17b4b20e39a4c11a934b3c (patch) | |
| tree | 66d7ea0b8b81075f8f76014f43f8fa7e8bfa9435 /src/components | |
| parent | 8e0c8c9255ba5ab466d8372fe223efeb5a3f0833 (diff) | |
chore: make year sticky in posts list
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/PostsList/PostsList.module.scss | 23 | ||||
| -rw-r--r-- | src/components/PostsList/PostsList.tsx | 6 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/components/PostsList/PostsList.module.scss b/src/components/PostsList/PostsList.module.scss index 0b9aa2d..471b172 100644 --- a/src/components/PostsList/PostsList.module.scss +++ b/src/components/PostsList/PostsList.module.scss @@ -1,11 +1,32 @@ +@use "@styles/abstracts/mixins" as mix; @use "@styles/abstracts/placeholders"; .list { @extend %reset-ordered-list; - margin: var(--spacing-md) auto; + margin: 0 auto var(--spacing-md); } li.item { margin: var(--spacing-md) 0; + + &:first-of-type { + margin-top: var(--spacing-sm); + } +} + +.section { + @include mix.media("screen") { + @include mix.dimensions("sm") { + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + align-items: first baseline; + gap: var(--spacing-md); + } + } +} + +.year { + position: sticky; + top: 0; } diff --git a/src/components/PostsList/PostsList.tsx b/src/components/PostsList/PostsList.tsx index da72032..51698e6 100644 --- a/src/components/PostsList/PostsList.tsx +++ b/src/components/PostsList/PostsList.tsx @@ -20,8 +20,8 @@ const PostsList = ({ return years.map((year) => { return ( - <Fragment key={year}> - {showYears && <h2>{year}</h2>} + <section key={year} className={styles.section}> + {showYears && <h2 className={styles.year}>{year}</h2>} <ol className={styles.list}> {posts[year].map((post) => { return ( @@ -31,7 +31,7 @@ const PostsList = ({ ); })} </ol> - </Fragment> + </section> ); }); }; |
