0.0.9-rc19 • Published 3 years ago

@bookassist/ba-header v0.0.9-rc19

Weekly downloads
55
License
MIT
Repository
-
Last release
3 years ago

Bookassist Header

This project is React Control that renders common Bookassist header. You can import this project to use into another react project or non-react project.

Build library

This project is also a library to use embedded in another apps. The library exports 2 things

  • Header: This is the React component
  • renderHeader: This is a function to render the header in anywhere.application.

To build the library you can execute

yarn install && yarn build

Publish library

You can publish this library to a npm repository. npm publish

How to use

You can use this library as part of es6 project as library and component into this project.

es6

To install the component, you have to include in your project as

npm install @bookassist/ba-js-header

To use into you project

import { Header } from '@bookassist/ba-js-header'
... 
<Header />

Another js project or website

You have to include the js file

<link rel="stylesheet" href="https://unpkg.com/@bookassist/ba-styles@0.0.13/dist/ha-styles.css">
<script type="text/javascript" src="https://unpkg.com/@bookassist/ba-header@0.0.9-rc18/dist/ba-header.js"></script>

...

<div id="header"></div>
<script type="text/javascript">
  renderHeader(document.getElementById("header"))
</script>

Options

Properties of the control

There are some properties you can configure to change the behaviour and adapt to your needdeds.

PropertyDescription-
titleTitle of the applicationMandatory string
pageTitleTitle of the pageString. Default value: ''
pageTitleBehaviourBehaviour of the page titlePossible values:hotelName: Use the name of the hotel as page titletitle: Use pageTitle property as page titlehotelNameOrTitle: Use the name of the hotel or pageTitle in case that it cannot retrieve the hotelnone: Not show page title block Default values is none
langControlThe way to show the language selectorPossible values:menu: Show as overlay layerdropdown: Show as dropdown controlnone: Not show language selector Default value is none
hotelChangeControlHow to show the hotel change controlPossible values:inline: As part of the headernone: Not show the hotel change control Default value is none
logoutControlHow to show the logout controlPossible values:inline: As part of the headeruser-menu: As part of the user menunone: Not show the logout control Default value is inline
breadcumbVisibleFlag to show or hide the breadcrumbBoolean. Default value: false
logoObject to configure the logo of the headerCheck logo configuration
menuItemsArray of items that compose the menu of the header.Check menu configuration
retrieveHotelInformationFunction to retrieve the hotel information. This function has to return a promise to get the hotel-
retrieveUserInformationFunction to retrieve the user information. This function has to return a promise to get the hotel. You have to define this function if you want to see the user control on the menu-
filterHotelFunction to retrieve a list of hotel, this list will be shown in the hotel selector. This function has to return a promise to get the list of hotels.This function has 2 parameters. user: User object with information of the userinput: String to filter the list
locationRenderFunction to render the location text-

All these properties are avaible for the control and the function. Control

<Header title={ 'My Application' } />

function

renderHeader(document.getElementById("header"), { title: 'My Application' }})

Logo Configuration

As part of the properties of the header, you can set the configuration of the logo. This configuration is an object where you can set some properties.

PropertyDescription-
typeType of the logo you want to usePossible values:url: This makes the control reads url property to load the logodefault: This makes an SVG logo is rendered by the control. size property will be read to customize this logo Default value default
sizeObject to customize the SVG logo-
size.widthWith of the SVG logoDefault value 260
size.heightHeight of the SVG logoDefault value 52
size.viewBoxViewBox of the SVG logoDefault value 0 0 524 52
badgeYou can set a badge next to the logo to set a label. This property is an object where you can set different attributes-
badge.visibleFlag to show or hide the badgeDefault value is false
badge.textText to show into the badgeDefault values is ''
badge.backgroundColorBackground color of the badgeDefault values is ''
badge.foregroundColorForeground color of the badgeDefault values is ''

Menu Configuration

The menu can be configured using children of the Header control or as property in the options. In case, you want to use as propety in the options, you have to fill the property menuItems with and array of objects with following properties.

PropertyDescription
idThe id of the menu. You can use this to access to the item searching by id
titleTitle of the item. You can set a i18n key because the control will try to translate it
badgeTextYou can set a badge next to the text of the item
hostThe host of the link where you want to go when click on the menu. https://www.bookassist.com
pathThe path of the link where you want to go when click on the menu. /path/to/my/page.html
selectedFlag to know if this is a selected item
childrenArray of the items like this. This attribute makes that the item is a menu

Menu only allows 2 levels of items.

Menu with child items is only available on Control not as function. You can see more details on Menu and Breadcrumb.

Callbacks or notification functions

There are some events that the header produces

EventDescriptionParameters
onChangeLanguageWhen the user changes the language from header menulanguage Language code of the new language
onChangeHotelWhen the user changes the active hotelhotel Hotel object
onLogoutWhen the user logout from header-

All these events are avaible for the control and the function. Control

<Header onLogout={ () => console.log('bye') } />

function

renderHeader(document.getElementById("header"), { onLogout: function() { console.log('bye') }})

Menu and Breadcrumb

The header can contains a menu and a breadcrumb. You can add them only in es6 format as children objects.

<Header>
  <Breadcrumb>
    <BreadcrumbItem name={'Home'}>
    <BreadcrumbItem name={'Vouchers'}>
  </Breadcrumb>
  <Menu
    id={'m_hotelinfo'}
    url={'https://test.bookassist.com/hotelinfo.jsp'}
    title={ 'Hotel Info' }
    selected
  >
    <MenuItem
      id={'mi_vou'}
      url={'https://test.bookassist.com/voucher.jsp'}
      text={ 'Vouchers' }
    />
    <MenuItem
      id={'mi_reviews'}
      url={'https://test.bookassist.com/review.jsp'}
      text={'Reviews'}
    />
  </Menu>
  <Menu
    id={ 'm_help' }
    url={ 'https://test.bookassit.com/help' }
    title={ 'help' }
  >
</Header>

Options

This library can be configured at global level to change the behaviour of the component. You can create a new global object called bookassist.header.config that can contain an object like

{
  "checkConfig": true,
  "api": {
    "server": "https://api.bookassist.com",
    "endpoints": {
      "i18n": "/iface/i18n",
      "hotel": "/iface/hotel",
      "group": "/sso/admin/group",
      "user": "/iface/user"
    }
  }
}