| 1 |
import React from 'react' |
| 2 |
import { __ } from '@wordpress/i18n' |
| 3 |
import { Notice } from './Notice' |
| 4 |
import type { ReactNode } from 'react' |
| 5 |
|
| 6 |
export interface LoadingStatusNoticesProps { |
| 7 |
isLoading: boolean |
| 8 |
errorMessage: string | undefined |
| 9 |
loadingNotice: ReactNode |
| 10 |
noticeLabel: string |
| 11 |
} |
| 12 |
|
| 13 |
export const LoadingStatusNotices: React.FC<LoadingStatusNoticesProps> = ({ |
| 14 |
isLoading, |
| 15 |
errorMessage, |
| 16 |
loadingNotice, |
| 17 |
noticeLabel |
| 18 |
}) => { |
| 19 |
switch (true) { |
| 20 |
case isLoading: |
| 21 |
return ( |
| 22 |
<Notice aria-label={noticeLabel} className="inline"> |
| 23 |
<p>{loadingNotice}</p> |
| 24 |
</Notice> |
| 25 |
) |
| 26 |
|
| 27 |
case errorMessage !== undefined: |
| 28 |
return ( |
| 29 |
<Notice aria-label={noticeLabel} className="inline" type="error"> |
| 30 |
<p>{errorMessage}</p> |
| 31 |
</Notice> |
| 32 |
) |
| 33 |
|
| 34 |
default: |
| 35 |
return ( |
| 36 |
<Notice aria-label={noticeLabel} className="inline" type="warning"> |
| 37 |
<p>{__('An unknown error occurred. Please try again.', 'code-snippets')}</p> |
| 38 |
</Notice> |
| 39 |
) |
| 40 |
} |
| 41 |
} |
| 42 |
|