@talend/react-components
Version:
Set of react components.
51 lines • 1.84 kB
JavaScript
import classNames from 'classnames';
import { format } from 'date-fns/format';
import { setMonth } from 'date-fns/setMonth';
import { setYear } from 'date-fns/setYear';
import PropTypes from 'prop-types';
import { Action, ActionDropdown } from '../../../Actions';
import { getPickerLocale } from '../../generator';
import YearPicker from '../../pickers/YearPicker';
import theme from './HeaderTitle.module.scss';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function HeaderTitle(props) {
const isButton = !!props.button;
const className = classNames({
'btn-tertiary btn-info': isButton
}, props.className);
const pickerLocale = getPickerLocale();
const date = setYear(setMonth(new Date(0), props.monthIndex), props.year);
const yearLabel = format(date, 'yyyy', pickerLocale);
const monthLabel = format(date, 'MMMM', pickerLocale);
return /*#__PURE__*/_jsxs("div", {
className: theme.common,
children: [/*#__PURE__*/_jsx("div", {
className: theme.month,
children: isButton ? /*#__PURE__*/_jsx(Action, {
className: className,
label: monthLabel,
...props.button
}) : /*#__PURE__*/_jsx("span", {
className: className,
children: monthLabel
})
}), /*#__PURE__*/_jsx(ActionDropdown, {
className: "btn-tertiary btn-info",
label: yearLabel,
children: /*#__PURE__*/_jsx(YearPicker, {
id: "year-picker-in-datetime-header",
"data-feature": "actiondropdown.items",
onSelect: props.onSelectYear
})
})]
});
}
HeaderTitle.propTypes = {
monthIndex: PropTypes.number.isRequired,
year: PropTypes.number.isRequired,
button: PropTypes.object,
className: PropTypes.string,
onSelectYear: PropTypes.func
};
export default HeaderTitle;
//# sourceMappingURL=HeaderTitle.component.js.map