-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(EmptyDetailsView): add component #65
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
# Sidenav top-level section | ||
# should be the same for all markdown files | ||
section: AI-infra-ui-components | ||
# Sidenav secondary level section | ||
# should be the same for all markdown files | ||
id: EmptyDetailsView | ||
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) | ||
source: react | ||
# If you use typescript, the name of the interface to display props for | ||
# These are found through the sourceProps function provided in patternfly-docs.source.js | ||
propComponents: ['EmptyDetailsView'] | ||
--- | ||
|
||
import { EmptyDetailsView } from "@patternfly/ai-infra-ui-components"; | ||
import clusterImage from './empty-state-cluster-storage.svg' | ||
|
||
Note: this component documents the API and enhances the [existing EmptyDetailsView](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/EmptyDetailsView.tsx) component from odh-dashboard. It can be imported from [@patternfly/ai-infra-ui-components](https://www.npmjs.com/package/@patternfly/AI-infra-ui-components). Alternatively, it can be used within the odh-dashboard via the import: `~/components/EmptyDetailsView` | ||
|
||
### Example | ||
|
||
```js file="./EmptyDetailsViewBasic.tsx" | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { EmptyDetailsView } from '@patternfly/ai-infra-ui-components'; | ||
import { Button } from '@patternfly/react-core'; | ||
import clusterImage from './empty-state-cluster-storage.svg'; | ||
|
||
export const EmptyDetailsViewBasic: React.FunctionComponent = () => ( | ||
<EmptyDetailsView | ||
title="Start by adding cluster storage" | ||
description="Cluster storage saves your project’s data on a selected cluster. You can optionally connect cluster storage to a workbench." | ||
iconImage={clusterImage} | ||
imageSize="240px" | ||
imageAlt="add cluster storage" | ||
createButton={<Button>Add cluster storage</Button>} | ||
/> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react'; | ||
import { | ||
EmptyState, | ||
EmptyStateBody, | ||
EmptyStateActions, | ||
EmptyStateFooter, | ||
EmptyStateProps | ||
} from '@patternfly/react-core'; | ||
|
||
export interface EmptyDetailsViewProps extends Omit<EmptyStateProps, 'children' | 'titleText'> { | ||
/** Empty state title text. */ | ||
title?: string; | ||
/** Empty state description - will be rendered inside EmptyStateBody. */ | ||
description?: React.ReactNode; | ||
/** Source path to an icon image. */ | ||
iconImage?: string; | ||
/** Alternative text for icon image if image can't load. */ | ||
imageAlt?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need alt text for this image? This image is purely decorative and doesn't provide any additional meaning to the user that isn't already provided with the contents on the page. |
||
/** Height of an icon image. */ | ||
imageSize?: string; | ||
/** Flag indicating that creation is allowed. */ | ||
allowCreate?: boolean; | ||
/** Button which initiates the creation. */ | ||
createButton?: React.ReactNode; | ||
/** Extra children to render inside EmptyStateFooter. */ | ||
footerExtraChildren?: React.ReactNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example provided in the preview shows an empty state with just a single primary action, but it would be good to have an example that shows a secondary action, too. |
||
} | ||
|
||
export const EmptyDetailsView: React.FunctionComponent<EmptyDetailsViewProps> = ({ | ||
title, | ||
description, | ||
iconImage, | ||
imageAlt, | ||
allowCreate = true, | ||
createButton, | ||
footerExtraChildren = null, | ||
imageSize = '320px', | ||
...props | ||
}: EmptyDetailsViewProps) => ( | ||
<EmptyState | ||
headingLevel="h3" | ||
titleText={title} | ||
variant="lg" | ||
icon={iconImage ? () => <img style={{ height: imageSize }} src={iconImage} alt={imageAlt} /> : undefined} | ||
{...props} | ||
> | ||
<EmptyStateBody>{description}</EmptyStateBody> | ||
{allowCreate && createButton ? ( | ||
<EmptyStateFooter> | ||
<EmptyStateActions>{createButton}</EmptyStateActions> | ||
{footerExtraChildren} | ||
</EmptyStateFooter> | ||
) : null} | ||
</EmptyState> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './EmptyDetailsView'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export * from './BulkActionExpandableSection'; | ||
export * from './DeleteModal'; | ||
export * from './EmptyDetailsView'; | ||
export * from './EmptyStateErrorMessage'; | ||
export * from './FieldGroupHelpLabelIcon'; | ||
export * from './IndentSection'; | ||
export * from './K8sNameDescriptionField'; | ||
export * from './TruncatedText'; | ||
export * from './EmptyStateErrorMessage'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change
240px
to320px
Also, this size is different than the size shown in /EmptyDetailsView/EmptyDetailsView.tsx below, which is using 320px.
We have new guidelines for empty states that recommend using 320px for illustrations. It would be ideal if our examples in the preview use the values we are recommending.