Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VDatePickerYears.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import '../../../src/stylus/components/_date-picker-years.styl';
  2. // Mixins
  3. import Colorable from '../../mixins/colorable';
  4. // Utils
  5. import { createNativeLocaleFormatter } from './util';
  6. import mixins from '../../util/mixins';
  7. export default mixins(Colorable
  8. /* @vue/component */
  9. ).extend({
  10. name: 'v-date-picker-years',
  11. props: {
  12. format: Function,
  13. locale: {
  14. type: String,
  15. default: 'en-us'
  16. },
  17. min: [Number, String],
  18. max: [Number, String],
  19. readonly: Boolean,
  20. value: [Number, String]
  21. },
  22. data: function data() {
  23. return {
  24. defaultColor: 'primary'
  25. };
  26. },
  27. computed: {
  28. formatter: function formatter() {
  29. return this.format || createNativeLocaleFormatter(this.locale, { year: 'numeric', timeZone: 'UTC' }, { length: 4 });
  30. }
  31. },
  32. mounted: function mounted() {
  33. var _this = this;
  34. setTimeout(function () {
  35. var activeItem = _this.$el.getElementsByClassName('active')[0];
  36. if (activeItem) {
  37. _this.$el.scrollTop = activeItem.offsetTop - _this.$el.offsetHeight / 2 + activeItem.offsetHeight / 2;
  38. } else {
  39. _this.$el.scrollTop = _this.$el.scrollHeight / 2 - _this.$el.offsetHeight / 2;
  40. }
  41. });
  42. },
  43. methods: {
  44. genYearItem: function genYearItem(year) {
  45. var _this2 = this;
  46. var formatted = this.formatter('' + year);
  47. var active = parseInt(this.value, 10) === year;
  48. var color = active && (this.color || 'primary');
  49. return this.$createElement('li', this.setTextColor(color, {
  50. key: year,
  51. 'class': { active: active },
  52. on: {
  53. click: function click() {
  54. return _this2.$emit('input', year);
  55. }
  56. }
  57. }), formatted);
  58. },
  59. genYearItems: function genYearItems() {
  60. var children = [];
  61. var selectedYear = this.value ? parseInt(this.value, 10) : new Date().getFullYear();
  62. var maxYear = this.max ? parseInt(this.max, 10) : selectedYear + 100;
  63. var minYear = Math.min(maxYear, this.min ? parseInt(this.min, 10) : selectedYear - 100);
  64. for (var year = maxYear; year >= minYear; year--) {
  65. children.push(this.genYearItem(year));
  66. }
  67. return children;
  68. }
  69. },
  70. render: function render() {
  71. return this.$createElement('ul', {
  72. staticClass: 'v-date-picker-years',
  73. ref: 'years'
  74. }, this.genYearItems());
  75. }
  76. });
  77. //# sourceMappingURL=VDatePickerYears.js.map