VDateRangePickerHeader.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
  2. // Styles
  3. import "./VDateRangePickerHeader.css";
  4. // Components
  5. import { VBtn } from "../../components/VBtn/index.mjs"; // Composables
  6. import { useBackgroundColor } from "../../composables/color.mjs";
  7. import { useLocale } from "../../composables/locale.mjs";
  8. import { useDate } from "../date/index.mjs";
  9. import { makeDateProps } from "../VDateInput/composables.mjs"; // Utilities
  10. import { computed } from 'vue';
  11. import { genericComponent, omit, propsFactory, useRender } from "../../util/index.mjs";
  12. export const makeVDateRangePickerHeaderProps = propsFactory({
  13. color: String,
  14. title: String,
  15. header: String,
  16. keyboardIcon: {
  17. type: String,
  18. default: '$edit'
  19. },
  20. calendarIcon: {
  21. type: String,
  22. default: '$calendar'
  23. },
  24. closeIcon: {
  25. type: String,
  26. default: '$close'
  27. },
  28. showInputSwitch: Boolean,
  29. range: null,
  30. ...omit(makeDateProps(), ['viewMode', 'format'])
  31. }, 'VDateRangePickerHeader');
  32. export const VDateRangePickerHeader = genericComponent()({
  33. name: 'VDateRangePickerHeader',
  34. props: makeVDateRangePickerHeaderProps(),
  35. emits: {
  36. cancel: () => true,
  37. save: () => true,
  38. 'update:inputMode': input => true,
  39. 'update:displayDate': date => true
  40. },
  41. setup(props, _ref) {
  42. let {
  43. emit
  44. } = _ref;
  45. const {
  46. t
  47. } = useLocale();
  48. const adapter = useDate();
  49. const {
  50. backgroundColorClasses,
  51. backgroundColorStyles
  52. } = useBackgroundColor(props, 'color');
  53. const headerText = computed(() => {
  54. if (props.header) return props.header;
  55. if (!props.modelValue.length) return t(`$vuetify.datePicker.${props.range ? 'range.' : ''}header.placeholder`);
  56. if (props.modelValue.length === 1) return adapter.format(props.modelValue[0], 'normalDateWithWeekday');
  57. return props.modelValue.map(date => adapter.format(date, 'shortDate')).join(' - ');
  58. });
  59. const titleText = computed(() => {
  60. if (props.title) return props.title;
  61. if (!props.modelValue.length) return t(`$vuetify.datePicker.${props.range ? 'range.' : ''}title.placeholder`);
  62. return t(`$vuetify.datePicker.${props.range ? 'range.' : ''}title.selected`);
  63. });
  64. function handleHeaderClick() {
  65. if (!props.modelValue.length) return;
  66. const date = props.modelValue[0];
  67. emit('update:displayDate', date);
  68. }
  69. useRender(() => _createVNode("div", {
  70. "class": ['v-date-range-picker-header', backgroundColorClasses.value, `v-date-range-picker-header--${props.inputMode}`],
  71. "style": backgroundColorStyles.value
  72. }, [props.inputMode === 'calendar' && _createVNode("div", {
  73. "key": "calendar-buttons",
  74. "class": "v-date-range-picker-header__buttons"
  75. }, [_createVNode(VBtn, {
  76. "variant": "text",
  77. "icon": props.closeIcon,
  78. "onClick": () => emit('cancel')
  79. }, null), _createVNode(VBtn, {
  80. "variant": "text",
  81. "onClick": () => emit('save')
  82. }, {
  83. default: () => [_createTextVNode("Save")]
  84. })]), _createVNode("div", {
  85. "class": "v-date-range-picker-header__wrapper"
  86. }, [_createVNode("div", {
  87. "class": "v-date-range-picker-header__title"
  88. }, [titleText.value]), _createVNode("div", {
  89. "class": "v-date-range-picker-header__text"
  90. }, [_createVNode("div", {
  91. "class": "v-date-range-picker-header__date",
  92. "onClick": handleHeaderClick
  93. }, [headerText.value]), _createVNode(VBtn, {
  94. "variant": "text",
  95. "icon": props.inputMode === 'keyboard' ? props.calendarIcon : props.keyboardIcon,
  96. "onClick": () => emit('update:inputMode', props.inputMode === 'keyboard' ? 'calendar' : 'keyboard')
  97. }, null)])])]));
  98. return {};
  99. }
  100. });
  101. //# sourceMappingURL=VDateRangePickerHeader.mjs.map