2023-08-13 16:28:12 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2023 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 ui, {
|
|
|
|
Button,
|
|
|
|
ButtonKind,
|
2023-08-23 03:11:35 +00:00
|
|
|
ButtonSize,
|
2023-08-13 16:28:12 +00:00
|
|
|
DatePopup,
|
|
|
|
SimpleDatePopup,
|
|
|
|
eventToHTMLElement,
|
2023-08-23 03:11:35 +00:00
|
|
|
showPopup,
|
2023-08-25 09:49:14 +00:00
|
|
|
TimeInputBox,
|
|
|
|
TimeShiftPresenter
|
2023-08-13 16:28:12 +00:00
|
|
|
} from '@hcengineering/ui'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
|
|
|
import DateLocalePresenter from './DateLocalePresenter.svelte'
|
|
|
|
|
|
|
|
export let date: number
|
2023-08-25 09:49:14 +00:00
|
|
|
export let difference: number = 0
|
2023-08-13 16:28:12 +00:00
|
|
|
export let direction: 'vertical' | 'horizontal' = 'vertical'
|
|
|
|
export let showDate: boolean = true
|
|
|
|
export let withoutTime: boolean
|
|
|
|
export let kind: ButtonKind = 'ghost'
|
2023-08-23 03:11:35 +00:00
|
|
|
export let size: ButtonSize = 'medium'
|
2023-08-13 16:28:12 +00:00
|
|
|
export let disabled: boolean = false
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
2023-08-23 03:11:35 +00:00
|
|
|
$: currentDate = new Date(date)
|
|
|
|
|
2023-08-13 16:28:12 +00:00
|
|
|
function timeClick (e: MouseEvent) {
|
2023-08-23 03:11:35 +00:00
|
|
|
if (!showDate) {
|
2023-08-13 16:28:12 +00:00
|
|
|
showPopup(
|
|
|
|
DatePopup,
|
2023-08-23 03:11:35 +00:00
|
|
|
{ currentDate, withTime: !withoutTime, label: ui.string.SelectDate, noShift: true },
|
2023-08-13 16:28:12 +00:00
|
|
|
undefined,
|
|
|
|
(res) => {
|
|
|
|
if (res) {
|
|
|
|
date = res.value.getTime()
|
|
|
|
dispatch('update', date)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dateClick (e: MouseEvent) {
|
2023-08-23 03:11:35 +00:00
|
|
|
showPopup(SimpleDatePopup, { currentDate }, eventToHTMLElement(e), (res) => {
|
2023-08-13 16:28:12 +00:00
|
|
|
if (res) {
|
|
|
|
date = res.getTime()
|
|
|
|
dispatch('update', date)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-08-23 03:11:35 +00:00
|
|
|
const updateTime = (d?: Date) => {
|
|
|
|
const dat = d ?? currentDate
|
|
|
|
date = dat.getTime()
|
|
|
|
dispatch('update', dat)
|
|
|
|
}
|
2023-08-13 16:28:12 +00:00
|
|
|
</script>
|
|
|
|
|
2023-08-25 09:49:14 +00:00
|
|
|
<div
|
|
|
|
class="dateEditor-container {direction}"
|
|
|
|
class:difference={difference > 0}
|
|
|
|
class:gap-1-5={direction === 'horizontal'}
|
|
|
|
>
|
2023-08-13 16:28:12 +00:00
|
|
|
{#if showDate || withoutTime}
|
2023-10-23 04:09:10 +00:00
|
|
|
<Button {kind} {size} padding={'0 .5rem'} on:click={dateClick} {disabled}>
|
2023-08-25 09:49:14 +00:00
|
|
|
<svelte:fragment slot="content">
|
2023-08-23 03:11:35 +00:00
|
|
|
<DateLocalePresenter date={currentDate.getTime()} />
|
2023-08-25 09:49:14 +00:00
|
|
|
</svelte:fragment>
|
2023-08-13 16:28:12 +00:00
|
|
|
</Button>
|
|
|
|
{/if}
|
|
|
|
{#if !withoutTime}
|
2023-10-23 04:09:10 +00:00
|
|
|
<Button {kind} {size} padding={'0 .5rem'} on:click={timeClick} {disabled}>
|
2023-08-23 03:11:35 +00:00
|
|
|
<svelte:fragment slot="content">
|
2023-11-20 10:01:43 +00:00
|
|
|
<TimeInputBox
|
|
|
|
bind:currentDate
|
|
|
|
noBorder
|
|
|
|
size={'small'}
|
|
|
|
on:update={(date) => {
|
|
|
|
updateTime(date.detail)
|
|
|
|
}}
|
|
|
|
/>
|
2023-08-25 09:49:14 +00:00
|
|
|
{#if difference > 0}
|
|
|
|
<div class="ml-2 flex-no-shrink content-darker-color overflow-label">
|
|
|
|
<TimeShiftPresenter value={date - difference} exact />
|
|
|
|
</div>
|
|
|
|
{/if}
|
2023-08-23 03:11:35 +00:00
|
|
|
</svelte:fragment>
|
2023-08-13 16:28:12 +00:00
|
|
|
</Button>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2023-08-23 03:11:35 +00:00
|
|
|
.dateEditor-container {
|
2023-08-13 16:28:12 +00:00
|
|
|
display: flex;
|
2023-08-23 03:11:35 +00:00
|
|
|
flex-wrap: nowrap;
|
2023-08-13 16:28:12 +00:00
|
|
|
|
2023-08-23 03:11:35 +00:00
|
|
|
&.horizontal {
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
&.vertical {
|
|
|
|
flex-direction: column;
|
2023-08-25 09:49:14 +00:00
|
|
|
|
|
|
|
&.difference {
|
|
|
|
align-items: start;
|
|
|
|
}
|
|
|
|
&:not(.difference) {
|
|
|
|
align-items: stretch;
|
|
|
|
}
|
2023-08-23 03:11:35 +00:00
|
|
|
}
|
2023-08-13 16:28:12 +00:00
|
|
|
}
|
|
|
|
</style>
|