Button
Overview
The Button
component provides a flexible and highly customizable button for your Bulma React UI. It supports all Bulma color, size, and state modifiers, as well as additional helper classes for text color, spacing, and more. It can render as either a <button>
or an <a>
element, and is designed to be fully accessible and composable.
tip
Make sure to provide meaningful text or accessible content for screen readers.
Import
import { Button } from '@allxsmith/bestax-bulma';
Props
Prop | Type | Default | Description |
---|---|---|---|
color | 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | — | Bulma color modifier for the button. |
size | 'small' | 'normal' | 'medium' | 'large' | — | Button size. |
isLight | boolean | false | Use the light version of the color. |
isRounded | boolean | false | Button is fully rounded. |
isLoading | boolean | false | Shows a loading spinner. |
isStatic | boolean | false | Non-interactive static button. |
isFullWidth | boolean | false | Button fills the width of its parent. |
isOutlined | boolean | false | Outlined button style. |
isInverted | boolean | false | Inverted color style. |
isFocused | boolean | false | Styled as focused. |
isActive | boolean | false | Styled as active. |
isHovered | boolean | false | Styled as hovered. |
isDisabled | boolean | false | Disabled state. (also applies aria-disabled and disables pointer events) |
as | 'button' | 'a' | 'button' | Render as a <button> or <a> element. |
href | string | — | If as="a" , the href for the anchor link. |
onClick | function | — | Click event handler. |
target | string | — | Target for anchor element. |
rel | string | — | Rel for anchor element. |
textColor | 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'black-bis' | 'black-ter' | 'grey-darker' | 'grey-dark' | 'grey' | 'grey-light' | 'grey-lighter' | 'white' | 'light' | 'dark' | 'inherit' | 'current' | — | Text color helper (e.g., 'danger' for has-text-danger ). |
bgColor | 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger' | 'black' | 'black-bis' | 'black-ter' | 'grey-darker' | 'grey-dark' | 'grey' | 'grey-light' | 'grey-lighter' | 'white' | 'light' | 'dark' | 'inherit' | 'current' | — | Background color helper (e.g., 'info' for has-background-info ). |
className | string | — | Additional CSS classes. |
children | React.ReactNode | — | Button content. |
... | All standard <button> and Bulma helper props | (See Helper Props) |
Usage
Default Button
<Button>Default Button</Button>
All Colors
import { Buttons } from './Buttons';
<Buttons>
{['primary', 'link', 'info', 'success', 'warning', 'danger'].map(color => (
<Button key={color} color={color}>
{color.charAt(0).toUpperCase() + color.slice(1)}
</Button>
))}
</Buttons>;
All Sizes
<Buttons>
{['small', 'normal', 'medium', 'large'].map(size => (
<Button key={size} size={size}>
{size.charAt(0).toUpperCase() + size.slice(1)}
</Button>
))}
</Buttons>
Light Variant
<Button color="primary" isLight>
Light Primary Button
</Button>
Rounded
<Button color="info" isRounded>
Rounded Button
</Button>
Loading
<Button color="success" isLoading>
Loading Button
</Button>
Static
<Button isStatic>Static Button</Button>
Full Width
<Button color="warning" isFullWidth>
Full Width Button
</Button>
Outlined
<Button color="danger" isOutlined>
Outlined Button
</Button>
Inverted
<Button color="link" isInverted>
Inverted Button
</Button>
Focused
<Button color="primary" isFocused>
Focused Button
</Button>
Active
<Button color="info" isActive>
Active Button
</Button>
Hovered
<Button color="success" isHovered>
Hovered Button
</Button>
Disabled
<Button color="warning" isDisabled disabled>
Disabled Button
</Button>
Custom Text and Background Color
<Button textColor="danger" bgColor="info">
Custom Text & Background
</Button>
Spacing Helpers
<Button m="2" p="3" mx="4" my="5" mt="1" mr="2" mb="3" ml="4">
Button with Spacing
</Button>
Text Alignment
<Button textAlign="centered">Centered Text Button</Button>
Responsive Viewport
<Button viewport="mobile">Mobile Responsive Button</Button>
Flexbox Layout
<Button display="flex" justifyContent="center" alignItems="center">
Flex Button
</Button>
Button Group
<Buttons hasAddons>
<Button color="primary">Left</Button>
<Button color="primary">Center</Button>
<Button color="primary">Right</Button>
</Buttons>
With HTML Attributes
<Button type="submit" className="custom-class">
Submit Button
</Button>
Accessibility
- Labeling: Always provide descriptive content for buttons for screen readers.
- States: The
isDisabled
anddisabled
props ensure correctaria-disabled
anddisabled
attributes. - Keyboard: When rendered as
<a>
, disabled buttons are not focusable. - Focus: Use
isFocused
andisActive
for visual feedback, but rely on browser focus for actual accessibility.
note
If your button has only an icon, use aria-label
to provide accessible text.
Related Components
Buttons
: Group multiple buttons together, including add-ons and alignment.Icon
: Inline icons for use inside buttons.- Helper Props: List of all supported Bulma helper props for spacing, colors, etc.
Additional Resources
Pro Tip
You can use all Bulma helper props with <Button />
for powerful utility-based styling.