项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

222 lines
7.2 KiB

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