项目原始demo,不改动
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Pode ver ficheiros e cloná-lo, mas não pode fazer envios ou lançar questões ou pedidos de integração.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // Styles
  2. import "../../../src/components/VAlert/VAlert.sass"; // Extensions
  3. import VSheet from '../VSheet'; // Components
  4. import VBtn from '../VBtn';
  5. import VIcon from '../VIcon'; // Mixins
  6. import Toggleable from '../../mixins/toggleable';
  7. import Themeable from '../../mixins/themeable';
  8. import Transitionable from '../../mixins/transitionable'; // Utilities
  9. import mixins from '../../util/mixins';
  10. import { breaking } from '../../util/console';
  11. /* @vue/component */
  12. export default mixins(VSheet, Toggleable, Transitionable).extend({
  13. name: 'v-alert',
  14. props: {
  15. border: {
  16. type: String,
  17. validator(val) {
  18. return ['top', 'right', 'bottom', 'left'].includes(val);
  19. }
  20. },
  21. closeLabel: {
  22. type: String,
  23. default: '$vuetify.close'
  24. },
  25. coloredBorder: Boolean,
  26. dense: Boolean,
  27. dismissible: Boolean,
  28. icon: {
  29. default: '',
  30. type: [Boolean, String],
  31. validator(val) {
  32. return typeof val === 'string' || val === false;
  33. }
  34. },
  35. outlined: Boolean,
  36. prominent: Boolean,
  37. text: Boolean,
  38. type: {
  39. type: String,
  40. validator(val) {
  41. return ['info', 'error', 'success', 'warning'].includes(val);
  42. }
  43. },
  44. value: {
  45. type: Boolean,
  46. default: true
  47. }
  48. },
  49. computed: {
  50. __cachedBorder() {
  51. if (!this.border) return null;
  52. let data = {
  53. staticClass: 'v-alert__border',
  54. class: {
  55. [`v-alert__border--${this.border}`]: true
  56. }
  57. };
  58. if (this.coloredBorder) {
  59. data = this.setBackgroundColor(this.computedColor, data);
  60. data.class['v-alert__border--has-color'] = true;
  61. }
  62. return this.$createElement('div', data);
  63. },
  64. __cachedDismissible() {
  65. if (!this.dismissible) return null;
  66. const color = this.iconColor;
  67. return this.$createElement(VBtn, {
  68. staticClass: 'v-alert__dismissible',
  69. props: {
  70. color,
  71. icon: true,
  72. small: true
  73. },
  74. attrs: {
  75. 'aria-label': this.$vuetify.lang.t(this.closeLabel)
  76. },
  77. on: {
  78. click: () => this.isActive = false
  79. }
  80. }, [this.$createElement(VIcon, {
  81. props: {
  82. color
  83. }
  84. }, '$cancel')]);
  85. },
  86. __cachedIcon() {
  87. if (!this.computedIcon) return null;
  88. return this.$createElement(VIcon, {
  89. staticClass: 'v-alert__icon',
  90. props: {
  91. color: this.iconColor
  92. }
  93. }, this.computedIcon);
  94. },
  95. classes() {
  96. const classes = { ...VSheet.options.computed.classes.call(this),
  97. 'v-alert--border': Boolean(this.border),
  98. 'v-alert--dense': this.dense,
  99. 'v-alert--outlined': this.outlined,
  100. 'v-alert--prominent': this.prominent,
  101. 'v-alert--text': this.text
  102. };
  103. if (this.border) {
  104. classes[`v-alert--border-${this.border}`] = true;
  105. }
  106. return classes;
  107. },
  108. computedColor() {
  109. return this.color || this.type;
  110. },
  111. computedIcon() {
  112. if (this.icon === false) return false;
  113. if (typeof this.icon === 'string' && this.icon) return this.icon;
  114. if (!['error', 'info', 'success', 'warning'].includes(this.type)) return false;
  115. return `$${this.type}`;
  116. },
  117. hasColoredIcon() {
  118. return this.hasText || Boolean(this.border) && this.coloredBorder;
  119. },
  120. hasText() {
  121. return this.text || this.outlined;
  122. },
  123. iconColor() {
  124. return this.hasColoredIcon ? this.computedColor : undefined;
  125. },
  126. isDark() {
  127. if (this.type && !this.coloredBorder && !this.outlined) return true;
  128. return Themeable.options.computed.isDark.call(this);
  129. }
  130. },
  131. created() {
  132. /* istanbul ignore next */
  133. if (this.$attrs.hasOwnProperty('outline')) {
  134. breaking('outline', 'outlined', this);
  135. }
  136. },
  137. methods: {
  138. genWrapper() {
  139. const children = [this.$slots.prepend || this.__cachedIcon, this.genContent(), this.__cachedBorder, this.$slots.append, this.$scopedSlots.close ? this.$scopedSlots.close({
  140. toggle: this.toggle
  141. }) : this.__cachedDismissible];
  142. const data = {
  143. staticClass: 'v-alert__wrapper'
  144. };
  145. return this.$createElement('div', data, children);
  146. },
  147. genContent() {
  148. return this.$createElement('div', {
  149. staticClass: 'v-alert__content'
  150. }, this.$slots.default);
  151. },
  152. genAlert() {
  153. let data = {
  154. staticClass: 'v-alert',
  155. attrs: {
  156. role: 'alert'
  157. },
  158. class: this.classes,
  159. style: this.styles,
  160. directives: [{
  161. name: 'show',
  162. value: this.isActive
  163. }]
  164. };
  165. if (!this.coloredBorder) {
  166. const setColor = this.hasText ? this.setTextColor : this.setBackgroundColor;
  167. data = setColor(this.computedColor, data);
  168. }
  169. return this.$createElement('div', data, [this.genWrapper()]);
  170. },
  171. /** @public */
  172. toggle() {
  173. this.isActive = !this.isActive;
  174. }
  175. },
  176. render(h) {
  177. const render = this.genAlert();
  178. if (!this.transition) return render;
  179. return h('transition', {
  180. props: {
  181. name: this.transition,
  182. origin: this.origin,
  183. mode: this.mode
  184. }
  185. }, [render]);
  186. }
  187. });
  188. //# sourceMappingURL=VAlert.js.map