PlainButton is an unstyled wrapper component that creates a button element with minimal styling. It's used internally by Pluma to build other button components.

Usage

You probably won't need to use this component much. This is used in Pluma internally to build other button components.

When an href prop is provided, PlainButton automatically renders as a link instead of a button element.

You can import the component via:

import { PlainButton } from '@customerio/pluma-components/react';
<PlainButton
  onClick={() => alert('Button clicked!')}
>
Click me
</PlainButton>
<PlainButton
  onClick={() => alert('Button clicked!')}
  isDisabled={true}
>
Disabled button
</PlainButton>

When you provide an href prop, PlainButton automatically renders as a link:

<PlainButton
  href="https://example.com"
  onClick={() => alert('Link clicked!')}
>
Link button
</PlainButton>
<PlainButton
  href="https://external.com"
  isExternal={true}
  onClick={() => alert('External link clicked!')}
>
External link
</PlainButton>

Loading functionality

PlainButton supports loading states and automatic loading detection when onClick returns a promise:

<PlainButton
  isLoading={true}
  onClick={() => alert('This won't fire while loading')}
>
Loading state
</PlainButton>
<PlainButton
  onClick={() => new Promise(resolve => setTimeout(resolve, 2000))}
  autoLoading={true}
>
Auto loading (click me)
</PlainButton>

When loading, PlainButton applies the plainButtonIsLoading CSS class and disables interactions. You can style this class to show loading indicators as needed.

State access

PlainButton yields an object with the following properties:

  • isLoading - a boolean indicating whether the button is in a loading state
  • isDisabled - a boolean indicating whether the button is disabled
<PlainButton
  isLoading={true}
  onClick={() => alert('Button clicked!')}
>
  {({ isLoading, isDisabled }) => (
    <div>
      {isLoading ? 'Loading...' : 'Click me'}
      {isDisabled && ' (disabled)'}
    </div>
  )}
</PlainButton>

API

If true, the button will automatically show the spinner when the onClick function is called and it returns a promise. If false, the spinner will only show if the isLoading prop is set to true. By default, this is true.

The URL passed into the link component (or a tag)

Disables the button. Use this instead of the native disabled prop, to make sure non-button elements (when used with as) get the correct styles

When this flag is true, an a tag will be used instead of the provider's linkComponent, even if it exists. Additionally, target="_blank" rel="noopener noreferrer" will be added automatically

Shows a spinner in the button overlaid on top of the button's content. The button will act as if disabled while in the loading state.

The function to call when the button is clicked

This is passed into the provider's linkComponent. It can be used by the link component implementation to handle replaceState instead of pushState

This allows turning off the automatic addition of target="_blank" rel="noopener noreferrer". This can be used for links to other protocols like mailto: