You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-features/navigation-api.md
+22-97Lines changed: 22 additions & 97 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,120 +155,45 @@ The `NavigationMenu` class represents a navigation menu. It contains a collectio
155
155
156
156
## NavigationItem
157
157
158
-
The `NavigationItem` class represents a single item in a navigation menu. It contains information such as the destination link or route, a label, and priority for ordering in the menu.
159
-
160
-
Here is the constructor signature and a quick reference of the methods available on the `NavigationItem` class, and their types. Keep on reading to see more detailed examples and explanations.
161
-
162
-
```php
163
-
use Hyde\Framework\Features\Navigation\NavigationItem;
164
-
165
-
$item = new NavigationItem(Route|string $destination, string $label, int $priority = 500);
166
-
167
-
$item->getLink(): string; // Returns the resolved link route or destination URL.
168
-
$item->getLabel(): string; // Returns the label of the item.
169
-
$item->isActive(): bool; // Returns true if the item is the page being rendered.
170
-
$item->getPriority(): int; // Returns the priority of the item.
171
-
$item->getPage(): ?HydePage; // Returns the underlying Page instance, if there is one.
172
-
```
158
+
The `NavigationItem` class is an abstraction for a navigation menu item containing useful information like the destination, label, and priority.
173
159
174
160
### Creating Navigation Items
175
161
176
-
There are several ways to create navigation items using the `NavigationItem` class.
177
-
178
-
#### Direct instantiation
179
-
180
-
You can create instances directly by passing either a URL or a Route instance to the constructor.
181
-
182
-
The first parameter is the destination, the second is the label, and the third optional parameter is the priority.
183
-
184
-
```php
185
-
$item = new NavigationItem('index', 'Home');
186
-
$item = new NavigationItem(Routes::get('index'), 'Home');
187
-
$item = new NavigationItem('https://example.com', 'External Link');
188
-
```
189
-
190
-
#### Setting Priority
162
+
There are two syntaxes for creating NavigationItem instances, you can use a standard constructor or the static create method.
163
+
Both options provide the exact same signature and functionality, so it's just a matter of preference which one you use.
191
164
192
-
You can set the priority of the item, which determines its position in the menu.
165
+
The constructors take three parameters: the destination, the label, and the optional priority.
166
+
The destination can be a `Route` instance, a route key string, or an external URL.
193
167
194
168
```php
195
-
$item = new NavigationItem(Routes::get('index'), 'Home', 25);
196
-
```
197
-
198
-
#### Static Creation Method
199
-
200
-
You can use the static `create` method, which can automatically fill in the label and priority from a Route.
0 commit comments