zartui 1.0.21 → 1.0.23

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.
@@ -0,0 +1,477 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ // Utils
3
+ import { createNamespace } from '../utils';
4
+ import { preventDefault } from '../utils/dom/event';
5
+ import { unitToPx } from '../utils/format/unit';
6
+ import { DEFAULT_WRAP_HEIGHT, radioPickerProps } from './shared'; // Components
7
+
8
+ import Loading from '../loading';
9
+ import { PopupMixin } from '../mixins/popup';
10
+ import Popup from '../popup';
11
+ import Search from '../search';
12
+ import PickerColumn from './PickerColumn';
13
+
14
+ var _createNamespace = createNamespace('radio-picker'),
15
+ createComponent = _createNamespace[0],
16
+ bem = _createNamespace[1],
17
+ t = _createNamespace[2];
18
+
19
+ export default createComponent({
20
+ mixins: [PopupMixin()],
21
+ props: _extends({}, radioPickerProps, {
22
+ defaultIndex: {
23
+ type: [Number, String],
24
+ default: 0
25
+ },
26
+ columns: {
27
+ type: Array,
28
+ default: function _default() {
29
+ return [];
30
+ }
31
+ },
32
+ headers: {
33
+ type: Array,
34
+ default: null
35
+ },
36
+ toolbarPosition: {
37
+ type: String,
38
+ default: 'top'
39
+ },
40
+ valueKey: {
41
+ type: String,
42
+ default: 'text'
43
+ },
44
+ searchable: {
45
+ type: Boolean,
46
+ default: false
47
+ },
48
+ searchPlaceholder: {
49
+ type: String,
50
+ default: '请输入'
51
+ }
52
+ }),
53
+ data: function data() {
54
+ return {
55
+ children: [],
56
+ formattedColumns: [],
57
+ confirmIndex: '',
58
+ searchVal: '',
59
+ searchConfirmVal: ''
60
+ };
61
+ },
62
+ computed: {
63
+ wrapPxHeight: function wrapPxHeight() {
64
+ return this.wrapHeight ? unitToPx(this.wrapHeight) : DEFAULT_WRAP_HEIGHT;
65
+ },
66
+ dataType: function dataType() {
67
+ var columns = this.columns;
68
+ var firstColumn = columns[0] || {};
69
+
70
+ if (firstColumn.children) {
71
+ return 'cascade';
72
+ }
73
+
74
+ if (firstColumn.values) {
75
+ return 'object';
76
+ }
77
+
78
+ return 'text';
79
+ }
80
+ },
81
+ watch: {
82
+ columns: {
83
+ handler: 'format',
84
+ immediate: true
85
+ },
86
+ showPicker: {
87
+ handler: function handler(val) {
88
+ var _this = this;
89
+
90
+ if (val) {
91
+ this.$nextTick(function () {
92
+ _this.children.forEach(function (child) {
93
+ child.setConfirmIndex();
94
+ });
95
+
96
+ _this.children.forEach(function (child) {
97
+ child.recordConfirmIndex();
98
+ });
99
+ });
100
+ }
101
+ },
102
+ immediate: true
103
+ }
104
+ },
105
+ methods: {
106
+ onClickOverlay: function onClickOverlay() {
107
+ if (this.closeOnClickOverlay) {
108
+ this.cancel();
109
+ }
110
+ },
111
+ format: function format() {
112
+ var columns = this.columns,
113
+ dataType = this.dataType;
114
+
115
+ if (dataType === 'text') {
116
+ this.formattedColumns = [{
117
+ values: columns
118
+ }];
119
+ } else if (dataType === 'cascade') {
120
+ this.formatCascade();
121
+ } else {
122
+ this.formattedColumns = columns;
123
+ }
124
+ },
125
+ formatCascade: function formatCascade() {
126
+ var formatted = [];
127
+ var cursor = {
128
+ children: this.columns
129
+ };
130
+
131
+ while (cursor && cursor.children) {
132
+ var _cursor$defaultIndex;
133
+
134
+ var _cursor = cursor,
135
+ children = _cursor.children;
136
+ var defaultIndex = (_cursor$defaultIndex = cursor.defaultIndex) != null ? _cursor$defaultIndex : +this.defaultIndex;
137
+
138
+ while (children[defaultIndex] && children[defaultIndex].disabled) {
139
+ if (defaultIndex < children.length - 1) {
140
+ defaultIndex++;
141
+ } else {
142
+ defaultIndex = 0;
143
+ break;
144
+ }
145
+ }
146
+
147
+ formatted.push({
148
+ values: cursor.children,
149
+ className: cursor.className,
150
+ defaultIndex: defaultIndex
151
+ });
152
+ cursor = children[defaultIndex];
153
+ }
154
+
155
+ this.formattedColumns = formatted;
156
+ },
157
+ emit: function emit(event) {
158
+ var _this2 = this;
159
+
160
+ if (this.dataType === 'text') {
161
+ this.$emit(event, this.getColumnValue(0), this.getColumnIndex(0));
162
+ } else {
163
+ var values = this.getValues(); // compatible with old version of wrong parameters
164
+ // should be removed in next major version
165
+ // see: https://github.com/vant-ui/vant/issues/5905
166
+
167
+ if (this.dataType === 'cascade') {
168
+ values = values.map(function (item) {
169
+ return item[_this2.valueKey];
170
+ });
171
+ }
172
+
173
+ this.$emit(event, values, this.getIndexes());
174
+ }
175
+ },
176
+ onCascadeChange: function onCascadeChange(columnIndex) {
177
+ var cursor = {
178
+ children: this.columns
179
+ };
180
+ var indexes = this.getIndexes();
181
+
182
+ for (var i = 0; i <= columnIndex; i++) {
183
+ cursor = cursor.children[indexes[i]];
184
+ }
185
+
186
+ while (cursor && cursor.children) {
187
+ columnIndex++;
188
+ this.setColumnValues(columnIndex, cursor.children);
189
+ cursor = cursor.children[cursor.defaultIndex || 0];
190
+ }
191
+ },
192
+ onChange: function onChange(columnIndex) {
193
+ var _this3 = this;
194
+
195
+ if (this.dataType === 'cascade') {
196
+ this.onCascadeChange(columnIndex);
197
+ }
198
+
199
+ if (this.dataType === 'text') {
200
+ this.$emit('change', this, this.getColumnValue(0), this.getColumnIndex(0));
201
+ } else {
202
+ var values = this.getValues(); // compatible with old version of wrong parameters
203
+ // should be removed in next major version
204
+ // see: https://github.com/vant-ui/vant/issues/5905
205
+
206
+ if (this.dataType === 'cascade') {
207
+ values = values.map(function (item) {
208
+ return item[_this3.valueKey];
209
+ });
210
+ }
211
+
212
+ this.$emit('change', this, values, columnIndex);
213
+ }
214
+ },
215
+ getColumnCount: function getColumnCount() {
216
+ return this.children ? this.children.length : 0;
217
+ },
218
+ // get column instance by index
219
+ getColumn: function getColumn(index) {
220
+ return this.children[index];
221
+ },
222
+ // @exposed-api
223
+ // get column value by index
224
+ getColumnValue: function getColumnValue(index) {
225
+ var column = this.getColumn(index);
226
+ return column && column.getValue();
227
+ },
228
+ // @exposed-api
229
+ // set column value by index
230
+ setColumnValue: function setColumnValue(index, value) {
231
+ var column = this.getColumn(index);
232
+
233
+ if (column) {
234
+ column.setValue(value);
235
+
236
+ if (this.dataType === 'cascade') {
237
+ this.onCascadeChange(index);
238
+ }
239
+ }
240
+ },
241
+ // @exposed-api
242
+ // get column option index by column index
243
+ getColumnIndex: function getColumnIndex(columnIndex) {
244
+ return (this.getColumn(columnIndex) || {}).currentIndex;
245
+ },
246
+ // @exposed-api
247
+ // set column option index by column index
248
+ setColumnIndex: function setColumnIndex(columnIndex, optionIndex) {
249
+ var column = this.getColumn(columnIndex);
250
+
251
+ if (column) {
252
+ column.setIndex(optionIndex);
253
+
254
+ if (this.dataType === 'cascade') {
255
+ this.onCascadeChange(columnIndex);
256
+ }
257
+ }
258
+ },
259
+ // @exposed-api
260
+ // get options of column by index
261
+ getColumnValues: function getColumnValues(index) {
262
+ return (this.children[index] || {}).options;
263
+ },
264
+ // @exposed-api
265
+ // set options of column by index
266
+ setColumnValues: function setColumnValues(index, options) {
267
+ var column = this.children[index];
268
+
269
+ if (column) {
270
+ column.setOptions(options);
271
+ }
272
+ },
273
+ // @exposed-api
274
+ // get values of all columns
275
+ getValues: function getValues() {
276
+ return this.children.map(function (child) {
277
+ return child.getValue();
278
+ });
279
+ },
280
+ // @exposed-api
281
+ // set values of all columns
282
+ setValues: function setValues(values) {
283
+ var _this4 = this;
284
+
285
+ values.forEach(function (value, index) {
286
+ _this4.setColumnValue(index, value);
287
+ });
288
+ },
289
+ // @exposed-api
290
+ // get indexes of all columns
291
+ getIndexes: function getIndexes() {
292
+ return this.children.map(function (child) {
293
+ return child.currentIndex;
294
+ });
295
+ },
296
+ // @exposed-api
297
+ // set indexes of all columns
298
+ setIndexes: function setIndexes(indexes) {
299
+ var _this5 = this;
300
+
301
+ indexes.forEach(function (optionIndex, columnIndex) {
302
+ _this5.setColumnIndex(columnIndex, optionIndex);
303
+ });
304
+ },
305
+ // @exposed-api
306
+ confirm: function confirm() {
307
+ this.children.forEach(function (child) {
308
+ return child.stopMomentum();
309
+ });
310
+ this.children.forEach(function (child) {
311
+ return child.recordConfirmIndex();
312
+ });
313
+ this.emit('confirm');
314
+ },
315
+ cancel: function cancel() {
316
+ this.$emit('update:showPicker', false);
317
+ this.emit('cancel');
318
+ },
319
+ genTitle: function genTitle() {
320
+ var h = this.$createElement;
321
+ var titleSlot = this.slots('title');
322
+
323
+ if (titleSlot) {
324
+ return titleSlot;
325
+ }
326
+
327
+ if (this.title) {
328
+ return h("div", {
329
+ "class": ['zt-ellipsis', bem('title')]
330
+ }, [this.title]);
331
+ }
332
+ },
333
+ genCancel: function genCancel() {
334
+ var h = this.$createElement;
335
+ return h("button", {
336
+ "attrs": {
337
+ "type": "button"
338
+ },
339
+ "class": bem('cancel'),
340
+ "on": {
341
+ "click": this.cancel
342
+ }
343
+ }, [this.slots('cancel') || this.cancelButtonText || t('cancel')]);
344
+ },
345
+ genConfirm: function genConfirm() {
346
+ var h = this.$createElement;
347
+ return h("button", {
348
+ "attrs": {
349
+ "type": "button"
350
+ },
351
+ "class": bem('confirm'),
352
+ "on": {
353
+ "click": this.confirm
354
+ }
355
+ }, [this.slots('confirm') || this.confirmButtonText || t('confirm')]);
356
+ },
357
+ genToolbar: function genToolbar() {
358
+ var h = this.$createElement;
359
+
360
+ if (this.showToolbar) {
361
+ return h("div", {
362
+ "class": bem('toolbar')
363
+ }, [this.slots() || [this.genCancel(), this.genTitle(), this.genConfirm()]]);
364
+ }
365
+ },
366
+ genHeaders: function genHeaders() {
367
+ var h = this.$createElement;
368
+ return h("ul", {
369
+ "class": bem('header')
370
+ }, [this.genHeaderItems()]);
371
+ },
372
+ genHeaderItems: function genHeaderItems() {
373
+ var h = this.$createElement;
374
+ return this.headers.map(function (header) {
375
+ return h("li", [header]);
376
+ });
377
+ },
378
+ genSearch: function genSearch() {
379
+ var h = this.$createElement;
380
+ return h(Search, {
381
+ "attrs": {
382
+ "value": this.searchVal,
383
+ "placeholder": this.searchPlaceholder
384
+ },
385
+ "on": {
386
+ "input": this.handleSearchInput,
387
+ "search": this.handleSearch
388
+ }
389
+ });
390
+ },
391
+ handleSearchInput: function handleSearchInput(inputVal) {
392
+ this.searchVal = inputVal; // 直接清空输入框的情况,就不继续展示已经查询的内容了
393
+
394
+ if (!inputVal) {
395
+ this.handleSearch(inputVal);
396
+ }
397
+ },
398
+
399
+ /**
400
+ * @description: 这里才将输入值实际传递给子组件进行过滤
401
+ * @param {*} e 搜索框的输入值
402
+ */
403
+ handleSearch: function handleSearch(e) {
404
+ this.searchConfirmVal = e;
405
+ },
406
+ genColumns: function genColumns() {
407
+ var h = this.$createElement;
408
+ var wrapHeight = this.wrapHeight;
409
+ var columnsStyle = {
410
+ height: wrapHeight + "px"
411
+ };
412
+ return h("div", {
413
+ "class": bem('columns'),
414
+ "style": columnsStyle,
415
+ "on": {
416
+ "touchmove": preventDefault
417
+ }
418
+ }, [this.genColumnItems()]);
419
+ },
420
+ genColumnItems: function genColumnItems() {
421
+ var _this6 = this;
422
+
423
+ var h = this.$createElement;
424
+ return this.formattedColumns.map(function (item, columnIndex) {
425
+ var _item$defaultIndex;
426
+
427
+ return h(PickerColumn, {
428
+ "attrs": {
429
+ "columnCollector": _this6.children,
430
+ "readonly": _this6.readonly,
431
+ "valueKey": _this6.valueKey,
432
+ "allowHtml": _this6.allowHtml,
433
+ "searchVal": _this6.searchConfirmVal,
434
+ "searchable": _this6.searchable,
435
+ "toolbarPosition": _this6.toolbarPosition,
436
+ "className": item.className,
437
+ "wrapHeight": _this6.wrapPxHeight,
438
+ "defaultIndex": (_item$defaultIndex = item.defaultIndex) != null ? _item$defaultIndex : +_this6.defaultIndex,
439
+ "swipeDuration": _this6.swipeDuration,
440
+ "initialOptions": item.values
441
+ },
442
+ "scopedSlots": {
443
+ option: _this6.$scopedSlots.option
444
+ },
445
+ "on": {
446
+ "change": function change() {
447
+ _this6.onChange(columnIndex);
448
+ }
449
+ }
450
+ });
451
+ });
452
+ }
453
+ },
454
+ render: function render(h) {
455
+ return h(Popup, {
456
+ "attrs": {
457
+ "value": this.showPicker,
458
+ "round": true,
459
+ "position": "bottom",
460
+ "closeOnPopstate": this.closeOnPopstate,
461
+ "closeOnClickOverlay": this.closeOnClickOverlay,
462
+ "customOnClickOverlay": this.onClickOverlay
463
+ }
464
+ }, [h("div", {
465
+ "class": bem(),
466
+ "ref": "columnParent"
467
+ }, [this.toolbarPosition === 'top' ? this.genToolbar() : h(), this.toolbarPosition === 'top' ? h("div", {
468
+ "class": bem('border')
469
+ }) : h(), this.loading ? h(Loading, {
470
+ "class": bem('loading')
471
+ }) : h(), this.slots('columns-top'), this.headers && this.headers.length > 0 ? this.genHeaders() : h(), this.headers && this.headers.length > 0 ? h("div", {
472
+ "class": bem('border')
473
+ }) : h(), this.searchable ? this.genSearch() : h(), this.searchable ? h("div", {
474
+ "class": bem('border')
475
+ }) : h(), this.genColumns(), this.slots('columns-bottom'), this.toolbarPosition === 'bottom' ? this.genToolbar() : h()])]);
476
+ }
477
+ });
@@ -0,0 +1,152 @@
1
+ @import '../style/var';
2
+ @import '../style/hairline';
3
+
4
+ .zt-radio-picker {
5
+ position: relative;
6
+ background-color: @picker-background-color;
7
+ user-select: none;
8
+
9
+ &__toolbar {
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: space-between;
13
+ height: @picker-toolbar-height;
14
+ }
15
+
16
+ &__border {
17
+ position: relative;
18
+ }
19
+
20
+ &__border::after {
21
+ .hairline-bottom();
22
+ }
23
+
24
+ &__cancel,
25
+ &__confirm {
26
+ height: 100%;
27
+ padding: @picker-action-padding;
28
+ font-size: @picker-action-font-size;
29
+ background-color: transparent;
30
+ border: none;
31
+ cursor: pointer;
32
+
33
+ &:active {
34
+ opacity: @active-opacity;
35
+ }
36
+ }
37
+
38
+ &__confirm {
39
+ color: @picker-confirm-action-color;
40
+ font-weight: @picker-confirm-action-font-weight;
41
+ }
42
+
43
+ &__cancel {
44
+ color: @picker-cancel-action-color;
45
+ font-weight: @picker-cancel-action-font-weight;
46
+ }
47
+
48
+ &__title {
49
+ max-width: 50%;
50
+ font-weight: @plain-font-weight;
51
+ font-size: @picker-title-font-size;
52
+ line-height: @picker-title-line-height;
53
+ text-align: center;
54
+ color: rgba(0, 0, 0, 0.4);
55
+ }
56
+
57
+ &__header {
58
+ width: 100%;
59
+ height: 40px;
60
+ display: flex;
61
+ align-items: center;
62
+ font-size: @picker-title-font-size;
63
+ font-weight: @plain-font-weight;
64
+
65
+ > li {
66
+ flex: auto;
67
+ text-align: center;
68
+ }
69
+ }
70
+
71
+ &__columns {
72
+ position: relative;
73
+ display: flex;
74
+ cursor: grab;
75
+ }
76
+
77
+ &__loading {
78
+ position: absolute;
79
+ top: 0;
80
+ right: 0;
81
+ bottom: 0;
82
+ left: 0;
83
+ z-index: 3;
84
+ display: flex;
85
+ align-items: center;
86
+ justify-content: center;
87
+ color: @picker-loading-icon-color;
88
+ background-color: @picker-loading-mask-color;
89
+ }
90
+
91
+ &__frame {
92
+ position: absolute;
93
+ top: 50%;
94
+ right: @padding-md;
95
+ left: @padding-md;
96
+ z-index: 2;
97
+ transform: translateY(-50%);
98
+ pointer-events: none;
99
+ }
100
+
101
+ &__background {
102
+ position: absolute;
103
+ width: 100%;
104
+ height: 100%;
105
+ background-color: #fff;
106
+ }
107
+
108
+ &-column {
109
+ flex: 1;
110
+ overflow: hidden;
111
+ font-size: @picker-option-font-size;
112
+
113
+ &__wrapper {
114
+ transition-timing-function: cubic-bezier(0.23, 1, 0.68, 1);
115
+ }
116
+
117
+ &__item {
118
+ position: relative;
119
+ display: flex;
120
+ align-items: center;
121
+ justify-content: flex-start;
122
+ padding: @radio-picker-warpper-item-padding;
123
+ color: @picker-option-text-color;
124
+
125
+ &::after {
126
+ // ui要求,border需居于文字底部,故去除了radio与一些padding、margin的距离
127
+ .hairline-bottom(@border-color, calc(16px + 24px + 8px));
128
+ }
129
+
130
+ &--disabled {
131
+ cursor: not-allowed;
132
+ opacity: @picker-option-disabled-opacity;
133
+ }
134
+
135
+ &--not-match {
136
+ display: none;
137
+ }
138
+
139
+ &--selected {
140
+ font-weight: @font-weight-bold;
141
+ }
142
+
143
+ // ui效果,需要修改label的行高
144
+ .zt-radio__label {
145
+ font-family: PingFangSC-Regular;
146
+ font-weight: 400;
147
+ font-size: @font-size-md;
148
+ line-height: @line-height-md;
149
+ }
150
+ }
151
+ }
152
+ }
@@ -0,0 +1,36 @@
1
+ export var DEFAULT_WRAP_HEIGHT = 350;
2
+ export var radioPickerProps = {
3
+ title: String,
4
+ loading: Boolean,
5
+ readonly: Boolean,
6
+ cancelButtonText: String,
7
+ confirmButtonText: String,
8
+ showToolbar: {
9
+ type: Boolean,
10
+ default: true
11
+ },
12
+ showPicker: {
13
+ type: Boolean,
14
+ default: false
15
+ },
16
+ wrapHeight: {
17
+ type: [Number, String],
18
+ default: DEFAULT_WRAP_HEIGHT
19
+ },
20
+ allowHtml: {
21
+ type: Boolean,
22
+ default: true
23
+ },
24
+ swipeDuration: {
25
+ type: [Number, String],
26
+ default: 1000
27
+ },
28
+ closeOnPopstate: {
29
+ type: Boolean,
30
+ default: true
31
+ },
32
+ closeOnClickOverlay: {
33
+ type: Boolean,
34
+ default: true
35
+ }
36
+ };
@@ -0,0 +1,13 @@
1
+ import '../../style/base.css';
2
+ import '../../overlay/index.css';
3
+ import '../../info/index.css';
4
+ import '../../icon/index.css';
5
+ import '../../radio/index.css';
6
+ import '../../cell/index.css';
7
+ import '../../field/index.css';
8
+ import '../../search/index.css';
9
+ import '../../popup/index.css';
10
+ import '../../loading/index.css';
11
+ import '../../empty/index.css';
12
+ import '../../radio-group/index.css';
13
+ import '../index.css';
@@ -0,0 +1,13 @@
1
+ import '../../style/base.less';
2
+ import '../../overlay/index.less';
3
+ import '../../info/index.less';
4
+ import '../../icon/index.less';
5
+ import '../../radio/index.less';
6
+ import '../../cell/index.less';
7
+ import '../../field/index.less';
8
+ import '../../search/index.less';
9
+ import '../../popup/index.less';
10
+ import '../../loading/index.less';
11
+ import '../../empty/index.less';
12
+ import '../../radio-group/index.less';
13
+ import '../index.less';
package/es/style/var.less CHANGED
@@ -654,6 +654,9 @@
654
654
  @multiple-picker-warpper-padding: 12px 16px 4px 16px;
655
655
  @multiple-picker-option-text-color: @gray-a6;
656
656
 
657
+ // RadioPicker
658
+ @radio-picker-warpper-item-padding: 10px @padding-md;
659
+
657
660
  // Popover
658
661
  @popover-arrow-size: 5px;
659
662
  @popover-border-radius: @border-radius-sm;