-
Notifications
You must be signed in to change notification settings - Fork 4
NestList
NestList
is a component that generates nests (one per item) that can shrink or expend. It is also scope sensitive, meaning that it can display different containers based on its current scope (see scoping at the bottom).
Extends
Uxi
Requires
Templater
{"selector:NestList":{CONFIG}}
NestList can also be created on the fly, at runtime
let config = {
el:_SELECTOR_ //requited, the HTML element where to instantiate this component
scope:_ARRAY_ //optional, defaults to ['public']
list:_ARRAY_ //Array of items to display, depends on mode,
map:_OBJECT_ //An optional map of properties (title, scope)
order:_ARRAY_ //Optional, the preferred order of nests
};
From an Object extending Uxi
let list = this.create('NestList', config);
Independently
let list = OGX.Object.create('NestList', config);
NestList
expects as data, an array of objects following this format.
{title:_STRING_, scope:_ARRAY_, open:_BOOL_}
NestList
support order preference. Despite the fact that you can declare your data as a List and then sort it the way you want before you pass it toNestList
, that order might become broken by adding/removing items to theNestList
. So to make sure some nests always appear at the same position, you can enforce that positioning. For instance, if your data looks like this
[
{title:'NestA', body:'Some stuff', ...},
{title:'NestB', body:'Some other stuff', ...}
]
but you want your
NestList
to always displayNestsB
on top, you can set theorder
flag in theconfig
to
{..., order:['NestB'], ...}
So even if you manipulate the list and remove
NestB
(which makesNestA
the top one), then re-add by code a newNestB
, that nest will always be on top. The nests that aren't defined in theorder
flag are added to the bottom of the list.
list.enable();
list.disable();
list.val(_ARRAY_); //Set/Retrieve list of nests
list.addNest(_CONFIG_, _NODE_, _INDEX_); //Add a nest given a config object, an OML node with default selector and optional index
list.removeNest(_NEST_TITLE_);
list.replaceItem(_NEST_TITLE_, _NEW_OBJECT_)
list.removeItem(_NEST_TITLE_); //Remove a nest and destroy its content
list.updateItemHeight(_NEST_TITLE_); //Recompute the internal height of nest
list.scope(_ARRAY_); //set the current scope
list.updateHeight(_INDEX_); //Recalculate the height of a nested item given index
OGX.NestList.OPEN //Triggered when the user opens an item
OGX.NestList.CLOSE //Triggered when the user closes an item
OGX.NestList.READY, //Triggered when the component has rendered
list.destroy();
The component can display different containers based on scopes. To use scoping, you must set the current scope of the component in its config
scope:['admin', 'finance']
meaning the component will display all containers that match the admin OR finance scope. If a node or container does not possess any of the scope, it won't display. You can of course update the scope of the component on the fly using setScope
Here is an example of a configuration for the component.
let config = {
el:'#mydiv',
scope:['admin', 'finance'],
list:[
{title:'Permissions', body:'some html', scope:['admin'], open:false},
{title:'Details', body:'some html', scope:['admin', 'hr'], open:true},
{title:'Profile', body:'some html', scope:['admin', 'hr'], open:true},
{title:'Rate', body:'some html', scope:['admin', 'finance'], open:true},
{title:'Stats', body:'some html', scope:['admin', 'hr'], open:true},
{title:'Notes', body:'some html', scope:['admoin', 'hr'], open:false}
]
}
let list = this.create('NestList', config);
- Welcome
- Changelog
- Structure
- Configuration
- Getting started
- CLI
- Poly
- Core
- Templating
- Routing
- Controllers
- Components
- Extra Components
- Helpers
- Styling
- Debugging