UNPKG

wix-style-react

Version:
42 lines (35 loc) 1.1 kB
import React from 'react'; import PropTypes from 'prop-types'; import setMonth from 'date-fns/set_month'; import DatePickerDropdown from '../DatePickerDropdown'; var optionsOf = function optionsOf(items) { return items.map(function (item, index) { return { value: item, id: index }; }); }; var MonthDropdown = function MonthDropdown(_ref) { var months = _ref.months, date = _ref.date, _onChange = _ref.onChange; var options = optionsOf(months); var selectedMonth = options.find(function (_ref2) { var id = _ref2.id; return id === date.getMonth(); }); return React.createElement(DatePickerDropdown, { dataHook: 'datepicker-month-dropdown', caption: selectedMonth.value, options: options, selectedId: selectedMonth.id, onChange: function onChange(_ref3) { var id = _ref3.id; return _onChange(setMonth(date, id)); } }); }; MonthDropdown.propTypes = { months: PropTypes.arrayOf(PropTypes.string).isRequired, date: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired }; export default MonthDropdown;