[#MUI-33] Développer le composant Datepicker (#50)
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #50 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #50.
This commit is contained in:
31
app/components/malio/date/composables/dateRange.ts
Normal file
31
app/components/malio/date/composables/dateRange.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export type DateRangeValue = {start: string; end: string}
|
||||
|
||||
export function normalizeRange(a: string, b: string): DateRangeValue {
|
||||
return a <= b ? {start: a, end: b} : {start: b, end: a}
|
||||
}
|
||||
|
||||
export function resolveRangeBounds(
|
||||
start: string | null,
|
||||
end: string | null,
|
||||
preview: string | null,
|
||||
): {lo: string; hi: string} | null {
|
||||
if (!start) return null
|
||||
const other = end ?? preview
|
||||
if (!other) return {lo: start, hi: start}
|
||||
return start <= other ? {lo: start, hi: other} : {lo: other, hi: start}
|
||||
}
|
||||
|
||||
export type DayRangeRole = 'none' | 'single' | 'start' | 'end' | 'in-range'
|
||||
|
||||
export function dayRangeRole(
|
||||
iso: string,
|
||||
bounds: {lo: string; hi: string} | null,
|
||||
): DayRangeRole {
|
||||
if (!bounds) return 'none'
|
||||
const {lo, hi} = bounds
|
||||
if (lo === hi) return iso === lo ? 'single' : 'none'
|
||||
if (iso === lo) return 'start'
|
||||
if (iso === hi) return 'end'
|
||||
if (iso > lo && iso < hi) return 'in-range'
|
||||
return 'none'
|
||||
}
|
||||
Reference in New Issue
Block a user