-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add post 006 - drawer with mini menu
- Loading branch information
Showing
3 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
--- | ||
title: Mini drawer in Quasar that expands when focused and on mouse over | ||
description: Create slim drawers that expand on focus and on mouse over and stays open while you navigate its menus. | ||
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 want to free screen estate and use amini/slim drawer, but you want it to expand when it is focused and on mouse over. | ||
|
||
## Solution | ||
|
||
Nothing very complex, you just need: | ||
|
||
- a flag variable for the mini state of the drawer | ||
- a flag variable for when a menu from the drawer is opened. | ||
- only display the mini menu when it should be mini and there is no menu open | ||
|
||
::: code-group | ||
```vue [MyLayout.vue] | ||
<template> | ||
<div class="q-pa-md"> | ||
<q-layout view="hHh Lpr lff" container style="height: 400px" 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-btn flat autofocus label="Focus helper - tab from here to get in the drawer" /> | ||
</q-toolbar> | ||
</q-header> | ||
<q-drawer | ||
v-model="drawer" | ||
show-if-above | ||
:mini="miniState === true && miniMenuOpen !== true" | ||
@mouseover="miniState = false" | ||
@mouseout="miniState = true" | ||
@focusin="miniState = false" | ||
@focusout="miniState = true" | ||
:width="200" | ||
:breakpoint="500" | ||
bordered | ||
content-class="bg-grey-3" | ||
> | ||
<q-scroll-area class="fit" :horizontal-thumb-style="{ opacity: 0 }"> | ||
<q-list padding> | ||
<q-item class="q-pr-xs" clickable dense v-ripple> | ||
<q-item-section avatar> | ||
<q-icon class="q-py-sm" name="inbox" /> | ||
</q-item-section> | ||
<q-item-section> | ||
<q-item-label> | ||
Menu1 | ||
</q-item-label> | ||
</q-item-section> | ||
<q-item-section side> | ||
<q-btn icon="more_vert" color="grey" dense flat round @click.stop> | ||
<q-menu | ||
anchor="top left" | ||
self="top left" | ||
auto-close | ||
@before-show="miniMenuOpen = true" | ||
@hide="miniMenuOpen = false" | ||
> | ||
<q-list dense> | ||
<q-item clickable> | ||
<q-item-section>Open in a new Tab</q-item-section> | ||
<q-item-section avatar> | ||
<q-icon name="star" color="yellow" /> | ||
</q-item-section> | ||
</q-item> | ||
<q-item clickable> | ||
<q-item-section>Add to Favorite</q-item-section> | ||
<q-item-section avatar> | ||
<q-icon name="open_in_new" color="primary" /> | ||
</q-item-section> | ||
</q-item> | ||
</q-list> | ||
</q-menu> | ||
</q-btn> | ||
</q-item-section> | ||
</q-item> | ||
</q-list> | ||
</q-scroll-area> | ||
</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> | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
const drawer = ref(false); | ||
const miniState = ref(true); | ||
const miniMenuOpen = ref(false); | ||
</script> | ||
``` | ||
::: | ||
|
||
## Demo | ||
|
||
<code-frame | ||
:title="$frontmatter.title" | ||
src="https://pdanpdan.github.io/quasar-play/?file=src%2FApp.vue&preview=t&previewMode=preview&editor=codemirror#eNq9WG1zG7cR/itrTieSZ3RH2U6+sJIjJ60n7cTJ1OpMP5QdDXgHkohwwBnAUVI1+u99FvdCkDwqUaeNP1g87GJ3sbvPYhePE1XV1oWsEnX+i7dmMps8zg3RvCP4+WRGcYXXvjTCC8dL88k6hNrPptPG1LervLDVtKVevc3ffJ2fT0vlQ7eUS1/ltbMlVMwnZ720q5Y6lffBCT91dmGDzZbWhPR3XvhoxJjGl0g4prYSQToldKYKa/Y/X6D8N8hhC57m5mlyNllYG/Lg4e7WzxQeakmP9KGu6YmWzlZ0smnkyR/npmN4pL9FfQO5Vc8ccyPvI08pl6LRgZaNKYKyhk4fSbBExJB/zFr5r9uIYiFvvDxt5Z71Ya51s1LGD2Enmk7pJxvU8qHzYVz5Ew5nV93KE/62v3DapVolm0vhbmd0IppgTxJu/P8apsMd8AasynFaeOMiyKrW8N17Zrko1YYKLby/RPJltciqcj6JJBC/ZFo82CbQRsk7MKx/WNOPtSO9XM4nbEgQykhHPjxoyXSpVuswo6/Pz+t75ugE+7Uo7V32lpxtTCnLbGFdKR0C1mmKutZSYJGklhuYVw67F6tsoUVxm3BH/mCtXgiXLMblRTC0xAHpqtCquIWA0ok7CL6kV+0vWBYNQTSNl8T5A65KmgaU6b68Tk0WVNDy/Q/RyIvp/voxIzgqS1s0nrRYSA09H+PXWuoaNmUUxKJNt7V0koKllQykDIW1pMHc1KhE99Z7WGvdh6XEpZ2AYe8mq2wZrehFb2l+jRCpZSYWdiO3UohmlTKKHYQ/1wGhocvLSwqukfTVV8Srn+C6n2tp6FVHSOVeVRYYgEy3K4OWQvsxzibsMR5IjA5VMWjH5c1Dy3dcXnLEO1WGNdjenp+nmmYLJ8VtbZVhGd/sEtskluV2hREhTciSzF05+ZC9227bTWFfOKt1JqBlSP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