Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui/ux): move back button to the left #621

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions src/components/BackLink.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/FormContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<slot name="header" />
</PageHeader>

<!-- Invoice Form -->
<!-- Common Form -->
<div
class="
border
Expand Down
36 changes: 21 additions & 15 deletions src/components/PageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,48 @@
:class="spacerClass"
/>
</Transition>
<h1
class="text-xl font-semibold select-none whitespace-nowrap"
v-if="title"

<div
class="flex items-center window-no-drag gap-4 me-auto"
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"
>
{{ title }}
</h1>
<div class="flex items-stretch window-no-drag gap-2">
<slot name="left" />
<!-- Nav Group -->
<PageHeaderNavGroup />
<h1
class="text-xl font-semibold select-none whitespace-nowrap"
v-if="title"
>
{{ title }}
</h1>

<!-- Left Slot -->
<div class="flex items-stretch window-no-drag gap-4">
<slot name="left" />
</div>
</div>

<!-- Right (regular) Slot -->
<div
class="flex items-stretch window-no-drag gap-2 ms-auto"
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"
>
<slot />
<div class="border-e" v-if="showBorder" />
<BackLink v-if="backLink" class="window-no-drag rtl-rotate-180" />
<SearchBar v-if="!hideSearch" />
</div>
</div>
</template>
<script lang="ts">
import { languageDirectionKey } from 'src/utils/injectionKeys';
import { showSidebar } from 'src/utils/refs';
import { defineComponent, inject, Transition } from 'vue';
import BackLink from './BackLink.vue';
import SearchBar from './SearchBar.vue';
import PageHeaderNavGroup from './PageHeaderNavGroup.vue';

export default defineComponent({
props: {
title: { type: String, default: '' },
backLink: { type: Boolean, default: true },
hideSearch: { type: Boolean, default: false },
border: { type: Boolean, default: true },
searchborder: { type: Boolean, default: true },
},
components: { BackLink, SearchBar, Transition },
components: { Transition, PageHeaderNavGroup },
setup() {
return { showSidebar, languageDirection: inject(languageDirectionKey) };
},
Expand Down
70 changes: 70 additions & 0 deletions src/components/PageHeaderNavGroup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<div class="flex">
<SearchBar />
<!-- Back Button -->
<a
ref="backlink"
class="nav-link border-l border-r border-white"
:class="
historyState.back ? 'text-gray-700 cursor-pointer' : 'text-gray-400'
"
@click="$router.back()"
>
<feather-icon name="chevron-left" class="w-4 h-4" />
</a>
<!-- Forward Button -->
<a
class="nav-link rounded-md rounded-l-none"
:class="
historyState.forward ? 'text-gray-700 cursor-pointer' : 'text-gray-400'
"
@click="$router.forward()"
>
<feather-icon name="chevron-right" class="w-4 h-4" />
</a>
</div>
</template>
<script lang="ts">
import { shortcutsKey } from 'src/utils/injectionKeys';
import { ref, inject } from 'vue';
import { defineComponent } from 'vue';
import SearchBar from './SearchBar.vue';
import { historyState } from 'src/utils/refs';

const COMPONENT_NAME = 'PageHeaderNavGroup';

export default defineComponent({
setup() {
return {
historyState,
backlink: ref<HTMLAnchorElement | null>(null),
shortcuts: inject(shortcutsKey),
};
},
activated() {
this.shortcuts?.shift.set(COMPONENT_NAME, ['Backspace'], () => {
this.backlink?.click();
});
// @ts-ignore
window.ng = this;
},
deactivated() {
this.shortcuts?.delete(COMPONENT_NAME);
},
components: { SearchBar },
computed: {
hasBack() {
return !!history.back;
},
hasForward() {
return !!history.forward;
},
},
});
</script>

<style scoped>
.nav-link {
@apply flex items-center bg-gray-200 px-3;
}
</style>
16 changes: 2 additions & 14 deletions src/components/SearchBar.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<template>
<div>
<!-- Search Bar Button -->
<Button @click="open" class="px-2" :padding="false">
<feather-icon name="search" class="w-4 h-4 me-1 text-gray-800" />
<p>{{ t`Search` }}</p>
<div class="text-gray-500 px-1 ms-4 text-sm whitespace-nowrap">
{{ modKeyText('k') }}
</div>
<Button @click="open" class="px-3 py-2 rounded-r-none" :padding="false">
<feather-icon name="search" class="w-4 h-4 text-gray-700" />
</Button>
</div>

Expand Down Expand Up @@ -292,14 +288,6 @@ export default defineComponent({
this.shortcuts!.pmod.set(COMPONENT_NAME, [shortcut], callback);
}
},
modKeyText(key: string): string {
key = key.toUpperCase();
if (this.platform === 'Mac') {
return `⌘ ${key}`;
}

return `Ctrl ${key}`;
},
open(): void {
this.openModal = true;
this.searcher?.updateKeywords();
Expand Down
8 changes: 8 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import QuickEditForm from 'src/pages/QuickEditForm.vue';
import Report from 'src/pages/Report.vue';
import Settings from 'src/pages/Settings/Settings.vue';
import TemplateBuilder from 'src/pages/TemplateBuilder/TemplateBuilder.vue';
import { reactive } from 'vue';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { historyState } from './utils/refs';

const routes: RouteRecordRaw[] = [
{
Expand Down Expand Up @@ -112,4 +114,10 @@ const routes: RouteRecordRaw[] = [
];

const router = createRouter({ routes, history: createWebHistory() });

router.afterEach(() => {
historyState.forward = !!history.state.forward;
historyState.back = !!history.state.back;
});

export default router;
6 changes: 5 additions & 1 deletion src/utils/refs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ref } from 'vue';
import { reactive, ref } from 'vue';

export const showSidebar = ref(true);
export const docsPathRef = ref<string>('');
export const systemLanguageRef = ref<string>('');
export const historyState = reactive({
forward: !!history.state.forward,
back: !!history.state.back,
});