CxJS

Button

import { Button } from 'cx/widgets'; Copied

Buttons trigger actions when clicked. They support various visual styles, icons, and built-in confirmation dialogs.

<div className="flex flex-wrap gap-2 items-center">
  <Button>Regular</Button>
  <Button pressed>Pressed</Button>
  <Button disabled>Disabled</Button>
</div>

Use pressed to show a toggled state, and disabled to prevent interaction.

Mods

Buttons support visual modifiers: primary for main actions, danger for destructive actions, and hollow for secondary actions.

<div className="flex flex-wrap gap-2 items-center">
  <Button mod="primary">Primary</Button>
  <Button mod="danger">Danger</Button>
  <Button mod="hollow">Hollow</Button>
</div>

Icons

Add icons using the icon prop. Buttons can have both icon and text, or just an icon.

<div className="flex flex-wrap gap-2 items-center">
  <Button icon="search">Search</Button>
  <Button icon="plus" mod="primary">
    Add
  </Button>
  <Button icon="pencil" mod="hollow" />
  <Button icon="refresh-cw" mod="hollow" />
  <Button icon="x" mod="hollow" />
</div>

Confirmation

Use the confirm prop to show a confirmation dialog before executing the onClick handler.

<div className="flex flex-wrap gap-2 items-center">
  <Button
    mod="danger"
    confirm="Are you sure you want to delete this item?"
    onClick={() => MsgBox.alert("Item deleted!")}
  >
    Delete
  </Button>
</div>

To enable CxJS-based confirmation dialogs, call enableMsgBoxAlerts() at application startup:

import { enableMsgBoxAlerts } from "cx/widgets";
enableMsgBoxAlerts();

Configuration

PropertyTypeDescription
textStringPropButton text content.
iconStringPropName of the icon to display.
modstringVisual modifier: primary, danger, hollow.
pressedBooleanPropShows the button in a pressed/toggled state.
disabledBooleanPropDisables the button.
enabledBooleanPropInverse of disabled.
confirmstring | objectConfirmation message or MsgBox configuration.
dismissbooleanIf true, closes the parent overlay when clicked.
submitbooleanSets type="submit" for form submission.
typestringButton type: submit or button. Default: button.
focusOnMouseDownbooleanAllow focus on mouse click. Default: false.
onClickfunctionClick handler: (e, instance) => void.