Skip to main content

IconButton

The IconButton widget is generally used to trigger a callback function that is called when the button is pressed.

Properties

The IconButton widget inherits from Button class → Has all Button properties.
  • icon: Icon → The icon of the button.
  • label: Label → The label of the button.

Constructor

ParameterTypeRequiredDescription
idstringyesThe id of the widget
iconstringyesThe icon of the widget
parentWidgetnoThe parent of the widget. Default is null
src/main.ts
import { IconButton } from "@cedro/ui";

const myIcnBtn = new IconButton("my-icnbtn", "home", parentWidget);

myIcnBtn.setVariant("contained");

myIcnBtn.subscribe({
event: "click",
then: (_e: Event, _w: Widget) => {
console.log("You have clicked!");
}
});

Public Methods

setIcon

Set a icon of the button.

Parameters

ParameterTypeRequiredDescription
iconstringyesThe icon. See all available icons here!

Returns Value

void

Example

src/main.ts
myIcnBtn.setIcon("home");

setText

Set a text of the button.

Parameters

ParameterTypeRequiredDescription
textstringyesThe text.

Returns Value

void

Example

src/main.ts
myIcnBtn.setText("Click me!");
src/main.tsx
//Using TSX/JSX syntax
<WIconButton id="my-iconbutton" text="Click me!" />

hideIcon

Hide the icon of the button.

Parameters

void

Returns Value

void

Example

src/main.ts
myIcnBtn.hideIcon();

hideText

Hide the text of the button.

Parameters

void

Returns Value

void

Example

src/main.ts
myIcnBtn.hideText();
src/main.tsx
//Using TSX/JSX syntax
<WIconButton id="my-iconbutton" onlyIcon />

displayIcon

Show the icon of the button.

Parameters

void

Returns Value

void

Example

src/main.ts
myIcnBtn.displayIcon();

displayText

Show the text of the button.

Parameters

void

Returns Value

void

Example

src/main.ts
myIcnBtn.displayText();