@renderlesskit/react
Version:
Collection of headless components/hooks that are accessible, composable, customizable from low level to build your own UI & Design System powered by Reakit
46 lines (45 loc) • 1.36 kB
JavaScript
/**
* All credit goes to [React Spectrum](https://github.com/adobe/react-spectrum)
* for these utils inspiration
*/
import { useDateFormatter } from "@react-aria/i18n";
import { setDay, toUTCString } from "../../utils";
export function useWeekDays(weekStart) {
var dayFormatter = useDateFormatter({
weekday: "short"
});
var dayFormatterLong = useDateFormatter({
weekday: "long"
});
return [0, 1, 2, 3, 4, 5, 6].map(index => {
var dateDay = setDay(Date.now(), (index + weekStart) % 7);
var day = dayFormatter.format(dateDay);
var dayLong = dayFormatterLong.format(dateDay);
return {
title: dayLong,
abbr: day
};
});
}
export function generateDaysInMonthArray(month, monthStartsAt, weeksInMonth, year) {
return Array(weeksInMonth).fill(1).reduce((weeks, _, weekIndex) => {
var daysInWeek = [0, 1, 2, 3, 4, 5, 6].reduce((days, dayIndex) => {
var day = weekIndex * 7 + dayIndex - monthStartsAt + 2;
var utcDate = toUTCString(new Date(year, month, day));
var cellDate = new Date(utcDate);
return [...days, cellDate];
}, []);
return [...weeks, daysInWeek];
}, []);
}
export function makeRange(start, end) {
if (end < start) {
[start, end] = [end, start];
}
return {
start,
end
};
}
export * from "./useWeekStart";
//# sourceMappingURL=index.js.map