Usage
Variants
Gradient variant
To use gradient as Button background:
- set
variant
togradient
- set
gradient
to{ from: 'color-from', to: 'color-to', deg: 135 }
, wherecolor-from
andcolor-to
are color fromtheme.colors
deg
is linear gradient deg
White variant
White is a variant in which button background color is always white (both in light and dark theme) and color is controlled with color
prop:
Loading state
Button supports loading state. In this state Loader component replaces left or right icon, button becomes disabled and white or dark overlay is added.
You can control loading state and Loader component with following props:
loading
– enable loading stateloaderPosition
– Loader position relative to button label, left, right or centerloaderProps
– props spread to Loader component, you can choose loader type, size and any other supported prop
Styles API
Compact
Full width and overflow
Button can take full width of container if you set fullWidth
prop.
If button is too large for its container, overflow content will be hidden:
Button.Group
Note that you cannot wrap child Button
components with any additional elements:
If you want to use Tooltip, Popover or other overlay component,
it is required to set withinPortal
prop:
data- attributes
Button has the following attributes on the root element:
data-disabled
whendisabled
prop istrue
data-loading
whenloading
prop istrue
You can customize disabled and loading styles with these attributes:
Disabled button with tooltip
Disabled buttons do not trigger onMouseLeave
(react issue).
If you need to display tooltip for disabled button, do not use disabled
prop, instead set data-disabled
attribute:
Polymorphic component
Button is a polymorphic component, you can change root element:
Get ref
Button component props
Name | Type | Description |
---|---|---|
children | ReactNode | Button label |
color | MantineColor | Button color from theme |
compact | boolean | Reduces vertical and horizontal spacing |
disabled | boolean | Disabled state |
fullWidth | boolean | Sets button width to 100% of parent element |
gradient | MantineGradient | Controls gradient settings in gradient variant only |
leftIcon | ReactNode | Adds icon before button label |
loaderPosition | "left" | "right" | "center" | Loader position relative to button label |
loaderProps | LoaderProps | Props spread to Loader component |
loading | boolean | Indicate loading state |
radius | number | "xs" | "sm" | "md" | "lg" | "xl" | Button border-radius from theme or number to set border-radius in px |
rightIcon | ReactNode | Adds icon after button label |
size | "xs" | "sm" | "md" | "lg" | "xl" | Predefined button size |
type | "button" | "reset" | "submit" | Button type attribute |
uppercase | boolean | Set text-transform to uppercase |
variant | "outline" | "white" | "light" | "default" | "filled" | "subtle" | "gradient" | Controls button appearance |
Button.Group component props
Name | Type | Description |
---|---|---|
buttonBorderWidth | number | Child <Button /> border width in px |
children | ReactNode | <Button /> components |
orientation | "horizontal" | "vertical" | Switch between vertical and horizontal orientation |
Button component Styles API
Name | Static selector | Description |
---|---|---|
root | .mantine-Button-root | Root button element |
icon | .mantine-Button-icon | Shared icon styles |
leftIcon | .mantine-Button-leftIcon | Left icon |
rightIcon | .mantine-Button-rightIcon | Right icon |
centerLoader | .mantine-Button-centerLoader | Center loader |
inner | .mantine-Button-inner | Contains label, left and right icons |
label | .mantine-Button-label | Contains button children |