StatefulButton
The stateful button is a button used to display an actionable icon.
Basic usage
Show editable code example
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
Show editable code example
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
Show editable code example
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
Default'default'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' />
- labels
Object.<
Requirednode
>Required. Each state has a
label
. - icons
Object.<
node
>Default{ default: undefined, pending: <Icon src={SpinnerSimple} className={classNames('icon-spin')} />, complete: <Icon src={CheckCircleOutline} />, error: <Icon src={Cancel} />, }Required. Each state has an
icon
. - disabledStates
string
[]
Default['pending', 'complete']Required. Each state has a
disabledState
- onClick
func
Specifies the callback function when the button is clicked
Usage Insights#
StatefulButton
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-account | 20.36.0 | 8 | |
frontend-app-admin-portal | 20.26.3 | 15 | |
frontend-app-authn | 20.36.2 | 7 | |
frontend-app-communications | 20.30.1 | 1 | |
frontend-app-course-authoring | 20.32.0 | 3 | |
frontend-app-discussions | 20.15.0 | 2 | |
frontend-app-ecommerce | 20.35.0 | 1 | |
frontend-app-gradebook | 19.25.4 | 1 | |
frontend-app-learner-dashboard | 20.32.0 | 1 | |
frontend-app-learner-portal-enterprise | 20.36.0 | 7 | |
frontend-app-learner-portal-programs | 20.28.4 | 1 | |
frontend-app-learner-record | 20.32.0 | 1 | |
frontend-app-learning | 20.28.4 | 1 | |
frontend-app-library-authoring | 20.30.1 | 4 | |
frontend-app-ora-grading | 20.30.0 | 2 | |
frontend-app-payment | 20.30.1 | 3 | |
frontend-app-profile | 20.32.0 | 1 | |
frontend-app-publisher | 20.28.5 | 1 | |
frontend-app-support-tools | 20.26.0 | 1 | |
frontend-learner-portal-base | 12.2.0 | 2 | |
frontend-lib-special-exams | 20.22.4 | 1 |