|
| 1 | +import Component from './Base.mjs'; |
| 2 | + |
| 3 | +/** |
| 4 | + * @summary A component to render an `<img>` tag with reactive `src` and `alt` attributes. |
| 5 | + * |
| 6 | + * This component provides a simple, object-oriented wrapper for the native `<img>` element, |
| 7 | + * allowing its `src` and `alt` text to be updated dynamically via the config system. |
| 8 | + * |
| 9 | + * This is a key component for data-binding scenarios, such as displaying an image from a store record |
| 10 | + * or implementing lazy-loading by updating the `src` config at runtime. |
| 11 | + * |
| 12 | + * @example |
| 13 | + * // Basic usage |
| 14 | + * Neo.create({ |
| 15 | + * module: Image, |
| 16 | + * alt : 'A beautiful landscape', |
| 17 | + * src : 'https://www.neomjs.com/resources/images/logo.png' |
| 18 | + * }); |
| 19 | + * |
| 20 | + * @class Neo.component.Image |
| 21 | + * @extends Neo.component.Base |
| 22 | + */ |
| 23 | +class Image extends Component { |
| 24 | + static config = { |
| 25 | + /** |
| 26 | + * @member {String} className='Neo.component.Image' |
| 27 | + * @protected |
| 28 | + */ |
| 29 | + className: 'Neo.component.Image', |
| 30 | + /** |
| 31 | + * @member {String} ntype='image' |
| 32 | + * @protected |
| 33 | + */ |
| 34 | + ntype: 'image', |
| 35 | + /** |
| 36 | + * The alt attribute for the image. |
| 37 | + * @member {String|null} alt_=null |
| 38 | + * @reactive |
| 39 | + */ |
| 40 | + alt_: null, |
| 41 | + /** |
| 42 | + * The src attribute for the image. |
| 43 | + * @member {String|null} src_=null |
| 44 | + * @reactive |
| 45 | + */ |
| 46 | + src_: null, |
| 47 | + /** |
| 48 | + * The HTML tag for this component. |
| 49 | + * @member {String} tag='img' |
| 50 | + * @reactive |
| 51 | + */ |
| 52 | + tag: 'img' |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Hook that fires after the `alt` config has been changed. |
| 57 | + * Updates the `alt` attribute in the component's VDOM. |
| 58 | + * @param {String|null} value The new value |
| 59 | + * @param {String|null} oldValue The old value |
| 60 | + * @protected |
| 61 | + */ |
| 62 | + afterSetAlt(value, oldValue) { |
| 63 | + this.changeVdomRootKey('alt', value) |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Hook that fires after the `src` config has been changed. |
| 68 | + * Updates the `src` attribute in the component's VDOM. |
| 69 | + * @param {String|null} value The new value |
| 70 | + * @param {String|null} oldValue The old value |
| 71 | + * @protected |
| 72 | + */ |
| 73 | + afterSetSrc(value, oldValue) { |
| 74 | + this.changeVdomRootKey('src', value) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +export default Neo.setupClass(Image); |
0 commit comments