-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(date picker): add date picker component
change behaviour of number input: now adding seperate dates instead of having all dates be the same in all search bars
- Loading branch information
1 parent
f0a68d2
commit a5c614b
Showing
6 changed files
with
151 additions
and
108 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
94 changes: 94 additions & 0 deletions
94
packages/lib/src/components/catalogue/DatePickerComponent.svelte
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,94 @@ | ||
<script lang="ts"> | ||
import type { Category } from "../../types/treeData"; | ||
import { catalogueTextStore } from "../../stores/texts"; | ||
import QueryAddButtonComponent from "./QueryAddButtonComponent.svelte"; | ||
import type { QueryItem } from "../../types/queryData"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
export let element: Category; | ||
let from: string = element.min || "1900-01-01"; | ||
let to: string = element.max || new Date().toISOString().split("T")[0]; | ||
/** | ||
* build the proper name for the query value | ||
* @returns the "from", "≥ from", "≤ to", "from - to" or "invalid" | ||
*/ | ||
const transformName = (): string => { | ||
if (from === to) return `${from}`; | ||
if (!to && from) return `≥ ${from}`; | ||
if (!from && to) return `≤ ${to}`; | ||
if (from < to) return ` ${from} - ${to}`; | ||
return "invalid"; | ||
}; | ||
/** | ||
* builds the query item each time the values change | ||
*/ | ||
let queryItem: QueryItem; | ||
$: queryItem = { | ||
id: uuidv4(), | ||
key: element.key, | ||
name: element.name, | ||
type: "type" in element && element.type, | ||
values: [ | ||
{ | ||
name: transformName(), | ||
value: { min: from, max: to }, | ||
queryBindId: uuidv4(), | ||
}, | ||
], | ||
}; | ||
/** | ||
* when the fields loose focus, the values are reset to the starting values | ||
*/ | ||
const handleInputFrom = (): void => { | ||
if (from === null || from === "" || from === undefined) { | ||
from = element.min || new Date().toISOString().split("T")[0]; | ||
} | ||
}; | ||
const handleInputTo = (): void => { | ||
if (to === null || to === "" || to === undefined) { | ||
to = element.max || new Date().toISOString().split("T")[0]; | ||
} | ||
}; | ||
</script> | ||
|
||
<div part="criterion-wrapper date-input-wrapper"> | ||
<div part="criterion-item"> | ||
<div part="criterion-section criterion-section-values"> | ||
<label | ||
part="date-input-label date-input-values-label lens-date-input-values-label-from" | ||
> | ||
{$catalogueTextStore.numberInput.labelFrom} | ||
<input | ||
part="date-input-formfield date-input-formfield-from {to && | ||
from > to | ||
? ' formfield-error' | ||
: ''}" | ||
type="date" | ||
bind:value={from} | ||
on:focusout={handleInputFrom} | ||
/> | ||
</label> | ||
|
||
<label | ||
part="date-input-label date-input-values-label lens-date-input-values-label-to" | ||
> | ||
{$catalogueTextStore.numberInput.labelTo} | ||
<input | ||
part="date-input-formfield date-input-formfield-to{to && | ||
from > to | ||
? ' formfield-error' | ||
: ''}" | ||
type="date" | ||
bind:value={to} | ||
on:focusout={handleInputTo} | ||
/> | ||
</label> | ||
</div> | ||
<QueryAddButtonComponent {queryItem} /> | ||
</div> | ||
</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