@chayns-components/date
Version:
A set of beautiful React components for developing your own applications with chayns.
33 lines • 1.11 kB
JavaScript
import React, { useMemo } from 'react';
import { StyledWeekdayWrapper } from './WeekdayWrapper.styles';
import Weekday from './weekday/Weekday';
import { eachDayOfInterval, endOfWeek, startOfWeek } from '../../../../../utils/date';
const WeekdayWrapper = ({
locale
}) => {
const monday = startOfWeek(new Date());
const sunday = endOfWeek(new Date());
const weekdays = eachDayOfInterval({
start: monday,
end: sunday
});
const weekdayElements = useMemo(() => {
const items = [];
weekdays.forEach(day => {
const options = {
weekday: 'short'
};
const formatter = new Intl.DateTimeFormat(locale, options);
const formattedDay = formatter.format(day);
items.push(/*#__PURE__*/React.createElement(Weekday, {
key: `weekday-${formattedDay}`,
name: formattedDay
}));
});
return items;
}, [locale, weekdays]);
return /*#__PURE__*/React.createElement(StyledWeekdayWrapper, null, weekdayElements);
};
WeekdayWrapper.displayName = 'WeekdayWrapper';
export default WeekdayWrapper;
//# sourceMappingURL=WeekdayWrapper.js.map