| 1 |
import { useState } from 'react'; |
| 2 |
import { Form, FormGroup, ActionGroup, TextInput, Button } from '@patternfly/react-core'; |
| 3 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 4 |
|
| 5 |
export const ButtonProgress: React.FunctionComponent = () => { |
| 6 |
const [loginState, setLoginState] = useState<'notLoggedIn' | 'loading' | 'loggedIn'>('notLoggedIn'); |
| 7 |
|
| 8 |
return ( |
| 9 |
<Form> |
| 10 |
<FormGroup label="Username" isRequired fieldId="progress-button-initial-login"> |
| 11 |
<TextInput |
| 12 |
isRequired |
| 13 |
type="text" |
| 14 |
id="progress-button-initial-login" |
| 15 |
name="progress-button-initial-login" |
| 16 |
value="johndoe" |
| 17 |
aria-label="username input" |
| 18 |
/> |
| 19 |
</FormGroup> |
| 20 |
<FormGroup label="Password" isRequired fieldId="progress-button-initial-password"> |
| 21 |
<TextInput |
| 22 |
isRequired |
| 23 |
type="password" |
| 24 |
value="p@ssw0rd" |
| 25 |
id="progress-button-initial-password" |
| 26 |
name="progress-button-initial-password" |
| 27 |
aria-label="password input" |
| 28 |
/> |
| 29 |
</FormGroup> |
| 30 |
<ActionGroup> |
| 31 |
<Button |
| 32 |
variant="primary" |
| 33 |
onClick={ |
| 34 |
loginState === 'notLoggedIn' |
| 35 |
? () => { |
| 36 |
setLoginState('loading'); |
| 37 |
setTimeout(() => { |
| 38 |
setLoginState('loggedIn'); |
| 39 |
}, 3000); |
| 40 |
} |
| 41 |
: null |
| 42 |
} |
| 43 |
isLoading={loginState === 'loading'} |
| 44 |
icon={loginState === 'loggedIn' ? <RhUiCheckCircleFillIcon /> : null} |
| 45 |
spinnerAriaValueText="Loading..." |
| 46 |
> |
| 47 |
{loginState === 'notLoggedIn' && 'Link account and log in'} |
| 48 |
{loginState === 'loading' && 'Linking account'} |
| 49 |
{loginState === 'loggedIn' && 'Logged in'} |
| 50 |
</Button> |
| 51 |
</ActionGroup> |
| 52 |
</Form> |
| 53 |
); |
| 54 |
}; |