sharkey/packages/frontend/src/components/form/link.vue

96 lines
1.8 KiB
Vue
Raw Normal View History

2021-11-28 20:07:37 +09:00
<template>
2023-05-27 11:35:26 +09:00
<div :class="[$style.root, { [$style.inline]: inline }]">
<a v-if="external" :class="$style.main" class="_button" :href="to" target="_blank">
<span :class="$style.icon"><slot name="icon"></slot></span>
<span :class="$style.text"><slot></slot></span>
<span :class="$style.suffix">
<span :class="$style.suffixText"><slot name="suffix"></slot></span>
<i class="ti ti-external-link"></i>
2021-11-28 20:07:37 +09:00
</span>
</a>
2023-05-27 11:35:26 +09:00
<MkA v-else :class="[$style.main, { [$style.active]: active }]" class="_button" :to="to" :behavior="behavior">
<span :class="$style.icon"><slot name="icon"></slot></span>
<span :class="$style.text"><slot></slot></span>
<span :class="$style.suffix">
<span :class="$style.suffixText"><slot name="suffix"></slot></span>
<i class="ti ti-chevron-right"></i>
2021-11-28 20:07:37 +09:00
</span>
</MkA>
</div>
</template>
2022-07-25 21:24:37 +09:00
<script lang="ts" setup>
import { } from 'vue';
2021-11-28 20:07:37 +09:00
2022-07-25 21:24:37 +09:00
const props = defineProps<{
to: string;
active?: boolean;
external?: boolean;
2023-05-27 11:38:08 +09:00
behavior?: null | 'window' | 'browser';
2022-07-25 21:24:37 +09:00
inline?: boolean;
}>();
2021-11-28 20:07:37 +09:00
</script>
2023-05-27 11:35:26 +09:00
<style lang="scss" module>
.root {
2021-11-28 20:07:37 +09:00
display: block;
&.inline {
display: inline-block;
}
2023-05-27 11:35:26 +09:00
}
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
.main {
display: flex;
align-items: center;
width: 100%;
box-sizing: border-box;
padding: 10px 14px;
background: var(--buttonBg);
border-radius: 6px;
font-size: 0.9em;
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
&:hover {
text-decoration: none;
background: var(--buttonHoverBg);
}
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
&.active {
color: var(--accent);
background: var(--buttonHoverBg);
}
}
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
.icon {
margin-right: 0.75em;
flex-shrink: 0;
text-align: center;
color: var(--fgTransparentWeak);
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
&:empty {
display: none;
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
& + .text {
padding-left: 4px;
2021-11-28 20:07:37 +09:00
}
2023-05-27 11:35:26 +09:00
}
}
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
.text {
flex-shrink: 1;
white-space: normal;
padding-right: 12px;
text-align: center;
}
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
.suffix {
margin-left: auto;
opacity: 0.7;
white-space: nowrap;
2021-11-28 20:07:37 +09:00
2023-05-27 11:35:26 +09:00
> .suffixText:not(:empty) {
margin-right: 0.75em;
2021-11-28 20:07:37 +09:00
}
}
</style>