src/button/icon-button.component.ts
Get started with importing the module:
Example :import { ButtonModule } from 'carbon-components-angular';
AfterViewInit
selector | cds-icon-button, ibm-icon-button |
template |
|
Properties |
|
Methods |
Inputs |
Outputs |
Accessors |
constructor(renderer: Renderer2)
|
||||||
Defined in src/button/icon-button.component.ts:143
|
||||||
Parameters :
|
buttonAttributes | |
Type : literal type
|
|
Defined in src/button/icon-button.component.ts:75
|
buttonId | |
Type : string
|
|
Default value : `icon-btn-${IconButton.iconButtonCounter++}`
|
|
Defined in src/button/icon-button.component.ts:101
|
|
Override id |
buttonNgClass | |
Type : literal type
|
|
Defined in src/button/icon-button.component.ts:62
|
|
Pass global carbon classes to icon button |
description | |
Type : string | TemplateRef<any>
|
|
Defined in src/button/icon-button.component.ts:125
|
|
The string or template content to be exposed by the tooltip. |
disabled | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/button/icon-button.component.ts:121
|
|
Set to |
isExpressive | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/button/icon-button.component.ts:117
|
|
Set to |
kind | |
Type : ButtonType
|
|
Default value : "primary"
|
|
Defined in src/button/icon-button.component.ts:105
|
|
Sets the button type. |
showTooltipWhenDisabled | |
Type : boolean
|
|
Default value : false
|
|
Defined in src/button/icon-button.component.ts:129
|
|
Indicates whether the tooltip should be shown when the button is disabled |
size | |
Type : ButtonSize
|
|
Default value : "lg"
|
|
Defined in src/button/icon-button.component.ts:109
|
|
Specify the size of the button. |
type | |
Type : string
|
|
Default value : "button"
|
|
Defined in src/button/icon-button.component.ts:113
|
|
Set button type, |
align | |
Type : "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right" | "left" | "left-bottom" | "left-top" | "right" | "right-bottom" | "right-top"
|
|
Default value : "bottom"
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:32
|
|
Set popover alignment |
autoAlign | |
Type : boolean
|
|
Default value : false
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:40
|
|
Experimental: Use floating-ui to position the tooltip This is not toggleable - should be assigned once |
caret | |
Type : boolean
|
|
Default value : true
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:16
|
|
Set to |
dropShadow | |
Type : boolean
|
|
Default value : true
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:20
|
|
Set to |
enterDelayMs | |
Type : number
|
|
Default value : 100
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:44
|
|
Set delay before tooltip is shown |
highContrast | |
Type : boolean
|
|
Default value : true
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:24
|
|
Set to |
isOpen | |
Type : boolean
|
|
Default value : false
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:28
|
|
Set to |
leaveDelayMs | |
Type : number
|
|
Default value : 300
|
|
Inherited from
BaseIconButton
|
|
Defined in
BaseIconButton:48
|
|
Set delay when tooltip disappears |
blur | |
Type : EventEmitter
|
|
Defined in src/button/icon-button.component.ts:136
|
click | |
Type : EventEmitter
|
|
Defined in src/button/icon-button.component.ts:134
|
|
Common button events |
focus | |
Type : EventEmitter
|
|
Defined in src/button/icon-button.component.ts:135
|
tooltipClick | |
Type : EventEmitter
|
|
Defined in src/button/icon-button.component.ts:140
|
|
Event to emit when click event is fired from tooltip |
emitClickEvent | ||||||||||||
emitClickEvent(event, element: "tooltip" | "button")
|
||||||||||||
Defined in src/button/icon-button.component.ts:158
|
||||||||||||
Stop propogation of click event Else double fires (click) event
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Defined in src/button/icon-button.component.ts:149
|
Returns :
void
|
Private attributeList |
Type : literal type
|
Default value : {}
|
Defined in src/button/icon-button.component.ts:143
|
button |
Type : ElementRef
|
Decorators :
@ViewChild('button')
|
Defined in src/button/icon-button.component.ts:96
|
Private classList |
Type : literal type
|
Default value : {}
|
Defined in src/button/icon-button.component.ts:142
|
Static iconButtonCounter |
Type : number
|
Default value : 0
|
Defined in src/button/icon-button.component.ts:94
|
buttonNgClass | ||||||
getbuttonNgClass()
|
||||||
Defined in src/button/icon-button.component.ts:66
|
||||||
setbuttonNgClass(obj: literal type)
|
||||||
Defined in src/button/icon-button.component.ts:62
|
||||||
Pass global carbon classes to icon button
Parameters :
Returns :
void
|
buttonAttributes | ||||||||
getbuttonAttributes()
|
||||||||
Defined in src/button/icon-button.component.ts:90
|
||||||||
setbuttonAttributes(obj: literal type)
|
||||||||
Defined in src/button/icon-button.component.ts:75
|
||||||||
User can pass additional button attributes if component property does not already exist Key is the attribute name & value is the attribute value for the button
Parameters :
Returns :
void
|
import {
AfterViewInit,
Component,
ElementRef,
EventEmitter,
Input,
Output,
Renderer2,
TemplateRef,
ViewChild
} from "@angular/core";
import { BaseIconButton } from "./base-icon-button.component";
import { ButtonSize, ButtonType } from "./button.types";
/**
* Get started with importing the module:
*
* ```typescript
* import { ButtonModule } from 'carbon-components-angular';
* ```
*
* [See demo](../../?path=/story/components-button-icon-button--basic)
*/
@Component({
selector: "cds-icon-button, ibm-icon-button",
template: `
<cds-tooltip
class="cds--icon-tooltip"
[description]="description"
[disabled]="showTooltipWhenDisabled ? false : disabled"
[caret]="caret"
[dropShadow]="dropShadow"
[highContrast]="highContrast"
[isOpen]="isOpen"
[align]="align"
[autoAlign]="autoAlign"
[enterDelayMs]="enterDelayMs"
[leaveDelayMs]="leaveDelayMs"
(click)="emitClickEvent($event, 'tooltip')">
<button
#button
[id]="buttonId"
[disabled]="disabled"
[attr.type]="type"
[iconOnly]="true"
[ngClass]="buttonNgClass"
[cdsButton]="kind"
[size]="size"
[isExpressive]="isExpressive"
(click)="emitClickEvent($event)"
(focus)="focus.emit($event)"
(blur)="blur.emit($event)">
<ng-content></ng-content>
</button>
</cds-tooltip>
`
})
export class IconButton extends BaseIconButton implements AfterViewInit {
/**
* Pass global carbon classes to icon button
*/
@Input() set buttonNgClass(obj: { [key: string]: boolean }) {
this.classList = Object.assign({ "cds--btn--disabled": this.disabled }, obj);
}
get buttonNgClass() {
return this.classList;
}
/**
* @param obj: { [key: string]: string
* User can pass additional button attributes if component property does not already exist
* Key is the attribute name & value is the attribute value for the button
*/
@Input() set buttonAttributes(obj: { [key: string]: string }) {
if (this.button) {
// Remove old attributes
Object.keys(this.attributeList).forEach((key: string) => {
this.renderer.removeAttribute(this.button.nativeElement, key);
});
// Set new attributes
Object.keys(obj).forEach((key: string) => {
this.renderer.setAttribute(this.button.nativeElement, key, obj[key]);
});
}
// Set new attributes
this.attributeList = obj;
}
get buttonAttributes() {
return this.buttonAttributes;
}
static iconButtonCounter = 0;
@ViewChild("button") button: ElementRef;
/**
* Override id
*/
@Input() buttonId = `icon-btn-${IconButton.iconButtonCounter++}`;
/**
* Sets the button type.
*/
@Input() kind: ButtonType = "primary";
/**
* Specify the size of the button.
*/
@Input() size: ButtonSize = "lg";
/**
* Set button type, `button` by default
*/
@Input() type = "button";
/**
* Set to `true` to make button expressive
*/
@Input() isExpressive = false;
/**
* Set to `true` to disable button
*/
@Input() disabled = false;
/**
* The string or template content to be exposed by the tooltip.
*/
@Input() description: string | TemplateRef<any>;
/**
* Indicates whether the tooltip should be shown when the button is disabled
*/
@Input() showTooltipWhenDisabled = false;
/**
* Common button events
*/
@Output() click = new EventEmitter<Event>();
@Output() focus = new EventEmitter<Event>();
@Output() blur = new EventEmitter<Event>();
/**
* Event to emit when click event is fired from tooltip
*/
@Output() tooltipClick = new EventEmitter<Event>();
private classList: { [key: string]: boolean } = {};
private attributeList: { [key: string]: string } = {};
constructor(private renderer: Renderer2) {
super();
}
ngAfterViewInit(): void {
// Set attributes once element is found
this.buttonAttributes = this.attributeList;
}
/**
* Stop propogation of click event
* Else double fires (click) event
*/
emitClickEvent(event, element: "tooltip" | "button" = "button") {
event.preventDefault();
event.stopPropagation();
// Prevents (click) event from bubbling since it would appear user clicked the `button`
if (element === "tooltip") {
this.tooltipClick.emit(event);
return;
}
this.click.emit(event);
}
}