-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3055 from Akshat55/tag-components
feat: introduce selectable & operational tags
- Loading branch information
Showing
9 changed files
with
283 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from "./tag-filter.component"; | ||
export * from "./tag.component"; | ||
export * from "./tag-icon.directive"; | ||
export * from "./tag-selectable.component"; | ||
export * from "./tag-operational.component"; | ||
export * from "./tag.module"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Directive, HostBinding } from "@angular/core"; | ||
|
||
@Directive({ | ||
selector: "[cdsTagIcon], [ibmTagIcon]" | ||
}) | ||
export class TagIconDirective { | ||
@HostBinding("class.cds--tag__custom-icon") tagIcon = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
HostBinding, | ||
Input | ||
} from "@angular/core"; | ||
import { Tag } from "./tag.component"; | ||
|
||
@Component({ | ||
selector: "cds-tag-operational, ibm-tag-operational", | ||
template: ` | ||
<ng-container *ngIf="!skeleton"> | ||
<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content> | ||
<span class="cds--tag__label"> | ||
<ng-content></ng-content> | ||
</span> | ||
</ng-container> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class TagOperationalComponent extends Tag { | ||
@HostBinding("attr.role") role = "button"; | ||
@HostBinding("attr.type") buttonType = "button"; | ||
@HostBinding("attr.tabindex") tabIndex = 0; | ||
|
||
@Input() disabled = false; | ||
|
||
/** | ||
* @todo | ||
* Remove `cds--tag--${this.size}` in v7 | ||
*/ | ||
@HostBinding("attr.class") get attrClass() { | ||
const disabledClass = this.disabled ? "cds--tag--disabled" : ""; | ||
const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`; | ||
const skeletonClass = this.skeleton ? "cds--skeleton" : ""; | ||
|
||
return `cds--tag cds--tag--operational cds--tag--${this.type} ${disabledClass} ${sizeClass} ${skeletonClass} ${this.class}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
EventEmitter, | ||
HostBinding, | ||
HostListener, | ||
Input, | ||
Output | ||
} from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "cds-tag-selectable, ibm-tag-selectable", | ||
template: ` | ||
<ng-container *ngIf="!skeleton"> | ||
<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content> | ||
<span class="cds--tag__label"> | ||
<ng-content></ng-content> | ||
</span> | ||
</ng-container> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class TagSelectableComponent { | ||
@HostBinding("attr.role") role = "button"; | ||
@HostBinding("attr.type") buttonType = "button"; | ||
@HostBinding("attr.tabindex") tabIndex = 0; | ||
@HostBinding("attr.aria-pressed") get ariaPressed() { | ||
return this.selected; | ||
} | ||
|
||
@Input() size: "sm" | "md" | "lg" = "md"; | ||
@Input() skeleton = false; | ||
@Input() disabled = false; | ||
@Input() class = ""; | ||
@Input() selected = false; | ||
|
||
@Output() selectedChange = new EventEmitter<boolean>(); | ||
|
||
@HostListener("click") | ||
onClick() { | ||
this.selected = !this.selected; | ||
this.selectedChange.emit(this.selected); | ||
} | ||
|
||
/** | ||
* @todo | ||
* Remove `cds--tag--${this.size}` in v7 | ||
*/ | ||
@HostBinding("attr.class") get attrClass() { | ||
const disabledClass = this.disabled ? "cds--tag--disabled" : ""; | ||
const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`; | ||
const skeletonClass = this.skeleton ? "cds--skeleton" : ""; | ||
const selectedClass = this.selected ? "cds--tag--selectable-selected" : ""; | ||
|
||
return `cds--tag cds--tag--selectable ${selectedClass} ${disabledClass} ${sizeClass} ${skeletonClass} ${this.class}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.