Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/combobox.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/filter-bar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/multi-select.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions site/src/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@
{
"title": "Option icons",
"module": "combobox/icons"
},
{
"title": "Search over keywords and group headings, with a custom search placeholder",
"module": "combobox/keywords"
}
]
},
Expand Down Expand Up @@ -932,6 +936,10 @@
{
"title": "Search only",
"module": "filter-bar/search-only"
},
{
"title": "Exact-match text field: the chip reads is instead of contains",
"module": "filter-bar/exact-match"
}
]
},
Expand Down
64 changes: 64 additions & 0 deletions site/src/examples/combobox/keywords.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useState } from "react";

import { Combobox, type ComboboxOption } from "@infisical/cipher/ui/combobox";
import { Field } from "@infisical/cipher/ui/field";

const products: ComboboxOption[] = [
{
value: "pro-monthly",
label: "Pro, monthly",
meta: "$18",
group: "Self-serve",
keywords: ["price_1QfPro0Monthly", "prod_SecretsPro"]
},
{
value: "pro-yearly",
label: "Pro, yearly",
meta: "$180",
group: "Self-serve",
keywords: ["price_1QfPro0Yearly", "prod_SecretsPro"]
},
{
value: "enterprise",
label: "Enterprise",
group: "Sales-led",
keywords: ["price_1QfEnt0Custom", "prod_SecretsEnterprise"]
},
{
value: "enterprise-gov",
label: "Enterprise for government and regulated industries, annual commitment",
group: "Sales-led",
keywords: ["price_1QfEnt0FedRAMP", "FedRAMP", "GovCloud"]
},
{
value: "pam-addon",
label: "Privileged access add-on",
group: "Add-ons",
keywords: ["price_1QfPam0Seat", "PAM"]
}
];

const Product = ({ label, initial }: { label: string; initial: string }) => {
const [value, setValue] = useState(initial);
return (
<Field label={label}>
<Combobox
label={label}
options={products}
value={value}
onChange={setValue}
searchPlaceholder="Search products, groups or price IDs"
/>
</Field>
);
};

export default function Example() {
return (
<div className="grid w-full min-w-0 grid-cols-[repeat(auto-fit,minmax(min(100%,15rem),1fr))] items-start gap-x-6 gap-y-8">
<Product label="Product" initial="" />
<Product label="Product" initial="pro-yearly" />
<Product label="Product" initial="enterprise-gov" />
</div>
);
}
44 changes: 44 additions & 0 deletions site/src/examples/filter-bar/exact-match.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useState } from "react";

import {
FilterBar,
type FilterBarField,
type FilterBarFilter
} from "@infisical/cipher/patterns/filter-bar";

const fields: FilterBarField[] = [
{ key: "org", label: "Org ID", type: "text", placeholder: "Exact org ID", verb: "is" },
{ key: "customer", label: "Customer", type: "text", placeholder: "Part of a name" }
];

const Bar = ({ initial }: { initial: FilterBarFilter[] }) => {
const [filters, setFilters] = useState(initial);
const [query, setQuery] = useState("");
return (
<FilterBar
label="Licenses"
fields={fields}
value={filters}
onChange={setFilters}
searchValue={query}
onSearchChange={setQuery}
searchLabel="Search licenses"
slashShortcut={false}
/>
);
};

export default function Example() {
return (
<div className="flex w-full min-w-0 flex-col gap-6">
<Bar initial={[]} />
<Bar initial={[{ field: "org", values: ["org_9f2c41"] }]} />
<Bar
initial={[
{ field: "org", values: ["org_9f2c41d7-3b8e-4a6f-a1c2-7e5d0b9f8a34-eu-west-production"] },
{ field: "customer", values: ["Acme payments"] }
]}
/>
</div>
);
}
12 changes: 10 additions & 2 deletions src/patterns/filter-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ export type FilterBarField =
| (FilterBarChoiceField & { type: "multi-select" })
| { key: string; label: string; type: "date"; defaultMonth?: Date }
| { key: string; label: string; type: "date-range"; defaultMonth?: Date }
| { key: string; label: string; type: "text"; placeholder?: string };
| {
key: string;
label: string;
type: "text";
placeholder?: string;
/** How the chip reads the value, such as "is" for an exact match. Defaults to "contains". */
verb?: string;
};
export type FilterBarFilter = {
field: string;
operator?: "before" | "after";
Expand Down Expand Up @@ -88,7 +95,8 @@ export const describeFilter = (field: FilterBarField, filter: FilterBarFilter) =
if (!from || !to) return { verb: "is", value: "any date" };
return { verb: from.getTime() === to.getTime() ? "on" : "from", value: shortRange(from, to) };
}
if (field.type === "text") return { verb: "contains", value: filter.values[0] ?? "anything" };
if (field.type === "text")
return { verb: field.verb ?? "contains", value: filter.values[0] ?? "anything" };
const labels = filter.values.map(
(value) => field.options.find((option) => option.value === value)?.label ?? value
);
Expand Down
13 changes: 10 additions & 3 deletions src/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export type ComboboxOption = {
/** A muted line under the label. Search matches it as well as the label. */
description?: string;
meta?: string;
/** Options that share a group sit under its heading, in the order each group first appears. */
/** Options that share a group sit under its heading, in the order each group first appears. Search matches the heading too. */
group?: string;
/** Extra words search matches but never shows, such as a product's other names or an ID. */
keywords?: readonly string[];
disabled?: boolean;
};
export type ComboboxCreationFormProps = {
Expand Down Expand Up @@ -96,6 +98,8 @@ type SharedComboboxProps = {
id?: string;
"aria-describedby"?: string;
emptyText?: string;
/** The search field's placeholder. Defaults to "Search options". */
searchPlaceholder?: string;
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
disabled?: boolean;
invalid?: boolean;
mono?: boolean;
Expand Down Expand Up @@ -144,6 +148,7 @@ export function Combobox({
placeholder = "Select an option",
label,
emptyText = "No options found",
searchPlaceholder = "Search options",
disabled,
invalid,
mono,
Expand Down Expand Up @@ -229,7 +234,8 @@ export function Combobox({
const filtered = onSearch
? options
: options.filter((option) =>
`${option.label} ${option.description ?? ""} ${option.meta ?? ""}`
[option.label, option.description, option.meta, option.group, ...(option.keywords ?? [])]
.join(" ")
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
.toLowerCase()
.includes(query.toLowerCase())
);
Expand Down Expand Up @@ -318,6 +324,7 @@ export function Combobox({
disabled={disabled}
invalid={invalid}
searchable
searchPlaceholder={searchPlaceholder}
quickActions={false}
anchorRef={fieldRef}
open={open}
Expand Down Expand Up @@ -442,7 +449,7 @@ export function Combobox({
<CommandInput
value={query}
onValueChange={changeQuery}
placeholder="Search options"
placeholder={searchPlaceholder}
aria-label={`Search ${label}`}
onKeyDown={(event) => {
if (event.nativeEvent.isComposing || event.keyCode === 229) event.stopPropagation();
Expand Down
13 changes: 9 additions & 4 deletions src/ui/multi-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export type MultiSelectOption = {
/** A short muted value at the row's end, such as a count. */
meta?: string;
disabled?: boolean;
/** Search matches the group's heading too. */
group?: string;
/** Extra words the search matches but never shows, such as an ID or an alias. */
keywords?: readonly string[];
};
type Shared = {
onCreate?: OptionCreateHandler;
Expand All @@ -39,6 +42,7 @@ type Shared = {
disabled?: boolean;
invalid?: boolean;
searchable?: boolean;
searchPlaceholder?: string;
/** Searches on the server: called with each query (and with "" when the menu closes), while options holds the results as they arrive. It turns on the search field. Include the selected options in options on first render so their labels show. */
onSearch?: (query: string) => void;
/** While onSearch is in flight: a spinner in the search field, and Searching… in place of No options found. */
Expand Down Expand Up @@ -84,6 +88,7 @@ export function MultiSelect({
disabled,
invalid,
searchable: searchableProp = false,
searchPlaceholder = "Search options",
onSearch,
loading = false,
anchorRef,
Expand Down Expand Up @@ -209,7 +214,8 @@ export function MultiSelect({
const filtered = onSearch
? options
: options.filter((option) =>
`${option.label} ${option.description ?? ""} ${option.meta ?? ""}`
[option.label, option.description, option.meta, option.group, ...(option.keywords ?? [])]
.join(" ")
.toLowerCase()
.includes(query.toLowerCase())
);
Expand Down Expand Up @@ -380,8 +386,7 @@ export function MultiSelect({
}}
onInteractOutside={(event) => {
const clear =
event.target instanceof Element &&
event.target.closest('[data-slot="combobox-clear"]');
event.target instanceof Element && event.target.closest('[data-slot="combobox-clear"]');
if (clear && (!clear.isConnected || anchorRef?.current?.contains(clear)))
event.preventDefault();
}}
Expand All @@ -404,7 +409,7 @@ export function MultiSelect({
aria-activedescendant={currentActive ? optionId(currentActive.value) : undefined}
value={query}
onChange={(event) => changeQuery(event.target.value)}
placeholder="Search options"
placeholder={searchPlaceholder}
/>
{loading && <Spinner />}
</div>
Expand Down
Loading