Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

2.2 KB
Raw Blame
<template>
  <NuxtLink
    v-if="to || href"
    :to="to"
    :href="href"
    :target="blank ? '_blank' : undefined"
    v-bind="download ? { download: '' } : {}"
    :class="[{ 'btn-nav': nav }, display]"
    @click="emit('click')"
  >
    <Icon :name="icon" :display="display" fill="var(--btn-fill)" />
    <slot />
    <span v-if="tooltip" class="hint-tooltip btn-tooltip">{{ tooltip }}</span>
  </NuxtLink>

  <button v-else v-bind="attrs" :class="[{ fill, 'btn-nav': nav }, display]" @click="emit('click')">
    <Icon :name="icon" :display="display" fill="var(--btn-fill)" />
    <slot />
    <span v-if="tooltip" class="hint-tooltip btn-tooltip">{{ tooltip }}</span>
  </button>
</template>

<script setup lang="ts">
withDefaults(
  defineProps<{
    icon: string;
    tooltip?: string;
    to?: string;
    blank?: boolean;
    href?: string;
    download?: boolean;
    nav?: boolean;
    fill?: boolean;
    display?: 'sm' | 'md' | 'lg';
  }>(),
  {
    tooltip: undefined,
    to: undefined,
    href: undefined,
    display: 'lg',
  },
);
const emit = defineEmits<{ (e: 'click'): void }>();

const attrs = useAttrs();
</script>

<style scoped lang="scss">
button,
a {
  --btn-fill: var(--text-primary-light);

  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 1px;
  border-radius: var(--radius-sm);
  transition:
    background-color $transition-fast ease-in-out,
    border-color $transition-fast ease-in-out;

  &:hover {
    --btn-fill: var(--text-inverse);

    background-color: var(--surface-raised);
  }

  &.sm {
    padding: 2px;
  }

  &.md {
    padding: 3px;
  }

  &.lg {
    padding: 4.5px;
  }
}

@media screen and (width > 768px) {
  a:hover > .btn-tooltip,
  button:hover > .btn-tooltip {
    opacity: 1;
    visibility: visible;
  }
}

.fill {
  background-color: var(--surface-raised);
}

@media screen and (width <= 768px) {
  .btn-tooltip {
    position: static !important;
    order: 1;
    margin: 0 !important;
    padding: 0 !important;
    color: inherit !important;
    background-color: transparent !important;
    box-shadow: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: auto !important;
  }
}
</style>