@shopgate/engage
Version:
Shopgate's ENGAGE library.
38 lines (37 loc) • 1.09 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { i18n } from "../../../core";
import { storeHoursToday } from "./Store.style";
import { jsx as _jsx } from "react/jsx-runtime";
const weekdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
/**
* Renders the store's opening hours for "today".
* @param {Object} props The component props.
* @param {Object} props.hours The store's opening hours.
* @param {boolean} props.longLabel Whether to render the opening hours with a long label
* @returns {JSX.Element}
*/
export function StoreHoursToday({
hours,
longLabel
}) {
if (!hours) {
return null;
}
const today = weekdays[new Date().getDay()];
const hoursToday = hours[today] || null;
if (!hoursToday || hoursToday === '') {
return null;
}
const label = longLabel ? 'locations.today_hours_long' : 'locations.today_hours';
return /*#__PURE__*/_jsx("div", {
className: storeHoursToday,
children: i18n.text(label, {
hours: hoursToday
})
});
}
StoreHoursToday.defaultProps = {
hours: null,
longLabel: false
};