1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _vue = require("vue");
|
9 |
|
10 | var _classNames2 = _interopRequireDefault(require("../_util/classNames"));
|
11 |
|
12 | var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));
|
13 |
|
14 | var _CloseOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CloseOutlined"));
|
15 |
|
16 | var _wave = _interopRequireDefault(require("../_util/wave"));
|
17 |
|
18 | var _colors = require("../_util/colors");
|
19 |
|
20 | var _configProvider = require("../config-provider");
|
21 |
|
22 | var _CheckableTag = _interopRequireDefault(require("./CheckableTag"));
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | 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; }
|
27 |
|
28 | function _isSlot(s) {
|
29 | return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !(0, _vue.isVNode)(s);
|
30 | }
|
31 |
|
32 | var PresetColorRegex = new RegExp("^(".concat(_colors.PresetColorTypes.join('|'), ")(-inverse)?$"));
|
33 | var PresetStatusColorRegex = new RegExp("^(".concat(_colors.PresetStatusColorTypes.join('|'), ")$"));
|
34 | var tagProps = {
|
35 | prefixCls: _vueTypes.default.string,
|
36 | color: {
|
37 | type: String
|
38 | },
|
39 | closable: _vueTypes.default.looseBool.def(false),
|
40 | closeIcon: _vueTypes.default.VNodeChild,
|
41 | visible: _vueTypes.default.looseBool,
|
42 | onClose: {
|
43 | type: Function
|
44 | },
|
45 | icon: _vueTypes.default.VNodeChild
|
46 | };
|
47 | var Tag = (0, _vue.defineComponent)({
|
48 | name: 'ATag',
|
49 | emits: ['update:visible', 'close'],
|
50 | setup: function setup(props, _ref) {
|
51 | var slots = _ref.slots,
|
52 | emit = _ref.emit,
|
53 | attrs = _ref.attrs;
|
54 |
|
55 | var _inject = (0, _vue.inject)('configProvider', _configProvider.defaultConfigProvider),
|
56 | getPrefixCls = _inject.getPrefixCls;
|
57 |
|
58 | var visible = (0, _vue.ref)(true);
|
59 | (0, _vue.watchEffect)(function () {
|
60 | if (props.visible !== undefined) {
|
61 | visible.value = props.visible;
|
62 | }
|
63 | });
|
64 |
|
65 | var handleCloseClick = function handleCloseClick(e) {
|
66 | e.stopPropagation();
|
67 | emit('update:visible', false);
|
68 | emit('close', e);
|
69 |
|
70 | if (e.defaultPrevented) {
|
71 | return;
|
72 | }
|
73 |
|
74 | if (props.visible === undefined) {
|
75 | visible.value = false;
|
76 | }
|
77 | };
|
78 |
|
79 | var isPresetColor = function isPresetColor() {
|
80 | var color = props.color;
|
81 |
|
82 | if (!color) {
|
83 | return false;
|
84 | }
|
85 |
|
86 | return PresetColorRegex.test(color) || PresetStatusColorRegex.test(color);
|
87 | };
|
88 |
|
89 | return function () {
|
90 | var _classNames;
|
91 |
|
92 | var _a, _b, _c;
|
93 |
|
94 | var customizePrefixCls = props.prefixCls,
|
95 | _props$icon = props.icon,
|
96 | icon = _props$icon === void 0 ? (_a = slots.icon) === null || _a === void 0 ? void 0 : _a.call(slots) : _props$icon,
|
97 | color = props.color,
|
98 | _props$closeIcon = props.closeIcon,
|
99 | closeIcon = _props$closeIcon === void 0 ? (_b = slots.closeIcon) === null || _b === void 0 ? void 0 : _b.call(slots) : _props$closeIcon,
|
100 | _props$closable = props.closable,
|
101 | closable = _props$closable === void 0 ? false : _props$closable;
|
102 | var presetColor = isPresetColor();
|
103 | var prefixCls = getPrefixCls('tag', customizePrefixCls);
|
104 |
|
105 | var renderCloseIcon = function renderCloseIcon() {
|
106 | if (closable) {
|
107 | return closeIcon ? (0, _vue.createVNode)("div", {
|
108 | "class": "".concat(prefixCls, "-close-icon"),
|
109 | "onClick": handleCloseClick
|
110 | }, _isSlot(closeIcon) ? closeIcon : {
|
111 | default: function _default() {
|
112 | return [closeIcon];
|
113 | }
|
114 | }) : (0, _vue.createVNode)(_CloseOutlined.default, {
|
115 | "class": "".concat(prefixCls, "-close-icon"),
|
116 | "onClick": handleCloseClick
|
117 | }, null);
|
118 | }
|
119 |
|
120 | return null;
|
121 | };
|
122 |
|
123 | var tagStyle = {
|
124 | backgroundColor: color && !isPresetColor() ? color : undefined
|
125 | };
|
126 | var tagClassName = (0, _classNames2.default)(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(color), presetColor), _defineProperty(_classNames, "".concat(prefixCls, "-has-color"), color && !presetColor), _defineProperty(_classNames, "".concat(prefixCls, "-hidden"), !visible.value), _classNames));
|
127 | var iconNode = icon || null;
|
128 | var children = (_c = slots.default) === null || _c === void 0 ? void 0 : _c.call(slots);
|
129 | var kids = iconNode ? (0, _vue.createVNode)(_vue.Fragment, null, [iconNode, (0, _vue.createVNode)("span", null, _isSlot(children) ? children : {
|
130 | default: function _default() {
|
131 | return [children];
|
132 | }
|
133 | })]) : children;
|
134 | var isNeedWave = ('onClick' in attrs);
|
135 | var tagNode = (0, _vue.createVNode)("span", {
|
136 | "class": tagClassName,
|
137 | "style": tagStyle
|
138 | }, [kids, renderCloseIcon()]);
|
139 | return isNeedWave ? (0, _vue.createVNode)(_wave.default, null, _isSlot(tagNode) ? tagNode : {
|
140 | default: function _default() {
|
141 | return [tagNode];
|
142 | }
|
143 | }) : tagNode;
|
144 | };
|
145 | }
|
146 | });
|
147 | Tag.props = tagProps;
|
148 | Tag.CheckableTag = _CheckableTag.default;
|
149 |
|
150 | Tag.install = function (app) {
|
151 | app.component(Tag.name, Tag);
|
152 | app.component(_CheckableTag.default.name, _CheckableTag.default);
|
153 | return app;
|
154 | };
|
155 |
|
156 | var _default2 = Tag;
|
157 | exports.default = _default2; |
\ | No newline at end of file |