Skip to main content

Message

Overview​

The Message component provides Bulma's flexible notice/message box for your Bulma React UI.

It supports color, optional headers, close buttons, custom content, and Bulma helper classes for text/background. Use it for inline feedback, status messages, alerts, or general notifications.

info

Supports Bulma color modifiers, sizes, and both header/body sections. The close button is optional and triggers your onClose callback.


Import​

import { Message, MessageHeader, MessageBody } from '@allxsmith/bestax-bulma';

Usage​

Message with Header (per color)​

To display a message box with a header, use the Message component with the color and title props. This allows you to visually distinguish messages by context—such as primary, info, success, warning, or danger—and provide a clear heading for the content. The onClose prop adds a close button for dismissible messages, and you can use Bulma helper props for further customization.

<>
  <Message color="primary" title="Primary">
    This is a primary message.
  </Message>
  <Message color="link" title="Link">
    This is a link message.
  </Message>
  <Message color="info" title="Info">
    This is an info message.
  </Message>
  <Message color="success" title="Success">
    This is a success message.
  </Message>
  <Message color="warning" title="Warning">
    This is a warning message.
  </Message>
  <Message color="danger" title="Danger">
    This is a danger message.
  </Message>
</>


Message Body Only (no header)​

You can omit the title prop to render a message with only a body section. This is useful for simple notifications or inline feedback without a heading.

<>
  <Message color="primary">This is a primary message with no header.</Message>
  <Message color="danger">This is a danger message with no header.</Message>
</>


Dismissible Message​

Add the onClose prop to make the message dismissible. When the close button is clicked, your callback will be triggered, allowing you to hide or remove the message from the UI. The button is named "delete" for screen readers; ariaCloseLabel gives it a name of your own, such as one in your app's language.

function example() {
  const [open, setOpen] = useState(true);

  return (
    <>
      {open && (
        <Message color="info" title="Dismiss Me" onClose={() => setOpen(false)}>
          You can close this message by clicking the X button.
        </Message>
      )}
    </>
  );
}


Sizes​

Use the size prop ('small', 'medium', 'large') to adjust the size of the message box for different contexts.

<>
  <Message title="Default Size">This is the default size message.</Message>
  <Message size="small" title="Small">
    This is a small message.
  </Message>
  <Message size="medium" title="Medium">
    This is a medium message.
  </Message>
  <Message size="large" title="Large">
    This is a large message.
  </Message>
</>


Compound (dot-notation) usage​

The message header and body are available as the Message.Header and Message.Body statics, so a whole message can be composed from the single Message import. Each static's props are listed under Compound component props. The same parts are named exports, MessageHeader and MessageBody, and each is the same component as the dotted name. A Next.js Server Component imports the named export, because the dotted name is undefined there.

Built from its parts, a message puts Message.Header and Message.Body straight inside its <article>, the way Bulma lays them out. Plain children, as in the examples above, get a .message-body around them.

Complete Message with Compound Components​

<Message color="info">
  <Message.Header>
    <Paragraph>Compound Component Message</Paragraph>
    <Delete aria-label="delete" />
  </Message.Header>
  <Message.Body>
    <Paragraph>
      This message is built using compound components for maximum flexibility
      and control over each section.
    </Paragraph>
    <Paragraph>
      You can include multiple paragraphs and elements in the body.
    </Paragraph>
  </Message.Body>
</Message>

Minimal Message with Body Only​

<Message color="success">
  <Message.Body>
    <Paragraph>
      A simple message using only the Message.Body compound component.
    </Paragraph>
  </Message.Body>
</Message>

Header-Only Message​

<Message color="warning">
  <Message.Header>
    <Paragraph>Header-only message</Paragraph>
    <Delete aria-label="delete" />
  </Message.Header>
</Message>

Mixed Approach​

You can combine the traditional prop-based API with compound components. The header that title (or onClose) makes comes first, and the parts follow it:

<Message color="danger" title="Mixed Approach">
  <Message.Body>
    <Paragraph>
      You can mix prop-based and compound component approaches!
    </Paragraph>
    <Paragraph>
      This message uses the title prop but compound components for the body.
    </Paragraph>
  </Message.Body>
</Message>


Accessibility​

  • The message is rendered as <article class="message">.
  • If onClose is provided, a close button is rendered, named "delete" unless ariaCloseLabel names it. It's drawn as an icon, so its name is all a screen reader says about it: in an app in another language, give it one in the page's language. An aria-label on Message names the <article>, not the button. It takes presses on a box at least 24px square around its circle, as Delete does.
  • For optimal accessibility, use clear and descriptive titles/content.
note

Always provide a visible or accessible way to dismiss important, interruptive messages.


  • Notification: For simpler, single-box notifications.
  • Helper Props: Bulma helper props for spacing and other utilities.

Additional Resources​

Pro Tip

You can use Bulma helper props with <Message /> for powerful utility-based styling.


Props​

PropTypeDefaultDescription
classNamestring—Additional CSS classes.
titleReact.ReactNode—Title string/node (renders header section).
textColorBulma color | 'inherit' | 'current'—Text color for the message (Bulma helper).
color'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger'—Bulma color modifier for the message.
bgColorBulma color | 'inherit' | 'current'—Background color for the message (Bulma helper).
size'small' | 'medium' | 'large'—Size of the message.
onClose() => void—Callback for the close ("X") button.
ariaCloseLabelstring'delete'ARIA label for the close button onClose renders. The button is drawn as an icon, so its name is all a screen reader says about it: give it one in the page's language. An empty one falls back to the default. An aria-label on Message names the <article>, not the button.
childrenReact.ReactNode—Body content for the message, wrapped in a .message-body. Children that include a Message.Header or Message.Body aren't wrapped: they render as the article's own children, after the header title and onClose make.
...All standard HTML attributes and Bulma helper props—See Helper Props

Subcomponents:

  • Message.Header: Message header compound component. Renders a .message-header element.
  • Message.Body: Message body compound component. Renders a .message-body element.

Message.Header​

PropTypeDefaultDescription
classNamestring—Additional CSS classes.
childrenReact.ReactNode—Header content (title, close button, etc.).
...All standard <div> attributes—

Message.Body​

PropTypeDefaultDescription
classNamestring—Additional CSS classes.
childrenReact.ReactNode—Message body content.
...All standard <div> attributes—

Compound component props​

The Message component also supports a compound component API for maximum flexibility. This allows you to compose messages with fine-grained control over each section.

Message.Header​

Renders the message header section with proper styling.

Props:

  • className?: Additional CSS classes
  • All standard HTML attributes for <div>

Message.Body​

Renders the message body section.

Props:

  • className?: Additional CSS classes
  • All standard HTML attributes for <div>

CSS & Sass Variables​

Message registers these variables on its own .message element. Override them there (or via className) — a value set on an ancestor is only inherited, and loses to the component-level declaration. See Theme.

CSS VariableSass VariableDefault
--bulma-message-border-l-delta$message-border-l-delta-20%
--bulma-message-radius$message-radiusvar(--bulma-radius)
--bulma-message-header-weight$message-header-weightvar(--bulma-weight-semibold)
--bulma-message-header-padding$message-header-padding1em 1.25em
--bulma-message-header-radius$message-header-radiusvar(--bulma-radius)
--bulma-message-body-border-width$message-body-border-width0 0 0 4px
--bulma-message-body-color$message-body-colorvar(--bulma-text)
--bulma-message-body-padding$message-body-padding1.25em 1.5em
--bulma-message-body-radius$message-body-radiusvar(--bulma-radius-small)
--bulma-message-body-pre-code-background-color$message-body-pre-code-background-colortransparent
--bulma-message-header-body-border-width$message-header-body-border-width0
--bulma-message-h$message-hvar(--bulma-scheme-h)
--bulma-message-s$message-svar(--bulma-scheme-s)
--bulma-message-background-l$message-background-lvar(--bulma-background-l)
--bulma-message-border-l$message-border-lvar(--bulma-border-l)
--bulma-message-border-style$message-border-stylesolid
--bulma-message-border-width$message-border-width0.25em
--bulma-message-color-l$message-color-lvar(--bulma-text-l)
--bulma-message-header-background-l$message-header-background-lvar(--bulma-dark-l)
--bulma-message-header-color-l$message-header-color-lvar(--bulma-text-dark-invert-l)