Rocky_Mountain_Vending/.pnpm-store/v10/files/82/83da3c02f99165032075c3f273db951f6999ced081c97c3ff208523c08454c8b3f9d0c7839b221d237cb103e30039282f4002f1da75dec331580c4ba268a75
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

42 lines
No EOL
1.8 KiB
Text

import { useControlledValue } from "../helpers/useControlledValue.js";
import { addToRange, rangeContainsModifiers } from "../utils/index.js";
import { rangeIncludesDate } from "../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.
*/
export function useRange(props, dateLib) {
const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect } = props;
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : undefined);
const selected = !onSelect ? internallySelected : initiallySelected;
const isSelected = (date) => selected && rangeIncludesDate(selected, date, false, dateLib);
const select = (triggerDate, modifiers, e) => {
const { min, max } = props;
const newRange = triggerDate
? addToRange(triggerDate, selected, min, max, required, dateLib)
: undefined;
if (excludeDisabled && disabled && newRange?.from && newRange.to) {
if (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
};
}
//# sourceMappingURL=useRange.js.map