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" })}
results={results}
onAction={onAction}
renderEmptyState={true}
/>
) : null}
{showHistory ? (

View File

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

View File

@@ -23,6 +23,7 @@ export function Results({
"aria-label": ariaLabel,
results,
onAction,
renderEmptyState = false,
}: ResultsProps) {
const intl = useIntl()
@@ -40,6 +41,25 @@ export function Results({
className={styles.menu}
items={results}
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
}}
>

View File

@@ -1,6 +1,17 @@
.menu {
height: 100%;
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 {
@@ -40,10 +51,6 @@
color: var(--UI-Text-Placeholder);
}
.noResults {
padding-left: var(--Space-x1);
}
.noResultsLabel {
color: var(--Text-Default);
}

View File

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