-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Add date format (#3675)
* feat(frontend): Add date format * feat(frontend): Add date format * feat(frontend): add missing case * feat(frontend): add date format * fix(frontend): added missing tooltip + added default value to the date component
- Loading branch information
1 parent
b656236
commit 86d958e
Showing
10 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
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,56 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte' | ||
import { format, isValid } from 'date-fns' | ||
export let value: string | undefined = undefined | ||
export let autofocus: boolean | null = false | ||
export let minDate: string | undefined = undefined | ||
export let maxDate: string | undefined = undefined | ||
export let dateFormat: string | undefined = 'dd-MM-yyyy' | ||
let date: string | undefined = undefined | ||
const dispatch = createEventDispatcher() | ||
function updateValue(newDate: string | undefined) { | ||
if (newDate && isValid(new Date(newDate))) { | ||
if (dateFormat === undefined) { | ||
dateFormat = 'dd-MM-yyyy' | ||
} | ||
try { | ||
let dateFromValue: Date | undefined = newDate ? new Date(newDate) : undefined | ||
if (dateFromValue === undefined) { | ||
return | ||
} | ||
const parsedDate = format(dateFromValue, dateFormat) | ||
value = parsedDate | ||
dispatch('change', value) | ||
} catch (error) { | ||
console.error('Failed to parse date:', error) | ||
return | ||
} | ||
} | ||
} | ||
let randomId = 'datetarget-' + Math.random().toString(36).substring(7) | ||
</script> | ||
|
||
<div class="flex flex-row gap-1 items-center w-full" id={randomId} on:pointerdown on:focus> | ||
<input | ||
type="date" | ||
bind:value={date} | ||
{autofocus} | ||
class="!w-full app-editor-input" | ||
min={minDate} | ||
max={maxDate} | ||
on:change={() => { | ||
if (date) { | ||
updateValue(date) | ||
} | ||
}} | ||
/> | ||
</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
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