Pitaya-Framework Component Top-Bar.
npm install @pitaya-components/top-barbash
npm install @pitaya-components/topbar --save
`
Basic Usage
$3
##### Simple registration
You can register this component as an aurelia plugin. In that case you don´t have to do anything else.
`ts
export function configure( aurelia: Aurelia )
{
aurelia.use.standardConfiguration()
.plugin( "@pitaya-components/topbar" )
.feature( "resources" );
aurelia.start().then( () => aurelia.setRoot( "app/app", document.body ) );
}
`
##### With plugin configuration
You can optionally specify which sub components you will need and thus want to define to globally available.
`ts
import { PitayaTopbarConfiguration } from "@pitaya-components/topbar";
export function configure( aurelia: Aurelia )
{
aurelia.use.standardConfiguration()
.plugin( "@pitaya-components/topbar", ( pluginConfig: PitayaTopbarConfiguration ) =>
{
pluginConfig.use(
"pitaya-topbar-row.html",
"pitaya-topbar-navigation.html",
"pitaya-topbar-actions.html",
"pitaya-topbar-action-icon.html"
);
} )
.feature( "resources" );
aurelia.start().then( () => aurelia.setRoot( "app/app", document.body ) );
}
`
$3
If you don´t want this component to be handled as a plugin you have a few other options when importing a component into your layout:
##### Template
`html
...
`
##### View model
`ts
@viewResources(
"@pitaya-components/topbar/dist/native-modules/pitaya-topbar",
"@pitaya-components/topbar/dist/native-modules/pitaya-topbar-row.html",
"@pitaya-components/topbar/dist/native-modules/pitaya-topbar-navigation.html",
"@pitaya-components/topbar/dist/native-modules/pitaya-topbar-actions.html",
"@pitaya-components/topbar/dist/native-modules/pitaya-topbar-action-icon.html"
)
export class MyView
{
...
}
`
##### Global resources
`ts
export function configure( config: FrameworkConfiguration )
{
config.globalResources( [
PLATFORM.moduleName( "@pitaya-components/master-component/dist/native-modules/master-component" )
] );
}
`
$3
Our components are usually initialized by defining them in your views HTML.
And can be accessed afterwards in the corresponding view model.
##### Template
`html
view-model.ref="topbar"
on-attached.call="doSomething(component)"
>
...
`
##### View model
`ts
import {PiTopBar} from "@pitaya-components/topbar";
export class MyView
{
public topbar: PiTopBar;
public doSomething(component: PiTopBar)
{
this.topbar.type = "short";
}
}
`
Variants
$3
`html
icon="manu"
on-icon-click.call="openDrawer()"
title="My Topbar Title"
>
icon="event"
on-click.call="openCalendar()"
>
icon="more_vert"
on-click.call="openMenu()"
>
`
Event handlers
Attaching an event handler is as simple as adding on-.
> NOTE: The function that you specify has to be defined as a method on the view model class, so that aurelias template engine can use it.
##### Template
`html
on-navigation.call="topbarNavigated(event, component)"
on-attached.call="topbarHasBeenAttached(component)"
>
...
`
##### View model
`ts
export class MyView
{
public topbarNavigated(event: CustomEvent, component: PiTopBar)
{
...
}
public topbarHasBeenAttached(component: PiTopBar)
{
...
}
}
`
You also can pass any parameter you like.
Specifying event just tells the component that you wish to receive the event object, but if you define something else, it will be passed down to your function just like one would expect.
##### Template
`html
on-attached.call="topbarHasBeenAttached('my custom message')"
>
...
`
##### View model
`ts
export class MyView
{
public topbarHasBeenAttached(message: string)
{
...
}
}
`
Bindables
A bindable is part of a core functionality of aurelia which basically allows you to configure a component from within your HTML code.
They can be set/accessed via HTML attribute and also programmatically.
##### Template
`html
type="dense"
>
...
`
##### View model
`ts
import {PiTopBar} from "@pitaya-components/topbar";
export class MyView
{
public topbar: PiTopBar;
public someMethod()
{
this.topbar.type = "prominent";
}
}
`
$3
#####
| Attribute | Type | Description
| --- | --- | ---
| type | dense \| prominent \| short | Sets the type
| on-attached | ( component: PiTopBar ) => void | Is called when the component is attached to the DOM
| on-navigation | ( component: PiTopBar \| event: CustomEvent ) => void | Is called when the navigation icon has been clicked/tapped
#####
| Attribute | Type | Description
| --- | --- | ---
| icon | string | Sets the icon (material-icons)
| onIconClick | ( event: CustomEvent ) => void | Is called when the navigation icon has been clicked/tapped
| title | string | Sets the title
#####
| Attribute | Type | Description
| --- | --- | ---
| icon | string | Sets the icon (material-icons)
| onClick | ( event: CustomEvent ) => void | Is called when the action icon has been clicked/tapped
Methods and properties
##### PiTopBar
| Signature | Description
| --- | --- |
| container: Container | The components container object
| type: dense \| prominent \| short | Sets the type
| onAttached: ( component: PiTopBar ) => {} | Sets a callback that is called when the component is attached to the DOM
| onNavigation: ( component: PiTopBar \| event ) => void | Sets a callback that is called when the navigation icon has been clicked/tapped
| setScrollTarget( target: HTMLElement ) => void |
| listen( eventName: TopbarEvent, handler: ( event?: CustomEvent ) => void, options?: AddEventListenerOptions ) => void |
| unlisten( eventName: TopbarEvent, handler: ( event?: CustomEvent ) => void, options?: AddEventListenerOptions ) => void |
| reinitialize( component \| event ) => void \| Promise< void > | Reinitializes the component
Style Customization
$3
With this component we are relying on the Top-App-Bar component of MDC.
Check out the documentation to learn how to use their SASS mixins.
> Note: SASS mixins are always applied on the main component by using the .pitaya-topbar` selector.