2.1.0 • Published 2 years ago

edc-popover-ng1 v2.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
2 years ago

edc-popover-ng1

Build Status npm version

AngularJS popover component to display a contextual help.

This project is part of easy doc contents (edc).

edc is a simple yet powerful tool for agile-like documentation management.

Learn more at https://www.easydoccontents.com.

Dependencies

The required dependencies are:

How to use

Import

You can import this module with npm by running:

npm install edc-popover-ng1 --save

Or with yarn:

yarn add edc-popover-ng1

import the css file in your main style file (e.g. style.less) :

@import '~edc-popover-ng1/dist/edc-popover-ng1.css';

You need to download font-awesome or install it as a dependency

npm install font-awesome --save

Then import the style.

<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">

Note that if you use scss, you'll need to specify the font localisation too, defining the $fa-font-path variable

$fa-font-path: '~font-awesome/fonts/';
@import '~font-awesome/scss/font-awesome';

More info here.

Setup

To import the edc help module, add it to your module dependencies (edcHelpModule). The help module needs a basic configuration, injected with the edcConfigurationProvider.

angular.module('myApp', [
  'edcHelpModule'
]).config(EdcConfiguration);

// Where EdcConfiguration is a function to retrieve the edc configuration provider
function EdcConfiguration(edcConfigurationProvider) {
    // A setter is available to save your configuration, for example:
    edcConfigurationProvider.set({
        helpPath: '/help',
        docPath: '/doc',
        pluginId: 'edchelp',
        icon: 'fa-question-circle-o',
        // You can specify the options to be set globally 
        options: {
            placement: 'top'
        }
    });
}

Usage

The edc-help component will then be available in your application

<edc-help main-key="'my.key'" sub-key="'my.sub.key'"></edc-help>

Inputs and options

Mandatory inputs

Mandatory inputs or the EdcHelp (see HelpComponent):

PropTypeDescription
mainKeystringThe main key of the contextual help
subKeystringThe sub key of the contextual help

Optional inputs

Optional inputs for the component:

Input NameReturn typeDescriptionDefault value
pluginIdstringA different pluginId from the one defined in the main serviceundefined
langstringThe language to use, for labels and contents, identified by the 2 letters from the ISO639-1 standard. Will use documentation's default if no value is providedundefined
optionsEdcPopoverOptionsOptions for this popover - will overwrite global optionsundefined

Available options (EdcPopoverOptions):

PropertyTypeDescriptionDefault
iconPopoverIconIcon settings, see IconPopoverIcon
failBehaviorFailBehaviorIcon and popover behavior on error, see Fail BehaviorFailBehavior
placementpopper.js PlacementPopover positioning relatively to the iconbottom
hideOnClickbooleanIf true, any click outside of the popover will close it (inside too if interactive is false)true
interactivebooleanDetermine if we can interact with the popover contenttrue
triggerstringEvent that will trigger the popover: click mouseenter focusclick
customClassstringclass name that will be added to the main popover containerundefined
darkbooleanDark modefalse
themestringPopover's theme nameundefined
displayPopoverbooleanShow the popover / Go directly to the web help viewer on clicktrue
displaySeparatorbooleanShow / Hide the separator between header and bodytrue
displayTitlebooleanShow / Hide the header containing the titletrue
displayArticlesbooleanShow / Hide the articles sectiontrue
displayRelatedTopicsbooleanShow / Hide the related Topics (aka Links) sectiontrue
displayTooltipbooleanShow / Hide the icon tooltiptrue
delaynumber | [number, number]Delay in milliseconds before showing the popover - if array, delay for opening and closing respectivelyundefined
animationAnimationAnimation when opening / closing the popoverundefined
appendTo'parent' | Element | (() => Element)The element to which append the popover to(() => documentation.body)

Icon

PopoverIcon contains the options for the icon.

PropertyTypeDescriptionDefault
classstringClass name for the icon. Font awesome icon classes are handled natively'fa fa-question-circle-o'
urlstringImage url, size is determined by height, and width propertiesundefined
heightnumberImage height in pixels (for url images only)18
widthnumberImage width in pixels (for url images only). Will take height value if none is provided18

If class property is provided, it will overwrite the default class 'fa fa-question-circle-o'. If url is defined, it will override the class property, even if class is defined.

Fail behavior

If the help content failed to be loaded - or any other error occured, the icon and the popover will look for the FailBehavior options to define their style and content.

There are separate behaviors for the help icon, and the popover itself.

For the help icon when an error occurs, it adds the following css selector.

BehaviorDescriptionCSS selector
SHOWNThe help icon is shown as usual (default).edc-help-icon
DISABLEDThe help icon is greyed out.edc-icon-disabled
HIDDENThe help icon is completely hidden (but stays in DOM to avoid breaking the UI).edc-icon-hidden
ERRORThe help icon is replaced by an exclamation point.edc-icon-error

Default values are in file help.less

For the popover when an error occurs:

  • ERROR_SHOWN An error message is shown in the popover
  • FRIENDLY_MSG A friendly and translated message is shown in the popover
  • NO_POPOVER No popover appears when the help icon is triggered

By default, the icon is SHOWN and the popover is set to FRIENDLY_MSG.

Customization

CSS

Global

When dark-mode is enabled, the CSS class edc-on-dark is applied to the help icon.

Popover

You can customize the popover with CSS classes as described below :

CSS Classes

For more control, the customClass option will add the given class name to the popover container .edc-popover-container. You can then override the main classes.

For example, if you'd like to change the background color of the popover

.my-custom-class {
    background-color: lightgreen;
}
/* or the title font-size */
.my-custom-class .edc-popover-title {
    font-size: 18px;
}

Providing your own translations for the popover labels

You can set additional translations (or replace the existing ones) by adding i18n json files to the documentation folder.

Please note that one file is required per language (see file example below), and should be named following the ISO639-1 two letters standards (ie en.json, it.json...).

By default, edc-popover-ng will be looking for the files in yourDocPath/popover/i18n/ (*.json), but you can change this path by modifying getI18nPath() in your PopoverConfigurationHandler.

edc-popover-ng comes with English and French translations, and supports up to 36 languages. For the full list, please refer to LANGUAGE_CODES.

JSON file structure

Here is the en.json file used by default:

{
  "labels": {
  "articles": "Need more...",
  "links": "Related topics",
  "iconAlt": "Help",
  "comingSoon": "Contextual help is coming soon.",
  "errorTitle":  "Error",
  "errors": {
    "failedData": "An error occurred when fetching data !\nCheck the brick keys provided to the EdcHelp component."
  },
  "content": null,
  "url": "",
  "exportId": ""
  }
}

Tests

Unit

You can test the project by running:

npm run test

or

yarn test
2.1.0

2 years ago

2.0.0

4 years ago

1.1.0-beta-1

4 years ago

1.1.0-beta-0

4 years ago

1.0.0

4 years ago

1.0.0-beta-0

4 years ago