fix(SW-1446): optionally render empty state

This commit is contained in:
Michael Zetterberg
2025-04-08 04:31:58 +02:00
parent 2953b3571d
commit fd0d4ca174
5 changed files with 35 additions and 5 deletions

View File

@@ -116,6 +116,7 @@ export function ClientInline({
aria-label={intl.formatMessage({ id: "Results" })} aria-label={intl.formatMessage({ id: "Results" })}
results={results} results={results}
onAction={onAction} onAction={onAction}
renderEmptyState={true}
/> />
) : null} ) : null}
{showHistory ? ( {showHistory ? (

View File

@@ -37,7 +37,7 @@ export function ClientModal({
const [isPending, startTransition] = useTransition() const [isPending, startTransition] = useTransition()
const showResults = !!results const showResults = !!results
const showHistory = !results || results.length === 0 const showHistory = latest.length > 0 && (!results || results.length === 0)
return ( return (
<DialogTrigger> <DialogTrigger>
@@ -135,6 +135,7 @@ export function ClientModal({
aria-label={intl.formatMessage({ id: "Results" })} aria-label={intl.formatMessage({ id: "Results" })}
results={results} results={results}
onAction={onAction} onAction={onAction}
renderEmptyState={true}
/> />
) : null} ) : null}
{showHistory ? ( {showHistory ? (

View File

@@ -23,6 +23,7 @@ export function Results({
"aria-label": ariaLabel, "aria-label": ariaLabel,
results, results,
onAction, onAction,
renderEmptyState = false,
}: ResultsProps) { }: ResultsProps) {
const intl = useIntl() const intl = useIntl()
@@ -40,6 +41,25 @@ export function Results({
className={styles.menu} className={styles.menu}
items={results} items={results}
renderEmptyState={() => { renderEmptyState={() => {
if (renderEmptyState) {
return (
<>
<Typography variant="Body/Paragraph/mdBold">
<Header className={styles.noResultsLabel}>
{intl.formatMessage({ id: "No results" })}
</Header>
</Typography>
<Typography variant="Body/Paragraph/mdRegular">
<span className={styles.noResultsDescription}>
{intl.formatMessage({
id: "We couldn't find a matching location for your search.",
})}
</span>
</Typography>
</>
)
}
return null return null
}} }}
> >

View File

@@ -1,6 +1,17 @@
.menu { .menu {
height: 100%; height: 100%;
overflow-y: auto; overflow-y: auto;
&[data-empty] {
height: initial;
overflow-y: initial;
padding-left: var(--Space-x1);
}
}
.menu ~ .menu {
padding-top: var(--Space-x2);
border-top: solid 1px var(--Border-Divider-Subtle);
} }
.sectionHeader { .sectionHeader {
@@ -40,10 +51,6 @@
color: var(--UI-Text-Placeholder); color: var(--UI-Text-Placeholder);
} }
.noResults {
padding-left: var(--Space-x1);
}
.noResultsLabel { .noResultsLabel {
color: var(--Text-Default); color: var(--Text-Default);
} }

View File

@@ -3,4 +3,5 @@ import type { ClientProps } from "./client"
export type ResultsProps = Pick<ClientProps, "onAction"> & { export type ResultsProps = Pick<ClientProps, "onAction"> & {
results: NonNullable<ClientProps["results"]> results: NonNullable<ClientProps["results"]>
"aria-label": string "aria-label": string
renderEmptyState?: boolean
} }