Sider.vue 1.3 KB
Newer Older
L
LeoKu 已提交
1 2 3 4 5
<template>
  <aside class="sider" :class="{ collapsed: isCollapsed }">
    <slot />

    <div class="trigger" @click="isCollapsed ? openSider() : closeSider()">
L
LeoKu 已提交
6
      <img :src="IconRight" class="icon-right" alt="arrow" />
L
LeoKu 已提交
7 8 9 10 11 12 13 14 15 16 17 18
    </div>
  </aside>
</template>

<script lang="ts" setup>
import IconRight from '@/assets/icons/icon-right.svg'
import { useSider } from '@/hooks'

const { isCollapsed, openSider, closeSider } = useSider()
</script>

<style lang="scss" scoped>
19 20
@use 'src/styles/var';

L
LeoKu 已提交
21 22 23 24 25 26
.sider {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 200;
  height: 100%;
L
LeoKu 已提交
27 28

  @media (prefers-reduced-motion: no-preference) {
L
LeoKu 已提交
29 30
    transition: transform 0.2s;
    will-change: transform;
L
LeoKu 已提交
31
  }
L
LeoKu 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

  .icon-right {
    transition: transform 0.2s;
  }

  &.collapsed {
    transform: translateX(100%);

    .icon-right {
      transform: rotateY(-180deg);
    }
  }

  .trigger {
    position: absolute;
    top: 50%;
L
LeoKu 已提交
48
    left: 1px;
L
LeoKu 已提交
49 50 51 52 53
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 4rem;
L
LeoKu 已提交
54
    background-color: var.$color-configurator;
L
LeoKu 已提交
55 56 57 58 59 60 61
    border-radius: 0.4rem 0 0 0.4rem;
    transform: translate(-100%, -50%);
    cursor: pointer;
    transition: width 0.2s, background-color 0.2s;

    &:hover {
      width: 1.5rem;
62
      background-color: lighten(var.$color-configurator, 5);
L
LeoKu 已提交
63 64 65 66
    }
  }
}
</style>