Building a design system requires the ability to create components at the molecular levels for optimal reusability and flexibility. When creating components, XD lets you nest them within each other and create complex objects such as menus, card-based layouts, and many more.
Using nested components, you can build more robust design systems. When you update a main component, all its instances receive those updates, even if the update is in its nested component.
- You can create a component with multiple component instances nested inside. However, when components have multiple states with many objects, performance can take a hit. In such cases, to achieve optimal performance, you can nest components three levels deep at most, and limit the number of states per level, to a maximum of ten states per component.
- Do not nest a component within itself. This might result in an invalid component since components are self-referencing.
- If you have a nested component with multiple states in an outer main component, you can switch the state of the nested component. The state change then propagates to all the outer component’s instances.
With nested components syncing, changes made to components nested within a main component propagate to all the instances of that main component.
Let's see how that works.
Now, create two instances of the main button, two instances of the main toggle menu, and an instance of the main container.
Let's look at some scenarios:
Change the color of the button nested inside the main toggle menu to blue.
All the buttons nested inside the toggle menu's instances and inside the containers got the color change to blue.
However, the two instances of the main button don't change color. This is because changes to nested components are contextual to their containers. The color change only applies to instances of the button inside the toggle menu.
Change the color of the button inside the main container to pink. The button inside the container's instance will also turn pink.
Notice that the other buttons don't get the color change. This is because changes to nested components are contextual to their containers. The color change only applies to instances of the button inside the toggle menu within the container.
- Nested components cannot be main components. So, if you need the change to be on the main component, right-click the nested component and select Edit Main Component.
- If a nested component in an instance of the outer component is swapped, Reset to Main State on the main's nested component will not change the instance with the swapped component.
Here are some best practices when working with overrides in nested component instances:
- To create a variation of the component for reuse, create a state in the main component rather than an instance with overrides.
- While overriding instances, ensure that you override the property that does not need updates from the main component. For example, in a button component, overriding the text ensures that the label can be different, but the size and color are still in sync with the main component.
Libraries help you distribute your design system styles and components to be reused consistently across your documents. To build and distribute a design system through libraries, curate your design system assets by adding colors, character styles, and components to the Document Assets panel, and publish them as a library to reuse across all your XD and other Creative Cloud applications. For more information on how to use Creative Cloud Libraries, see Work with Creative Cloud Libraries in XD.
In the previous versions of XD, changes made in a nested component do not update across instances of the outer component. To get an improved experience, open your documents in the latest version of XD.
When XD opened your document, these specific components did not match their version in the Assets panel. To migrate without data loss, these main components have been converted to instances on canvas. If you want to bring your main component back to the canvas, right-click the outer instance and select Edit Main Component. Then, if you want your main component to look like the instance on canvas, you can transfer any necessary overrides from your instance to the main component.
We've got you started on how to work with components in XD. Take a step forward and learn how to share your designs with designers or stakeholders for feedback.