Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Web

Button

The Swiss Army knife of buttons, the Button component displays a button or a component that looks like a button. It supports various styles, sizes, and functionality such as icons, loading states, and navigation.

Usage

import { Button } from 'components/lib';

function MyComponent({ ...props }){

  return (
    <Button 
      text='Click Me' 
      color='blue' 
      action={ () => alert('You clicked me') }
    />
  );
}

Props

PropDescriptionRequiredValue
actioncallback functionrequired if no url prop function
asChildrender as a slotoptionalboolean
childenbutton label or child componentoptionalstring or component
classNamecustom stylingoptionalSCSS or Tailwind
colorbutton coloroptionalstring (red/orange/blue/green) default: black
iconIcon nameoptionalstring
iconColoricon outline coloroptionalstring (light/dark/green/blue/orange/red) or hex string
iconFillicon fill coloroptionalhex string
iconSizeicon size optionalinteger, default: 16
loadingtoggle loading spinneroptionalboolean
paramsobject passed to the callback functionoptionalobject
sizeSize of the buttonoptionalstring (xs/sm/lg/icon/full)
textbutton labelrequiredstring
typebutton type eg. submitoptionalstring
urlnavigate to an internal or external URLoptionalstring
variantbutton variantoptionalstring (destructive/ghost/icon/link/naked/outline/rounded/secondary)

Example

import { Button } from 'components/lib';

function Example({ ...props }){
  return (
    <div>
      <Button 
        text='Primary Button'
        color='blue'
        action={() => alert('Primary Button clicked!')}
      />
      <Button 
        text='Secondary Button'
        variant='secondary'
        action={() => alert('Secondary Button clicked!')}
      />
      <Button 
        icon='search'
        size='icon'
        action={() => alert('Icon Button clicked!')}
      />
    </div>
  );
}

Notes

  • The Button component uses the Icon and useNavigate from 'components/lib' and Slot from @radix-ui/react-slot.
  • The variant prop determines the styling of the button.
  • Custom styles can be applied using the className prop.
  • The color prop sets the color of the button, defaulting to ‘black’.
  • The action prop is a callback function that gets called when the button is clicked.
  • The loading prop toggles a loading animation on the button.
  • The url prop navigates to a specified URL when provided.
  • For more details, refer to the Shadcn Button documentation.