{"id":28906,"date":"2024-09-09T05:00:00","date_gmt":"2024-09-09T03:00:00","guid":{"rendered":"https:\/\/sii.pl\/blog\/?p=28906"},"modified":"2024-08-27T10:07:27","modified_gmt":"2024-08-27T08:07:27","slug":"adaptive-card-extensions-tips-and-tricks-for-developers","status":"publish","type":"post","link":"https:\/\/sii.pl\/blog\/en\/adaptive-card-extensions-tips-and-tricks-for-developers\/","title":{"rendered":"Adaptive Card Extensions \u2013 tips and tricks for developers"},"content":{"rendered":"\n<p>If you are a developer and have dipped your toe in Viva Connections, you may know that SPFx offers a dedicated component type for all your Viva needs \u2013 Adaptive Card Extension, aka ACE! ACE can be used in multiple scenarios, from displaying your users&#8217; fight details or food order to rendering an image gallery. As usual, Microsoft provides a basic tutorial on building ACEs. <\/p>\n\n\n\n<p>Even if you are an absolute #1 fan of Microsoft and follow their guidelines to the dot, you still may have some questions. Let&#8217;s tackle those doubts and create the best SPFx extension of your life!<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic1.png\"><img decoding=\"async\" width=\"914\" height=\"411\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic1.png\" alt=\"Example of a Viva Connections dashboard\" class=\"wp-image-28897\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic1.png 914w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic1-300x135.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic1-768x345.png 768w\" sizes=\"(max-width: 914px) 100vw, 914px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 1 Example of a Viva Connections dashboard<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wait, what? How do I even create an Adaptive Card Extension?! I don&#8217;t see this option in my Yeoman!<\/strong><\/h2>\n\n\n\n<p>Hey, don&#8217;t panic! Make sure your SharePoint generator is updated. Currently, it&#8217;s best if you have SPFx v1.18 installed. If you&#8217;re not sure how to check your SPFx version, you can follow <a href=\"https:\/\/blog.mastykarz.nl\/how-to-check-sharepoint-framework-version\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >Waldek&#8217;s<\/a>. <\/p>\n\n\n\n<p>While at it, you may want to look at this <a href=\"https:\/\/learn.microsoft.com\/en-us\/sharepoint\/dev\/spfx\/compatibility#spfx-development-environment-compatibility\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >compatibility table<\/a> to ensure that your Node.js, TypeScript, and React are also properly versioned.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The adaptive cards seem really complicated. How do I even start designing one?<\/strong><\/h2>\n\n\n\n<p>Browse <a href=\"https:\/\/adaptivecards.io\/samples\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >Microsoft samples<\/a> for some inspiration or take a look at examples <a href=\"https:\/\/github.com\/pnp\/AdaptiveCards-Templates\/tree\/main\/samples\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >provided by PnP<\/a>. \u00a0When you find something interesting, customize it <a href=\"https:\/\/adaptivecards.io\/designer\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >in the designer<\/a>.<\/p>\n\n\n\n<p>But don&#8217;t worry \u2013 you don&#8217;t have to copy your template to the designer whenever you want to update it! Install Microsoft&#8217;s &#8220;Adaptive Card Previewer&#8221; extension to make small changes in your Visual Studio Code.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic2.png\"><img decoding=\"async\" width=\"605\" height=\"151\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic2.png\" alt=\"Adaptive Card Previewer extension in Visual Studio Code\" class=\"wp-image-28899\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic2.png 605w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic2-300x75.png 300w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 2 Adaptive Card Previewer extension in Visual Studio Code<\/figcaption><\/figure>\n\n\n\n<p>And remember \u2013 as with many skills, practice makes perfect!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The extension&#8217;s icon doesn&#8217;t display. Am I setting it wrong?<\/strong><\/h2>\n\n\n\n<p>Firstly, take a look at the Microsoft tutorial, which explains that the icon needs to be set in the solution&#8217;s manifest. Actually, I suggest configuring two properties for your icons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8220;officeFabricIconFontName\u201d \u2013 so your solution has a nice icon in the editor&#8217;s Toolbox,<\/li>\n\n\n\n<li>&#8220;iconProperty\u201d (as suggested by Microsoft) \u2013 for the card bar&#8217;s icon.<\/li>\n<\/ul>\n\n\n\n<p>Secondly, use correct iconography. As always, you can use Fluent UI icons for the first property. For the card bar&#8217;s icon, take a look at <a href=\"https:\/\/learn.microsoft.com\/en-us\/sharepoint\/dev\/spfx\/viva\/get-started\/fluent-icons-limitations#card-designer-icons-set\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >a list of supported values<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Can you imagine a user saying that my ACE is hard to read and the images have weird backgrounds?! It looks great on my app!<\/strong><\/h2>\n\n\n\n<p>First of all, the audacity of some people. Second of all, remember that users have the option of changing themes on their apps. As a result, your beautiful adaptive card may look different to different users.<\/p>\n\n\n\n<p>You can check the user&#8217;s theme in your adaptive card&#8217;s onInit function:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nthis.context.sdks?.microsoftTeams?.teamsJs.app.getContext().then((context) =&gt; {\n    this.setState({\n      theme: context.app.appInfo.theme\n    });\n  });\n<\/pre><\/div>\n\n\n<p><strong>Important!<\/strong> Make sure you&#8217;re using at least SPFx v1.18, or you may be missing the sdks property in the context. <\/p>\n\n\n\n<p>Now, you can render your card according to the current theme! You can read more about it here: <a href=\"https:\/\/learn.microsoft.com\/en-us\/sharepoint\/dev\/spfx\/viva\/get-started\/making-quickview-compatable-darkmode-mobile\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >Making Quick View compatible with dark mode in mobile devices<\/a>. \u00a0\u00a0\u00a0\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-scaled.jpg\"><img decoding=\"async\" width=\"1024\" height=\"646\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-1024x646.jpg\" alt=\"An example of a card reacting to different themes\" class=\"wp-image-28901\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-1024x646.jpg 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-300x189.jpg 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-768x485.jpg 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-1536x970.jpg 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/pic3-2048x1293.jpg 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 3 <a href=\"https:\/\/learn.microsoft.com\/en-us\/sharepoint\/dev\/images\/viva-design\/img_quickview_tutorial_light_and_dark.png\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >An example of a card reacting to different themes<\/a><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>I want to show some dynamic content on my card. How can I display SharePoint list items in quick view? Is there a way to pass them to the template?<\/strong><\/h2>\n\n\n\n<p>Yes, of course! Firstly, reference your data in the quick view \u2013 for example, pass the values from the card&#8217;s state:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npublic get data(): IQuickViewData {\n  return {\n    items: this.state.items\n  };\n}\n<\/pre><\/div>\n\n\n<p>With that in place, you can refer to your items in the template. Remember that a parent container should have a &#8220;$data&#8221; property set:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  &quot;type&quot;: &quot;AdaptiveCard&quot;,\n  &quot;$schema&quot;: &quot;http:\/\/adaptivecards.io\/schemas\/adaptive-card.json&quot;,\n  &quot;version&quot;: &quot;1.5&quot;,\n  &quot;body&quot;: &#x5B;\n    {\n      &quot;type&quot;: &quot;Container&quot;,\n      &quot;$data&quot;: &quot;${items}&quot;,\n      &quot;items&quot;: &#x5B;\n        {\n          &quot;type&quot;: &quot;TextBlock&quot;,\n          &quot;text&quot;: &quot;${title}&quot;,\n        },\n        \u2026\n      ]\n    }\n}\n<\/pre><\/div>\n\n\n<p>And just like that, the card will display all your list items! As with the data property, the item properties are identified by the dollar character, for example, &#8220;${title}&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>It seems that adaptive cards don&#8217;t allow icons in their schema. I really want to use a Fluent UI icon on my card. What should I do?<\/strong><\/h2>\n\n\n\n<p>Use an image instead! Either reference the pic&#8217;s URL:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n      &quot;type&quot;: &quot;Image&quot;,\n      &quot;url&quot;: &quot;https:\/\/adaptivecards.io\/content\/cats\/1.png&quot;,\n      &quot;altText&quot;: &quot;Cat&quot;\n    }\n<\/pre><\/div>\n\n\n<p>Alternatively, convert your icon to base64 format:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n      &quot;type&quot;: &quot;Image&quot;,\n      &quot;url&quot;: &quot;data:image\/png;base64,iVBORw0KGgoAAAA\u2026&quot;,\n      &quot;altText&quot;: &quot;Cat&quot;\n    }\n<\/pre><\/div>\n\n\n<p>You can look online for image converters or try this <a href=\"https:\/\/codepen.io\/joshmcrty\/pen\/GOBWeV\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >clever CodePen solution<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>I hope I&#8217;ve answered the most common questions that arise and will help you find your way around the world of Adaptive Card Extension. I&#8217;d love to hear what your tips and observations are about working with this tool \ud83d\ude0a<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;28906&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;3&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;11&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;5\\\/5 ( votes: 3)&quot;,&quot;size&quot;:&quot;18&quot;,&quot;title&quot;:&quot;Adaptive Card Extensions \u2013 tips and tricks for developers&quot;,&quot;width&quot;:&quot;139.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} ( {votes}: {count})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 139.5px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 14.4px;\">\n            5\/5 ( votes: 3)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are a developer and have dipped your toe in Viva Connections, you may know that SPFx offers a &hellip; <a class=\"continued-btn\" href=\"https:\/\/sii.pl\/blog\/en\/adaptive-card-extensions-tips-and-tricks-for-developers\/\">Continued<\/a><\/p>\n","protected":false},"author":546,"featured_media":28905,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","inline_featured_image":false,"footnotes":""},"categories":[1320],"tags":[2653,1590,1526,1361],"class_list":["post-28906","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hard-development","tag-adaptive-card-extension-en","tag-tools","tag-guidebook","tag-microsoft-en"],"acf":[],"aioseo_notices":[],"republish_history":[],"featured_media_url":"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2024\/08\/Adaptive-Card-Extension-\u2013-wskazowki-i-porady-dla-programistow.jpg","category_names":["Hard development"],"_links":{"self":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/28906"}],"collection":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/users\/546"}],"replies":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/comments?post=28906"}],"version-history":[{"count":1,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/28906\/revisions"}],"predecessor-version":[{"id":28908,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/28906\/revisions\/28908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media\/28905"}],"wp:attachment":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media?parent=28906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/categories?post=28906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/tags?post=28906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}