|
| 1 | +# Dynamic Tag Gallery Component |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +This Power App demonstrates a component displaying a gallery of hashtags detected automatically from text and which dynamically places the hashtags in buttons across rows depending on the width of each and the room available on the row. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +Kudos to Dave Wyatt for his implementation of this concept and for giving me the idea for this approach. Building on his version that uses a predetermined number of buttons within a container, my approach uses a gallery to create as many buttons as required dynamically. Please do read [Dave’s excellent blog](https://community.powerplatform.com/blogs/post/?postid=b3d4acb9-bfc6-ef11-b8e8-7c1e5267b708) first. |
| 10 | + |
| 11 | +## Applies to |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +## Compatibility |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Contributors |
| 28 | + |
| 29 | +* [James Williams](https://github.com/wjamesw) |
| 30 | + |
| 31 | +## Version history |
| 32 | + |
| 33 | +Version|Date|Comments |
| 34 | +-------|----|-------- |
| 35 | +1.0|Febrary 2nd, 2025|Initial release |
| 36 | + |
| 37 | +## Prerequisites |
| 38 | + |
| 39 | +None |
| 40 | + |
| 41 | +## Minimal path to awesome |
| 42 | + |
| 43 | +### Using the solution zip |
| 44 | + |
| 45 | +* [Download](./solution/dynamic-tag-gallery.zip) the `.zip` from the `solution` folder |
| 46 | +* Within **Power Apps Studio**, import the solution `.zip` file using **Solutions** > **Import Solution** and select the `.zip` file you just downloaded. |
| 47 | + |
| 48 | +### Using the source code |
| 49 | + |
| 50 | +You can also use the [Power Apps CLI](https://docs.microsoft.com/powerapps/developer/data-platform/powerapps-cli) to pack the source code by following these steps: |
| 51 | + |
| 52 | +* Clone the repository to a local drive |
| 53 | +* Pack the source files back into a solution `.zip` file: |
| 54 | + |
| 55 | + ```bash |
| 56 | + pac solution pack --zipfile pathtodestinationfile --folder pathtosourcefolder --processCanvasApps |
| 57 | + ``` |
| 58 | + |
| 59 | + Making sure to replace `pathtosourcefolder` to point to the path to this sample's `sourcecode` folder, and `pathtodestinationfile` to point to the path of this solution's `.zip` file (located under the `solution` folder) |
| 60 | +* Within **Power Apps Studio**, import the solution `.zip` file using **Solutions** > **Import Solution** and select the `.zip` file you just packed. |
| 61 | + |
| 62 | +### Use the component in your app |
| 63 | + |
| 64 | +Open your target app and click the **Get more components** icon from the **Insert** tab. On the **Import components** pane, select **cptTagGallery** from the **Dynamic Tag Gallery Component Library** and then click **Import** to import the component into your target app. |
| 65 | + |
| 66 | +Then select **cptTagGallery** from the **Library components** group on the **Insert** tab. |
| 67 | + |
| 68 | +Set the **Input Text** property of the component instance to the text, or the source of the text, you want the component to analyse. |
| 69 | + |
| 70 | +Set the **Button Padding** and **Button Margin** properties of the component instance, or leave these as their default values. |
| 71 | + |
| 72 | +Add logic to your app to retrieve the **Output Tags** property from the component instance. |
| 73 | + |
| 74 | +## Features |
| 75 | + |
| 76 | +The component displays a gallery of hashtags detected automatically from text and which dynamically places the hashtags in buttons across rows depending on the width of each and the room available on the row. |
| 77 | + |
| 78 | +This is done using a technique whereby the controls in the gallery all have their co-ordinates calculated dynamically using the whole space within the gallery, rather than just the usual row per item within the gallery. This technique can be used to create many interesting visuals. |
| 79 | + |
| 80 | +The dynamic calculations take place predominantly within the OnReset function of the component. |
| 81 | + |
| 82 | +The key to successfully aligning controls in a gallery space is ensuring that you compensate for the offset of (at least) one pixel, resulting from the Template Size property of the vertical gallery control, which can not be set to zero. Apart from that one issue, controls across items in a gallery do not have to stay within the bounds of their item's row. |
| 83 | + |
| 84 | +This solution illustrates the following concepts: |
| 85 | + |
| 86 | +* Power Apps components |
| 87 | + |
| 88 | +## Help |
| 89 | + |
| 90 | +We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues. |
| 91 | + |
| 92 | +If you encounter any issues while using this sample, you can [create a new issue](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=dynamic-tag-gallery&authors=@wjamesw&title=dynamic-tag-gallery%20-%20). |
| 93 | + |
| 94 | +For questions regarding this sample, [create a new question](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=dynamic-tag-gallery&authors=@wjamesw&title=dynamic-tag-gallery%20-%20). |
| 95 | + |
| 96 | +Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/powerapps-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=dynamic-tag-gallery&authors=@wjamesw&title=dynamic-tag-gallery%20-%20). |
| 97 | + |
| 98 | +## Disclaimer |
| 99 | + |
| 100 | +**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** |
| 101 | + |
| 102 | +<img src="https://m365-visitor-stats.azurewebsites.net/powerplatform-samples/samples/dynamic-tag-gallery" aria-hidden="true" /> |
0 commit comments