mirror of
https://github.com/hcengineering/platform.git
synced 2025-02-10 21:04:51 +00:00
73 lines
2.3 KiB
Svelte
73 lines
2.3 KiB
Svelte
![]() |
<!--
|
||
|
// Copyright © 2022 Hardcore Engineering Inc.
|
||
|
//
|
||
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License. You may
|
||
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
//
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
-->
|
||
|
<script lang="ts">
|
||
|
import { Timestamp } from '@anticrm/core'
|
||
|
import { DatePresenter, Tooltip, getDaysDifference } from '@anticrm/ui'
|
||
|
import DueDatePopup from './DueDatePopup.svelte'
|
||
|
import { getDueDateIconModifier } from '../utils'
|
||
|
|
||
|
export let dateMs: number | null = null
|
||
|
export let shouldRender: boolean = true
|
||
|
export let onDateChange: (newDate: number | null) => void
|
||
|
|
||
|
$: today = new Date(new Date(Date.now()).setHours(0, 0, 0, 0))
|
||
|
$: isOverdue = dateMs !== null && dateMs < today.getTime()
|
||
|
$: dueDate = dateMs === null ? null : new Date(dateMs)
|
||
|
$: daysDifference = dueDate === null ? null : getDaysDifference(today, dueDate)
|
||
|
$: iconModifier = getDueDateIconModifier(isOverdue, daysDifference)
|
||
|
$: formattedDate = !dateMs ? '' : new Date(dateMs).toLocaleString('default', { month: 'short', day: 'numeric' })
|
||
|
|
||
|
const handleDueDateChanged = async (event: CustomEvent<Timestamp>) => {
|
||
|
const newDate = event.detail
|
||
|
|
||
|
if (newDate === undefined || dateMs === newDate) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
onDateChange(newDate)
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
{#if shouldRender}
|
||
|
{#if formattedDate}
|
||
|
<Tooltip
|
||
|
direction={'top'}
|
||
|
component={DueDatePopup}
|
||
|
props={{
|
||
|
formattedDate: formattedDate,
|
||
|
daysDifference: daysDifference,
|
||
|
isOverdue: isOverdue,
|
||
|
iconModifier: iconModifier
|
||
|
}}
|
||
|
>
|
||
|
<DatePresenter
|
||
|
value={dateMs}
|
||
|
editable={true}
|
||
|
shouldShowLabel={false}
|
||
|
icon={iconModifier}
|
||
|
on:change={handleDueDateChanged}
|
||
|
/>
|
||
|
</Tooltip>
|
||
|
{:else}
|
||
|
<DatePresenter
|
||
|
value={dateMs}
|
||
|
editable={true}
|
||
|
shouldShowLabel={false}
|
||
|
icon={iconModifier}
|
||
|
on:change={handleDueDateChanged}
|
||
|
/>
|
||
|
{/if}
|
||
|
{/if}
|