Files
housesof/src/components/molecules/ShopLocationSwitcher.svelte

43 lines
1.3 KiB
Svelte

<style lang="scss">
@import "../../style/molecules/shop-locationswitcher";
</style>
<script lang="ts">
import { goto } from '$app/navigation'
import { getContext } from 'svelte'
import { shopCurrentProductSlug } from '$utils/stores/shop'
import { smoothScroll } from '$utils/functions'
export let isOver: boolean = false
const { shopLocations } = getContext('shop')
const classes = [
'shop-locationswitcher',
isOver && 'is-over',
$$props.class
].join(' ').trim()
// Quick location change
const quickLocationChange = ({ target: { value }}: any) => {
const newPath = `/shop/poster-${value}`
goto(newPath, { replaceState: true, noscroll: true, keepfocus: true })
// Scroll to anchor
setTimeout(() => smoothScroll({ hash: 'poster' }), 1000)
}
</script>
<dl class={classes}>
<dt class="text-label">Choose a city</dt>
<dd>
<svg width="18" height="18">
<use xlink:href="#icon-map-pin" />
</svg>
<select on:change={quickLocationChange}>
{#each shopLocations as { name, slug }}
<option value={slug} selected={slug === $shopCurrentProductSlug}>{name}</option>
{/each}
</select>
</dd>
</dl>