2015-10-07 13:16:40 +09:00
|
|
|
# Menu Component
|
|
|
|
|
|
|
|
This is a component for generating flexible, nestable menus. It can generates nested menus from a flat list with node `id`s and `parentId`s.
|
|
|
|
|
2015-10-08 15:43:23 +09:00
|
|
|
|
|
|
|
### Demo
|
|
|
|
|
|
|
|
[http://menu-demo.meteor.com](http://menu-demo.meteor.com)
|
|
|
|
|
2015-10-07 13:16:40 +09:00
|
|
|
### Usage
|
|
|
|
|
2015-10-08 11:13:48 +09:00
|
|
|
Install with:
|
|
|
|
|
|
|
|
```
|
|
|
|
meteor add telescope:menu
|
|
|
|
```
|
|
|
|
|
|
|
|
Then just include the `menuComponent` template while passing the necessary arguments:
|
2015-10-07 13:16:40 +09:00
|
|
|
|
|
|
|
```
|
2015-10-07 15:04:22 +09:00
|
|
|
{{> menuComponent menuItems=menuItems menuLabel="My Menu" menuClass="my-menu-class"}}
|
2015-10-07 13:16:40 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
All arguments are optional unless specified otherwise.
|
|
|
|
|
2015-10-07 13:16:40 +09:00
|
|
|
##### `menuItems` (Array) [required]
|
|
|
|
|
|
|
|
An array containing the menu's contents (see below).
|
|
|
|
|
|
|
|
##### `menuName` (String)
|
|
|
|
|
|
|
|
The name of the menu. Used to set a `*name*-menu` CSS class on the menu.
|
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
##### `menuLabel` (String/Function)
|
2015-10-07 13:16:40 +09:00
|
|
|
|
2015-10-07 21:50:48 +09:00
|
|
|
The menu title label, or a function that returns a label. Note that this is required for dropdown menus.
|
2015-10-07 13:16:40 +09:00
|
|
|
|
|
|
|
##### `menuLabelTemplate` (String)
|
|
|
|
|
|
|
|
If provided, will replace the menu label with a custom template.
|
|
|
|
|
|
|
|
##### `menuClass` (String)
|
|
|
|
|
|
|
|
An optional CSS class given to the menu
|
|
|
|
|
|
|
|
##### `itemTemplate` (String)
|
|
|
|
|
|
|
|
A custom template used to display individual menu items (defaults to "defaultMenuItem")
|
|
|
|
|
2015-10-07 21:50:48 +09:00
|
|
|
##### `startPosition` (String)
|
|
|
|
|
|
|
|
For collapsible menus only, defines whether the menu should start off as `expanded` or `collapsed`. Defaults to `collapsed`.
|
|
|
|
|
2015-10-07 13:16:40 +09:00
|
|
|
### Menu Items Properties
|
|
|
|
|
|
|
|
Menu items can have the following properties:
|
|
|
|
|
|
|
|
##### `label` (String/Function)
|
|
|
|
|
|
|
|
The menu item's label, or a function that returns a label.
|
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
##### `description` (String/Function)
|
|
|
|
|
|
|
|
The menu item's description, or a function that returns a description.
|
|
|
|
|
2015-10-07 13:16:40 +09:00
|
|
|
##### `route` (String/Function)
|
|
|
|
|
|
|
|
Either the name of a route to which the menu item should point, or a function that returns a route.
|
|
|
|
|
|
|
|
If a route is provided, the class `item-active` will automatically be added to the menu item when its route is the currently active one.
|
|
|
|
|
|
|
|
##### `data` (Object)
|
|
|
|
|
|
|
|
The data context for the item.
|
|
|
|
|
|
|
|
##### `itemClass` (String)
|
|
|
|
|
|
|
|
The menu item's CSS class.
|
|
|
|
|
|
|
|
##### `template` (String)
|
|
|
|
|
|
|
|
An optional custom template. Overrides both the default template and the `itemTemplate` menu-level option.
|
|
|
|
|
|
|
|
### Nested Menu Items Properties
|
|
|
|
|
|
|
|
Additionally, menu items take a few additional properties to generate nested menus.
|
|
|
|
|
|
|
|
##### `_id` (String)
|
|
|
|
|
|
|
|
A unique id used for arranging nodes in nested menus.
|
|
|
|
|
|
|
|
##### `parentId` (String)
|
|
|
|
|
|
|
|
The parent node's id.
|
|
|
|
|
|
|
|
##### `isExpanded` (Boolean)
|
|
|
|
|
2015-10-07 21:50:48 +09:00
|
|
|
Whether the item's sub-menu should start off expanded
|
2015-10-07 13:16:40 +09:00
|
|
|
|
|
|
|
### The Menu Item Template
|
|
|
|
|
|
|
|
The menu item template is called with the following data context:
|
|
|
|
|
|
|
|
##### `menu` (Object)
|
|
|
|
|
|
|
|
A reference pointing back to the menu object.
|
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
##### `level` (Number)
|
2015-10-07 13:16:40 +09:00
|
|
|
|
|
|
|
The current nesting level.
|
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
##### `item` (Object)
|
|
|
|
|
|
|
|
The current item to display.
|
|
|
|
|
|
|
|
### Styling
|
|
|
|
|
|
|
|
Out of the box, the menu component accepts a few classes
|
|
|
|
|
2015-10-07 21:53:18 +09:00
|
|
|
##### `menu-list` (default)
|
2015-10-07 15:04:22 +09:00
|
|
|
|
|
|
|
A simple list. Serves as the base for the other styles.
|
|
|
|
|
2015-10-07 21:53:18 +09:00
|
|
|
##### `menu-dropdown`
|
2015-10-07 15:04:22 +09:00
|
|
|
|
|
|
|
A dropdown menu.
|
|
|
|
|
2015-10-07 21:53:18 +09:00
|
|
|
##### `menu-collapsible`
|
2015-10-07 15:04:22 +09:00
|
|
|
|
|
|
|
A collapsible menu.
|
|
|
|
|
|
|
|
### Events
|
|
|
|
|
|
|
|
The menu component includes a few events. Classes used for JS event targeting start with the `js-` prefix.
|
|
|
|
|
2015-10-07 21:53:18 +09:00
|
|
|
##### `click .js-menu-toggle`
|
2015-10-07 13:16:40 +09:00
|
|
|
|
2015-10-07 15:04:22 +09:00
|
|
|
Makes the current node's child menu expand and collapse.
|