In this blog post, I will discuss about the implementation of a horizontally scrollable component to display skill based on metrics. The purpose of the implementation is to show top skills based on metrics related to usage, ratings, etc in SUSI.AI Skills CMS.
- We call this component SkillCardScrollList which takes in a list of cards to be displayed along with some other properties and returns an UI, as shown in the above GIF.
- The parameters that the component takes are:
- scrollId: It is a required field of the type String. It is the id name of the horizontally scrollable div.
- skills: It contains an array of cards that are to displayed inside the container.
- languageValue: It represents the language of the skills that are shown.
- skillUrl: It contains the URL that the app would be taken to, on clicking individual Skill Card.
- modelValue: It contains the model that the skill belongs to.
- Here is a sample of how it is used in the BrowseSkill component, for showing the Top Rated Skills in a SkillCardsScrollList –
- The reason behind passing an unique scrollId as a prop to the component is that, there was a need to trigger the scroll event of the scrollable div n the click of left and right Floating Action Buttons (FABs) as shown in the UI. And, on multiple imports of this component, there would have been inconsistent scroll behaviour seen, had it not been unique.
- Following in the code block of the component, which will be explained in details, that deals with the main implementation –
- The div with class scrolling-wrapper is actually scrolled on the click of the left and right FAB. For choosing the correct div to be scrolled, there was a necessary condition of an unique id as explained earlier, which has been set to the div.
- For making the component horizontally scrollable, specific CSS rules are added to the div. They are –
- The CSS rules for the FABs make them fixed in a position and only lets the card list scroll.
- Lastly, there was a issue regarding the presence of horizontal scroll-bar been shown, which makes the UI look a bit unpleasant.
- It was hidden with a pseudo selector CSS rule.
This was the implementation for the horizontally scrollable component for displaying Skill List based on a standard metrics. I hope, you found the blog helpful in making the understanding of the implementation better.
- Actual code implementation for reference : https://github.com/fossasia/susi_skill_cms/blob/master/src/__tests__/components/SkillCardScrollList/SkillCardScrollList.js
- Blog Post that I had read : https://codepen.io/colinlord/post/horizontal-scrolling-containers