-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
239 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<script lang="ts"> | ||
import { cn } from '../../utils/cn'; | ||
import Fa from 'svelte-fa'; | ||
import { faChevronLeft, faChevronRight } from '@fortawesome/free-solid-svg-icons'; | ||
import Dropdown from '../Dropdown/Dropdown.svelte'; | ||
export let Arrayitem: string[] = []; | ||
export let pageChoice: string[] = ['5', '10', '15']; | ||
export let itemsPerPage: string = '5'; | ||
let currentPage: number | string = 1; | ||
let totalPages: number = Math.ceil(Arrayitem.length / parseInt(itemsPerPage)); | ||
let paginatedItems: string[] = []; | ||
function changePage(page: number | string) { | ||
currentPage = page; | ||
paginateItems(); | ||
} | ||
function paginateItems() { | ||
const startIndex = (Number(currentPage) - 1) * parseInt(itemsPerPage); | ||
const endIndex = startIndex + parseInt(itemsPerPage); | ||
paginatedItems = Arrayitem.slice(startIndex, endIndex); | ||
} | ||
function getVisiblePages(totalPages: number, currentPage: number) { | ||
let pages = []; | ||
if (totalPages <= 7) { | ||
pages = Array.from({ length: totalPages }, (_, i) => i + 1); | ||
} else { | ||
pages.push(1); | ||
if (currentPage > 4) { | ||
pages.push('...'); | ||
} | ||
let startPage = Math.max(2, currentPage - 2); | ||
let endPage = Math.min(totalPages - 1, currentPage + 2); | ||
for (let i = startPage; i <= endPage; i++) { | ||
pages.push(i); | ||
} | ||
if (currentPage < totalPages - 3) { | ||
pages.push('...'); | ||
} | ||
pages.push(totalPages); | ||
} | ||
return pages; | ||
} | ||
$: { | ||
totalPages = Math.ceil(Arrayitem.length / parseInt(itemsPerPage)); | ||
paginateItems(); | ||
} | ||
$: if (!itemsPerPage || parseInt(itemsPerPage) < 1) { | ||
itemsPerPage = '5'; | ||
} | ||
$: paginateItems(); | ||
</script> | ||
|
||
<div class="flex flex-col gap-2 justify-center items-center"> | ||
<div class="flex gap-2 max-md:flex-col max-md:gap-1"> | ||
<div class="flex gap-2 max-md:gap-1"> | ||
<button | ||
class="px-4 py-2 rounded bg-white border max-md:scale-75" | ||
on:click={() => changePage(Number(currentPage) - 1)} | ||
disabled={currentPage === 1} | ||
> | ||
<Fa icon={faChevronLeft} scale={0.75} /> | ||
</button> | ||
|
||
<div class="gap-2 flex flex-wrap"> | ||
{#each getVisiblePages(totalPages, Number(currentPage)) as page} | ||
{#if page === '...'} | ||
<span class="px-4 py-2 max-md:scale-75">...</span> | ||
{:else} | ||
<button | ||
class={cn( | ||
' px-4 max-md:px-4 py-2 rounded max-md:scale-75', | ||
currentPage === page ? 'text-white bg-sucu-pink-02 ' : 'text-black bg-white border' | ||
)} | ||
on:click={() => changePage(page)} | ||
> | ||
{page} | ||
</button> | ||
{/if} | ||
{/each} | ||
</div> | ||
|
||
<button | ||
class="px-4 py-2 rounded bg-white border max-md:scale-75" | ||
on:click={() => changePage(Number(currentPage) + 1)} | ||
disabled={Number(currentPage) === totalPages} | ||
> | ||
<Fa icon={faChevronRight} scale={0.75} /> | ||
</button> | ||
</div> | ||
<div class="flex gap-2 max-md:gap-1"> | ||
<div class="flex items-center max-md:scale-75"> | ||
<Dropdown | ||
items={pageChoice} | ||
bind:currentChoice={itemsPerPage} | ||
outerClass="w-20 bg-opacity-50 " | ||
on:change={(e) => (itemsPerPage = e.detail)} | ||
/> | ||
</div> | ||
<div class="flex items-center">/ page</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="items-list mt-5"> | ||
{#each paginatedItems as item} | ||
<div class="item"> | ||
{item} | ||
</div> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import dayjs from 'dayjs'; | ||
import buddhistEra from 'dayjs/plugin/buddhistEra'; | ||
import 'dayjs/locale/th'; | ||
import 'dayjs/locale/th'; | ||
|
||
dayjs.extend(buddhistEra); | ||
|
||
export function formatDateTH(dateString: string): string { | ||
return dayjs(dateString).locale('th').format('DD MMMM BBBB'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<script> | ||
import Footer from '$lib/components/Footer/Footer.svelte'; | ||
import Navbar from '$lib/components/Navbar.svelte'; | ||
import '../styles/app.css'; | ||
</script> | ||
|
||
<slot /> | ||
<div> | ||
<Navbar /> | ||
<slot /> | ||
<Footer /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script lang="ts"> | ||
import MaxWidthWrapper from '$lib/components/MaxWidthWrapper.svelte'; | ||
import { cn } from '$lib/utils'; | ||
import { faCircleArrowLeft } from '@fortawesome/free-solid-svg-icons'; | ||
import Fa from 'svelte-fa'; | ||
import { typography } from '../../../styles/tailwind/typography'; | ||
import dayjs from 'dayjs'; | ||
import buddhistEra from 'dayjs/plugin/buddhistEra'; | ||
import 'dayjs/locale/th'; | ||
import { formatDateTH } from '$lib/utils/date'; | ||
import Button from '$lib/components/Button.svelte'; | ||
import { modalShow } from '$lib/components/Modal/store'; | ||
import Modal from '$lib/components/Modal/Modal.svelte'; | ||
export let data; | ||
const { document } = data; | ||
modalShow.set(false); | ||
dayjs.extend(buddhistEra); | ||
</script> | ||
|
||
<MaxWidthWrapper class="mt-10 space-y-6 lg:space-y-12 min-h-screen"> | ||
<div class="flex flex-col gap-3 items-start"> | ||
<button on:click={() => history.back()} class="lg:relative -left-14 top-12"> | ||
<Fa icon={faCircleArrowLeft} size="lg" /> | ||
</button> | ||
<div class="flex items-center gap-4"> | ||
<h1 class={cn(typography({ variant: 'heading4' }), 'md:text-5xl lg:order-first')}> | ||
{document?.title} | ||
</h1> | ||
</div> | ||
<div> | ||
<p> | ||
โดย {document?.author.first_name} | ||
</p> | ||
<p>{formatDateTH(document?.updated_at || '')}</p> | ||
</div> | ||
</div> | ||
|
||
<hr class="border-t border-gray-300 my-12" /> | ||
|
||
<div class="flex flex-col gap-6 lg:gap-12"> | ||
<p>{document?.content.repeat(8)}</p> | ||
<div class="w-[342px] h-[220px] lg:w-[876px] lg:h-[500px] bg-sucu-gray-light" /> | ||
<Button class="w-fit mb-16" on:click={() => modalShow.set(true)} | ||
>ดาวน์โหลดเอกสารที่เกี่ยวข้อง</Button | ||
> | ||
{#if modalShow} | ||
<Modal /> | ||
{/if} | ||
</div> | ||
</MaxWidthWrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { documents } from '$lib/mock/document'; | ||
import type { PageLoad } from './$types'; | ||
import 'dayjs/locale/th'; | ||
|
||
export const load: PageLoad = async ({ params }) => { | ||
const document = documents.find((doc) => doc.id === params.id); | ||
return { params, document }; | ||
}; |