Skip to content

Commit 541ad7b

Browse files
committed
Merge #150: Improve Slider Component with Navigation Buttons & Bindings
636b750 scrollbar on mobile, arrows on tablets and up (Graeme Byrne) 88863d5 add buttons to slider (Graeme Byrne) Pull request description: ## Changes Introduced Based on issue #145, this PR enhances the `Slider` SvelteKit component by introducing navigation buttons for improved user experience and refactoring the component structure for better maintainability. ### New Features & Improvements: - **Added Previous & Next Buttons** - Implemented navigation buttons (`.pre-btn`, `.nxt-btn`) to allow users to scroll through the slider items more easily. - Buttons are now hidden by default and only appear when hovering over the component. - Simplified event listeners by using `onclick` directly in the template. - **Improved Accessibility** - Added `aria-label` attributes to the buttons for better screen reader support. - **Refactored CSS for Better Readability & Maintainability** - Extracted `.slider-item` for consistent styling. - Improved button visibility logic: Buttons now fade in when the user hovers over the slider. - **Removed Scrollbar** - Implemented `::-webkit-scrollbar` on `.slider-container`, setting `display: none;` so as to remove the unnecessary and distracting grey scrollbar which wasn't consistent over different browsers. ACKs for top commit: josecelano: ACK 636b750 Tree-SHA512: 089c3966c045db61ec5e66e4a9f4ce0ce94267914d6a376374bbaa56f507befb71377904f866c066f732cf349c8f1cfdf4b7d3bee0112a9d03e4e5a525d1d94a
2 parents a23bcbc + 636b750 commit 541ad7b

File tree

2 files changed

+187
-59
lines changed

2 files changed

+187
-59
lines changed

src/lib/components/atoms/Slider.svelte

Lines changed: 144 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import Icon from '@iconify/svelte';
3+
24
interface TitleObj {
35
title: string;
46
link: string;
@@ -9,38 +11,89 @@
911
}
1012
1113
let { titleArr = [] }: Props = $props();
14+
let sliderContainer: HTMLElement;
15+
let prevButton: HTMLElement;
16+
let nextButton: HTMLElement;
17+
18+
function handlePrevClick() {
19+
if (sliderContainer) {
20+
sliderContainer.scrollLeft -= sliderContainer.offsetWidth;
21+
}
22+
}
23+
24+
function handleNextClick() {
25+
if (sliderContainer) {
26+
sliderContainer.scrollLeft += sliderContainer.offsetWidth;
27+
}
28+
}
1229
</script>
1330

14-
<div class="slider-container">
15-
{#each titleArr as item}
16-
{#if item.link}
17-
<a href={item.link} target="_blank" rel="noopener noreferrer">
18-
<div class={item.link ? 'has-link' : ''}>
31+
<section class="slider">
32+
<div class="button-group">
33+
<button
34+
class="pre-btn"
35+
aria-label="Previous slide"
36+
bind:this={prevButton}
37+
onclick={handlePrevClick}
38+
>
39+
<Icon icon="fa6-solid:angle-left" />
40+
</button>
41+
42+
<button
43+
class="nxt-btn"
44+
aria-label="Next slide"
45+
bind:this={nextButton}
46+
onclick={handleNextClick}
47+
>
48+
<Icon icon="fa6-solid:angle-right" />
49+
</button>
50+
</div>
51+
52+
<div class="slider-container" bind:this={sliderContainer}>
53+
{#each titleArr as item (item)}
54+
{#if item.link}
55+
<a href={item.link} target="_blank" rel="noopener noreferrer">
56+
<div class="slider-item has-link">
57+
<p>{item.title}</p>
58+
</div>
59+
</a>
60+
{:else}
61+
<div class="slider-item">
1962
<p>{item.title}</p>
2063
</div>
21-
</a>
22-
{:else}
23-
<div class={item.link ? 'has-link' : ''}>
24-
<p>{item.title}</p>
25-
</div>
26-
{/if}
27-
{/each}
28-
</div>
64+
{/if}
65+
{/each}
66+
</div>
67+
</section>
2968

3069
<style lang="scss">
70+
@use '$lib/scss/breakpoints.scss' as bp;
71+
72+
.slider {
73+
position: relative;
74+
overflow: hidden;
75+
padding-block: 20px;
76+
}
77+
3178
.slider-container {
79+
padding: 0 10vw;
3280
display: flex;
33-
gap: 1rem;
3481
overflow-x: auto;
82+
scroll-behavior: smooth;
83+
gap: 1rem;
3584
width: 100vw;
3685
margin: 3rem 0rem 0 0rem;
37-
padding-inline: 1.5rem;
86+
padding-inline: 0rem;
3887
padding-bottom: 1rem;
39-
scroll-behavior: smooth;
4088
box-sizing: border-box;
4189
position: relative;
4290
left: 0;
4391
92+
padding-left: 2rem;
93+
transition:
94+
margin 0.3s ease-out,
95+
padding 0.3s ease-out;
96+
4497
div {
4598
flex: 0 0 auto;
4699
width: 280px;
@@ -72,4 +125,79 @@
72125
font-size: 20px;
73126
}
74127
}
128+
129+
.slider-container {
130+
// Firefox specific styling
131+
scrollbar-width: thin;
132+
scrollbar-color: rgba(255, 49, 0, 0.8) transparent;
133+
134+
@include bp.for-tablet-portrait-up {
135+
&::-webkit-scrollbar {
136+
display: none !important;
137+
}
138+
scrollbar-width: none !important;
139+
}
140+
141+
&::-webkit-scrollbar {
142+
width: 2px !important;
143+
min-width: 2px;
144+
}
145+
146+
&::-webkit-scrollbar-track {
147+
background: transparent;
148+
}
149+
150+
&::-webkit-scrollbar-thumb {
151+
background: rgba(255, 49, 0, 0.8);
152+
border-radius: 10px;
153+
width: 2px;
154+
min-width: 2px;
155+
}
156+
157+
&::-webkit-scrollbar-thumb:hover {
158+
background: rgba(255, 49, 0, 0.8);
159+
}
160+
}
161+
162+
.button-group {
163+
display: none;
164+
opacity: 0;
165+
transition: opacity 0.3s ease-in-out;
166+
pointer-events: none;
167+
168+
@include bp.for-tablet-portrait-up {
169+
display: flex;
170+
justify-content: center;
171+
gap: 1rem;
172+
}
173+
174+
.slider:hover & {
175+
opacity: 1;
176+
pointer-events: auto;
177+
}
178+
}
179+
180+
.pre-btn,
181+
.nxt-btn {
182+
border: none;
183+
width: 10vw;
184+
height: 100%;
185+
position: absolute;
186+
top: 10px;
187+
display: flex;
188+
justify-content: center;
189+
align-items: center;
190+
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0) 0% 100%);
191+
cursor: pointer;
192+
z-index: 8;
193+
font-size: 2em;
194+
}
195+
196+
.pre-btn {
197+
left: 0;
198+
}
199+
200+
.nxt-btn {
201+
right: 0;
202+
}
75203
</style>

static/blogMetadata.json

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
[
22
{
3-
"title": "Benchmarking the Torrust BitTorrent Tracker",
4-
"slug": "benchmarking-the-torrust-bittorrent-tracker",
5-
"contributor": "Jose Celano",
6-
"contributorSlug": "jose-celano",
7-
"date": "2024-03-19T00:00:00.000Z",
8-
"coverImage": "/images/posts/benchmarking-the-torrust-bittorrent-tracker/benchmarking-the-torrust-bittorrent-tracker-banner.webp",
9-
"excerpt": "In the ever-evolving landscape of BitTorrent technology, performance and scalability are paramount. Torrust stands at the forefront, offering a suite of open-source software products designed to enhance peer-to-peer file sharing. At the heart of this suite is the Torrust BitTorrent Tracker, a Rust-based engine crafted for efficiency and speed. This post will introduce you to the benchmarking tools we are using at the moment for the tracker.",
10-
"tags": [
11-
"Performance",
12-
"Benchmarking"
13-
]
14-
},
15-
{
16-
"title": "Deploying Torrust To Production",
17-
"slug": "deploying-torrust-to-production",
3+
"title": "Containerizing Rust Applications",
4+
"slug": "containerizing-rust-applications-best-practices",
185
"contributor": "Jose Celano",
196
"contributorSlug": "jose-celano",
20-
"date": "2023-12-20T00:00:00.000Z",
21-
"coverImage": "/images/posts/deploying-torrust-to-production/deploy-torrust-to-a-digital-ocean-droplet.png",
22-
"excerpt": "Dive into our step-by-step tutorial on deploying a BitTorrent Index and Tracker, written in Rust, on a Digital Ocean droplet. From initial server setup to advanced configurations, this guide is designed for both non-developers and tech-savvy users, ensuring a seamless, production-ready deployment.",
7+
"date": "2023-11-09T12:08:04.295Z",
8+
"coverImage": "/images/posts/rust-crab-carrying-a-shipping-container.jpeg",
9+
"excerpt": "Torrust services (Tracker and Index) support docker, we want to ensure that contributors understand our containerfile and we also want to share good practices for containerizing Rust applications.",
2310
"tags": [
24-
"Tutorial",
25-
"Deployment",
26-
"Production"
11+
"Torrent",
12+
"Tracker",
13+
"BitTorrent"
2714
]
2815
},
2916
{
@@ -41,20 +28,6 @@
4128
"Rust"
4229
]
4330
},
44-
{
45-
"title": "Contributor Path",
46-
"slug": "contributor-path",
47-
"contributor": "Jose Celano",
48-
"contributorSlug": "jose-celano",
49-
"date": "2024-10-29T09:20:51.608Z",
50-
"coverImage": "/images/posts/contributor-path/rust-crab-going-safe-into-water.webp",
51-
"excerpt": "Ready to contribute to Torrust? Here's your guide to get started and make meaningful contributions, from small fixes to full-fledged features.",
52-
"tags": [
53-
"Community",
54-
"Onboarding",
55-
"Contributors"
56-
]
57-
},
5831
{
5932
"title": "Hash2Torrent - Retrieve Torrent Files Effortlessly!",
6033
"slug": "hash2torrent-retrieve-torrent-files-effortlessly",
@@ -72,17 +45,31 @@
7245
]
7346
},
7447
{
75-
"title": "Containerizing Rust Applications",
76-
"slug": "containerizing-rust-applications-best-practices",
48+
"title": "Deploying Torrust To Production",
49+
"slug": "deploying-torrust-to-production",
7750
"contributor": "Jose Celano",
7851
"contributorSlug": "jose-celano",
79-
"date": "2023-11-09T12:08:04.295Z",
80-
"coverImage": "/images/posts/rust-crab-carrying-a-shipping-container.jpeg",
81-
"excerpt": "Torrust services (Tracker and Index) support docker, we want to ensure that contributors understand our containerfile and we also want to share good practices for containerizing Rust applications.",
52+
"date": "2023-12-20T00:00:00.000Z",
53+
"coverImage": "/images/posts/deploying-torrust-to-production/deploy-torrust-to-a-digital-ocean-droplet.png",
54+
"excerpt": "Dive into our step-by-step tutorial on deploying a BitTorrent Index and Tracker, written in Rust, on a Digital Ocean droplet. From initial server setup to advanced configurations, this guide is designed for both non-developers and tech-savvy users, ensuring a seamless, production-ready deployment.",
8255
"tags": [
83-
"Torrent",
84-
"Tracker",
85-
"BitTorrent"
56+
"Tutorial",
57+
"Deployment",
58+
"Production"
59+
]
60+
},
61+
{
62+
"title": "Contributor Path",
63+
"slug": "contributor-path",
64+
"contributor": "Jose Celano",
65+
"contributorSlug": "jose-celano",
66+
"date": "2024-10-29T09:20:51.608Z",
67+
"coverImage": "/images/posts/contributor-path/rust-crab-going-safe-into-water.webp",
68+
"excerpt": "Ready to contribute to Torrust? Here's your guide to get started and make meaningful contributions, from small fixes to full-fledged features.",
69+
"tags": [
70+
"Community",
71+
"Onboarding",
72+
"Contributors"
8673
]
8774
},
8875
{
@@ -98,6 +85,19 @@
9885
"Announcement"
9986
]
10087
},
88+
{
89+
"title": "Benchmarking the Torrust BitTorrent Tracker",
90+
"slug": "benchmarking-the-torrust-bittorrent-tracker",
91+
"contributor": "Jose Celano",
92+
"contributorSlug": "jose-celano",
93+
"date": "2024-03-19T00:00:00.000Z",
94+
"coverImage": "/images/posts/benchmarking-the-torrust-bittorrent-tracker/benchmarking-the-torrust-bittorrent-tracker-banner.webp",
95+
"excerpt": "In the ever-evolving landscape of BitTorrent technology, performance and scalability are paramount. Torrust stands at the forefront, offering a suite of open-source software products designed to enhance peer-to-peer file sharing. At the heart of this suite is the Torrust BitTorrent Tracker, a Rust-based engine crafted for efficiency and speed. This post will introduce you to the benchmarking tools we are using at the moment for the tracker.",
96+
"tags": [
97+
"Performance",
98+
"Benchmarking"
99+
]
100+
},
101101
{
102102
"title": "How To Contribute To This Site",
103103
"slug": "how-to-contribute-to-this-site",

0 commit comments

Comments
 (0)