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.

VRadio.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  3. // Styles
  4. import '../../../src/stylus/components/_radios.styl';
  5. // Components
  6. import VIcon from '../VIcon';
  7. import VLabel from '../VLabel';
  8. // Mixins
  9. import Colorable from '../../mixins/colorable';
  10. import Rippleable from '../../mixins/rippleable';
  11. import Themeable from '../../mixins/themeable';
  12. import Selectable from '../../mixins/selectable';
  13. import { inject as RegistrableInject } from '../../mixins/registrable';
  14. /* @vue/component */
  15. export default {
  16. name: 'v-radio',
  17. mixins: [Colorable, Rippleable, RegistrableInject('radio', 'v-radio', 'v-radio-group'), Themeable],
  18. inheritAttrs: false,
  19. props: {
  20. color: {
  21. type: String,
  22. default: 'accent'
  23. },
  24. disabled: Boolean,
  25. label: String,
  26. onIcon: {
  27. type: String,
  28. default: '$vuetify.icons.radioOn'
  29. },
  30. offIcon: {
  31. type: String,
  32. default: '$vuetify.icons.radioOff'
  33. },
  34. readonly: Boolean,
  35. value: null
  36. },
  37. data: function data() {
  38. return {
  39. isActive: false,
  40. isFocused: false,
  41. parentError: false
  42. };
  43. },
  44. computed: {
  45. computedData: function computedData() {
  46. return this.setTextColor(!this.parentError && this.isActive && this.color, {
  47. staticClass: 'v-radio',
  48. 'class': _extends({
  49. 'v-radio--is-disabled': this.isDisabled,
  50. 'v-radio--is-focused': this.isFocused
  51. }, this.themeClasses)
  52. });
  53. },
  54. computedColor: function computedColor() {
  55. return this.isActive ? this.color : this.radio.validationState || false;
  56. },
  57. computedIcon: function computedIcon() {
  58. return this.isActive ? this.onIcon : this.offIcon;
  59. },
  60. hasState: function hasState() {
  61. return this.isActive || !!this.radio.validationState;
  62. },
  63. isDisabled: function isDisabled() {
  64. return this.disabled || !!this.radio.disabled;
  65. },
  66. isReadonly: function isReadonly() {
  67. return this.readonly || !!this.radio.readonly;
  68. }
  69. },
  70. mounted: function mounted() {
  71. this.radio.register(this);
  72. },
  73. beforeDestroy: function beforeDestroy() {
  74. this.radio.unregister(this);
  75. },
  76. methods: {
  77. genInput: function genInput() {
  78. var _Selectable$options$m;
  79. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  80. args[_key] = arguments[_key];
  81. }
  82. // We can't actually use the mixin directly because
  83. // it's made for standalone components, but its
  84. // genInput method is exactly what we need
  85. return (_Selectable$options$m = Selectable.options.methods.genInput).call.apply(_Selectable$options$m, [this].concat(_toConsumableArray(args)));
  86. },
  87. genLabel: function genLabel() {
  88. return this.$createElement(VLabel, {
  89. on: { click: this.onChange },
  90. attrs: {
  91. for: this.id
  92. },
  93. props: {
  94. color: this.radio.validationState || '',
  95. dark: this.dark,
  96. focused: this.hasState,
  97. light: this.light
  98. }
  99. }, this.$slots.label || this.label);
  100. },
  101. genRadio: function genRadio() {
  102. return this.$createElement('div', {
  103. staticClass: 'v-input--selection-controls__input'
  104. }, [this.genInput('radio', _extends({
  105. name: this.radio.name || (this.radio._uid ? 'v-radio-' + this.radio._uid : false),
  106. value: this.value
  107. }, this.$attrs)), this.genRipple(this.setTextColor(this.computedColor)), this.$createElement(VIcon, this.setTextColor(this.computedColor, {
  108. props: {
  109. dark: this.dark,
  110. light: this.light
  111. }
  112. }), this.computedIcon)]);
  113. },
  114. onFocus: function onFocus(e) {
  115. this.isFocused = true;
  116. this.$emit('focus', e);
  117. },
  118. onBlur: function onBlur(e) {
  119. this.isFocused = false;
  120. this.$emit('blur', e);
  121. },
  122. onChange: function onChange() {
  123. if (this.isDisabled || this.isReadonly) return;
  124. if (!this.isDisabled && (!this.isActive || !this.radio.mandatory)) {
  125. this.$emit('change', this.value);
  126. }
  127. },
  128. onKeydown: function onKeydown() {}
  129. },
  130. render: function render(h) {
  131. return h('div', this.computedData, [this.genRadio(), this.genLabel()]);
  132. }
  133. };
  134. //# sourceMappingURL=VRadio.js.map