Files
classroomio/src/components/PageNav/index.svelte
T

133 lines
2.9 KiB
Svelte
Raw Normal View History

2021-05-06 08:22:25 +03:00
<script>
2021-08-18 19:47:02 +03:00
import NewButton from '../PrimaryContainedButton/index.svelte';
import TextField from '../Form/TextField.svelte';
export let title = '';
export let overidableStyle = '';
2021-05-06 08:22:25 +03:00
export let navItems = [];
2021-08-24 10:45:43 +03:00
export let addButtonHref = '';
export let addButtonLabel = '';
export let disableSticky = false;
2021-08-18 19:47:02 +03:00
export let isTitleEditable = false;
export let onEditComplete = () => {};
2021-08-24 10:45:43 +03:00
export let paddingClass = 'px-2';
2021-07-08 09:44:16 +03:00
2021-08-18 19:47:02 +03:00
let dynamicRootClass = '';
let enterEditTitleMode = false;
2021-05-07 03:43:37 +03:00
$: dynamicRootClass =
2021-08-18 19:47:02 +03:00
Array.isArray(navItems) && navItems.length > 4 ? 'bring-down' : '';
2021-05-06 08:22:25 +03:00
</script>
2021-06-26 21:32:42 +03:00
<div
class="header flex items-center justify-between {!disableSticky &&
2021-08-24 10:45:43 +03:00
'sticky'} {paddingClass} {dynamicRootClass}"
2021-06-26 21:32:42 +03:00
style={overidableStyle}
>
{#if !!title}
2021-08-18 19:47:02 +03:00
{#if isTitleEditable}
{#if !enterEditTitleMode}
<h4
class="title editable-title hover:bg-gray-100 px-3 rounded-md overflow-ellipsis"
on:click={() => (enterEditTitleMode = true)}
>
{title}
</h4>
{:else}
<TextField
bind:value={title}
placeholder="Course title"
onChange={() => {
enterEditTitleMode = false;
if (typeof onEditComplete === 'function') {
onEditComplete();
}
}}
/>
{/if}
{:else}
2021-08-26 13:35:56 +03:00
<div class="flex items-center" {title}>
<slot name="image" />
<h4 class="title">{title}</h4>
</div>
2021-08-18 19:47:02 +03:00
{/if}
2021-06-26 21:32:42 +03:00
{/if}
{#if Array.isArray(navItems) && navItems.length}
<div class="flex justify-evenly items-center">
{#each navItems as item}
<a class="mr-5 text-sm {item.isActive && 'active'}" href={item.href}>
{item.label}
</a>
{/each}
{#if addButtonHref}
<NewButton href={addButtonHref} label={addButtonLabel} />
{/if}
</div>
{/if}
<slot name="widget" />
</div>
2021-05-06 08:22:25 +03:00
<style>
.header {
border-bottom: 1px solid var(--border-color);
2021-05-07 03:43:37 +03:00
min-height: 61px;
background-color: #fff;
2021-06-26 21:32:42 +03:00
z-index: 1;
}
.header.sticky {
2021-05-07 03:43:37 +03:00
position: sticky;
top: 0;
2021-05-06 08:22:25 +03:00
}
.title {
2021-08-26 13:35:56 +03:00
font-size: 18px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 250px;
margin-left: 5px;
2021-05-06 08:22:25 +03:00
}
h4 {
font-size: 16px;
font-weight: 900;
word-break: break-word;
overflow-wrap: break-word;
margin: 0;
}
.active {
position: relative;
display: inline-block;
}
.active::after {
position: absolute;
2021-08-18 19:47:02 +03:00
content: '';
2021-05-06 08:22:25 +03:00
width: 100%;
height: 3px;
background-color: var(--main-primary-color);
display: block;
}
2021-05-07 03:43:37 +03:00
.header.bring-down {
flex-direction: column;
align-items: flex-start;
}
.spacing {
flex-grow: 1;
}
2021-05-07 03:43:37 +03:00
2021-08-18 19:47:02 +03:00
.editable-title {
font-size: 16px;
display: flex;
/* justify-content: center; */
align-items: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding: 10px;
}
2021-05-06 08:22:25 +03:00
</style>