Documentation
Components
Button

Button

The Button component allows users to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.

Usage

Basic usage

import { Button } from '@snipshot/particles';

export default function ButtonDefault() {
  return <Button>Confirm</Button>;
}

Variants

The Button component comes with five different variants: filled, outlined, text, soft, and elevated.

Colors

You can choose from one of the predefined color options by passing a color props value: primary, secondary, tertiary, info, success, warning, error.
If you need an unstyled button, pass the uncolored value.

Radiuses

You can customize the border radius by providing a radius prop value.

Sizes

To make a button smaller or larger use the size props with the following values: xs, sm, md, lg, xl.

You can also use a dense property to reduce paddings:

Icons

You can add icons to the Button component using leftIcon and rightIcon props.

Disabled state

The component supports accessible disabled state with the disabled prop.

Loading state

The Button component supports a loading state with a loading spinner (or a custom loading element) and optional loading text using isLoading, loadingText, and loadingElement props.

Polymorphic component

The Button is a polymorphic component, which means that you can use the as prop to specify any valid HTML element as a string or a React component. This chosen element will serve as the base for rendering the Button component, replacing the default <button> element.

Accessibility

The Button component follows WAI-ARIA (opens in a new tab) best practices to ensure accessibility for all users. It includes semantic <button> element and appropriate ARIA attributes to enhance compatibility with screen readers and assistive technologies.

API Reference

PropTypeDefaultDescription
asReact.ElementType'button'HTML or React element that will be rendered by the component
color'primary' | 'secondary' | 'tertiary' |'success' | 'info' | 'warning' | 'error''primary'Buttons's color scheme
densebooleanfalseShrinks the button reducing paddings
disabledbooleanfalseButton's disabled state
isLoadingbooleanfalseApplies loading state styling and behaviour
loadingElementReact.ReactElementundefinedElement that will be displayed in the loading state instead of a default spinner
loadingTextstring''Button's content that will be displayed in loading state
loadingSpinnerbooleantrueDisable a loading spinner in the loading state
leftIconReact.ReactElementundefinedIcon element on the left
radius'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Border radius value
rightIconReact.ReactElementundefinedIcon element on the right
shadowOnPressbooleanfalseAdds inset box-shadow imitating button press. Only for filled variant.
shrinkOnPressbooleanfalseMakes the button a bit smaller on press
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Button's size value
variant'filled' | 'outlined' | 'text' | 'soft' | 'elevated''filled'Styling variant

CSS custom properties

The Button component provides several CSS variables that can be used for styling via CSS modules or using a style attribute of the component.

PropertyDescription
--pui-btn-font-sizefont-size value
--pui-btn-font-weightfont-weight value
--pui-btn-line-heightline-height value
--pui-btn-letter-spacingletter-spacing value
--pui-btn-icon-sizeSize of the .btn-icon and .btn-load-spinner elements
--pui-btn-colorMain button's color. If used, --pui-btn-color-channels has to be provided either
--pui-btn-color-channelsRGB channels of the main color (--pui-btn-color) represented as an rray of three numbers like 255 0 0
--pui-btn-on-colorColor that is used on the main color (e.g. font color).
--pui-btn-color-darkerDarker version of the main (--pui-btn-color) color. In some cases necessary for hover effects. If used, pui-btn-color-darker-channels has to be provided either
--pui-btn-color-darker-channelsRGB channels of the darker main color (--pui-btn-color-darker) represented as an array of three numbers like 255 0 0
--pui-btn-color-container-lowLighter version of the main (--pui-btn-color) color, used for background-color in the soft variant
--pui-btn-on-color-containerColor that is used on the --pui-btn-color-container-low color.