Toggle left bar in course page
This commit is contained in:
@@ -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,33 +81,63 @@
|
|||||||
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'}">
|
||||||
<PageNav title="React.JS" />
|
{#if show}
|
||||||
<div>
|
<PageNav title="React.JS" />
|
||||||
{#each navItems as navItem}
|
<div>
|
||||||
<Expandable
|
{#each navItems as navItem}
|
||||||
label={navItem.label}
|
<Expandable
|
||||||
handleClick={handleMainGroupClick(navItem.to)}
|
label={navItem.label}
|
||||||
isGroupActive={$page.path === navItem.to}
|
handleClick={handleMainGroupClick(navItem.to)}
|
||||||
hideSortIcon={navItem.hideSortIcon}
|
isGroupActive={$page.path === navItem.to}
|
||||||
>
|
hideSortIcon={navItem.hideSortIcon}
|
||||||
{#if Array.isArray(navItem.items)}
|
>
|
||||||
{#each navItem.items as item, index}
|
{#if Array.isArray(navItem.items)}
|
||||||
<a
|
{#each navItem.items as item, index}
|
||||||
class="item flex items-center {(item.to === $page.path ||
|
<a
|
||||||
!$page.path.length > 3) &&
|
class="item flex items-center {(item.to === $page.path ||
|
||||||
'active'} pl-7 py-2"
|
!$page.path.length > 3) &&
|
||||||
href={item.to}
|
'active'} pl-7 py-2"
|
||||||
>
|
href={item.to}
|
||||||
<span class="course-counter"> {getLectureNo(index + 1)} </span>
|
>
|
||||||
<span>{item.title}</span>
|
<span class="course-counter"> {getLectureNo(index + 1)} </span>
|
||||||
</a>
|
<span>{item.title}</span>
|
||||||
{/each}
|
</a>
|
||||||
{/if}
|
{/each}
|
||||||
</Expandable>
|
{/if}
|
||||||
{/each}
|
</Expandable>
|
||||||
|
{/each}
|
||||||
|
</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>
|
</div>
|
||||||
|
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -61,6 +61,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.rightBar {
|
.rightBar {
|
||||||
width: 80%;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user