Skip to content

Commit

Permalink
refactor(components): use composition API and teleport for side-panel…
Browse files Browse the repository at this point in the history
… generic component
  • Loading branch information
NicolasRichel committed Jun 10, 2021
1 parent 640a2cc commit b546f0b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 42 deletions.
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
</strong>
</noscript>
<div id="app"></div>
<div id="side-panel-container"></div>
<div id="notification-container"></div>
</body>
</html>
8 changes: 2 additions & 6 deletions src/components/generic/side-panel/SidePanel.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
.side-panel {
$title-height: 44px;

position: fixed;
z-index: 200;
top: 0;
right: 0;
width: 400px;
height: 100vh;
padding: $spacing-unit;
box-shadow: 0 -2px 10px 0 rgba(0, 0, 0, 0.1);
background-color: $color-white;

$title-height: 44px;

&__title {
display: flex;
justify-content: space-between;
Expand Down
36 changes: 24 additions & 12 deletions src/components/generic/side-panel/SidePanel.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<template>
<div class="side-panel">
<div class="side-panel__title">
<span>{{ title }}</span>
<BIMDataButton ghost rounded icon @click="$emit('close')">
<BIMDataIcon name="close" size="xxxs" />
</BIMDataButton>
</div>
<div class="side-panel__content">
<slot></slot>
</div>
</div>
<teleport to="#side-panel-container">
<transition name="slide-fade-right">
<div class="side-panel" v-show="showSidePanelOpen">
<div class="side-panel__title">
<span>{{ title }}</span>
<BIMDataButton ghost rounded icon @click="closeSidePanel">
<BIMDataIcon name="close" size="xxxs" />
</BIMDataButton>
</div>
<div class="side-panel__content">
<slot></slot>
</div>
</div>
</transition>
</teleport>
</template>

<script>
import { useSidePanel } from "@/composables/side-panel";
// Components
import BIMDataButton from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataButton.js";
import BIMDataIcon from "@bimdata/design-system/dist/js/BIMDataComponents/vue3/BIMDataIcon.js";
Expand All @@ -28,7 +33,14 @@ export default {
default: ""
}
},
emits: ["close"]
setup() {
const { showSidePanelOpen, closeSidePanel } = useSidePanel();
return {
showSidePanelOpen,
closeSidePanel
};
}
};
</script>

Expand Down
11 changes: 11 additions & 0 deletions src/composables/side-panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useToggle } from "./toggle";

const { isOpen, open, close } = useToggle();

export function useSidePanel() {
return {
showSidePanelOpen: isOpen,
openSidePanel: open,
closeSidePanel: close
};
}
16 changes: 16 additions & 0 deletions src/composables/toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ref } from "vue";

export function useToggle() {
const isOpen = ref(false);

const open = () => isOpen.value = true;
const close = () => isOpen.value = false;
const toggle = () => isOpen.value = !isOpen.value;

return {
isOpen,
open,
close,
toggle
}
};
14 changes: 14 additions & 0 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,19 @@ html {
body {
margin: 0;
padding: 0;

#side-panel-container {
position: fixed;
z-index: 200;
top: 0;
right: 0;
}

#notification-container {
position: fixed;
z-index: 300;
top: 0;
right: 0;
}
}
}
34 changes: 10 additions & 24 deletions src/views/space-board/SpaceBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,13 @@
</template>
</ViewHeader>

<transition name="fade">
<SidePanel
v-show="showUsersManager"
:title="$t('SpaceUsersManager.title')"
@close="closeUsersManager"
>
<SpaceUsersManager
:space="space"
:users="users"
:invitations="invitations"
/>
</SidePanel>
</transition>
<SidePanel :title="$t('SpaceUsersManager.title')">
<SpaceUsersManager
:space="space"
:users="users"
:invitations="invitations"
/>
</SidePanel>

<ResponsiveGrid itemWidth="320px">
<ProjectCreationCard
Expand All @@ -81,6 +75,7 @@

<script>
import { ref, watchEffect } from "vue";
import { useSidePanel } from "@/composables/side-panel";
import { useProjects } from "@/state/projects";
import { useSpaces } from "@/state/spaces";
// Components
Expand Down Expand Up @@ -111,6 +106,7 @@ export default {
setup() {
const { currentSpace, spaceUsers, spaceInvitations } = useSpaces();
const { spaceProjects } = useProjects();
const { openSidePanel } = useSidePanel();
const displayedProjects = ref([]);
watchEffect(() => (displayedProjects.value = spaceProjects.value));
Expand All @@ -137,26 +133,16 @@ export default {
.sort((a, b) => (a.name < b.name ? -1 : 1) * n);
};
const showUsersManager = ref(false);
const openUsersManager = () => {
showUsersManager.value = true;
};
const closeUsersManager = () => {
showUsersManager.value = false;
};
return {
// References
invitations: spaceInvitations,
projects: displayedProjects,
searchText,
showUsersManager,
space: currentSpace,
users: spaceUsers,
// Methods
closeUsersManager,
filterProjects,
openUsersManager,
openUsersManager: openSidePanel,
sortProjects
};
}
Expand Down

0 comments on commit b546f0b

Please sign in to comment.