@varlet/ui 3.18.2 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/action-sheet/ActionItem.mjs +28 -8
- package/es/action-sheet/actionSheet.css +1 -1
- package/es/action-sheet/index.mjs +4 -2
- package/es/action-sheet/style/index.mjs +1 -1
- package/es/alert/alert.css +1 -1
- package/es/badge/Badge.mjs +20 -10
- package/es/badge/badge.css +1 -1
- package/es/bottom-navigation-item/BottomNavigationItem.mjs +34 -20
- package/es/bottom-navigation-item/bottomNavigationItem.css +1 -1
- package/es/checkbox/Checkbox.mjs +45 -22
- package/es/checkbox/checkbox.css +1 -1
- package/es/chip/Chip.mjs +11 -4
- package/es/chip/chip.css +1 -1
- package/es/chip/props.mjs +4 -0
- package/es/date-input/DateInput.mjs +865 -0
- package/es/date-input/DateInputSfc.css +0 -0
- package/es/date-input/TimeSelect.mjs +201 -0
- package/es/date-input/date-input.css +1 -0
- package/es/date-input/index.mjs +12 -0
- package/es/date-input/props.mjs +77 -0
- package/es/date-input/style/index.mjs +14 -0
- package/es/date-picker/DatePicker.mjs +522 -451
- package/es/date-picker/DayPickerPanel.mjs +318 -0
- package/es/date-picker/MonthPickerPanel.mjs +187 -0
- package/es/date-picker/PanelHeader.mjs +332 -0
- package/es/date-picker/YearPickerPanel.mjs +199 -0
- package/es/date-picker/constants.mjs +31 -0
- package/es/date-picker/date-picker.css +1 -1
- package/es/date-picker/props.mjs +6 -9
- package/es/date-picker/style/index.mjs +0 -1
- package/es/date-picker/types.mjs +0 -0
- package/es/field-decorator/fieldDecorator.css +1 -1
- package/es/icon/icon.css +1 -1
- package/es/index.bundle.mjs +7 -1
- package/es/index.mjs +6 -1
- package/es/input/props.mjs +1 -1
- package/es/locale/en-US.mjs +2 -0
- package/es/locale/fa-IR.mjs +2 -0
- package/es/locale/ja-JP.mjs +2 -0
- package/es/locale/zh-CN.mjs +2 -0
- package/es/locale/zh-TW.mjs +2 -0
- package/es/menu-select/MenuSelect.mjs +11 -2
- package/es/menu-select/menuSelect.css +1 -1
- package/es/radio/Radio.mjs +30 -14
- package/es/radio/radio.css +1 -1
- package/es/rail-navigation-item/RailNavigationItem.mjs +33 -19
- package/es/rail-navigation-item/railNavigationItem.css +1 -1
- package/es/rate/Rate.mjs +23 -12
- package/es/rate/rate.css +1 -1
- package/es/select/Select.mjs +10 -1
- package/es/select/select.css +1 -1
- package/es/step/Step.mjs +50 -20
- package/es/step/step.css +1 -1
- package/es/style.mjs +1 -0
- package/es/themes/dark/alert.mjs +2 -2
- package/es/themes/dark/dateInput.mjs +9 -0
- package/es/themes/dark/datePicker.mjs +23 -19
- package/es/themes/dark/index.mjs +3 -2
- package/es/themes/md3-dark/alert.mjs +2 -2
- package/es/themes/md3-dark/dateInput.mjs +9 -0
- package/es/themes/md3-dark/datePicker.mjs +18 -13
- package/es/themes/md3-dark/index.mjs +3 -2
- package/es/themes/md3-light/alert.mjs +2 -2
- package/es/themes/md3-light/dateInput.mjs +9 -0
- package/es/themes/md3-light/datePicker.mjs +18 -13
- package/es/themes/md3-light/index.mjs +3 -2
- package/es/utils/elements.mjs +7 -0
- package/es/utils/shared.mjs +15 -0
- package/es/varlet.css +1 -1
- package/es/varlet.esm.js +11893 -10656
- package/highlight/web-types.en-US.json +599 -73
- package/highlight/web-types.zh-CN.json +572 -67
- package/lib/varlet.cjs.js +5592 -4211
- package/lib/varlet.css +1 -1
- package/package.json +7 -7
- package/types/actionSheet.d.ts +1 -1
- package/types/badge.d.ts +1 -0
- package/types/chip.d.ts +3 -0
- package/types/dateInput.d.ts +96 -0
- package/types/datePicker.d.ts +4 -2
- package/types/index.d.ts +2 -0
- package/types/locale.d.ts +2 -0
- package/types/rate.d.ts +7 -0
- package/types/step.d.ts +3 -0
- package/types/styleVars.d.ts +14 -4
- package/umd/varlet.js +7 -7
- package/es/date-picker/src/day-picker-panel.mjs +0 -385
- package/es/date-picker/src/month-picker-panel.mjs +0 -300
- package/es/date-picker/src/panel-header.mjs +0 -142
- package/es/date-picker/src/year-picker-panel.mjs +0 -311
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { onSmartMounted } from "@varlet/use";
|
|
18
|
+
import { computed, defineComponent, ref, watch } from "vue";
|
|
19
|
+
import VarButton from "../button/index.mjs";
|
|
20
|
+
import { t } from "../locale/index.mjs";
|
|
21
|
+
import { injectLocaleProvider } from "../locale-provider/provide.mjs";
|
|
22
|
+
import { createNamespace } from "../utils/components.mjs";
|
|
23
|
+
import { createDayjs } from "../utils/shared.mjs";
|
|
24
|
+
import { DatePickerFormats, DatePickerUnits, ShiftDirections, WeekHeader } from "./constants.mjs";
|
|
25
|
+
const dayjs = createDayjs();
|
|
26
|
+
const DAYS_PER_WEEK = 7;
|
|
27
|
+
const WEEKS_PER_PANEL = 6;
|
|
28
|
+
const MonthOffset = {
|
|
29
|
+
Prev: -1,
|
|
30
|
+
Current: 0,
|
|
31
|
+
Next: 1
|
|
32
|
+
};
|
|
33
|
+
const { n } = createNamespace("day-picker");
|
|
34
|
+
const { n: nDate } = createNamespace("date-picker");
|
|
35
|
+
import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, mergeProps as _mergeProps, withCtx as _withCtx, createVNode as _createVNode, Transition as _Transition } from "vue";
|
|
36
|
+
function __render__(_ctx, _cache) {
|
|
37
|
+
const _component_var_button = _resolveComponent("var-button");
|
|
38
|
+
return _openBlock(), _createElementBlock(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
class: _normalizeClass(_ctx.n())
|
|
42
|
+
},
|
|
43
|
+
[
|
|
44
|
+
_createElementVNode(
|
|
45
|
+
"div",
|
|
46
|
+
{
|
|
47
|
+
class: _normalizeClass(_ctx.n("content"))
|
|
48
|
+
},
|
|
49
|
+
[
|
|
50
|
+
_createVNode(_Transition, {
|
|
51
|
+
name: `${_ctx.nDate()}${_ctx.reverse ? "-reverse" : ""}-translatex`
|
|
52
|
+
}, {
|
|
53
|
+
default: _withCtx(() => [
|
|
54
|
+
(_openBlock(), _createElementBlock("div", { key: _ctx.panelKey }, [
|
|
55
|
+
_createElementVNode(
|
|
56
|
+
"ul",
|
|
57
|
+
{
|
|
58
|
+
class: _normalizeClass(_ctx.n("head"))
|
|
59
|
+
},
|
|
60
|
+
[
|
|
61
|
+
(_openBlock(true), _createElementBlock(
|
|
62
|
+
_Fragment,
|
|
63
|
+
null,
|
|
64
|
+
_renderList(_ctx.sortWeekList, (week) => {
|
|
65
|
+
return _openBlock(), _createElementBlock(
|
|
66
|
+
"li",
|
|
67
|
+
{ key: week },
|
|
68
|
+
_toDisplayString(_ctx.getDayAbbr(week)),
|
|
69
|
+
1
|
|
70
|
+
/* TEXT */
|
|
71
|
+
);
|
|
72
|
+
}),
|
|
73
|
+
128
|
|
74
|
+
/* KEYED_FRAGMENT */
|
|
75
|
+
))
|
|
76
|
+
],
|
|
77
|
+
2
|
|
78
|
+
/* CLASS */
|
|
79
|
+
),
|
|
80
|
+
_createElementVNode(
|
|
81
|
+
"ul",
|
|
82
|
+
{
|
|
83
|
+
class: _normalizeClass(_ctx.n("body"))
|
|
84
|
+
},
|
|
85
|
+
[
|
|
86
|
+
(_openBlock(true), _createElementBlock(
|
|
87
|
+
_Fragment,
|
|
88
|
+
null,
|
|
89
|
+
_renderList(_ctx.days, (cell, index) => {
|
|
90
|
+
return _openBlock(), _createElementBlock("li", { key: index }, [
|
|
91
|
+
_createVNode(_component_var_button, _mergeProps({
|
|
92
|
+
type: "primary",
|
|
93
|
+
"var-day-picker-cover": "",
|
|
94
|
+
round: "",
|
|
95
|
+
elevation: _ctx.panelProps.buttonElevation
|
|
96
|
+
}, { ref_for: true }, __spreadValues({}, _ctx.buttonProps(cell)), {
|
|
97
|
+
onClick: ($event) => _ctx.selectDay(cell)
|
|
98
|
+
}), {
|
|
99
|
+
default: _withCtx(() => [
|
|
100
|
+
_createTextVNode(
|
|
101
|
+
_toDisplayString(cell.day),
|
|
102
|
+
1
|
|
103
|
+
/* TEXT */
|
|
104
|
+
)
|
|
105
|
+
]),
|
|
106
|
+
_: 2
|
|
107
|
+
/* DYNAMIC */
|
|
108
|
+
}, 1040, ["elevation", "onClick"])
|
|
109
|
+
]);
|
|
110
|
+
}),
|
|
111
|
+
128
|
|
112
|
+
/* KEYED_FRAGMENT */
|
|
113
|
+
))
|
|
114
|
+
],
|
|
115
|
+
2
|
|
116
|
+
/* CLASS */
|
|
117
|
+
)
|
|
118
|
+
]))
|
|
119
|
+
]),
|
|
120
|
+
_: 1
|
|
121
|
+
/* STABLE */
|
|
122
|
+
}, 8, ["name"])
|
|
123
|
+
],
|
|
124
|
+
2
|
|
125
|
+
/* CLASS */
|
|
126
|
+
)
|
|
127
|
+
],
|
|
128
|
+
2
|
|
129
|
+
/* CLASS */
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const __sfc__ = defineComponent({
|
|
133
|
+
name: "DayPickerPanel",
|
|
134
|
+
components: {
|
|
135
|
+
VarButton
|
|
136
|
+
},
|
|
137
|
+
props: {
|
|
138
|
+
selection: {
|
|
139
|
+
type: Object,
|
|
140
|
+
required: true
|
|
141
|
+
},
|
|
142
|
+
preview: {
|
|
143
|
+
type: Object,
|
|
144
|
+
required: true
|
|
145
|
+
},
|
|
146
|
+
current: {
|
|
147
|
+
type: String,
|
|
148
|
+
required: true
|
|
149
|
+
},
|
|
150
|
+
panelProps: {
|
|
151
|
+
type: Object,
|
|
152
|
+
required: true
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
emits: ["choose-day"],
|
|
156
|
+
setup(props, { emit }) {
|
|
157
|
+
const [, , currentDay] = props.current.split("-");
|
|
158
|
+
const days = ref([]);
|
|
159
|
+
const reverse = ref(false);
|
|
160
|
+
const panelKey = ref(0);
|
|
161
|
+
const { t: pt } = injectLocaleProvider();
|
|
162
|
+
const previewIsSelectedMonth = computed(
|
|
163
|
+
() => props.selection.selectedYear === props.preview.previewYear && props.selection.selectedMonth === props.preview.previewMonth
|
|
164
|
+
);
|
|
165
|
+
const sortWeekList = computed(() => {
|
|
166
|
+
const index = WeekHeader.findIndex((week) => week === props.panelProps.firstDayOfWeek);
|
|
167
|
+
if (index === -1 || index === 0) {
|
|
168
|
+
return [...WeekHeader];
|
|
169
|
+
}
|
|
170
|
+
return [...WeekHeader.slice(index), ...WeekHeader.slice(0, index)];
|
|
171
|
+
});
|
|
172
|
+
function getDayAbbr(key) {
|
|
173
|
+
var _a, _b;
|
|
174
|
+
return (_b = (_a = (pt || t)("datePickerWeekDict")) == null ? void 0 : _a[key].abbr) != null ? _b : "";
|
|
175
|
+
}
|
|
176
|
+
function createCell(dayjsObject, monthOffset) {
|
|
177
|
+
return {
|
|
178
|
+
dateValue: dayjsObject.format(DatePickerFormats.Day),
|
|
179
|
+
day: dayjsObject.date(),
|
|
180
|
+
monthOffset
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function initDays() {
|
|
184
|
+
const {
|
|
185
|
+
preview: { previewMonth, previewYear }
|
|
186
|
+
} = props;
|
|
187
|
+
const firstDayjsObject = dayjs(`${previewYear}-${previewMonth}-01`);
|
|
188
|
+
const lastDayjsObject = firstDayjsObject.endOf(DatePickerUnits.Month);
|
|
189
|
+
const daysInMonth = firstDayjsObject.daysInMonth();
|
|
190
|
+
const leadingCount = Math.max(
|
|
191
|
+
0,
|
|
192
|
+
sortWeekList.value.findIndex((week) => week === `${firstDayjsObject.day()}`)
|
|
193
|
+
);
|
|
194
|
+
const trailingCount = WEEKS_PER_PANEL * DAYS_PER_WEEK - leadingCount - daysInMonth;
|
|
195
|
+
const cells = [];
|
|
196
|
+
for (let offset = leadingCount; offset > 0; offset--) {
|
|
197
|
+
cells.push(createCell(firstDayjsObject.subtract(offset, DatePickerUnits.Day), MonthOffset.Prev));
|
|
198
|
+
}
|
|
199
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
200
|
+
cells.push(createCell(firstDayjsObject.date(day), MonthOffset.Current));
|
|
201
|
+
}
|
|
202
|
+
for (let offset = 1; offset <= trailingCount; offset++) {
|
|
203
|
+
cells.push(createCell(lastDayjsObject.add(offset, DatePickerUnits.Day), MonthOffset.Next));
|
|
204
|
+
}
|
|
205
|
+
days.value = cells;
|
|
206
|
+
}
|
|
207
|
+
function isInRange(dateValue) {
|
|
208
|
+
const { min, max } = props.panelProps;
|
|
209
|
+
const isBeforeMax = max ? dayjs(dateValue).isSameOrBefore(dayjs(max), DatePickerUnits.Day) : true;
|
|
210
|
+
const isAfterMin = min ? dayjs(dateValue).isSameOrAfter(dayjs(min), DatePickerUnits.Day) : true;
|
|
211
|
+
return isBeforeMax && isAfterMin;
|
|
212
|
+
}
|
|
213
|
+
function getSelectedValue() {
|
|
214
|
+
const { selectedYear, selectedMonth, selectedDay } = props.selection;
|
|
215
|
+
return selectedYear && selectedMonth && selectedDay ? `${selectedYear}-${selectedMonth}-${selectedDay}` : void 0;
|
|
216
|
+
}
|
|
217
|
+
function isSingleSelectedDate(dateValue) {
|
|
218
|
+
const selectedDateValue = getSelectedValue();
|
|
219
|
+
return selectedDateValue ? dayjs(dateValue).isSame(dayjs(selectedDateValue), DatePickerUnits.Day) : false;
|
|
220
|
+
}
|
|
221
|
+
function isSelectedDate(dateValue) {
|
|
222
|
+
const {
|
|
223
|
+
selection: { selectedDays, selectedRangeDays },
|
|
224
|
+
panelProps: { range }
|
|
225
|
+
} = props;
|
|
226
|
+
if (!range) {
|
|
227
|
+
return selectedDays.includes(dateValue);
|
|
228
|
+
}
|
|
229
|
+
if (!selectedRangeDays.length) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (selectedRangeDays.length === 1) {
|
|
233
|
+
return dayjs(dateValue).isSame(dayjs(selectedRangeDays[0]), DatePickerUnits.Day);
|
|
234
|
+
}
|
|
235
|
+
const isBeforeMax = dayjs(dateValue).isSameOrBefore(dayjs(selectedRangeDays[1]), DatePickerUnits.Day);
|
|
236
|
+
const isAfterMin = dayjs(dateValue).isSameOrAfter(dayjs(selectedRangeDays[0]), DatePickerUnits.Day);
|
|
237
|
+
return isBeforeMax && isAfterMin;
|
|
238
|
+
}
|
|
239
|
+
function isDateDisabled(dateValue) {
|
|
240
|
+
const { allowedDates } = props.panelProps;
|
|
241
|
+
return !isInRange(dateValue) || (allowedDates ? !allowedDates(dateValue) : false);
|
|
242
|
+
}
|
|
243
|
+
function shouldShowOutline(dateValue, selected, disabled) {
|
|
244
|
+
const { multiple, range, showCurrent } = props.panelProps;
|
|
245
|
+
const current = showCurrent && dayjs(dateValue).isSame(dayjs(props.current), DatePickerUnits.Day);
|
|
246
|
+
if (!current) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if ((range || multiple || previewIsSelectedMonth.value) && disabled) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
if (range || multiple) {
|
|
253
|
+
return !selected;
|
|
254
|
+
}
|
|
255
|
+
return previewIsSelectedMonth.value ? props.selection.selectedDay !== currentDay : true;
|
|
256
|
+
}
|
|
257
|
+
function buttonProps(cell) {
|
|
258
|
+
const {
|
|
259
|
+
panelProps: { color, multiple, range }
|
|
260
|
+
} = props;
|
|
261
|
+
const { dateValue, monthOffset } = cell;
|
|
262
|
+
const isCurrentMonth = monthOffset === MonthOffset.Current;
|
|
263
|
+
const singleSelected = isSingleSelectedDate(dateValue);
|
|
264
|
+
const selected = range || multiple ? isSelectedDate(dateValue) : singleSelected;
|
|
265
|
+
const disabled = isDateDisabled(dateValue);
|
|
266
|
+
const text = disabled || (range || multiple ? !selected : !singleSelected);
|
|
267
|
+
const outline = shouldShowOutline(dateValue, selected, disabled);
|
|
268
|
+
const cover = !disabled && !outline && !selected;
|
|
269
|
+
const textColor = !disabled && outline ? color != null ? color : "" : "";
|
|
270
|
+
return {
|
|
271
|
+
text,
|
|
272
|
+
outline,
|
|
273
|
+
textColor,
|
|
274
|
+
[`${nDate()}-color-cover`]: cover,
|
|
275
|
+
class: [n("button"), { [n("button--usable")]: isCurrentMonth, [n("button--adjacent")]: !isCurrentMonth }],
|
|
276
|
+
disabled
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function shiftPreview(direction) {
|
|
280
|
+
reverse.value = direction === ShiftDirections.Prev;
|
|
281
|
+
panelKey.value += direction === ShiftDirections.Prev ? -1 : 1;
|
|
282
|
+
}
|
|
283
|
+
function shiftYearPreview(direction) {
|
|
284
|
+
reverse.value = direction === ShiftDirections.Prev;
|
|
285
|
+
panelKey.value += direction === ShiftDirections.Prev ? -1 : 1;
|
|
286
|
+
}
|
|
287
|
+
function selectDay(cell) {
|
|
288
|
+
emit("choose-day", cell.day, cell.monthOffset);
|
|
289
|
+
}
|
|
290
|
+
onSmartMounted(() => {
|
|
291
|
+
initDays();
|
|
292
|
+
});
|
|
293
|
+
watch(
|
|
294
|
+
() => props.preview,
|
|
295
|
+
() => {
|
|
296
|
+
initDays();
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
return {
|
|
300
|
+
n,
|
|
301
|
+
nDate,
|
|
302
|
+
days,
|
|
303
|
+
reverse,
|
|
304
|
+
panelKey,
|
|
305
|
+
sortWeekList,
|
|
306
|
+
shiftPreview,
|
|
307
|
+
shiftYearPreview,
|
|
308
|
+
getDayAbbr,
|
|
309
|
+
selectDay,
|
|
310
|
+
buttonProps
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
__sfc__.render = __render__;
|
|
315
|
+
var stdin_default = __sfc__;
|
|
316
|
+
export {
|
|
317
|
+
stdin_default as default
|
|
318
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { defineComponent, ref } from "vue";
|
|
18
|
+
import VarButton from "../button/index.mjs";
|
|
19
|
+
import { t } from "../locale/index.mjs";
|
|
20
|
+
import { injectLocaleProvider } from "../locale-provider/provide.mjs";
|
|
21
|
+
import { createNamespace } from "../utils/components.mjs";
|
|
22
|
+
import { createDayjs } from "../utils/shared.mjs";
|
|
23
|
+
import { DatePickerTypes, DatePickerUnits, MonthList, ShiftDirections } from "./constants.mjs";
|
|
24
|
+
const dayjs = createDayjs();
|
|
25
|
+
const { n } = createNamespace("month-picker");
|
|
26
|
+
const { n: nDate } = createNamespace("date-picker");
|
|
27
|
+
import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, resolveComponent as _resolveComponent, mergeProps as _mergeProps, withCtx as _withCtx, createVNode as _createVNode, Transition as _Transition, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode } from "vue";
|
|
28
|
+
function __render__(_ctx, _cache) {
|
|
29
|
+
const _component_var_button = _resolveComponent("var-button");
|
|
30
|
+
return _openBlock(), _createElementBlock(
|
|
31
|
+
"div",
|
|
32
|
+
{
|
|
33
|
+
class: _normalizeClass(_ctx.n())
|
|
34
|
+
},
|
|
35
|
+
[
|
|
36
|
+
_createElementVNode(
|
|
37
|
+
"div",
|
|
38
|
+
{
|
|
39
|
+
class: _normalizeClass(_ctx.n("content"))
|
|
40
|
+
},
|
|
41
|
+
[
|
|
42
|
+
_createVNode(_Transition, {
|
|
43
|
+
name: `${_ctx.nDate()}${_ctx.reverse ? "-reverse" : ""}-translatex`
|
|
44
|
+
}, {
|
|
45
|
+
default: _withCtx(() => [
|
|
46
|
+
(_openBlock(), _createElementBlock("ul", { key: _ctx.panelKey }, [
|
|
47
|
+
(_openBlock(true), _createElementBlock(
|
|
48
|
+
_Fragment,
|
|
49
|
+
null,
|
|
50
|
+
_renderList(_ctx.MonthList, (month) => {
|
|
51
|
+
return _openBlock(), _createElementBlock("li", { key: month }, [
|
|
52
|
+
_createVNode(_component_var_button, _mergeProps({
|
|
53
|
+
type: "primary",
|
|
54
|
+
"var-month-picker-cover": "",
|
|
55
|
+
elevation: _ctx.panelProps.buttonElevation
|
|
56
|
+
}, { ref_for: true }, __spreadValues({}, _ctx.buttonProps(month)), {
|
|
57
|
+
onClick: ($event) => _ctx.selectMonth(month)
|
|
58
|
+
}), {
|
|
59
|
+
default: _withCtx(() => [
|
|
60
|
+
_createTextVNode(
|
|
61
|
+
_toDisplayString(_ctx.getMonthAbbr(month)),
|
|
62
|
+
1
|
|
63
|
+
/* TEXT */
|
|
64
|
+
)
|
|
65
|
+
]),
|
|
66
|
+
_: 2
|
|
67
|
+
/* DYNAMIC */
|
|
68
|
+
}, 1040, ["elevation", "onClick"])
|
|
69
|
+
]);
|
|
70
|
+
}),
|
|
71
|
+
128
|
|
72
|
+
/* KEYED_FRAGMENT */
|
|
73
|
+
))
|
|
74
|
+
]))
|
|
75
|
+
]),
|
|
76
|
+
_: 1
|
|
77
|
+
/* STABLE */
|
|
78
|
+
}, 8, ["name"])
|
|
79
|
+
],
|
|
80
|
+
2
|
|
81
|
+
/* CLASS */
|
|
82
|
+
)
|
|
83
|
+
],
|
|
84
|
+
2
|
|
85
|
+
/* CLASS */
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const __sfc__ = defineComponent({
|
|
89
|
+
name: "MonthPickerPanel",
|
|
90
|
+
components: {
|
|
91
|
+
VarButton
|
|
92
|
+
},
|
|
93
|
+
props: {
|
|
94
|
+
preview: {
|
|
95
|
+
type: Object,
|
|
96
|
+
required: true
|
|
97
|
+
},
|
|
98
|
+
selection: {
|
|
99
|
+
type: Object,
|
|
100
|
+
required: true
|
|
101
|
+
},
|
|
102
|
+
panelProps: {
|
|
103
|
+
type: Object,
|
|
104
|
+
required: true
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
emits: ["choose-month"],
|
|
108
|
+
setup(props, { emit }) {
|
|
109
|
+
const reverse = ref(false);
|
|
110
|
+
const panelKey = ref(0);
|
|
111
|
+
const { t: pt } = injectLocaleProvider();
|
|
112
|
+
function getMonthAbbr(key) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
return (_b = (_a = (pt || t)("datePickerMonthDict")) == null ? void 0 : _a[key].abbr) != null ? _b : "";
|
|
115
|
+
}
|
|
116
|
+
function isInRange(month) {
|
|
117
|
+
const {
|
|
118
|
+
preview: { previewYear },
|
|
119
|
+
panelProps: { min, max }
|
|
120
|
+
} = props;
|
|
121
|
+
const monthValue = `${previewYear}-${month}`;
|
|
122
|
+
const isBeforeMax = max ? dayjs(monthValue).isSameOrBefore(dayjs(max), DatePickerUnits.Month) : true;
|
|
123
|
+
const isAfterMin = min ? dayjs(monthValue).isSameOrAfter(dayjs(min), DatePickerUnits.Month) : true;
|
|
124
|
+
return isBeforeMax && isAfterMin;
|
|
125
|
+
}
|
|
126
|
+
function isSelectedMonth(monthValue, month) {
|
|
127
|
+
const {
|
|
128
|
+
preview: { previewYear },
|
|
129
|
+
selection: { selectedMonth, selectedYear, selectedMonths, selectedRangeMonths },
|
|
130
|
+
panelProps: { multiple, range }
|
|
131
|
+
} = props;
|
|
132
|
+
if (range) {
|
|
133
|
+
if (!selectedRangeMonths.length) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (selectedRangeMonths.length === 1) {
|
|
137
|
+
return dayjs(monthValue).isSame(dayjs(selectedRangeMonths[0]), DatePickerUnits.Month);
|
|
138
|
+
}
|
|
139
|
+
const isBeforeMax = dayjs(monthValue).isSameOrBefore(dayjs(selectedRangeMonths[1]), DatePickerUnits.Month);
|
|
140
|
+
const isAfterMin = dayjs(monthValue).isSameOrAfter(dayjs(selectedRangeMonths[0]), DatePickerUnits.Month);
|
|
141
|
+
return isBeforeMax && isAfterMin;
|
|
142
|
+
}
|
|
143
|
+
return multiple ? selectedMonths.includes(monthValue) : selectedYear === previewYear && selectedMonth === month;
|
|
144
|
+
}
|
|
145
|
+
function buttonProps(month) {
|
|
146
|
+
const {
|
|
147
|
+
preview: { previewYear },
|
|
148
|
+
panelProps: { allowedDates, color, type: pickerType }
|
|
149
|
+
} = props;
|
|
150
|
+
const monthValue = `${previewYear}-${month}`;
|
|
151
|
+
const active = isSelectedMonth(monthValue, month);
|
|
152
|
+
const disabled = !isInRange(month) || (pickerType === DatePickerTypes.Month && allowedDates ? !allowedDates(monthValue) : false);
|
|
153
|
+
return {
|
|
154
|
+
outline: false,
|
|
155
|
+
text: disabled || !active,
|
|
156
|
+
color: active && !disabled ? color : "",
|
|
157
|
+
textColor: "",
|
|
158
|
+
[`${nDate()}-color-cover`]: !active && !disabled,
|
|
159
|
+
class: n("button"),
|
|
160
|
+
disabled
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function selectMonth(month) {
|
|
164
|
+
emit("choose-month", month);
|
|
165
|
+
}
|
|
166
|
+
function shiftPreview(direction) {
|
|
167
|
+
reverse.value = direction === ShiftDirections.Prev;
|
|
168
|
+
panelKey.value += direction === ShiftDirections.Prev ? -1 : 1;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
n,
|
|
172
|
+
nDate,
|
|
173
|
+
MonthList,
|
|
174
|
+
reverse,
|
|
175
|
+
panelKey,
|
|
176
|
+
shiftPreview,
|
|
177
|
+
buttonProps,
|
|
178
|
+
getMonthAbbr,
|
|
179
|
+
selectMonth
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
__sfc__.render = __render__;
|
|
184
|
+
var stdin_default = __sfc__;
|
|
185
|
+
export {
|
|
186
|
+
stdin_default as default
|
|
187
|
+
};
|