Optimize some components
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Use binding of this over `document.querySelector` calls - Use else if over a chained else and if condition
This commit is contained in:
@@ -6,12 +6,14 @@
|
||||
export let className = null
|
||||
|
||||
// Variables
|
||||
let counter
|
||||
const numbers = [...Array(10).keys()]
|
||||
|
||||
// Reactive variables depending on currentIndex
|
||||
$: actualIndex = currentIndex + 1
|
||||
$: amount = String(actualIndex).length
|
||||
$: index = (actualIndex < 10) ? String(actualIndex).padStart(2, '0') : String(actualIndex)
|
||||
$: digits = index.split('')
|
||||
let counter
|
||||
const numbers = [...Array(10).keys()]
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
// Variables
|
||||
let toggleEl
|
||||
let toggleLayout
|
||||
let layoutSetting
|
||||
|
||||
@@ -17,17 +18,16 @@
|
||||
const layoutGridClass = 'photos--grid'
|
||||
const layoutListClass = 'photos--list'
|
||||
const grid = document.querySelector('.photos')
|
||||
const toggle = document.querySelector('.toggle')
|
||||
const pill = toggle.querySelector('.pill')
|
||||
const pill = toggleEl.querySelector('.pill')
|
||||
|
||||
// Change active pill
|
||||
const toggleAnimate = (elem, pill, toggle) => {
|
||||
pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px'
|
||||
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggle.getBoundingClientRect().left) + 'px'
|
||||
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
|
||||
}
|
||||
|
||||
// Init of first option
|
||||
toggleAnimate(document.querySelector(`.toggle [data-layout="${layoutSetting}"]`), pill, toggle)
|
||||
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
|
||||
|
||||
// Toggle layout
|
||||
toggleLayout = event => {
|
||||
@@ -48,10 +48,10 @@
|
||||
}
|
||||
|
||||
// Animate the active pill
|
||||
toggleAnimate(clicked, pill, toggle)
|
||||
toggleAnimate(clicked, pill, toggleEl)
|
||||
|
||||
// Add/Remove active classes
|
||||
document.querySelectorAll('.toggle button').forEach(button => button.classList.remove('active'))
|
||||
toggleEl.querySelectorAll('button').forEach(button => button.classList.remove('active'))
|
||||
clicked.classList.add('active')
|
||||
|
||||
// Remember this setting
|
||||
@@ -60,7 +60,7 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="toggle">
|
||||
<div class="toggle" bind:this={toggleEl}>
|
||||
<button data-layout="list" class:active={layoutSetting === 'list'} on:click={toggleLayout}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="17" viewBox="0 0 19 17">
|
||||
<g class="anim">
|
||||
|
||||
Reference in New Issue
Block a user