Toggle left bar in course page

This commit is contained in:
Ibitoye Rotimi Best
2021-07-04 19:52:16 +03:00
parent fbdfd3321b
commit 3b575adc54
4 changed files with 90 additions and 31 deletions
@@ -1,12 +1,19 @@
<script> <script>
import { onMount } from "svelte";
import hotkeys from "hotkeys-js";
import ChevronLeft32 from "carbon-icons-svelte/lib/ChevronLeft32";
import ChevronRight32 from "carbon-icons-svelte/lib/ChevronRight32";
import { stores, goto } from "@sapper/app"; import { stores, goto } from "@sapper/app";
import Expandable from "../../Expandable/index.svelte"; import Expandable from "../../Expandable/index.svelte";
import PageNav from "../../PageNav/index.svelte"; import PageNav from "../../PageNav/index.svelte";
import IconButton from "../../IconButton/index.svelte";
import { getNavItemRoute, getLectureRoute, getLectureNo } from "../function"; import { getNavItemRoute, getLectureRoute, getLectureNo } from "../function";
// export let lectureId; // export let lectureId;
export let courseId; export let courseId;
let show = true;
const { page } = stores(); const { page } = stores();
function handleMainGroupClick(href) { function handleMainGroupClick(href) {
@@ -74,9 +81,21 @@
hideSortIcon: true, hideSortIcon: true,
}, },
]; ];
onMount(() => {
hotkeys("ctrl+b", function (event, handler) {
event.preventDefault();
switch (handler.key) {
case "ctrl+b":
show = !show;
break;
}
});
});
</script> </script>
<div class="root"> <div class="root z-10 {!show && 'hide'}">
{#if show}
<PageNav title="React.JS" /> <PageNav title="React.JS" />
<div> <div>
{#each navItems as navItem} {#each navItems as navItem}
@@ -102,6 +121,24 @@
</Expandable> </Expandable>
{/each} {/each}
</div> </div>
{/if}
<div class="toggler absolute bottom-0 -right-0.5">
<IconButton
value="toggle"
onClick={() => (show = !show)}
toolTipProps={{
title: "Toggle sidebar",
hotkeys: ["Ctrl", "B"],
direction: "right",
}}
>
{#if show}
<ChevronLeft32 class="carbon-icon" />
{:else}
<ChevronRight32 class="carbon-icon" />
{/if}
</IconButton>
</div>
</div> </div>
<style lang="scss"> <style lang="scss">
@@ -113,7 +150,10 @@
position: sticky; position: sticky;
top: 0; top: 0;
border-right: 1px solid var(--border-color); border-right: 1px solid var(--border-color);
overflow: auto;
&.hide {
width: 0px;
}
} }
.active { .active {
@@ -136,4 +176,12 @@
background-color: #cae2f9; background-color: #cae2f9;
} }
} }
.toggler {
right: -58px;
z-index: 10;
border: 1px solid var(--border-color);
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
}
</style> </style>
+9 -2
View File
@@ -3,11 +3,13 @@
export let onClick; export let onClick;
export let disabled = false; export let disabled = false;
export let selected = false; export let selected = false;
export let buttonClassName = "";
export let contained = false; export let contained = false;
export let value; export let value;
export let toolTipProps = { export let toolTipProps = {
title: "", title: "",
hotkeys: [], hotkeys: [],
direction: "",
}; };
function handleClick() { function handleClick() {
@@ -15,9 +17,14 @@
} }
</script> </script>
<ToolTip title={toolTipProps.title} hotkeys={toolTipProps.hotkeys}> <ToolTip
title={toolTipProps.title}
hotkeys={toolTipProps.hotkeys}
direction={toolTipProps.direction}
>
<button <button
class="root {selected && 'active'} {contained && 'contained'}" class="root {selected && 'active'} {contained &&
'contained'} {buttonClassName}"
{disabled} {disabled}
on:click={handleClick} on:click={handleClick}
> >
+6 -2
View File
@@ -1,11 +1,12 @@
<script> <script>
export let title; export let title;
export let hotkeys = []; export let hotkeys = [];
export let direction;
</script> </script>
{#if !!title} {#if !!title}
<div class="tooltip"> <div class="tooltip">
<span class="tooltiptext z-20"> <span class="tooltiptext z-20 {direction === 'right' && 'right'}">
{title} {title}
{#if Array.isArray(hotkeys) && hotkeys.length} {#if Array.isArray(hotkeys) && hotkeys.length}
<span class="shortcut"> <span class="shortcut">
@@ -24,7 +25,10 @@
position: relative; position: relative;
display: inline-block; display: inline-block;
} }
.right {
left: 100%;
right: unset !important;
}
.tooltip .tooltiptext { .tooltip .tooltiptext {
color: #fff; color: #fff;
padding: 8px; padding: 8px;
+1 -1
View File
@@ -61,6 +61,6 @@
} }
.rightBar { .rightBar {
width: 80%; flex-grow: 1;
} }
</style> </style>