nicco.io/src/lib/components/IconList.svelte

59 lines
1.0 KiB
Svelte
Raw Normal View History

2021-08-02 09:53:08 +02:00
<script lang="ts">
2021-03-09 15:37:35 +01:00
import Icon from './Icon.svelte'
2021-08-02 09:53:08 +02:00
type Link = {
href: string
name: string
icon: string
}
export let links: Link[] = []
2021-04-06 16:30:09 +02:00
2021-08-02 09:53:08 +02:00
function isExternal(link: string) {
2021-04-06 16:30:09 +02:00
return /^https?\:\/\//.test(link)
}
$: list = links.map((link) => ({
...link,
external: isExternal(link.href),
}))
2021-03-09 15:37:35 +01:00
</script>
<ul>
2021-04-06 16:30:09 +02:00
{#each list as { href, name, icon, external }}
2021-08-02 09:53:08 +02:00
<a rel={external ? 'noopener noreferrer' : ''} {href} target={external ? '_blank' : ''}>
2021-04-06 16:30:09 +02:00
<li>
2021-03-09 15:37:35 +01:00
<Icon class="icon" {icon} />
{name}
2021-04-06 16:30:09 +02:00
</li>
</a>
2021-03-09 15:37:35 +01:00
{/each}
</ul>
<style>
ul {
list-style: none;
margin: 0;
padding: 0;
}
2021-04-06 16:30:09 +02:00
a {
2021-03-09 15:37:35 +01:00
transition: transform 200ms ease;
padding: 0.75em 0.5em;
cursor: pointer;
border-radius: 0.5em;
2021-04-06 16:30:09 +02:00
display: block;
2021-03-09 15:37:35 +01:00
}
2021-04-06 16:30:09 +02:00
a:hover {
2021-03-09 15:37:35 +01:00
box-shadow: 0px 6px 6px -3px #00000012;
transform: translateY(0.25em) translateX(0.15em) scale(1.05);
}
2021-04-06 16:30:09 +02:00
a :global(.icon) {
2021-03-09 15:37:35 +01:00
transform: translateY(0.3em);
font-size: 2em;
margin-right: 0.5rem;
}
</style>