|
| 1 | +import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; |
| 2 | +import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; |
| 3 | + |
| 4 | +// Template |
| 5 | +import AvatarTemplate from "./generated/templates/AvatarTemplate.lit.js"; |
| 6 | + |
| 7 | +// Styles |
| 8 | +import AvatarCss from "./generated/themes/Avatar.css.js"; |
| 9 | + |
| 10 | +import Icon from "./Icon.js"; |
| 11 | +import AvatarSize from "./types/AvatarSize.js"; |
| 12 | +import AvatarShape from "./types/AvatarShape.js"; |
| 13 | + |
| 14 | +/** |
| 15 | + * @public |
| 16 | + */ |
| 17 | +const metadata = { |
| 18 | + tag: "ui5-avatar", |
| 19 | + properties: /** @lends sap.ui.webcomponents.main.Avatar.prototype */ { |
| 20 | + |
| 21 | + /** |
| 22 | + * Defines the source path to the desired image. |
| 23 | + * @type {string} |
| 24 | + * @defaultvalue "" |
| 25 | + * @public |
| 26 | + */ |
| 27 | + img: { |
| 28 | + type: String, |
| 29 | + }, |
| 30 | + |
| 31 | + /** |
| 32 | + * Defines the name of the UI5 Icon, that would be displayed. |
| 33 | + * <br> |
| 34 | + * <b>Note:</b> if <code>img</code> is set, the property would be ignored. |
| 35 | + * <br> |
| 36 | + * <b>Note:</b> you should import the desired icon first, then use its name as "icon". |
| 37 | + * <br><br> |
| 38 | + * import "@ui5/webcomponents-icons/dist/icons/{icon_name}.js" |
| 39 | + * <br> |
| 40 | + * <pre><ui5-avatar icon-src="employee"></pre> |
| 41 | + * |
| 42 | + * See all the available icons in the <ui5-link target="_blank" href="https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/iconExplorer/webapp/index.html" class="api-table-content-cell-link">Icon Explorer</ui5-link>. |
| 43 | + * @type {string} |
| 44 | + * @defaultvalue "" |
| 45 | + * @public |
| 46 | + */ |
| 47 | + icon: { |
| 48 | + type: String, |
| 49 | + }, |
| 50 | + |
| 51 | + /** |
| 52 | + * Defines the shape of the <code>ui5-avatar</code>. |
| 53 | + * <br><br> |
| 54 | + * Available options are: |
| 55 | + * <ul> |
| 56 | + * <li><code>Circle</code></li> |
| 57 | + * <li><code>Square</code></li> |
| 58 | + * <ul> |
| 59 | + * @public |
| 60 | + * @defaultvalue "Circle" |
| 61 | + */ |
| 62 | + shape: { |
| 63 | + type: String, |
| 64 | + defaultValue: AvatarShape.Circle, |
| 65 | + }, |
| 66 | + |
| 67 | + /** |
| 68 | + * Defines predefined size of the <code>ui5-avatar</code>. |
| 69 | + * <br><br> |
| 70 | + * Available options are: |
| 71 | + * <ul> |
| 72 | + * <li><code>XS</code></li> |
| 73 | + * <li><code>S</code></li> |
| 74 | + * <li><code>M</code></li> |
| 75 | + * <li><code>L</code></li> |
| 76 | + * <li><code>XL</code></li> |
| 77 | + * <ul> |
| 78 | + * @public |
| 79 | + * @defaultvalue "S" |
| 80 | + */ |
| 81 | + size: { |
| 82 | + type: String, |
| 83 | + defaultValue: AvatarSize.S, |
| 84 | + }, |
| 85 | + }, |
| 86 | + slots: /** @lends sap.ui.webcomponents.main.Avatar.prototype */ { |
| 87 | + }, |
| 88 | + events: /** @lends sap.ui.webcomponents.main.Avatar.prototype */ { |
| 89 | + }, |
| 90 | +}; |
| 91 | + |
| 92 | +/** |
| 93 | + * @class |
| 94 | + * |
| 95 | + * <h3 class="comment-api-title">Overview</h3> |
| 96 | + * |
| 97 | + * An image-like control that has different display options for representing images and icons |
| 98 | + * in different shapes and sizes, depending on the use case. |
| 99 | + * |
| 100 | + * The shape can be circular or square. There are several predefined sizes, as well as an option to |
| 101 | + * set a custom size. |
| 102 | + * |
| 103 | + * <h3>ES6 Module Import</h3> |
| 104 | + * |
| 105 | + * <code>import @ui5/webcomponents/dist/Avatar.js";</code> |
| 106 | + * |
| 107 | + * @constructor |
| 108 | + * @author SAP SE |
| 109 | + * @alias sap.ui.webcomponents.main.Avatar |
| 110 | + * @extends UI5Element |
| 111 | + * @tagname ui5-avatar |
| 112 | + * @since 1.0.0-rc.6 |
| 113 | + * @public |
| 114 | + */ |
| 115 | +class Avatar extends UI5Element { |
| 116 | + static get metadata() { |
| 117 | + return metadata; |
| 118 | + } |
| 119 | + |
| 120 | + static get render() { |
| 121 | + return litRender; |
| 122 | + } |
| 123 | + |
| 124 | + static get styles() { |
| 125 | + return AvatarCss; |
| 126 | + } |
| 127 | + |
| 128 | + static get template() { |
| 129 | + return AvatarTemplate; |
| 130 | + } |
| 131 | + |
| 132 | + static async define(...params) { |
| 133 | + await Icon.define(); |
| 134 | + super.define(...params); |
| 135 | + } |
| 136 | + |
| 137 | + get displayIcon() { |
| 138 | + return !!this.icon && !this.img; |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +Avatar.define(); |
| 143 | + |
| 144 | +export default Avatar; |
0 commit comments