Theme

PlaygroundBeta

npm_versionnpm Paragon package page

StatefulButton

The stateful button is a button used to display an actionable icon.

Basic usage

Any Paragon component or export may be added to the code example.

() => {
const props = {
labels: {
default: 'Save',
pending: 'Saving',
complete: 'Saved',
error: 'Error'
},
variant: 'primary',
};
return (
<Stack direction="horizontal" gap={2}>
<StatefulButton {...props} />
<StatefulButton state="pending" {...props} />
<StatefulButton state="complete" {...props} />
<StatefulButton state="error" {...props} />
</Stack>
);
};

Custom icons and disabled states

Any Paragon component or export may be added to the code example.

() => {
const downloadButtonProps = {
labels: {
default: 'Download',
pending: 'Downloading',
complete: 'Downloaded',
},
icons: {
default: <Icon src={Download} />,
pending: <Icon src={SpinnerSimple} className="icon-spin" />,
complete: <Icon src={Check} />,
},
disabledStates: ['pending', 'complete'],
variant: 'primary',
};
return (
<Stack direction="horizontal" gap={2}>
<StatefulButton state="default" {...downloadButtonProps} />
<StatefulButton state="pending" {...downloadButtonProps} />
<StatefulButton state="complete" {...downloadButtonProps} />
</Stack>
);
};

Custom states with Paragon icons

Any Paragon component or export may be added to the code example.

() => {
const buttonProps = {
labels: {
unedited: 'Save (no changes)',
edited: 'Save Changes',
},
icons: {
unedited: <Icon src={Add} />,
edited: <Icon src={Add} />,
},
disabledStates: ['unedited'],
variant: 'primary',
};
return (
<Stack direction="horizontal" gap={2}>
<StatefulButton state="unedited" {...buttonProps} />
<StatefulButton state="edited" {...buttonProps} />
</Stack>
);
};

Props API#

StatefulButton Props API
  • className string
  • state string

    Each state has:

    • A label (required)
    • An icon
    • an option to be disabled

    Control the state with the state prop. Example usage:

    <StatefulButton
      state="pending"
      labels={{
        default: 'Download',
        pending: 'Downloading',
        complete: 'Downloaded',
      }}
      icons={{
        default: <Icon className="fa fa-download" />,
        pending: <Icon className="fa fa-spinner fa-spin" />,
        complete: <Icon className="fa fa-check" />,
      }}
      disabledStates=['pending']
      className='btn-primary mr-2'
    />
    
    Default'default'
  • labels Object.<node> Required

    Required. Each state has a label.

  • icons Object.<node>

    Required. Each state has an icon.

    Default{ default: undefined, pending: <Icon src={SpinnerSimple} className={classNames('icon-spin')} />, complete: <Icon src={CheckCircleOutline} />, error: <Icon src={Cancel} />, }
  • disabledStates string[]

    Required. Each state has a disabledState

    Default['pending', 'complete']
  • onClick func

    Specifies the callback function when the button is clicked

Usage Insights#

StatefulButton

Project NameParagon VersionInstance Count
frontend-app-account20.36.08
frontend-app-admin-portal20.26.315
frontend-app-authn20.36.27
frontend-app-communications20.30.11
frontend-app-course-authoring20.32.03
frontend-app-discussions20.15.02
frontend-app-ecommerce20.35.01
frontend-app-gradebook19.25.41
frontend-app-learner-dashboard20.32.01
frontend-app-learner-portal-enterprise20.36.07
frontend-app-learner-portal-programs20.28.41
frontend-app-learner-record20.32.01
frontend-app-learning20.28.41
frontend-app-library-authoring20.30.14
frontend-app-ora-grading20.30.02
frontend-app-payment20.30.13
frontend-app-profile20.32.01
frontend-app-publisher20.28.51
frontend-app-support-tools20.26.01
frontend-learner-portal-base12.2.02
frontend-lib-special-exams20.22.41