Skip to content

Commit

Permalink
feat(post 007): add resizable drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
pdanpdan committed Nov 24, 2023
1 parent 811cd4d commit 2d8fd2d
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions pages/posts/post_007.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
title: Resizable drawer in Quasar
description: Create a drawer width resizable width.
date: 2023-11-24
tags: [quasar]
outline: deep
---

<script setup>
import PostHeader from 'components/PostHeader.vue';
import CodeFrame from 'components/CodeFrame.vue';
</script>

<PostHeader />

## Problem description

You need a resizable drawer - change width with you mouse or keys.

## Solution

Use a div and vTouchPan to resize.

::: code-group
```vue [MyLayout.vue]
<template>
<div class="q-pa-md">
<q-layout
view="hHh Lpr lff"
container
style="height: 300px"
class="shadow-2 rounded-borders"
>
<q-header elevated class="bg-black">
<q-toolbar>
<q-btn flat @click="drawer = !drawer" round dense icon="menu" />
<q-toolbar-title>Header</q-toolbar-title>
</q-toolbar>
</q-header>
<q-drawer
v-model="drawer"
show-if-above
:width="drawerWidth"
:breakpoint="0"
bordered
>
<q-list>
<q-item v-for="i in 5" :key="i" clickable v-ripple>
<q-item-section> Menu item {{ i }} </q-item-section>
</q-item>
</q-list>
<!-- NEXT LINE -->
<div
autofocus
tabindex="0"
v-touch-pan.preserveCursor.prevent.mouse.horizontal="resizeDrawer"
@keydown="resizeDrawer"
class="q-drawer__resizer"
/>
</q-drawer>
<q-page-container>
<q-page padding>
<p v-for="n in 15" :key="n">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit nihil
praesentium molestias a adipisci, dolore vitae odit, quidem
consequatur optio voluptates asperiores pariatur eos numquam rerum
delectus commodi perferendis voluptate?
</p>
</q-page>
</q-page-container>
</q-layout>
</div>
</template>
<style>
.q-drawer__resizer {
position: absolute;
top: 0;
bottom: 0;
right: -2px;
width: 4px;
background-color: #999;
cursor: ew-resize;
}
.q-drawer__resizer:after {
content: '';
position: absolute;
top: 50%;
height: 30px;
left: -5px;
right: -5px;
transform: translateY(-50%);
background-color: inherit;
border-radius: 4px;
}
</style>
<script setup lang="ts">
import { ref } from 'vue';
let initialDrawerWidth;
const drawerWidth = ref(300);
const drawer = ref(true);
function resizeDrawer(ev) {
if (ev.type === 'keydown') {
if (ev.code === 'ArrowLeft') {
drawerWidth.value -= 1;
} else if (ev.code === 'ArrowRight') {
drawerWidth.value += 1;
}
} else {
if (ev.isFirst === true) {
initialDrawerWidth = drawerWidth.value;
}
drawerWidth.value = initialDrawerWidth + ev.offset.x;
}
drawerWidth.value = initialDrawerWidth + ev.offset.x
}
</script>
```
:::

## Demo

<code-frame
:title="$frontmatter.title"
src="https://pdanpdan.github.io/quasar-play/?file=src%2FApp.vue&preview=t&previewMode=preview&editor=codemirror#eNqtV21vGzcS/isT3R0ko96VkzTARWenSdsU7SHJ4ZwDeofTwaB2uRJrLrkmubJdw//9Hr7saldS0gaoP1hLznA4nJdnZh4mom60cVnNmvwXq9VkMXlYKqJlItjlZEFhx+/dtMwy47eWk41zjV3M561qrtd5oet5pL5+lj/9Oj+bl8K6tJVzW+eN0SWuWE5OO2mvI3XO75xhdm70SjudVVq54Xde2KDEsRu/RMKnrq2Z40YwmYlCq/3lF1z+O+R4DR6X6nFyOllp7XJnYe5oZ3L3DacHetM09EiV0TVNty2f/m2pEsMD/TPc15Pj9Z5jqfhd4Cl5xVrpqGpV4YRWNHsg5iXCh/5jEeWfRI9iI28tn0W5p52bG9muhbK924nmc/qgnajukw3Dzvd4nF6nnUf8xi+8thLrweGSmesFTVnr9HTAjf8nUB3mgDWgVY7XwhrnjteNhO1eeZbzUmypkMzaCwRf1rCsLpeTQALxJpPsXreuu2kr+C34Nj9u6F1jSFZVNHlSyzGhuOk2rLuX3HNzsd64BT0/O2vuBvzpUrthpb7NnpHRrSp5ma20KblJziRKugRtNpyBRFzyLR5Q9jJW62wlWXHda574ndZyxcxgM2yvnKIKJqDXhRTFNQSUht1C8AU9iV/LSVQH/laWk48wcN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