Skip to content

Commit

Permalink
"Taiga UI" hint tour UI (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimio authored Sep 22, 2021
1 parent 946b03c commit 4b2c82c
Show file tree
Hide file tree
Showing 32 changed files with 852 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Demo and documentation can be found at [hakimio.github.io/ngx-ui-tour](https://h
# install the core package
yarn add ngx-ui-tour-core

# install one of the UI packages (ngx-ui-tour-md-menu, ngx-ui-tour-ng-bootstrap, ngx-ui-tour-ngx-bootstrap, ngx-ui-tour-tui-dropdown)
# install one of the UI packages (ngx-ui-tour-md-menu, ngx-ui-tour-ng-bootstrap, ngx-ui-tour-ngx-bootstrap, ngx-ui-tour-tui-dropdown, ngx-ui-tour-tui-hint)
yarn add ngx-ui-tour-md-menu
```

Expand All @@ -52,7 +52,7 @@ yarn add ngx-ui-tour-md-menu
# install the core package
npm i --save ngx-ui-tour-core

# install one of the UI packages (ngx-ui-tour-md-menu, ngx-ui-tour-ng-bootstrap, ngx-ui-tour-ngx-bootstrap, ngx-ui-tour-tui-dropdown)
# install one of the UI packages (ngx-ui-tour-md-menu, ngx-ui-tour-ng-bootstrap, ngx-ui-tour-ngx-bootstrap, ngx-ui-tour-tui-dropdown, ngx-ui-tour-tui-hint)
npm i --save ngx-ui-tour-md-menu
```

Expand Down
40 changes: 40 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,46 @@
}
}
}
},
"ngx-ui-tour-tui-hint": {
"projectType": "library",
"root": "projects/ngx-ui-tour-tui-hint",
"sourceRoot": "projects/ngx-ui-tour-tui-hint/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"project": "projects/ngx-ui-tour-tui-hint/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/ngx-ui-tour-tui-hint/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "projects/ngx-ui-tour-tui-hint/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ngx-ui-tour-tui-hint/src/test.ts",
"tsConfig": "projects/ngx-ui-tour-tui-hint/tsconfig.spec.json",
"karmaConfig": "projects/ngx-ui-tour-tui-hint/karma.conf.js"
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"projects/ngx-ui-tour-tui-hint/**/*.ts",
"projects/ngx-ui-tour-tui-hint/**/*.html"
]
}
}
}
}
},
"defaultProject": "ngx-ui-tour",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"build:lib:ngx-bootstrap:base": "ng build ngx-ui-tour-ngx-bootstrap && cpy README.md projects/ngx-ui-tour-ngx-bootstrap/CHANGELOG.md dist/ngx-ui-tour-ngx-bootstrap/",
"build:lib:tui-dropdown": "npm run build:lib:core && npm run build:lib:tui-dropdown:base",
"build:lib:tui-dropdown:base": "ng build ngx-ui-tour-tui-dropdown && cpy README.md projects/ngx-ui-tour-tui-dropdown/CHANGELOG.md dist/ngx-ui-tour-tui-dropdown/",
"build:lib:tui-hint": "npm run build:lib:core && npm run build:lib:tui-hint:base",
"build:lib:tui-hint:base": "ng build ngx-ui-tour-tui-hint && cpy README.md projects/ngx-ui-tour-tui-hint/CHANGELOG.md dist/ngx-ui-tour-tui-hint/",
"test": "ng test",
"lint": "ng lint",
"pub": "npm run pub:lib && npm run pub:demo",
Expand All @@ -40,7 +42,8 @@
"pub:lib:ng-bootstrap": "cd dist/ngx-ui-tour-ng-bootstrap && npm publish",
"pub:lib:ngx-bootstrap": "cd dist/ngx-ui-tour-ngx-bootstrap && npm publish",
"pub:lib:md-menu": "cd dist/ngx-ui-tour-md-menu && npm publish",
"pub:lib:tui-dropdown": "cd dist/ngx-ui-tour-tui-dropdown && npm publish"
"pub:lib:tui-dropdown": "cd dist/ngx-ui-tour-tui-dropdown && npm publish",
"pub:lib:tui-hint": "cd dist/ngx-ui-tour-tui-hint && npm publish"
},
"dependencies": {
"@angular/animations": "^12.2.3",
Expand Down
44 changes: 44 additions & 0 deletions projects/ngx-ui-tour-tui-hint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"parserOptions": {
"project": [
"projects/ngx-ui-tour-tui-hint/tsconfig.lib.json",
"projects/ngx-ui-tour-tui-hint/tsconfig.spec.json"
],
"createDefaultProgram": true
},
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "tour",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "tour",
"style": "kebab-case"
}
]
}
},
{
"files": [
"*.html"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions projects/ngx-ui-tour-tui-hint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<a name="1.0.0"></a>

# [1.0.0](https://github.com/hakimio/ngx-ui-tour) (2021-09-22)

### Features

- Initial release!
20 changes: 20 additions & 0 deletions projects/ngx-ui-tour-tui-hint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ngx-UI-Tour Taiga UI Hint

## About

> UI tour library for Angular 9+
`ngx-ui-tour` is a fork of __Isaac Mann's__ `ngx-tour`. The project had to be forked since the original is no longer
maintained.

## Demo

[hakimio.github.io/ngx-ui-tour](https://hakimio.github.io/ngx-ui-tour)

## Homepage

[github.com/hakimio/ngx-ui-tour](https://github.com/hakimio/ngx-ui-tour)

## License

MIT
44 changes: 44 additions & 0 deletions projects/ngx-ui-tour-tui-hint/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/ngx-ui-tour-tui-hint'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
12 changes: 12 additions & 0 deletions projects/ngx-ui-tour-tui-hint/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ngx-ui-tour-tui-hint",
"lib": {
"entryFile": "src/public_api.ts",
"umdModuleIds": {
"ngx-ui-tour-core": "ngxUiTourCore",
"@taiga-ui/core": "taigaUiCore",
"@taiga-ui/cdk": "taigaUiCdk"
}
}
}
30 changes: 30 additions & 0 deletions projects/ngx-ui-tour-tui-hint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "ngx-ui-tour-tui-hint",
"description": "UI tour library for Angular 9+",
"keywords": [
"angular",
"ngx",
"taiga-ui",
"tour",
"product-tour",
"ui-tour",
"onboarding",
"onboarding-tour"
],
"repository": "https://github.com/hakimio/ngx-ui-tour.git",
"author": "Tomas Rimkus <[email protected]>",
"license": "MIT",
"version": "1.0.0",
"peerDependencies": {
"@angular/common": ">=9.0.0 <13.0.0",
"@angular/core": ">=9.0.0 <13.0.0",
"@taiga-ui/core": "^2.15.0",
"@taiga-ui/cdk": "^2.15.0",
"@taiga-ui/icons": "^2.15.0",
"ngx-ui-tour-core": "7.0.1",
"typescript": ">=3.8.0"
},
"dependencies": {
"tslib": "^2.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {IStepOption} from 'ngx-ui-tour-core';
import {TuiDirection} from '@taiga-ui/core';

export interface ITuiHintStepOption extends IStepOption {
placement?: TuiDirection;
}
75 changes: 75 additions & 0 deletions projects/ngx-ui-tour-tui-hint/src/lib/tour-anchor.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {Directive, ElementRef, HostBinding, Input, OnDestroy, OnInit} from '@angular/core';
import {TuiManualHintDirective} from '@taiga-ui/core';
import {ScrollingUtil, TourAnchorDirective, TourBackdropService, TourState} from 'ngx-ui-tour-core';
import {TourTuiHintService} from './tour-tui-hint.service';
import {ITuiHintStepOption} from './step-option.interface';
import {TourStepTemplateService} from './tour-step-template.service';

@Directive({
selector: '[tourAnchor]',
providers: [
TuiManualHintDirective
]
})
export class TourAnchorTuiHintDirective implements OnInit, OnDestroy, TourAnchorDirective {

@Input()
tourAnchor: string;

@HostBinding('class.touranchor--is-active')
isActive: boolean;

constructor(
private readonly tourService: TourTuiHintService,
private readonly tourBackdropService: TourBackdropService,
private readonly tourStepTemplateService: TourStepTemplateService,
private readonly tuiHint: TuiManualHintDirective,
private elementRef: ElementRef
) {}

ngOnInit(): void {
this.tourService.register(this.tourAnchor, this);
}

public ngOnDestroy(): void {
this.tourService.unregister(this.tourAnchor);
}

showTourStep(step: ITuiHintStepOption) {
const htmlElement: HTMLElement = this.elementRef.nativeElement,
templateComponent = this.tourStepTemplateService.templateComponent;

templateComponent.step = step;
this.isActive = true;

if (!step.disableScrollToAnchor) {
ScrollingUtil.ensureVisible(htmlElement);
}

this.tuiHint.direction = step.placement || 'bottom-right';
this.tuiHint.content = templateComponent.template;
this.tuiHint.mode = 'onDark';

if (step.enableBackdrop) {
this.tourBackdropService.show(this.elementRef);
} else {
this.tourBackdropService.close();
}

step.prevBtnTitle = step.prevBtnTitle || 'Prev';
step.nextBtnTitle = step.nextBtnTitle || 'Next';
step.endBtnTitle = step.endBtnTitle || 'End';

this.tuiHint.tuiManualHintShow = true;
}

hideTourStep() {
this.isActive = false;
this.tuiHint.tuiManualHintShow = false;

if (this.tourService.getStatus() === TourState.OFF) {
this.tourBackdropService.close();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Injectable} from '@angular/core';
import {TourStepTemplateComponent} from './tour-step-template/tour-step-template.component';

@Injectable()
export class TourStepTemplateService {

public templateComponent: TourStepTemplateComponent;

}
Loading

0 comments on commit 4b2c82c

Please sign in to comment.