-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from HBO-i/feat/update-methods-per-phase
Update method per phase page
- Loading branch information
Showing
27 changed files
with
583 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import TabButton from '$lib/components/tabs/TabButton.svelte'; | ||
import { phaseRoutes } from '$lib/routes'; | ||
let ul: HTMLElement; | ||
let activeTab = $page.url.pathname.slice(1, -1); | ||
const updateSelectedTab = (phase: string, event: Event) => { | ||
if (event) { | ||
const buttonElement = event.target as HTMLElement; | ||
if (buttonElement) { | ||
const linkElement = buttonElement.parentElement; | ||
if (linkElement) { | ||
const li = linkElement.parentElement; | ||
if (li) { | ||
// 1). Find the active element | ||
const activeLi = li; | ||
// 2). Get the center of active element | ||
const centerOfLi = activeLi.offsetWidth / 2; | ||
// 3). Get left position + center position | ||
const leftBorderPositionOfLi = activeLi.offsetLeft; | ||
const positionOfCenterLi = leftBorderPositionOfLi + centerOfLi; | ||
// 4). Get current scroll position | ||
const currentScrollPosition = ul.scrollLeft; // 0 - 527 | ||
// 5). Get container width | ||
const containerWidth = ul.offsetWidth; // 351 | ||
const centerOfContainer = containerWidth / 2; // 175.5 | ||
// 6). Set position | ||
const position = positionOfCenterLi + currentScrollPosition - centerOfContainer; | ||
// 7. Set scrollLeft | ||
ul.scrollLeft = position / 2; // Doesn't work correctly, yet | ||
// ul.scrollLeft = position / 2 + 10; // Works one way => left to right | ||
// ul.scrollLeft = position / 2 - 10; // Works one way => right to left | ||
activeTab = phase; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<ul class="non-style phase-tab" bind:this={ul}> | ||
{#each phaseRoutes as route} | ||
<li | ||
class:active={activeTab === route.phase} | ||
on:click={(event) => updateSelectedTab(route.phase, event)} | ||
> | ||
<TabButton phase={route.phase} content={route.title} /> | ||
</li> | ||
{/each} | ||
</ul> | ||
|
||
<style lang="scss"> | ||
ul.phase-tab { | ||
background-color: var(--color-white); | ||
border-radius: 1.5em; | ||
max-width: fit-content; | ||
overflow-x: auto; | ||
display: flex; | ||
gap: 2em; | ||
padding: 0.5em 1.25em; | ||
scroll-snap-type: x mandatory; | ||
@include tablet { | ||
padding: 0.25rem; | ||
} | ||
@include desktop-small { | ||
box-sizing: border-box; | ||
min-height: 3rem; | ||
justify-content: center; | ||
padding: 0 1rem; | ||
border-radius: 0.75rem; | ||
gap: 5px; | ||
overflow-y: hidden; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<script lang="ts"> | ||
export let label: string; | ||
export let fontSize = 16; | ||
export let checked = true; | ||
const uniqueID = Math.floor(Math.random() * 100); | ||
function handleClick(event: MouseEvent) { | ||
const target = event.target; | ||
const state = target.getAttribute('aria-checked'); | ||
checked = state === 'true' ? false : true; | ||
} | ||
</script> | ||
|
||
<div class="switch" style="font-size:{fontSize}px"> | ||
<label for="switch" id={`switch-${uniqueID}`}>{label}</label> | ||
<button | ||
id="switch" | ||
role="switch" | ||
aria-checked={checked} | ||
aria-labelledby={`switch-${uniqueID}`} | ||
on:click={handleClick} | ||
/> | ||
</div> | ||
|
||
<style> | ||
.switch { | ||
display: flex; | ||
align-items: center; | ||
} | ||
.switch button { | ||
width: 3em; | ||
height: 1.6em; | ||
position: relative; | ||
margin: 0 0 0 0.5em; | ||
background: var(--color-grey); | ||
border: none; | ||
} | ||
.switch button::before { | ||
content: ''; | ||
position: absolute; | ||
width: 1.3em; | ||
height: 1.3em; | ||
background: #fff; | ||
top: 0.13em; | ||
right: 1.5em; | ||
transition: transform 0.3s; | ||
} | ||
.switch button[aria-checked='true'] { | ||
background-color: var(--color-blue); | ||
} | ||
.switch button[aria-checked='true']::before { | ||
transform: translateX(1.3em); | ||
transition: transform 0.3s; | ||
} | ||
.switch button:focus { | ||
box-shadow: 0 0px 0px 1px var(--color-blue); | ||
} | ||
.switch label { | ||
font-weight: bold; | ||
} | ||
.switch button { | ||
border-radius: 1.5em; | ||
} | ||
.switch button::before { | ||
border-radius: 100%; | ||
} | ||
.switch button:focus { | ||
box-shadow: 0 0px 8px var(--color-blue); | ||
border-radius: 1.5em; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.