Skip to content

Commit fed17f8

Browse files
committed
update component compositions
1 parent 6850488 commit fed17f8

1 file changed

Lines changed: 14 additions & 27 deletions

File tree

‎docs/components/compositions/index.md‎

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ description: Build complex UIs by combining components through nesting and slots
55

66
# Compositions
77

8-
Component composition in Nordcraft refers to combining components in various ways to create more complex interfaces. By using different composition techniques, you can build flexible, maintainable, and reusable user interfaces.
9-
10-
The primary composition patterns in Nordcraft include:
8+
Component composition in Nordcraft refers to combining components in various ways. The primary composition patterns in Nordcraft include:
119

1210
- [Nesting components](#nesting-components): Adding components inside other components
1311
- [Slots](#slots): Creating placeholders that can be filled with external content
@@ -32,42 +30,35 @@ This example shows two different ways to build a component:
3230

3331
- Provides empty placeholder areas (slots)
3432
- You must manually add elements into slots
35-
- Different instances can contain different elements
33+
- Different component instances can contain different elements
3634

3735
## Nesting components
3836

39-
Nesting is the most basic form of component composition, where you add components inside other components:
37+
Nesting is where you add components inside other components:
4038

4139
1. Open a component in the editor
4240
2. Add another component from the [element catalog](/the-editor/element-tree#element-catalog)
4341
3. Configure the nested component's attributes as needed
4442

4543
Benefits of nesting include:
4644

47-
- Breaking complex interfaces into manageable pieces
45+
- Breaking more complex interfaces into manageable pieces
4846
- Reusing functionality at different levels of your project
4947
- Creating clear relationships between UI elements
5048

51-
### Nesting considerations
52-
5349
When nesting components, consider the following:
5450

5551
- **Responsibility boundaries**: Each component should have a clear, focused responsibility
5652
- **Data flow**: Parent components pass data down to child components through [attributes](/components/interface-and-lifecycle#defining-attributes) or [contexts](/contexts/overview). Child components send data up to parents through [events](/components/interface-and-lifecycle#adding-events) or [contexts](/contexts/overview)
5753
- **Styling**: Parent components can [style the root element](/styling/conditional-styles#component-style-overrides) of nested components
5854

5955
::: tip
60-
As your project grows, you'll naturally develop deeper component hierarchies. While there's no strict limit to nesting depth, it's good practice to maintain clear boundaries of responsibility between components to ensure maintainability.
56+
As your project grows, you may develop deeper component hierarchies (e.g. components within comonents within components). While there's no strict limit to nesting depth, it's good practice to maintain clear boundaries of responsibility between components to ensure maintainability.
6157
:::
6258

6359
## Slots
6460

65-
Slots are a powerful feature in Nordcraft that allow components to receive and display content provided when the component is used. They act as placeholders that can be filled with content passed into the component from the outside.
66-
67-
- Slots build upon native web standards
68-
- Slots create areas in your component that can be filled with external content
69-
- Slots allow for flexible, composable component architectures
70-
- Slots help maintain component encapsulation while enabling customization
61+
Components have access to a special element called a slot, which you can find in the element catalogue. Slots allow you to create placeholders for child content of components. This means that when you use the component in an element tree, you can nest other elements inside that component in situ and render them in a specific area in the component, rather than having to set up a complex system of attributes and configuration inside the component to decide what goes where.
7162

7263
::: info
7364
The slot element in Nordcraft follows the web components standard. For more technical details, see the [MDN documentation on the slot element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot).
@@ -79,20 +70,20 @@ When [exporting a component](/components/export-a-component) as a web component,
7970

8071
### Adding slots to components
8172

82-
Slots are added to components like any other element using the [element catalog](/the-editor/element-tree#adding-elements):
73+
You can add slots to components using the [element catalog](/the-editor/element-tree#adding-elements):
8374

84-
1. Select where you want to add the slot in your component
75+
1. Select where you want to add the slot in your component in the element tree
8576
2. Add a slot element from the [element catalog](/the-editor/element-tree#adding-elements)
8677
3. Optional: add a name attribute (without a name, the slot is named `default`)
8778

8879
![A component is being edited, a slot element is highlighted in the HTML element tree. In the right panel the name for the slot is defined as content.|16/9](add-a-slot-element.webp 'Add a slot element'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?canvas-width=800&rightpanel=attributes&selection=nodes.Iry7BeAO7AjcLcJEL-sPT&canvas-height=800}
8980

9081
### Naming
9182

92-
Slots in Nordcraft work with a naming system:
83+
Slots have a naming system. To give a slot a name, select it in the element tree, and name the slot in the right panel in the editor.
9384

94-
- **Default slot**: A slot without a name attribute that receives any unassigned content
95-
- **Named slot**: A slot with a name attribute that receives content specifically targeted to it
85+
- **Default slot**: displays any child content of that component
86+
- **Named slot**: receives any child content specifically targeted to it.
9687

9788
![A component is selected, making the attributes panel visible on the right. In the slot section of the panel, a dropdown shows that this particular selected component has been assigned to the content slot, which was defined as a named slot in the parent component.|16/9](assign-to-a-slot.webp 'Assign to a slot'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card?canvas-width=800&rightpanel=attributes&selection=nodes.47Ndqw5Wmw5WAwpiV13p8&canvas-height=800}
9889

@@ -108,17 +99,13 @@ Elements without a specified slot are placed in the `default` slot
10899
Slots can contain default content that appears when no content is provided. This default content:
109100

110101
- Is shown when no matching content is provided
111-
- Gets replaced when matching content is provided
112-
- Provides visual cues during development
102+
- Is replaced when matching content is provided to that slot
113103

114104
![A view of a component that shows placeholder content added into a slot. The placeholder content is shown on the canvas.|16/9](placeholder-content.webp 'Placeholder content'){https://editor.nordcraft.com/projects/docs_examples/branches/main/components/screenshot-card-container?canvas-width=800&rightpanel=events&selection=nodes.Iry7BeAO7AjcLcJEL-sPT&canvas-height=800}
115105

116106
## Comparing composition approaches
117107

118-
Both nested components and slot-based assembly involve nesting components within other components. The key difference is in _how_ and _when_ this composition happens:
119-
120-
- With nesting, composition happens when creating the component
121-
- With slots, composition happens when using the component
108+
Both nested components and slot-based assembly involve nesting components within other components.
122109

123110
**When to use fixed nested components:**
124111

@@ -134,4 +121,4 @@ Both nested components and slot-based assembly involve nesting components within
134121
- You want to allow completely different elements in each instance
135122
- You need to compose from existing components rather than building everything from scratch
136123

137-
Many complex components combine both approaches, using nested components for core functionality, and slots for customizable areas.
124+
You can also combine both approaches, using nested components for core functionality, and slots for customizable areas.

0 commit comments

Comments
 (0)