Skip to content

Commit 4c33198

Browse files
authored
feat(components/pages): add option for click event from needs attention items (#496)
* feat(components/pages): add option for click event from needs attention items * Updates based on feedback
1 parent 8e30e78 commit 4c33198

File tree

8 files changed

+101
-7
lines changed

8 files changed

+101
-7
lines changed

apps/playground/src/app/components/pages/action-hub/settings/settings.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component } from '@angular/core';
2+
import { SkyModalService } from '@skyux/modals';
23
import {
34
SkyActionHubNeedsAttention,
45
SkyPageLink,
@@ -16,7 +17,7 @@ export class SettingsComponent {
1617
public settingsLinks: SkyPageModalLink[] = [];
1718
public needsAttention: SkyActionHubNeedsAttention[];
1819

19-
constructor() {
20+
constructor(private modalService: SkyModalService) {
2021
['Back', 'Home'].forEach((label) => {
2122
this.relatedLinks.push({
2223
label,
@@ -81,6 +82,22 @@ export class SettingsComponent {
8182
url: '#',
8283
},
8384
},
85+
{
86+
title: 'Click to open a modal',
87+
click: () => {
88+
this.modalService.open(SettingsModalComponent, {
89+
providers: [
90+
{ provide: 'modalTitle', useValue: 'Click event modal' },
91+
],
92+
});
93+
},
94+
},
95+
{
96+
title: 'Click to show alert',
97+
click: () => {
98+
alert('Click event alert');
99+
},
100+
},
84101
];
85102
}
86103
}

libs/components/pages/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './lib/modules/action-hub/action-hub.module';
22
export * from './lib/modules/action-hub/types/action-hub-needs-attention';
3+
export * from './lib/modules/action-hub/types/action-hub-needs-attention-click-handler';
34
export * from './lib/modules/action-hub/types/page-link';
45
export * from './lib/modules/action-hub/types/page-links-input';
56
export * from './lib/modules/action-hub/types/page-modal-link';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type SkyActionHubNeedsAttentionClickHandler = (
2+
_: SkyActionHubNeedsAttentionClickHandlerArgs
3+
) => void;
4+
5+
export type SkyActionHubNeedsAttentionClickHandlerArgs = {
6+
item: unknown;
7+
};

libs/components/pages/src/lib/modules/action-hub/types/action-hub-needs-attention.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { NavigationExtras } from '@angular/router';
22

3+
import { SkyActionHubNeedsAttentionClickHandler } from './action-hub-needs-attention-click-handler';
4+
35
/**
46
* Specifies action items that require attention and directs users to pages
57
* where they can resolve them.
@@ -16,11 +18,15 @@ export interface SkyActionHubNeedsAttention {
1618
/**
1719
* Specifies a link to resolve the action item.
1820
*/
19-
permalink: {
21+
permalink?: {
2022
route?: {
2123
commands: any[];
2224
extras?: NavigationExtras;
2325
};
2426
url?: string;
2527
};
28+
/**
29+
* Specifies a click handler for the action item.
30+
*/
31+
click?: SkyActionHubNeedsAttentionClickHandler;
2632
}

libs/components/pages/src/lib/modules/link-as/link-as.pipe.spec.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,57 @@ describe('LinkAsPipe', () => {
77
expect(pipe.transform(undefined, undefined)).toBeFalsy();
88
});
99

10-
it('should validate when linkAs is href', () => {
10+
it('should validate when linkAs is button', () => {
1111
const pipe = new LinkAsPipe();
1212
expect(
1313
pipe.transform(
14-
{ label: 'Link', permalink: { url: 'https://www.example.com' } },
15-
'href'
14+
{
15+
title: 'Action',
16+
click: () => {
17+
[1].pop();
18+
},
19+
},
20+
'button'
21+
)
22+
).toBeTruthy();
23+
expect(
24+
pipe.transform(
25+
{
26+
title: 'Action',
27+
permalink: { url: 'https://www.example.com' },
28+
click: () => {
29+
[1].pop();
30+
},
31+
},
32+
'button'
1633
)
1734
).toBeFalsy();
1835
expect(
1936
pipe.transform(
20-
{ label: 'Link', permalink: { url: '1bb-nav://spa/path' } },
37+
{ title: 'Action', permalink: { url: 'https://www.example.com' } },
38+
'button'
39+
)
40+
).toBeFalsy();
41+
expect(
42+
pipe.transform(
43+
{ title: 'Action', permalink: { route: { commands: ['test'] } } },
44+
'button'
45+
)
46+
).toBeFalsy();
47+
expect(
48+
pipe.transform({ title: 'Action', permalink: { url: '' } }, 'button')
49+
).toBeFalsy();
50+
expect(pipe.transform(undefined, 'button')).toBeFalsy();
51+
expect(
52+
pipe.transform({ label: 'Link', permalink: { url: 'invalid' } }, 'button')
53+
).toBeFalsy();
54+
});
55+
56+
it('should validate when linkAs is href', () => {
57+
const pipe = new LinkAsPipe();
58+
expect(
59+
pipe.transform(
60+
{ label: 'Link', permalink: { url: 'https://www.example.com' } },
2161
'href'
2262
)
2363
).toBeFalsy();

libs/components/pages/src/lib/modules/link-as/link-as.pipe.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import { SkyPageLink } from '../action-hub/types/page-link';
99
export class LinkAsPipe implements PipeTransform {
1010
public transform(
1111
value: SkyActionHubNeedsAttention | SkyPageLink | undefined,
12-
linkAs: 'href' | 'skyHref' | 'skyAppLink'
12+
linkAs: 'button' | 'href' | 'skyHref' | 'skyAppLink'
1313
): boolean {
1414
switch (linkAs) {
15+
case 'button':
16+
return (
17+
(value as SkyActionHubNeedsAttention)?.click !== undefined &&
18+
value.permalink === undefined
19+
);
1520
case 'href':
1621
return (
1722
value?.permalink !== undefined &&

libs/components/pages/src/lib/modules/needs-attention/needs-attention.component.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ <h2 class="sky-font-heading-2">
7373
>
7474
<ng-container *ngTemplateOutlet="link"></ng-container>
7575
</a>
76+
<button
77+
*ngIf="item | linkAs: 'button'"
78+
class="sky-needs-attention-item sky-padding-vertical-lg sky-btn sky-btn-link-inline"
79+
[ngClass]="{
80+
'sky-border-bottom-row': !isLast
81+
}"
82+
type="button"
83+
(click)="item.click({item})"
84+
>
85+
<ng-container *ngTemplateOutlet="link"></ng-container>
86+
</button>
7687
</sky-column>
7788
</sky-row>
7889
</sky-fluid-grid>

libs/components/pages/src/lib/modules/needs-attention/needs-attention.component.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
display: flex;
1010
flex-wrap: nowrap;
1111
align-items: center;
12+
text-align: left;
13+
width: 100%;
14+
white-space: normal;
1215

1316
&-icon {
1417
color: $sky-theme-modern-font-deemphasized-color;
@@ -34,3 +37,7 @@
3437
}
3538
}
3639
}
40+
41+
button.sky-needs-attention-item.sky-border-bottom-row {
42+
@include sky-border(row, bottom);
43+
}

0 commit comments

Comments
 (0)