@remit/ui 0.0.168 → 0.0.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { renderToString } from "react-dom/server";
|
|
5
|
+
import {
|
|
6
|
+
ListResultHeader,
|
|
7
|
+
type ListResultHeaderProps,
|
|
8
|
+
} from "./list-result-header.js";
|
|
9
|
+
|
|
10
|
+
const text = (props: ListResultHeaderProps): string =>
|
|
11
|
+
renderToString(createElement(ListResultHeader, props)).replace(
|
|
12
|
+
/<[^>]*>/g,
|
|
13
|
+
"",
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
describe("ListResultHeader", () => {
|
|
17
|
+
it("states the server's total for the whole match set", () => {
|
|
18
|
+
assert.equal(
|
|
19
|
+
text({ query: "invoice", count: { kind: "exact", value: 1284 } }),
|
|
20
|
+
`${(1284).toLocaleString()} results for “invoice”`,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("reads in the singular for one match", () => {
|
|
25
|
+
assert.equal(
|
|
26
|
+
text({ query: "invoice", count: { kind: "exact", value: 1 } }),
|
|
27
|
+
"1 result for “invoice”",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("states a zero rather than dropping the number", () => {
|
|
32
|
+
assert.equal(
|
|
33
|
+
text({ query: "zzzz", count: { kind: "exact", value: 0 } }),
|
|
34
|
+
"0 results for “zzzz”",
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders no number at all when the count is unknown", () => {
|
|
39
|
+
const rendered = text({ query: "invoice", count: { kind: "unknown" } });
|
|
40
|
+
assert.equal(rendered, "Results for “invoice”");
|
|
41
|
+
assert.doesNotMatch(rendered, /\d/);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Decorator, Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { ListResultHeader } from "./list-result-header.js";
|
|
3
|
+
|
|
4
|
+
/** Frames the header at the width of the list pane it sits at the top of. */
|
|
5
|
+
const listPaneFrame: Decorator = (Story) => (
|
|
6
|
+
<div
|
|
7
|
+
className="overflow-hidden rounded-lg border border-line bg-canvas"
|
|
8
|
+
style={{ width: 360 }}
|
|
9
|
+
>
|
|
10
|
+
<Story />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const meta: Meta<typeof ListResultHeader> = {
|
|
15
|
+
title: "Components/ListResultHeader",
|
|
16
|
+
component: ListResultHeader,
|
|
17
|
+
parameters: { layout: "centered" },
|
|
18
|
+
decorators: [listPaneFrame],
|
|
19
|
+
};
|
|
20
|
+
export default meta;
|
|
21
|
+
|
|
22
|
+
type Story = StoryObj<typeof ListResultHeader>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The count the server answered for the whole match set. It is the total, not
|
|
26
|
+
* the length of the pages loaded, so it does not climb as the reader scrolls.
|
|
27
|
+
*/
|
|
28
|
+
export const ExactCount: Story = {
|
|
29
|
+
args: { query: "invoice", count: { kind: "exact", value: 1284 } },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** One match reads in the singular. */
|
|
33
|
+
export const SingleResult: Story = {
|
|
34
|
+
args: {
|
|
35
|
+
query: "quarterly reconciliation",
|
|
36
|
+
count: { kind: "exact", value: 1 },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** A search that matched nothing states the zero rather than dropping to no number. */
|
|
41
|
+
export const NoResults: Story = {
|
|
42
|
+
args: { query: "zzzz", count: { kind: "exact", value: 0 } },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* No number at all: the count was not requested, has not arrived, or the
|
|
47
|
+
* criteria carry an off-row term the server will not count exactly. The header
|
|
48
|
+
* still names what the list is showing — it never substitutes a page length and
|
|
49
|
+
* never falls back to zero.
|
|
50
|
+
*/
|
|
51
|
+
export const CountUnknown: Story = {
|
|
52
|
+
args: { query: "invoice", count: { kind: "unknown" } },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** A long query keeps the number readable rather than pushing it off the line. */
|
|
56
|
+
export const LongQuery: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
query:
|
|
59
|
+
"consolidated quarterly reconciliation of the shared drive migration",
|
|
60
|
+
count: { kind: "exact", value: 42 },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Search } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How many rows match a search, as the server answered it.
|
|
5
|
+
*
|
|
6
|
+
* `exact` is the whole match set — the number does not move as the reader pages.
|
|
7
|
+
* `unknown` is every other case: the count was not requested, has not arrived,
|
|
8
|
+
* or the criteria carry an off-row term the server will not count exactly
|
|
9
|
+
* (`senderTrust`, `dkimMismatch`). It renders as no number at all.
|
|
10
|
+
*
|
|
11
|
+
* A union rather than an optional number, so a page length cannot be handed to
|
|
12
|
+
* this component by accident: there is no shape here that accepts one.
|
|
13
|
+
*/
|
|
14
|
+
export type ResultCount =
|
|
15
|
+
| { kind: "exact"; value: number }
|
|
16
|
+
| { kind: "unknown" };
|
|
17
|
+
|
|
18
|
+
export interface ListResultHeaderProps {
|
|
19
|
+
/** The query as the reader typed it, quoted back to them. */
|
|
20
|
+
query: string;
|
|
21
|
+
count: ResultCount;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const formatCount = (n: number): string => n.toLocaleString();
|
|
25
|
+
|
|
26
|
+
const resultsLabel = (count: ResultCount, query: string): string => {
|
|
27
|
+
if (count.kind === "unknown") return `Results for “${query}”`;
|
|
28
|
+
const noun = count.value === 1 ? "result" : "results";
|
|
29
|
+
return `${formatCount(count.value)} ${noun} for “${query}”`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Names what the list is showing, and how much of it there is.
|
|
34
|
+
*
|
|
35
|
+
* The number is the server's count of the whole match set, never the length of
|
|
36
|
+
* the pages fetched so far: a page length presented as a total contradicts the
|
|
37
|
+
* completeness the filtered empty state states in the same view (#307).
|
|
38
|
+
*/
|
|
39
|
+
export function ListResultHeader({ query, count }: ListResultHeaderProps) {
|
|
40
|
+
return (
|
|
41
|
+
<div className="flex items-center gap-2 border-b border-line bg-surface-sunken/30 px-3 py-2">
|
|
42
|
+
<Search className="size-4 text-fg-muted" aria-hidden="true" />
|
|
43
|
+
<span className="text-sm text-fg-muted">
|
|
44
|
+
{resultsLabel(count, query)}
|
|
45
|
+
</span>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -492,6 +492,11 @@ export {
|
|
|
492
492
|
type LabelChipData,
|
|
493
493
|
type LabelChipProps,
|
|
494
494
|
} from "./components/label-chip.js";
|
|
495
|
+
export {
|
|
496
|
+
ListResultHeader,
|
|
497
|
+
type ListResultHeaderProps,
|
|
498
|
+
type ResultCount,
|
|
499
|
+
} from "./components/list-result-header.js";
|
|
495
500
|
export {
|
|
496
501
|
type MailAction,
|
|
497
502
|
MailActionToolbar,
|