Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+12
View File
@@ -0,0 +1,12 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps, Selection } from "../types/index.js";
/**
* Hook to manage multiple-date selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected dates, a function to select dates,
* and a function to check if a date is selected.
*/
export declare function useMulti<T extends DayPickerProps>(props: T, dateLib: DateLib): Selection<T>;
+57
View File
@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMulti = useMulti;
const useControlledValue_js_1 = require("../helpers/useControlledValue.js");
/**
* Hook to manage multiple-date selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected dates, a function to select dates,
* and a function to check if a date is selected.
*/
function useMulti(props, dateLib) {
const { selected: initiallySelected, required, onSelect, } = props;
const [internallySelected, setSelected] = (0, useControlledValue_js_1.useControlledValue)(initiallySelected, onSelect ? initiallySelected : undefined);
const selected = !onSelect ? internallySelected : initiallySelected;
const { isSameDay } = dateLib;
const isSelected = (date) => {
return selected?.some((d) => isSameDay(d, date)) ?? false;
};
const { min, max } = props;
const select = (triggerDate, modifiers, e) => {
let newDates = [...(selected ?? [])];
if (isSelected(triggerDate)) {
if (selected?.length === min) {
// Min value reached, do nothing
return;
}
if (required && selected?.length === 1) {
// Required value already selected do nothing
return;
}
newDates = selected?.filter((d) => !isSameDay(d, triggerDate));
}
else {
if (selected?.length === max) {
// Max value reached, reset the selection to date
newDates = [triggerDate];
}
else {
// Add the date to the selection
newDates = [...newDates, triggerDate];
}
}
if (!onSelect) {
setSelected(newDates);
}
onSelect?.(newDates, triggerDate, modifiers, e);
return newDates;
};
return {
selected,
select,
isSelected,
};
}
+12
View File
@@ -0,0 +1,12 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps, Selection } from "../types/index.js";
/**
* Hook to manage range selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected range, a function to select a
* range, and a function to check if a date is within the range.
*/
export declare function useRange<T extends DayPickerProps>(props: T, dateLib: DateLib): Selection<T>;
+44
View File
@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRange = useRange;
const useControlledValue_js_1 = require("../helpers/useControlledValue.js");
const index_js_1 = require("../utils/index.js");
const rangeIncludesDate_js_1 = require("../utils/rangeIncludesDate.js");
/**
* Hook to manage range selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected range, a function to select a
* range, and a function to check if a date is within the range.
*/
function useRange(props, dateLib) {
const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect, } = props;
const [internallySelected, setSelected] = (0, useControlledValue_js_1.useControlledValue)(initiallySelected, onSelect ? initiallySelected : undefined);
const selected = !onSelect ? internallySelected : initiallySelected;
const isSelected = (date) => selected && (0, rangeIncludesDate_js_1.rangeIncludesDate)(selected, date, false, dateLib);
const select = (triggerDate, modifiers, e) => {
const { min, max } = props;
const newRange = triggerDate
? (0, index_js_1.addToRange)(triggerDate, selected, min, max, required, dateLib)
: undefined;
if (excludeDisabled && disabled && newRange?.from && newRange.to) {
if ((0, index_js_1.rangeContainsModifiers)({ from: newRange.from, to: newRange.to }, disabled, dateLib)) {
// if a disabled days is found, the range is reset
newRange.from = triggerDate;
newRange.to = undefined;
}
}
if (!onSelect) {
setSelected(newRange);
}
onSelect?.(newRange, triggerDate, modifiers, e);
return newRange;
};
return {
selected,
select,
isSelected,
};
}
+17
View File
@@ -0,0 +1,17 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DayPickerProps, SelectedValue, SelectHandler, Selection } from "../types/index.js";
export type UseSingle<T extends DayPickerProps> = {
select: SelectHandler<T>;
isSelected: (date: Date) => boolean;
selected: SelectedValue<T>;
};
/**
* Hook to manage single-date selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected date, a function to select a date,
* and a function to check if a date is selected.
*/
export declare function useSingle<T extends DayPickerProps>(props: DayPickerProps, dateLib: DateLib): Selection<T>;
+44
View File
@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSingle = useSingle;
const useControlledValue_js_1 = require("../helpers/useControlledValue.js");
/**
* Hook to manage single-date selection in the DayPicker component.
*
* @template T - The type of DayPicker props.
* @param props - The DayPicker props.
* @param dateLib - The date utility library instance.
* @returns An object containing the selected date, a function to select a date,
* and a function to check if a date is selected.
*/
function useSingle(props, dateLib) {
const { selected: initiallySelected, required, onSelect, } = props;
const [internallySelected, setSelected] = (0, useControlledValue_js_1.useControlledValue)(initiallySelected, onSelect ? initiallySelected : undefined);
const selected = !onSelect ? internallySelected : initiallySelected;
const { isSameDay } = dateLib;
const isSelected = (compareDate) => {
return selected ? isSameDay(selected, compareDate) : false;
};
const select = (triggerDate, modifiers, e) => {
let newDate = triggerDate;
if (!required && selected && selected && isSameDay(triggerDate, selected)) {
// If the date is the same, clear the selection.
newDate = undefined;
}
if (!onSelect) {
setSelected(newDate);
}
if (required) {
onSelect?.(newDate, triggerDate, modifiers, e);
}
else {
onSelect?.(newDate, triggerDate, modifiers, e);
}
return newDate;
};
return {
selected,
select,
isSelected,
};
}