BrowserKit/Sources/ComponentLibrary/Documentation.docc/HowToAddNewComponent.md
This article is aimed at developers wanting to add new components inside the library.
Let's go over the different considerations before adding a component inside the library, then we can discuss the guidelines on how to add one.
If your UI component is used for one feature only, then let's keep this component with the feature code. If the UI component you are building has UI elements that can be reused (Example: with a specific type of container, or a specific type of button) then it can be worth moving it to the component library. If there's ambiguity, then you should bring this up with teammates for discussion in #firefox-ios-dev Slack channel or during our weekly engineering meeting.
Once you have made sure you indeed have a component that should be added to that library, please see previous section first.
When adding a new component, there are two steps you need to be aware of. The first one is adding the component to the actual component library package located in BrowserKit, and the second one is adding the component to the sample application.
You should add the code under the ComponentLibrary folder in BrowserKit, following the guidelines:
StandardImageIndentifiers. If the image isn't standard, then it's probably a feature component that shouldn't live in Component Library.configure method on the component rather than making properties public. This will ensure we have a standard way of using components. This will make code easier to maintain and understand over time.Dynamic Type. This means the component should be able to resize itself dynamically depending on its content size, and cannot have fixed height under any circumstances. Constraints should be done for that in all directions (top, bottom, trailing, leading). If you find yourself using a center constraint, you should make sure this is indeed needed and works properly (hint, extra work needs to be done if you center things only, the component won't behave properly otherwise).imageFlippedForRightToLeftLayoutDirection for more information.ThemeApplicable.You will need to close the Client application to be able to navigate
BrowserKitin the Sample application when you openSample app xcodeproj
Once your component is added under the library, you are now ready to add an example of usage of that component in the sample application. This step is mandatory, to ensure that we have an easy way to keep track of components, know how to use them, and keep them relevant. Sample application could also be used to have screenshot tests at one point to ensure the components looks as they should on different device, with different text size, theme and so on.
UIViewController that will show the component you created. Make sure it constrained properly so Dynamic Type will work with it. Make sure it's the view controller is Themeable and listenForThemeChange, making sure the component you added is themed. If there are multiple states to the component, ensure this view controller shows all the components states (so you can add more than one component to the view controller).ComponentViewModel protocol.ComponentData data array includes your new view model.