File

src/button/button.directive.ts

Description

A convenience directive for applying styling to a button. Get started with importing the module:

Example :
import { ButtonModule } from 'carbon-components-angular';

Example:

Example :
<button cdsButton>A button</button>
<button cdsButton="secondary">A secondary button</button>

See the vanilla carbon docs for more detail.

See demo

Metadata

Index

Properties
Inputs
HostBindings
Accessors

Inputs

cdsButton
Type : ButtonType | string
Default value : "primary"

Sets the button type Accepts ButtonType or nothing (empty string which is equivalent to "primary") Empty string has been added as an option for Angular 16+ to resolve type errors

ibmButton
Type : ButtonType
iconOnly
Type : boolean
Default value : false

Set to true if the button contains only an icon This should only be used for creating custom icon buttons, otherwise use <cds-icon-button></cds-icon-button> component

isExpressive
Type : boolean
Default value : false

Set to true for a "expressive" style button

size
Type : ButtonSize

Specify the size of the button

skeleton
Type : boolean
Default value : false

Set to true for a skeleton state button

HostBindings

class.cds--btn
Type : boolean
Default value : true
class.cds--btn--2xl
Type : boolean
class.cds--btn--danger
Type : boolean
class.cds--btn--danger--ghost
Type : boolean
class.cds--btn--danger--tertiary
Type : boolean
class.cds--btn--ghost
Type : boolean
class.cds--btn--lg
Type : boolean
class.cds--btn--md
Type : boolean
class.cds--btn--primary
Type : boolean
class.cds--btn--secondary
Type : boolean
class.cds--btn--sm
Type : boolean
class.cds--btn--tertiary
Type : boolean
class.cds--btn--xl
Type : boolean
class.cds--layout--size-2xl
Type : boolean
class.cds--layout--size-lg
Type : boolean
class.cds--layout--size-md
Type : boolean
class.cds--layout--size-sm
Type : boolean
class.cds--layout--size-xl
Type : boolean

Properties

baseClass
Default value : true
Decorators :
@HostBinding('class.cds--btn')

Accessors

ibmButton
setibmButton(type: ButtonType)
Parameters :
Name Type Optional
type ButtonType No
Returns : void
primaryButton
getprimaryButton()
secondaryButton
getsecondaryButton()
tertiaryButton
gettertiaryButton()
ghostButton
getghostButton()
dangerButton
getdangerButton()
dangerTertiary
getdangerTertiary()
dangerGhost
getdangerGhost()
smallSize
getsmallSize()
mediumSize
getmediumSize()
largeSize
getlargeSize()
extraLargeSize
getextraLargeSize()
twoExtraLargeSize
gettwoExtraLargeSize()
smallLayoutSize
getsmallLayoutSize()
mediumLayoutSize
getmediumLayoutSize()
largeLayoutSize
getlargeLayoutSize()
extraLargeLayoutSize
getextraLargeLayoutSize()
twoExtraLargeLayoutSize
gettwoExtraLargeLayoutSize()
import {
	Directive,
	HostBinding,
	Input
} from "@angular/core";
import { ButtonSize, ButtonType } from "./button.types";

/**
 * A convenience directive for applying styling to a button. Get started with importing the module:
 *
 * ```typescript
 * import { ButtonModule } from 'carbon-components-angular';
 * ```
 *
 * Example:
 *
 * ```html
 * <button cdsButton>A button</button>
 * <button cdsButton="secondary">A secondary button</button>
 * ```
 *
 * See the [vanilla carbon docs](http://www.carbondesignsystem.com/components/button/code) for more detail.
 *
 * [See demo](../../?path=/story/components-button--basic)
 */
@Directive({
	selector: "[cdsButton], [ibmButton]"
})
export class Button {
	/**
	 * @deprecated as of v5 - Use `cdsButton` input property instead
	 */
	@Input() set ibmButton(type: ButtonType) {
		this.cdsButton = type;
	}
	/**
	 * Sets the button type
	 * Accepts `ButtonType` or nothing (empty string which is equivalent to "primary")
	 * Empty string has been added as an option for Angular 16+ to resolve type errors
	 */
	@Input() cdsButton: ButtonType | "" = "primary";
	/**
	 * Specify the size of the button
	 */
	@Input() size: ButtonSize;
	/**
	 * Set to `true` for a skeleton state button
	 */
	@HostBinding("class.cds--skeleton") @Input() skeleton = false;
	/**
	 * Set to `true` if the button contains only an icon
	 * This should only be used for creating custom icon buttons, otherwise use
	 * `<cds-icon-button></cds-icon-button>` component
	 */
	@HostBinding("class.cds--btn--icon-only") @Input() iconOnly = false;

	/**
	 * Set to `true` for a "expressive" style button
	 */
	@HostBinding("class.cds--btn--expressive") @Input() isExpressive = false;

	// a whole lot of HostBindings ... this way we don't have to touch the elementRef directly
	@HostBinding("class.cds--btn") baseClass = true;
	@HostBinding("class.cds--btn--primary") get primaryButton() {
		return this.cdsButton === "primary" || !this.cdsButton;
	}
	@HostBinding("class.cds--btn--secondary") get secondaryButton() {
		return this.cdsButton === "secondary";
	}
	@HostBinding("class.cds--btn--tertiary") get tertiaryButton() {
		return this.cdsButton === "tertiary";
	}
	@HostBinding("class.cds--btn--ghost") get ghostButton() {
		return this.cdsButton === "ghost";
	}
	@HostBinding("class.cds--btn--danger") get dangerButton() {
		return this.cdsButton === "danger" || this.cdsButton === "danger--primary";
	}
	@HostBinding("class.cds--btn--danger--tertiary") get dangerTertiary() {
		return this.cdsButton === "danger--tertiary";
	}
	@HostBinding("class.cds--btn--danger--ghost") get dangerGhost() {
		return this.cdsButton === "danger--ghost";
	}
	/**
	 * @todo remove `cds--btn--${size}` classes in v12
	 */
	@HostBinding("class.cds--btn--sm") get smallSize() {
		return this.size === "sm" && !this.isExpressive;
	}
	@HostBinding("class.cds--btn--md") get mediumSize() {
		return this.size === "md" && !this.isExpressive;
	}
	@HostBinding("class.cds--btn--lg") get largeSize() {
		return this.size === "lg";
	}
	@HostBinding("class.cds--btn--xl") get extraLargeSize() {
		return this.size === "xl";
	}
	@HostBinding("class.cds--btn--2xl") get twoExtraLargeSize() {
		return this.size === "2xl";
	}

	// Size classes
	@HostBinding("class.cds--layout--size-sm") get smallLayoutSize() {
		return this.size === "sm" && !this.isExpressive;
	}
	@HostBinding("class.cds--layout--size-md") get mediumLayoutSize() {
		return this.size === "md" && !this.isExpressive;
	}
	@HostBinding("class.cds--layout--size-lg") get largeLayoutSize() {
		return this.size === "lg";
	}
	@HostBinding("class.cds--layout--size-xl") get extraLargeLayoutSize() {
		return this.size === "xl";
	}
	@HostBinding("class.cds--layout--size-2xl") get twoExtraLargeLayoutSize() {
		return this.size === "2xl";
	}


}

results matching ""

    No results matching ""