useToggleDates.js 703 B

123456789101112131415161718192021
  1. import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
  2. import { isSame } from "../utils/dateUtil";
  3. /**
  4. * Toggles the presence of a value in an array.
  5. * If the value exists in the array, removed it.
  6. * Else add it.
  7. */
  8. export default function useToggleDates(generateConfig, locale, panelMode) {
  9. function toggleDates(list, target) {
  10. var index = list.findIndex(function (date) {
  11. return isSame(generateConfig, locale, date, target, panelMode);
  12. });
  13. if (index === -1) {
  14. return [].concat(_toConsumableArray(list), [target]);
  15. }
  16. var sliceList = _toConsumableArray(list);
  17. sliceList.splice(index, 1);
  18. return sliceList;
  19. }
  20. return toggleDates;
  21. }