Skip to content

Commit 9222f6c

Browse files
authored
Merge pull request #3056 from Akshat55/link-icon
feat: create link directive to pair icon with link
2 parents d4adac4 + 7db29d7 commit 9222f6c

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

src/icon/icon.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export class IconDirective implements AfterViewInit, OnChanges {
9191
"aria-label": this.ariaLabel,
9292
"aria-labelledby": this.ariaLabelledBy,
9393
"aria-hidden": this.ariaHidden,
94-
focusable: this.isFocusable.toString()
94+
focusable: this.isFocusable.toString(),
95+
fill: icon.attrs.fill
9596
});
9697

9798
const attrKeys = Object.keys(attributes);

src/link/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./link.directive";
2+
export * from "./link-icon.directive";
23
export * from "./link.module";

src/link/link-icon.directive.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Directive, HostBinding } from "@angular/core";
2+
3+
@Directive({
4+
selector: "[ibmLinkIcon], [cdsLinkIcon]"
5+
})
6+
export class LinkIconDirective {
7+
@HostBinding("class.cds--link__icon") iconClass = true;
8+
}

src/link/link.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { NgModule } from "@angular/core";
22
import { CommonModule } from "@angular/common";
33

44
import { Link } from "./link.directive";
5+
import { LinkIconDirective } from "./link-icon.directive";
56

67
@NgModule({
78
declarations: [
8-
Link
9+
Link,
10+
LinkIconDirective
911
],
1012
exports: [
11-
Link
13+
Link,
14+
LinkIconDirective
1215
],
1316
imports: [
1417
CommonModule

src/link/link.stories.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import { moduleMetadata, Meta } from "@storybook/angular";
44
import { LinkModule, Link } from "./";
55

6+
import { IconModule } from "../icon";
7+
68
export default {
79
title: "Components/Link",
810
decorators: [
911
moduleMetadata({
10-
imports: [LinkModule]
12+
imports: [LinkModule, IconModule]
1113
})
1214
],
1315
component: Link
@@ -24,3 +26,22 @@ Basic.args = {
2426
disabled: false,
2527
inline: false
2628
};
29+
30+
const IconTemplate = (args) => ({
31+
props: args,
32+
template: `
33+
<a
34+
href="#"
35+
cdsLink
36+
[disabled]="disabled"
37+
[inline]="inline">
38+
Link
39+
<svg cdsLinkIcon cdsIcon="close" size="16"></svg>
40+
</a>
41+
`
42+
});
43+
export const WithIcon = IconTemplate.bind({});
44+
WithIcon.args = {
45+
disabled: false,
46+
inline: false
47+
};

0 commit comments

Comments
 (0)