Files
classroomio/apps/dashboard/src/lib/components/PageNav/index.svelte
T

138 lines
3.6 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';
2021-08-31 21:59:17 +03:00
import Chip from '../Chip/index.svelte';
2024-04-19 05:45:48 +01:00
import { t } from '$lib/utils/functions/translations';
2023-08-05 04:44:32 +01:00
2021-08-18 19:47:02 +03:00
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';
2023-10-05 08:02:34 +01:00
export let hideOnMobile = false;
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
2023-08-05 04:44:32 +01:00
$: dynamicRootClass = 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
2024-05-13 19:35:06 +01:00
class="{hideOnMobile &&
2024-11-21 15:15:53 +01:00
'hideOnMobile'} header dark:bg-black dark:border-neutral-600 border-b border-gray-200 bg-white {!disableSticky &&
2024-02-21 20:10:36 +01:00
'sticky'} {dynamicRootClass}"
2021-06-26 21:32:42 +03:00
style={overidableStyle}
>
2024-02-21 18:59:10 +01:00
<div
class="{hideOnMobile
? 'hidden lg:flex'
2024-02-21 20:10:36 +01:00
: ''} {paddingClass} max-w-4xl m-auto flex items-center justify-between min-h-[61px]"
2024-02-21 18:59:10 +01:00
>
{#if !!title}
{#if isTitleEditable}
{#if !enterEditTitleMode}
<button class="w-full" on:click={() => (enterEditTitleMode = true)}>
<h4
class="editable-title hover:bg-gray-100 dark:bg-black px-3 rounded-md overflow-ellipsis"
>
{title}
</h4>
</button>
{:else}
<TextField
bind:value={title}
2024-04-19 05:45:48 +01:00
placeholder={$t('course.navItem.settings.course_title')}
2024-02-21 18:59:10 +01:00
onChange={() => {
enterEditTitleMode = false;
if (typeof onEditComplete === 'function') {
onEditComplete();
}
}}
/>
{/if}
{:else}
<div class="flex items-center w-full" {title}>
<slot name="image" />
2023-08-05 04:44:32 +01:00
<h4
2024-02-21 18:59:10 +01:00
class="{$$slots.image
? 'ml-2'
: ''} dark:text-white whitespace-nowrap truncate text-lg font-semibold"
2023-08-05 04:44:32 +01:00
>
{title}
</h4>
2024-02-21 18:59:10 +01:00
</div>
2021-08-18 19:47:02 +03:00
{/if}
2024-02-21 18:59:10 +01:00
{/if}
{#if Array.isArray(navItems) && navItems.length}
<div class="flex justify-evenly items-center">
{#each navItems as item}
<a
class="mr-5 pb-2 text-sm font-bold flex items-center relative {item.isActive
? 'text-primary-700'
: 'dark:text-white text-black'} hover:no-underline"
href={item.href}
>
{item.label}
{#if typeof item.badgeValue === 'number'}
<Chip value={item.badgeValue} className="ml-1 bg-gray-300 dark:text-black" />
{/if}
<span
class="absolute bottom-0 left-0 h-1 bg-primary-700 transition-all ease-in-out duration-500 {item.isActive
? 'w-full'
: 'w-0'}"
/>
</a>
{/each}
{#if addButtonHref}
<NewButton href={addButtonHref} label={addButtonLabel} />
{/if}
2021-08-26 13:35:56 +03:00
</div>
2021-08-18 19:47:02 +03:00
{/if}
2024-02-21 18:59:10 +01:00
<slot name="widget" />
</div>
2021-06-26 21:32:42 +03:00
</div>
2021-05-06 08:22:25 +03:00
<style>
.header {
2021-05-07 03:43:37 +03:00
min-height: 61px;
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
}
2021-05-07 03:43:37 +03:00
.header.bring-down {
flex-direction: column;
align-items: flex-start;
}
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-09-17 06:33:49 +03:00
2024-05-13 19:35:06 +01:00
@media (max-width: 1024px) {
2021-09-17 06:33:49 +03:00
.title {
width: fit-content;
}
2024-05-13 19:35:06 +01:00
.hideOnMobile {
display: none;
}
2021-09-17 06:33:49 +03:00
}
2021-05-06 08:22:25 +03:00
</style>