Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date-Picker: add className picker option #16632

Merged
merged 7 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/docs/en-US/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ When picking a date range, you can assign the time part for start date and end d
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | a { text, onClick } object array to set shortcut options, check the table below | object[] | — | — |
| disabledDate | a function determining if a date is disabled with that date as its parameter. Should return a Boolean | function | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | first day of week | Number | 1 to 7 | 7 |
| onPick | a callback that triggers when the selected date is changed. Only for `daterange` and `datetimerange`. | Function({ maxDate, minDate }) | - | - |

Expand Down
1 change: 1 addition & 0 deletions examples/docs/en-US/datetime-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ DateTimePicker is derived from DatePicker and TimePicker. For a more detailed ex
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | a { text, onClick } object array to set shortcut options, check the table below | object[] | — | — |
| disabledDate | a function determining if a date is disabled with that date as its parameter. Should return a Boolean | function | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | first day of week | Number | 1 to 7 | 7 |

### shortcuts
Expand Down
1 change: 1 addition & 0 deletions examples/docs/es/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ Al seleccionar un intervalo de fechas, puede asignar la hora para la fecha de in
| -------------- | ------------------------------------------------------------ | ------------------------------ | ----------------- | ----------- |
| shortcuts | { text, onClick } un array de objetos para establecer opciones de acceso directo, verifique la tabla siguiente | object[] | — | — |
| disabledDate | una función que determina si una fecha está desactivada con esa fecha como parámetro. Debería devolver un valor booleano | function | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | primer día de la semana | Number | 1 to 7 | 7 |
| onPick | una función que se dispara cuando se cambia la fecha seleccionada. Solamente para `daterange` y `datetimerange`. | Function({ maxDate, minDate }) | - | - |

Expand Down
1 change: 1 addition & 0 deletions examples/docs/es/datetime-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ DateTimePicker se deriva de DatePicker y TimePicker. Por una explicación más d
| -------------- | ---------------------------------------- | -------- | ----------------- | ----------- |
| shortcuts | un array de objetos { text, onClick } para establecer las opciones de acceso directo, verifique la tabla debajo | objeto[] | — | — |
| disabledDate | una función que determina si una fecha está desactivada con esa fecha como parámetro. Debería devolver un booleano | función | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | primera día de semana | Número | 1 to 7 | 7 |

### Accesos directos
Expand Down
1 change: 1 addition & 0 deletions examples/docs/fr-FR/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ Lorsque vous choisissez une plage de dates, vous pouvez assigner l'horaire de d
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | Un tableau d'objets { text, onClick } pour configurer les raccourcis, voir table ci-dessous. | object[] | — | — |
| 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 | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | Premier jour du mois. | Number | 1 to 7 | 7 |
| onPick | Callback se déclenchant quand la date sélectionnée change. Uniquement pour `daterange` et `datetimerange`. | Function({ maxDate, minDate }) | - | - |

Expand Down
1 change: 1 addition & 0 deletions examples/docs/fr-FR/datetime-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ DateTimePicker est dérivé de DatePicker et TimePicker. Pour plus d'information
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | Un tableau d'objets { text, onClick } pour mettre en place des raccourcis, vérifier le tableau ci-dessous | object[] | — | — |
| disabledDate | Une fonction déterminant si une date est désactivée avec cette date en paramètre. Retourne un Boolean | function | — | — |
| className | set custom className | Function(Date) | — | — |
| firstDayOfWeek | Le premier jour de la semaine | Number | 1 à 7 | 7 |

### Raccourcis
Expand Down
1 change: 1 addition & 0 deletions examples/docs/zh-CN/date-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | 设置快捷选项,需要传入 { text, onClick } 对象用法参考 demo 或下表 | Object[] | — | — |
| disabledDate | 设置禁用状态,参数为当前日期,要求返回 Boolean | Function | — | — |
| className | 设置日期的 className | Function(Date) | — | — |
| firstDayOfWeek | 周起始日 | Number | 1 到 7 | 7 |
| onPick | 选中日期后会执行的回调,只有当 `daterange` 或 `datetimerange` 才生效 | Function({ maxDate, minDate }) | — | — |

Expand Down
1 change: 1 addition & 0 deletions examples/docs/zh-CN/datetime-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ DateTimePicker 由 DatePicker 和 TimePicker 派生,`Picker Options` 或者其
|---------- |-------------- |---------- |-------------------------------- |-------- |
| shortcuts | 设置快捷选项,需要传入 { text, onClick } 对象用法参考 demo 或下表 | Object[] | — | — |
| disabledDate | 设置禁用状态,参数为当前日期,要求返回 Boolean | Function | — | — |
| className | 设置日期的 className | Function(Date) | — | — |
| firstDayOfWeek | 周起始日 | Number | 1 到 7 | 7 |

### Shortcuts
Expand Down
9 changes: 8 additions & 1 deletion packages/date-picker/src/basic/date-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
},

disabledDate: {},

className: {},

minDate: {},

Expand Down Expand Up @@ -140,6 +142,7 @@

const startDate = this.startDate;
const disabledDate = this.disabledDate;
const className = this.className;
const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
const now = getDateTimestamp(new Date());

Expand Down Expand Up @@ -192,7 +195,7 @@
let cellDate = new Date(time);
cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());

cell.customClass = typeof className === 'function' && className(cellDate);
this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
}

Expand Down Expand Up @@ -288,6 +291,10 @@
classes.push('selected');
}

if (cell.customClass) {
classes.push(cell.customClass);
}

return classes.join(' ');
},

Expand Down
3 changes: 3 additions & 0 deletions packages/date-picker/src/panel/date-range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
:max-date="maxDate"
:range-state="rangeState"
:disabled-date="disabledDate"
:class-name="className"
@changerange="handleChangeRange"
:first-day-of-week="firstDayOfWeek"
@pick="handleRangePick">
Expand Down Expand Up @@ -157,6 +158,7 @@
:max-date="maxDate"
:range-state="rangeState"
:disabled-date="disabledDate"
:class-name="className"
@changerange="handleChangeRange"
:first-day-of-week="firstDayOfWeek"
@pick="handleRangePick">
Expand Down Expand Up @@ -331,6 +333,7 @@
shortcuts: '',
visible: '',
disabledDate: '',
className: '',
firstDayOfWeek: 7,
minTimePickerVisible: false,
maxTimePickerVisible: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/date-picker/src/panel/date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
:value="value"
:default-value="defaultValue ? new Date(defaultValue) : null"
:date="date"
:class-name="className"
:disabled-date="disabledDate">
</date-table>
<year-table
Expand Down Expand Up @@ -515,6 +516,7 @@
visible: false,
currentView: 'date',
disabledDate: '',
className: '',
selectableRange: [],
firstDayOfWeek: 7,
showWeekNumber: false,
Expand Down
25 changes: 25 additions & 0 deletions test/unit/specs/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2831,4 +2831,29 @@ describe('DatePicker', () => {
}, DELAY);
});
});
describe('picker-options:className', () => {
it('set custom class name', done => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新添加的测试都使用 async 函数。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

vm = createVue({
template: '<el-date-picker type="datetime" v-model="value" ref="compo" :pickerOptions="pickerOptions" />',
data() {
return {
value: '',
pickerOptions: {
className() { return 'test-class'; }
}
};
}
}, true);
vm.$refs.compo.$el.querySelector('input').focus();
setTimeout(_ => {
setTimeout(_ => {
expect(
(vm.$refs.compo.picker.$el.querySelector('.el-date-table__row td').className)
.indexOf('test-class') > -1
).to.be.true;
done();
}, DELAY);
}, DELAY);
});
});
});