项目原始demo,不改动
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。
 
 
 
 

187 行
4.6 KiB

  1. // Styles
  2. import "../../../src/components/VBadge/VBadge.sass"; // Components
  3. import VIcon from '../VIcon/VIcon'; // Mixins
  4. import Colorable from '../../mixins/colorable';
  5. import Themeable from '../../mixins/themeable';
  6. import Toggleable from '../../mixins/toggleable';
  7. import Transitionable from '../../mixins/transitionable';
  8. import { factory as PositionableFactory } from '../../mixins/positionable'; // Utilities
  9. import mixins from '../../util/mixins';
  10. import { convertToUnit, getSlot } from '../../util/helpers';
  11. export default mixins(Colorable, PositionableFactory(['left', 'bottom']), Themeable, Toggleable, Transitionable).extend({
  12. name: 'v-badge',
  13. props: {
  14. avatar: Boolean,
  15. bordered: Boolean,
  16. color: {
  17. type: String,
  18. default: 'primary'
  19. },
  20. content: {
  21. required: false
  22. },
  23. dot: Boolean,
  24. label: {
  25. type: String,
  26. default: '$vuetify.badge'
  27. },
  28. icon: String,
  29. inline: Boolean,
  30. offsetX: [Number, String],
  31. offsetY: [Number, String],
  32. overlap: Boolean,
  33. tile: Boolean,
  34. transition: {
  35. type: String,
  36. default: 'scale-rotate-transition'
  37. },
  38. value: {
  39. default: true
  40. }
  41. },
  42. computed: {
  43. classes() {
  44. return {
  45. 'v-badge--avatar': this.avatar,
  46. 'v-badge--bordered': this.bordered,
  47. 'v-badge--bottom': this.bottom,
  48. 'v-badge--dot': this.dot,
  49. 'v-badge--icon': this.icon != null,
  50. 'v-badge--inline': this.inline,
  51. 'v-badge--left': this.left,
  52. 'v-badge--overlap': this.overlap,
  53. 'v-badge--tile': this.tile,
  54. ...this.themeClasses
  55. };
  56. },
  57. computedBottom() {
  58. return this.bottom ? 'auto' : this.computedYOffset;
  59. },
  60. computedLeft() {
  61. if (this.isRtl) {
  62. return this.left ? this.computedXOffset : 'auto';
  63. }
  64. return this.left ? 'auto' : this.computedXOffset;
  65. },
  66. computedRight() {
  67. if (this.isRtl) {
  68. return this.left ? 'auto' : this.computedXOffset;
  69. }
  70. return !this.left ? 'auto' : this.computedXOffset;
  71. },
  72. computedTop() {
  73. return this.bottom ? this.computedYOffset : 'auto';
  74. },
  75. computedXOffset() {
  76. return this.calcPosition(this.offsetX);
  77. },
  78. computedYOffset() {
  79. return this.calcPosition(this.offsetY);
  80. },
  81. isRtl() {
  82. return this.$vuetify.rtl;
  83. },
  84. // Default fallback if offsetX
  85. // or offsetY are undefined.
  86. offset() {
  87. if (this.overlap) return this.dot ? 8 : 12;
  88. return this.dot ? 2 : 4;
  89. },
  90. styles() {
  91. if (this.inline) return {};
  92. return {
  93. bottom: this.computedBottom,
  94. left: this.computedLeft,
  95. right: this.computedRight,
  96. top: this.computedTop
  97. };
  98. }
  99. },
  100. methods: {
  101. calcPosition(offset) {
  102. return `calc(100% - ${convertToUnit(offset || this.offset)})`;
  103. },
  104. genBadge() {
  105. const lang = this.$vuetify.lang;
  106. const label = this.$attrs['aria-label'] || lang.t(this.label);
  107. const data = this.setBackgroundColor(this.color, {
  108. staticClass: 'v-badge__badge',
  109. style: this.styles,
  110. attrs: {
  111. 'aria-atomic': this.$attrs['aria-atomic'] || 'true',
  112. 'aria-label': label,
  113. 'aria-live': this.$attrs['aria-live'] || 'polite',
  114. title: this.$attrs.title,
  115. role: this.$attrs.role || 'status'
  116. },
  117. directives: [{
  118. name: 'show',
  119. value: this.isActive
  120. }]
  121. });
  122. const badge = this.$createElement('span', data, [this.genBadgeContent()]);
  123. if (!this.transition) return badge;
  124. return this.$createElement('transition', {
  125. props: {
  126. name: this.transition,
  127. origin: this.origin,
  128. mode: this.mode
  129. }
  130. }, [badge]);
  131. },
  132. genBadgeContent() {
  133. // Dot prop shows no content
  134. if (this.dot) return undefined;
  135. const slot = getSlot(this, 'badge');
  136. if (slot) return slot;
  137. if (this.content) return String(this.content);
  138. if (this.icon) return this.$createElement(VIcon, this.icon);
  139. return undefined;
  140. },
  141. genBadgeWrapper() {
  142. return this.$createElement('span', {
  143. staticClass: 'v-badge__wrapper'
  144. }, [this.genBadge()]);
  145. }
  146. },
  147. render(h) {
  148. const badge = [this.genBadgeWrapper()];
  149. const children = [getSlot(this)];
  150. const {
  151. 'aria-atomic': _x,
  152. 'aria-label': _y,
  153. 'aria-live': _z,
  154. role,
  155. title,
  156. ...attrs
  157. } = this.$attrs;
  158. if (this.inline && this.left) children.unshift(badge);else children.push(badge);
  159. return h('span', {
  160. staticClass: 'v-badge',
  161. attrs,
  162. class: this.classes
  163. }, children);
  164. }
  165. });
  166. //# sourceMappingURL=VBadge.js.map