|
| 1 | +import Component from './Base.mjs'; |
| 2 | +import NeoArray from '../util/Array.mjs'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @class Neo.component.IconLink |
| 6 | + * @extends Neo.component.Base |
| 7 | + */ |
| 8 | +class IconLink extends Component { |
| 9 | + static config = { |
| 10 | + /** |
| 11 | + * @member {String} className='Neo.component.IconLink' |
| 12 | + * @protected |
| 13 | + */ |
| 14 | + className: 'Neo.component.IconLink', |
| 15 | + /** |
| 16 | + * @member {String} ntype='icon-link' |
| 17 | + * @protected |
| 18 | + */ |
| 19 | + ntype: 'icon-link', |
| 20 | + /** |
| 21 | + * @member {String[]} baseCls=['neo-icon-link'] |
| 22 | + */ |
| 23 | + baseCls: ['neo-icon-link'], |
| 24 | + /** |
| 25 | + * @member {String|null} iconCls_=null |
| 26 | + * @reactive |
| 27 | + */ |
| 28 | + iconCls_: null, |
| 29 | + /** |
| 30 | + * @member {String} tag='a' |
| 31 | + */ |
| 32 | + tag: 'a', |
| 33 | + /** |
| 34 | + * @member {String} target_='_blank' |
| 35 | + * @reactive |
| 36 | + */ |
| 37 | + target_: '_blank', |
| 38 | + /** |
| 39 | + * @member {String|null} url_=null |
| 40 | + * @reactive |
| 41 | + */ |
| 42 | + url_: null, |
| 43 | + /** |
| 44 | + * @member {Object} _vdom |
| 45 | + */ |
| 46 | + _vdom: |
| 47 | + {cn: [ |
| 48 | + {tag: 'i', cls: []} |
| 49 | + ]} |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Triggered after the iconCls config got changed |
| 54 | + * @param {String|String[]|null} value |
| 55 | + * @param {String|String[]|null} oldValue |
| 56 | + */ |
| 57 | + afterSetIconCls(value, oldValue) { |
| 58 | + let me = this, |
| 59 | + node = me.vdom.cn[0], |
| 60 | + cls = node.cls || []; |
| 61 | + |
| 62 | + NeoArray.removeAdd(cls, oldValue, value); |
| 63 | + |
| 64 | + node.cls = cls; |
| 65 | + me.update() |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Triggered after the target config got changed |
| 70 | + * @param {String} value |
| 71 | + * @param {String} oldValue |
| 72 | + */ |
| 73 | + afterSetTarget(value, oldValue) { |
| 74 | + this.changeVdomRootKey('target', value) |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Triggered after the url config got changed |
| 79 | + * @param {String|null} value |
| 80 | + * @param {String|null} oldValue |
| 81 | + */ |
| 82 | + afterSetUrl(value, oldValue) { |
| 83 | + let me = this; |
| 84 | + |
| 85 | + if (value) { |
| 86 | + me.vdom.href = value; |
| 87 | + me.hidden = false |
| 88 | + } else { |
| 89 | + delete me.vdom.href; |
| 90 | + me.hidden = true |
| 91 | + } |
| 92 | + |
| 93 | + me.update() |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Triggered before the iconCls config gets changed. Converts the string into an array if needed. |
| 98 | + * @param {Array|String|null} value The new value of the iconCls config. |
| 99 | + * @param {Array|String|null} oldValue The old value of the iconCls config. |
| 100 | + * @returns {Array} |
| 101 | + * @protected |
| 102 | + */ |
| 103 | + beforeSetIconCls(value, oldValue) { |
| 104 | + if (value && !Array.isArray(value)) { |
| 105 | + value = value.split(' ').filter(Boolean) |
| 106 | + } |
| 107 | + |
| 108 | + return value |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +export default Neo.setupClass(IconLink); |
0 commit comments