-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dropdown): add error and empty state template in dropdown component
- Loading branch information
1 parent
0b637f9
commit 3f84aa6
Showing
7 changed files
with
316 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react'; | ||
import { Text, Button } from '@/index'; | ||
import { ErrorType } from './Dropdown'; | ||
|
||
interface ErrorTemplateProps { | ||
dropdownStyle: React.CSSProperties; | ||
errorType: ErrorType; | ||
updateOptions: () => void; | ||
} | ||
|
||
const errorTitle: Record<string, string> = { | ||
FAILED_TO_FETCH: 'Failed to fetch data', | ||
NO_RECORDS_FOUND: 'No results found', | ||
DEFAULT: 'No record available', | ||
}; | ||
|
||
const errorDescription: Record<string, string> = { | ||
FAILED_TO_FETCH: "We couldn't load the data, try reloading.", | ||
NO_RECORDS_FOUND: 'Try modifying your search to find what you are looking for.', | ||
DEFAULT: 'We have nothing to show you at the moment.', | ||
}; | ||
|
||
export const ErrorTemplate: React.FC<ErrorTemplateProps> = ({ dropdownStyle, errorType, updateOptions }) => { | ||
return ( | ||
<div className="Dropdown-wrapper px-7 d-flex" style={dropdownStyle} data-test="DesignSystem-Dropdown--wrapper"> | ||
<div | ||
className="d-flex flex-column justify-content-center align-items-center" | ||
data-test="DesignSystem-Dropdown--errorWrapper" | ||
> | ||
<Text className="mb-3" weight="strong"> | ||
{errorTitle[errorType]} | ||
</Text> | ||
<Text className="text-align-center mb-6" weight="medium" size="small" appearance="subtle"> | ||
{errorDescription[errorType]} | ||
</Text> | ||
{errorType === 'FAILED_TO_FETCH' && ( | ||
<Button | ||
size="tiny" | ||
largeIcon={true} | ||
aria-label="reload" | ||
icon="refresh" | ||
iconAlign="left" | ||
onClick={() => updateOptions()} | ||
> | ||
Reload | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.