mirror of
https://github.com/frappe/books.git
synced 2024-11-14 09:24:04 +00:00
refactor: convert sidebar toggler to use ref
This commit is contained in:
parent
eda3bb7576
commit
45d39f4fcf
@ -8,9 +8,9 @@
|
|||||||
>
|
>
|
||||||
<Transition name="spacer">
|
<Transition name="spacer">
|
||||||
<div
|
<div
|
||||||
v-if="!sidebar && platform === 'Mac' && languageDirection !== 'rtl'"
|
v-if="!showSidebar && platform === 'Mac' && languageDirection !== 'rtl'"
|
||||||
class="h-full"
|
class="h-full"
|
||||||
:class="sidebar ? '' : 'w-tl me-4 border-e'"
|
:class="showSidebar ? '' : 'w-tl me-4 border-e'"
|
||||||
/>
|
/>
|
||||||
</Transition>
|
</Transition>
|
||||||
<h1 class="text-xl font-semibold select-none" v-if="title">
|
<h1 class="text-xl font-semibold select-none" v-if="title">
|
||||||
@ -31,12 +31,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { showSidebar } from 'src/utils/refs';
|
||||||
import { Transition } from 'vue';
|
import { Transition } from 'vue';
|
||||||
import BackLink from './BackLink.vue';
|
import BackLink from './BackLink.vue';
|
||||||
import SearchBar from './SearchBar.vue';
|
import SearchBar from './SearchBar.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['sidebar', 'languageDirection'],
|
inject: ['languageDirection'],
|
||||||
props: {
|
props: {
|
||||||
title: { type: String, default: '' },
|
title: { type: String, default: '' },
|
||||||
backLink: { type: Boolean, default: true },
|
backLink: { type: Boolean, default: true },
|
||||||
@ -45,6 +46,9 @@ export default {
|
|||||||
searchborder: { type: Boolean, default: true },
|
searchborder: { type: Boolean, default: true },
|
||||||
},
|
},
|
||||||
components: { SearchBar, BackLink, Transition },
|
components: { SearchBar, BackLink, Transition },
|
||||||
|
setup() {
|
||||||
|
return { showSidebar };
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
showBorder() {
|
showBorder() {
|
||||||
return !!this.$slots.default && this.searchborder;
|
return !!this.$slots.default && this.searchborder;
|
||||||
|
@ -165,7 +165,7 @@
|
|||||||
m-4
|
m-4
|
||||||
rtl-rotate-180
|
rtl-rotate-180
|
||||||
"
|
"
|
||||||
@click="$emit('toggle-sidebar')"
|
@click="() => toggleSidebar()"
|
||||||
>
|
>
|
||||||
<feather-icon name="chevrons-left" class="w-4 h-4" />
|
<feather-icon name="chevrons-left" class="w-4 h-4" />
|
||||||
</button>
|
</button>
|
||||||
@ -182,7 +182,7 @@ import { fyo } from 'src/initFyo';
|
|||||||
import { openLink } from 'src/utils/ipcCalls';
|
import { openLink } from 'src/utils/ipcCalls';
|
||||||
import { docsPathRef } from 'src/utils/refs';
|
import { docsPathRef } from 'src/utils/refs';
|
||||||
import { getSidebarConfig } from 'src/utils/sidebarConfig';
|
import { getSidebarConfig } from 'src/utils/sidebarConfig';
|
||||||
import { routeTo } from 'src/utils/ui';
|
import { routeTo, toggleSidebar } from 'src/utils/ui';
|
||||||
import router from '../router';
|
import router from '../router';
|
||||||
import Icon from './Icon.vue';
|
import Icon from './Icon.vue';
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
@ -191,7 +191,7 @@ import ShortcutsHelper from './ShortcutsHelper.vue';
|
|||||||
export default {
|
export default {
|
||||||
components: [Button],
|
components: [Button],
|
||||||
inject: ['languageDirection', 'shortcuts'],
|
inject: ['languageDirection', 'shortcuts'],
|
||||||
emits: ['change-db-file', 'toggle-sidebar'],
|
emits: ['change-db-file'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
companyName: '',
|
companyName: '',
|
||||||
@ -222,7 +222,7 @@ export default {
|
|||||||
|
|
||||||
this.shortcuts.shift.set(['KeyH'], () => {
|
this.shortcuts.shift.set(['KeyH'], () => {
|
||||||
if (document.body === document.activeElement) {
|
if (document.body === document.activeElement) {
|
||||||
this.$emit('toggle-sidebar');
|
this.toggleSidebar();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.shortcuts.set(['F1'], () => this.openDocumentation());
|
this.shortcuts.set(['F1'], () => this.openDocumentation());
|
||||||
@ -234,6 +234,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
routeTo,
|
routeTo,
|
||||||
reportIssue,
|
reportIssue,
|
||||||
|
toggleSidebar,
|
||||||
openDocumentation() {
|
openDocumentation() {
|
||||||
openLink('https://docs.frappebooks.com/' + docsPathRef.value);
|
openLink('https://docs.frappebooks.com/' + docsPathRef.value);
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { showSidebar } from 'src/utils/refs';
|
||||||
|
import { toggleSidebar } from 'src/utils/ui';
|
||||||
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex overflow-hidden">
|
<div class="flex overflow-hidden">
|
||||||
<Transition name="sidebar">
|
<Transition name="sidebar">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
v-show="sidebar"
|
v-show="showSidebar"
|
||||||
class="flex-shrink-0 border-e whitespace-nowrap w-sidebar"
|
class="flex-shrink-0 border-e whitespace-nowrap w-sidebar"
|
||||||
@change-db-file="$emit('change-db-file')"
|
@change-db-file="$emit('change-db-file')"
|
||||||
@toggle-sidebar="sidebar = !sidebar"
|
|
||||||
/>
|
/>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
@ -32,7 +35,7 @@
|
|||||||
|
|
||||||
<!-- Show Sidebar Button -->
|
<!-- Show Sidebar Button -->
|
||||||
<button
|
<button
|
||||||
v-show="!sidebar"
|
v-show="!showSidebar"
|
||||||
class="
|
class="
|
||||||
absolute
|
absolute
|
||||||
bottom-0
|
bottom-0
|
||||||
@ -45,29 +48,22 @@
|
|||||||
m-4
|
m-4
|
||||||
hover:opacity-100 hover:shadow-md
|
hover:opacity-100 hover:shadow-md
|
||||||
"
|
"
|
||||||
|
@click="() => toggleSidebar()"
|
||||||
@click="sidebar = !sidebar"
|
|
||||||
>
|
>
|
||||||
<feather-icon name="chevrons-right" class="w-4 h-4" />
|
<feather-icon name="chevrons-right" class="w-4 h-4" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { computed } from '@vue/reactivity';
|
import { defineComponent } from 'vue';
|
||||||
import Sidebar from '../components/Sidebar.vue';
|
import Sidebar from '../components/Sidebar.vue';
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'Desk',
|
name: 'Desk',
|
||||||
emits: ['change-db-file'],
|
emits: ['change-db-file'],
|
||||||
data() {
|
|
||||||
return { sidebar: true };
|
|
||||||
},
|
|
||||||
provide() {
|
|
||||||
return { sidebar: computed(() => this.sidebar) };
|
|
||||||
},
|
|
||||||
components: {
|
components: {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { FocusedDocContextSet } from './misc';
|
import { FocusedDocContextSet } from './misc';
|
||||||
|
|
||||||
|
export const showSidebar = ref(true);
|
||||||
export const docsPathRef = ref<string>('');
|
export const docsPathRef = ref<string>('');
|
||||||
export const systemLanguageRef = ref<string>('');
|
export const systemLanguageRef = ref<string>('');
|
||||||
export const focusedDocsRef = reactive<FocusedDocContextSet>(
|
export const focusedDocsRef = reactive<FocusedDocContextSet>(
|
||||||
|
@ -18,6 +18,7 @@ import { App, createApp, h } from 'vue';
|
|||||||
import { RouteLocationRaw } from 'vue-router';
|
import { RouteLocationRaw } from 'vue-router';
|
||||||
import { stringifyCircular } from './';
|
import { stringifyCircular } from './';
|
||||||
import { evaluateHidden } from './doc';
|
import { evaluateHidden } from './doc';
|
||||||
|
import { showSidebar } from './refs';
|
||||||
import {
|
import {
|
||||||
ActionGroup,
|
ActionGroup,
|
||||||
MessageDialogOptions,
|
MessageDialogOptions,
|
||||||
@ -467,3 +468,11 @@ export async function isPrintable(schemaName: string) {
|
|||||||
});
|
});
|
||||||
return numTemplates > 0;
|
return numTemplates > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toggleSidebar(value?: boolean) {
|
||||||
|
if (typeof value !== 'boolean') {
|
||||||
|
value = !showSidebar.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
showSidebar.value = value;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user