Skip to content

Commit 17688fa

Browse files
iamkunlzq4047
authored andcommitted
Date-Picker: add className picker option (ElemeFE#16632)
* add classname * add docs * add test * add range picker * update api name * update api name * update test
1 parent 379ea42 commit 17688fa

File tree

12 files changed

+42
-1
lines changed

12 files changed

+42
-1
lines changed

examples/docs/en-US/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ When picking a date range, you can assign the time part for start date and end d
462462
|---------- |-------------- |---------- |-------------------------------- |-------- |
463463
| shortcuts | a { text, onClick } object array to set shortcut options, check the table below | object[] |||
464464
| disabledDate | a function determining if a date is disabled with that date as its parameter. Should return a Boolean | function |||
465+
| cellClassName | set custom className | Function(Date) |||
465466
| firstDayOfWeek | first day of week | Number | 1 to 7 | 7 |
466467
| onPick | a callback that triggers when the selected date is changed. Only for `daterange` and `datetimerange`. | Function({ maxDate, minDate }) | - | - |
467468

examples/docs/en-US/datetime-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ DateTimePicker is derived from DatePicker and TimePicker. For a more detailed ex
219219
|---------- |-------------- |---------- |-------------------------------- |-------- |
220220
| shortcuts | a { text, onClick } object array to set shortcut options, check the table below | object[] |||
221221
| disabledDate | a function determining if a date is disabled with that date as its parameter. Should return a Boolean | function |||
222+
| cellClassName | set custom className | Function(Date) |||
222223
| firstDayOfWeek | first day of week | Number | 1 to 7 | 7 |
223224

224225
### shortcuts

examples/docs/es/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ Al seleccionar un intervalo de fechas, puede asignar la hora para la fecha de in
462462
| -------------- | ------------------------------------------------------------ | ------------------------------ | ----------------- | ----------- |
463463
| shortcuts | { text, onClick } un array de objetos para establecer opciones de acceso directo, verifique la tabla siguiente | object[] |||
464464
| disabledDate | una función que determina si una fecha está desactivada con esa fecha como parámetro. Debería devolver un valor booleano | function |||
465+
| cellClassName | set custom className | Function(Date) |||
465466
| firstDayOfWeek | primer día de la semana | Number | 1 to 7 | 7 |
466467
| onPick | una función que se dispara cuando se cambia la fecha seleccionada. Solamente para `daterange` y `datetimerange`. | Function({ maxDate, minDate }) | - | - |
467468

examples/docs/es/datetime-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ DateTimePicker se deriva de DatePicker y TimePicker. Por una explicación más d
221221
| -------------- | ---------------------------------------- | -------- | ----------------- | ----------- |
222222
| shortcuts | un array de objetos { text, onClick } para establecer las opciones de acceso directo, verifique la tabla debajo | objeto[] |||
223223
| disabledDate | una función que determina si una fecha está desactivada con esa fecha como parámetro. Debería devolver un booleano | función |||
224+
| cellClassName | set custom className | Function(Date) |||
224225
| firstDayOfWeek | primera día de semana | Número | 1 to 7 | 7 |
225226

226227
### Accesos directos

examples/docs/fr-FR/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ Lorsque vous choisissez une plage de dates, vous pouvez assigner l'horaire de d
463463
|---------- |-------------- |---------- |-------------------------------- |-------- |
464464
| shortcuts | Un tableau d'objets { text, onClick } pour configurer les raccourcis, voir table ci-dessous. | object[] |||
465465
| disabledDate | Une fonction qui détermine si une date est désactivée ou pas, avec cette date en paramètre. Doit retourner un booléen. | function |||
466+
| cellClassName | set custom className | Function(Date) |||
466467
| firstDayOfWeek | Premier jour du mois. | Number | 1 to 7 | 7 |
467468
| onPick | Callback se déclenchant quand la date sélectionnée change. Uniquement pour `daterange` et `datetimerange`. | Function({ maxDate, minDate }) | - | - |
468469

examples/docs/fr-FR/datetime-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ DateTimePicker est dérivé de DatePicker et TimePicker. Pour plus d'information
219219
|---------- |-------------- |---------- |-------------------------------- |-------- |
220220
| shortcuts | Un tableau d'objets { text, onClick } pour mettre en place des raccourcis, vérifier le tableau ci-dessous | object[] |||
221221
| disabledDate | Une fonction déterminant si une date est désactivée avec cette date en paramètre. Retourne un Boolean | function |||
222+
| cellClassName | set custom className | Function(Date) |||
222223
| firstDayOfWeek | Le premier jour de la semaine | Number | 1 à 7 | 7 |
223224

224225
### Raccourcis

examples/docs/zh-CN/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@
415415
|---------- |-------------- |---------- |-------------------------------- |-------- |
416416
| shortcuts | 设置快捷选项,需要传入 { text, onClick } 对象用法参考 demo 或下表 | Object[] |||
417417
| disabledDate | 设置禁用状态,参数为当前日期,要求返回 Boolean | Function |||
418+
| cellClassName | 设置日期的 className | Function(Date) |||
418419
| firstDayOfWeek | 周起始日 | Number | 1 到 7 | 7 |
419420
| onPick | 选中日期后会执行的回调,只有当 `daterange``datetimerange` 才生效 | Function({ maxDate, minDate }) |||
420421

examples/docs/zh-CN/datetime-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ DateTimePicker 由 DatePicker 和 TimePicker 派生,`Picker Options` 或者其
218218
|---------- |-------------- |---------- |-------------------------------- |-------- |
219219
| shortcuts | 设置快捷选项,需要传入 { text, onClick } 对象用法参考 demo 或下表 | Object[] |||
220220
| disabledDate | 设置禁用状态,参数为当前日期,要求返回 Boolean | Function |||
221+
| cellClassName | 设置日期的 className | Function(Date) |||
221222
| firstDayOfWeek | 周起始日 | Number | 1 到 7 | 7 |
222223

223224
### Shortcuts

packages/date-picker/src/basic/date-table.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
},
8787
8888
disabledDate: {},
89+
90+
cellClassName: {},
8991
9092
minDate: {},
9193
@@ -140,6 +142,7 @@
140142
141143
const startDate = this.startDate;
142144
const disabledDate = this.disabledDate;
145+
const cellClassName = this.cellClassName;
143146
const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
144147
const now = getDateTimestamp(new Date());
145148
@@ -192,7 +195,7 @@
192195
let cellDate = new Date(time);
193196
cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
194197
cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());
195-
198+
cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate);
196199
this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
197200
}
198201
@@ -288,6 +291,10 @@
288291
classes.push('selected');
289292
}
290293
294+
if (cell.customClass) {
295+
classes.push(cell.customClass);
296+
}
297+
291298
return classes.join(' ');
292299
},
293300

packages/date-picker/src/panel/date-range.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
:max-date="maxDate"
119119
:range-state="rangeState"
120120
:disabled-date="disabledDate"
121+
:cell-class-name="cellClassName"
121122
@changerange="handleChangeRange"
122123
:first-day-of-week="firstDayOfWeek"
123124
@pick="handleRangePick">
@@ -157,6 +158,7 @@
157158
:max-date="maxDate"
158159
:range-state="rangeState"
159160
:disabled-date="disabledDate"
161+
:cell-class-name="cellClassName"
160162
@changerange="handleChangeRange"
161163
:first-day-of-week="firstDayOfWeek"
162164
@pick="handleRangePick">
@@ -331,6 +333,7 @@
331333
shortcuts: '',
332334
visible: '',
333335
disabledDate: '',
336+
cellClassName: '',
334337
firstDayOfWeek: 7,
335338
minTimePickerVisible: false,
336339
maxTimePickerVisible: false,

0 commit comments

Comments
 (0)