Button
Usage
Variants
Button supports the following variants: default, subtle, white, gradient, filled, light and outline:
Default Button color is theme.primaryColor
, to change color and variant pass color
and variant
props:
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, either right or leftloaderProps
– props spread to Loader component, you can choose loader type, size and any other supported prop
Customize
You can change styles of any element in button component with Styles API to match your design requirements:
Size and radius
Control button font-size, height and padding with size
and border-radius with radius
props.
Both props have predefined values: xs, sm, md, lg, xl.
Alternatively, you can use a number to set radius in px:
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:
Change root element
You can use Button component both as button
and a
elements:
Usage with react-router and other libraries
You can use Button component with react-router-dom
or other similar libraries by passing Link
as component to Button:
Provide type to use custom element with TypeScript:
Get button ref
Unstyled button
To create custom buttons not related to Button component, use UnstyledButton component, it renders regular button without default browser styles and with Mantine focus styles: