Skip to content

Commit

Permalink
Merge pull request #18 from RobertThwaite/AwsomeButton
Browse files Browse the repository at this point in the history
Added ability to use font awsome Icons for close button
  • Loading branch information
andreasonny83 authored Feb 20, 2018
2 parents b9a9920 + c68a4f0 commit 715adcd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ If set to a valid absolute or relative URL, it will render an extra 'learn more'

![output with link](http://i.imgur.com/0nvb6sP.png)

### awsomeCloseIcon

Font Awsome is required in your header for this feature to work.

```html
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
```




| Type | Default value |
| --- | --- |
| string | null |

If set to a Font awsome Icon e.g. "fa-window-close" it will replace the standard SVG with the Font awsome Icon.

###### Example

```html
<cookie-law awsomeCloseIcon="fa-window-close"></cookie-law>
```

### target

| Type | Default value |
Expand Down
2 changes: 1 addition & 1 deletion demo/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
</a>
</cookie-law>
<cookie-law #cookieLaw (isSeen)="cookieLawSeen = $event" learnMore="/false" target="_blank"></cookie-law>
<cookie-law #cookieLaw (isSeen)="cookieLawSeen = $event" learnMore="/false" target="_blank" awsomeCloseIcon="fa-accessible-icon" ></cookie-law>
`,
styles: [`
a.link {
Expand Down
3 changes: 3 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>angular2-cookie-law demo app</title>
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>


</head>
<body>
<cookie-demo-app class="app">
Expand Down
20 changes: 17 additions & 3 deletions src/cookie-law-element.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ export class CookieLawElementComponent implements OnInit {
public transition: CookieLawAnimation;

@Input()
get learnMore() { return this._learnMore; }
get learnMore() { return this._learnMore; }
set learnMore(value: string) {
this._learnMore = (value !== null && `${value}` !== 'false') ? value : null;
}

@Input()
get awsomeCloseIcon() { return this._awsomeCloseIcon; }
set awsomeCloseIcon(value: string) {
this._awsomeCloseIcon = (value !== null && `${value}` !== 'false') ? value : null;
}

@Input()
get target() { return this._target; }
set target(value: CookieLawTarget) {
Expand All @@ -70,6 +76,7 @@ export class CookieLawElementComponent implements OnInit {
public noopener: boolean;

private _learnMore: string;
private _awsomeCloseIcon: string;
private _target: CookieLawTarget;
private _position: CookieLawPosition;

Expand All @@ -82,10 +89,17 @@ export class CookieLawElementComponent implements OnInit {
}

public ngOnInit(): void {
this.noopener = this._target === '_blank';
this.noopener = this._target === '_blank';
this.transition = this.position === 'bottom' ? 'bottomIn' : 'topIn';

this.closeSvg = this.domSanitizer.bypassSecurityTrustHtml(closeIcon);
if(this._awsomeCloseIcon){
this.closeSvg = this.domSanitizer.bypassSecurityTrustHtml("<i class='fab " + this._awsomeCloseIcon + "'></i>");
}else{
this.closeSvg = this.domSanitizer.bypassSecurityTrustHtml(closeIcon);
}




this.currentStyles = {
'top': this.position === 'top' ? '0' : null,
Expand Down
6 changes: 5 additions & 1 deletion src/cookie-law.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
selector: 'cookie-law',
template: `
<cookie-law-el *ngIf="!seen"
[awsomeCloseIcon]="awsomeCloseIcon"
[learnMore]="learnMore"
[target]="target"
[position]="position"
Expand Down Expand Up @@ -56,14 +57,17 @@ export class CookieLawComponent implements OnInit {
@Input()
public expiration: number;

@Input()
public awsomeCloseIcon: string;

@Output()
public isSeen = new EventEmitter<boolean>();

public get cookieLawSeen(): boolean {
return this._service.seen(this.name);
}

constructor (private _service: CookieLawService) {
constructor(private _service: CookieLawService) {
this.name = 'cookieLawSeen'; // set a default cookie name if not provided
}

Expand Down

0 comments on commit 715adcd

Please sign in to comment.