aboutsummaryrefslogtreecommitdiff
path: root/src/ui/c-link/c-link.vue
blob: 828d56f1ef11b55d43fc5fc7e8f41600747f84fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script lang="ts" setup>
import { type RouteLocationRaw, RouterLink } from 'vue-router';
import { useTheme } from './c-link.theme';

const props = defineProps<{
  href?: string
  to?: RouteLocationRaw
}>();

const { href, to } = toRefs(props);

const theme = useTheme();
const tag = computed(() => {
  if (href?.value) {
    return 'a';
  }
  if (to?.value) {
    return RouterLink;
  }
  return 'span';
});
</script>

<template>
  <component :is="tag" :href="href ?? to" class="c-link" :to="to">
    <slot />
  </component>
</template>

<style lang="less" scoped>
.c-link {
  line-height: inherit;
  font-family: inherit;
  font-size: inherit;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-weight: 400;
  color: v-bind('theme.default.textColor');
  border-radius: 4px;
  transition: color cubic-bezier(0.4, 0, 0.2, 1) 0.3s;

  outline-offset: 1px;

  &:hover {
    color: v-bind('theme.default.hover.textColor');
  }

  &:active {
    color: v-bind('theme.default.textColor');
  }

  &:focus {
    color: v-bind('theme.default.outline.color');
  }
}
</style>