A button containing text and/or an image. It extends HTMLButtonElement to take advantage of the accessibility given by browsers but it means that this component has a special way of instantiating.

Note: Using the minimal variant results in a button without a minimum value for its width or height. One possible usage could icon-only buttons, such as a close button for a dialog.

Coral.Button API

Constructor

JavaScript:

new Coral.Button() or document.createElement('coral-button', 'button')

HTML Tag:

<button is="coral-button">

Extends

Sub-components

Static Properties

Coral.Button.size {String}

Enumeration representing button sizes.

Properties:

Name Type Value Description
MEDIUM String M A medium button is the default, normal sized button.
LARGE String L A large button, which is larger than a medium button.

Coral.Button.variant {String}

Enum for button variant values.

Properties:

Name Type Value Description
DEFAULT String default A default, gray button
PRIMARY String primary A blue button that indicates that the button's action is the primary action.
QUIET String quiet A button with no border or background.
WARNING String warning A red button that indicates that the button's action is dangerous.
MINIMAL String minimal A minimal button with no background or border.

Instance Properties

instance.block {Boolean}

Reflected
Expands the button to the full width of the parent.
Default Value:
  • false
HTML Attribute:
  • block

instance.icon {String}

Specifies the icon name used inside the button. When the icon is set and no text is available, the button automatically changes to be square, in order to accomodate better the icon. See Coral.Icon for valid icon names.
Default Value:
  • ""
HTML Attribute:
  • icon
See:

instance.iconSize {Coral.Icon.size}

Size of the icon. It accepts both lower and upper case sizes.
Default Value:
  • Coral.Icon.size.SMALL
HTML Attribute:
  • iconsize
See:

instance.label {HTMLElement}

The label of the button.

instance.selected {Boolean}

Reflected
Whether the button is selected.
Default Value:
  • false
HTML Attribute:
  • selected

instance.size {Coral.Button.size}

Reflected
The size of the button. It accepts both lower and upper case sizes. Currently only "M" (the default) and "L" are available.
Default Value:
  • Coral.Button.size.MEDIUM
HTML Attribute:
  • size

instance.variant {Coral.Button.variant}

The button's variant.
Default Value:
  • Coral.Button.variant.DEFAULT
HTML Attribute:
  • variant

Methods

instance.get

Get the value of a property.
Parameters:
Name Type Description
property String The name of the property to fetch the value of.
Returns:
Property value. {*}
Inherited From:

instance.hide

Hide this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.off

Remove an event listener.
Parameters:
Name Type Optional Description
eventName String No
The event name to stop listening for.
selector String Yes
The selector that was used for event delegation.
func function No
The function that was passed to on().
useCapture Boolean Yes
Only remove listeners with useCapture set to the value passed in.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.on

Add an event listener.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to listen for.
selector String Yes
The selector to use for event delegation.
func function No
The function that will be called when the event is triggered.
useCapture Boolean Yes
false Whether or not to listen during the capturing or bubbling phase.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.remove

Non-destructively remove this element. It can be re-added by simply appending it to the document again. It will be garbage collected if there are no more references to it. This is different from using jQuery's remove(), which is destructive in that it removes data and listeners.
Inherited From:

instance.show

Show this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.trigger

Trigger an event.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to trigger.
props Object Yes
Additional properties to make available to handlers as event.detail.
bubbles Boolean Yes
true Set to false to prevent the event from bubbling.
cancelable Boolean Yes
true Set to false to prevent the event from being cancelable.
Returns:
CustomEvent object {CustomEvent}
Inherited From:

Events

coral-component:attached

Triggered when the component is attached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:detached

Triggered when the component is detached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:ready

Triggerred when the component has been upgraded and is ready for use.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From: