helper.sjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function keys(obj) {
  2. if (typeof Object.keys === 'function') {
  3. return Object.keys(obj);
  4. }
  5. }
  6. function getClassName(value, index) {
  7. var isSelected = value.isSelected,
  8. isSelectedBegin = value.isSelectedBegin,
  9. isSelectedEnd = value.isSelectedEnd,
  10. isRowBegin = value.isRowBegin,
  11. isRowEnd = value.isRowEnd,
  12. inThisMonth = value.inThisMonth,
  13. isToday = value.isToday,
  14. disabled = value.disabled;
  15. var classNames = {
  16. disabled: disabled,
  17. today: inThisMonth && isToday,
  18. selected: inThisMonth && isSelected,
  19. 'selected-begin': inThisMonth && isSelectedBegin,
  20. 'selected-end': inThisMonth && isSelectedEnd,
  21. 'selected-row-begin': inThisMonth && isRowBegin && isSelected,
  22. 'selected-row-end': inThisMonth && isRowEnd && isSelected,
  23. hidden: !inThisMonth,
  24. 'row-end': index % 7 === 6
  25. };
  26. var result = 'ant-calendar-cell';
  27. keys(classNames).forEach(function (key) {
  28. if (classNames[key]) {
  29. result += " ant-calendar-cell-".concat(key);
  30. }
  31. });
  32. return result;
  33. }
  34. function getSpaceClassName(index, items) {
  35. var isNotEnd = index % 7 !== 6;
  36. var nextItem = items[index + 1];
  37. var nextSelected = nextItem && nextItem.isSelected && nextItem.inThisMonth;
  38. var isSelected = items[index].isSelected;
  39. var classNames = {
  40. active: isNotEnd && isSelected && nextSelected
  41. };
  42. var result = 'ant-calendar-cell-space';
  43. keys(classNames).forEach(function (key) {
  44. if (classNames[key]) {
  45. result += " ant-calendar-cell-space-".concat(key);
  46. }
  47. });
  48. return result;
  49. }
  50. function getMarkCellClassName(index, items) {
  51. if (items[index].length - 1 === index) {
  52. return "ant-calendar-mark-cell ant-calendar-mark-cell-last";
  53. }
  54. return 'ant-calendar-mark-cell';
  55. }
  56. export default {
  57. getSpaceClassName: getSpaceClassName,
  58. getClassName: getClassName,
  59. getMarkCellClassName: getMarkCellClassName
  60. };