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/alert.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/avatar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/badge.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/field.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/file-input.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions r/item.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/secret-path-input.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/tile-picker.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"path": "src/components/cipher/patterns/tile-picker.tsx",
"type": "registry:file",
"target": "src/components/cipher/patterns/tile-picker.tsx",
"content": "import * as React from \"react\";\n\nimport { cn } from \"../lib/utils\";\nimport { Button } from \"../ui/button\";\nimport { type EmptyGhost, EmptyGhostScope, EmptyState } from \"../ui/empty\";\nimport type { IconSource } from \"../ui/icon\";\nimport { Input } from \"../ui/input\";\nimport { Media, Tile } from \"../ui/item\";\n\nimport styles from \"./tile-picker.module.css\";\n\nexport type TilePickerItem = {\n value: string;\n title: string;\n description?: string;\n /** A short group name, such as AWS or CI/CD, shown across from the media. */\n eyebrow?: string;\n icon?: IconSource;\n /** A logo or image, framed like an icon. Ignored when icon is set. */\n media?: React.ReactNode;\n /** Also listed under the popular section while the search is empty. */\n popular?: boolean;\n disabledReason?: string;\n /** Extra words the search matches, such as a vendor's other product names. */\n keywords?: readonly string[];\n};\n\nexport type TilePickerProps = Omit<React.ComponentPropsWithoutRef<\"div\">, \"onSelect\"> & {\n items: readonly TilePickerItem[];\n onSelect: (value: string) => void;\n searchLabel?: string;\n searchPlaceholder?: string;\n popularLabel?: string;\n /** Heads the full list when popular items are shown above it. */\n allLabel?: string;\n /** Names what the search found nothing of, as in No items match. */\n noun?: string;\n /** Shown in place of the grid when there are no items at all, such as an EmptyState. */\n empty?: React.ReactNode;\n /** The ghost behind an Empty in the empty slot. Defaults to cards; a search that finds nothing never draws one. */\n ghost?: EmptyGhost;\n};\n\nconst matches = (item: TilePickerItem, query: string) =>\n [item.title, item.eyebrow, item.description, ...(item.keywords ?? [])].some((text) =>\n text?.toLowerCase().includes(query)\n );\n\n/**\n * Search plus a responsive grid of stacked Tiles. With an empty search, popular items come first\n * under their own label and every item follows; a search lists its matches flat, and finding\n * nothing offers to clear it. The grid adds columns as the container widens, so it fits a sheet\n * or a page without a frame of its own.\n */\nexport function TilePicker({\n items,\n onSelect,\n searchLabel = \"Search\",\n searchPlaceholder,\n popularLabel = \"Popular\",\n allLabel = \"All\",\n noun = \"items\",\n empty,\n ghost,\n className,\n ref,\n ...props\n}: TilePickerProps & { ref?: React.Ref<HTMLDivElement> }) {\n const [search, setSearch] = React.useState(\"\");\n const inputRef = React.useRef<HTMLInputElement>(null);\n const query = search.trim().toLowerCase();\n const popular = query ? [] : items.filter((item) => item.popular);\n const grid = (list: readonly TilePickerItem[]) => (\n <div className={styles.grid}>\n {list.map((item) => (\n <Tile\n key={item.value}\n layout=\"stacked\"\n title={item.title}\n description={item.description}\n eyebrow={item.eyebrow}\n disabledReason={item.disabledReason}\n media={(item.icon || item.media) && <Media icon={item.icon}>{item.media}</Media>}\n onClick={() => onSelect(item.value)}\n />\n ))}\n </div>\n );\n const section = (label: string, list: readonly TilePickerItem[]) => (\n <section className={styles.section} aria-label={label}>\n <h3 className={styles.label}>{label}</h3>\n {grid(list)}\n </section>\n );\n const found = query ? items.filter((item) => matches(item, query)) : items;\n let body: React.ReactNode;\n if (items.length === 0 && empty !== undefined)\n body = <EmptyGhostScope ghost={ghost ?? \"cards\"}>{empty}</EmptyGhostScope>;\n else if (query && found.length === 0)\n body = (\n <EmptyState\n ghost={false}\n size=\"sm\"\n media=\"bare\"\n icon=\"search\"\n title={`No ${noun} match \"${search.trim()}\"`}\n actions={\n <Button\n variant=\"outline\"\n onClick={() => {\n setSearch(\"\");\n inputRef.current?.focus();\n }}\n >\n Clear search\n </Button>\n }\n />\n );\n else if (popular.length > 0)\n body = (\n <>\n {section(popularLabel, popular)}\n {section(allLabel, items)}\n </>\n );\n else body = grid(found);\n return (\n <div ref={ref} data-slot=\"tile-picker\" className={cn(styles.picker, className)} {...props}>\n <Input\n ref={inputRef}\n icon=\"search\"\n aria-label={searchLabel}\n placeholder={searchPlaceholder ?? searchLabel}\n value={search}\n data-cipher-escape-owner={search ? \"\" : undefined}\n onChange={(event) => setSearch(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Escape\" && search) {\n event.preventDefault();\n event.stopPropagation();\n setSearch(\"\");\n }\n }}\n />\n {body}\n </div>\n );\n}\nTilePicker.displayName = \"TilePicker\";\n"
"content": "import * as React from \"react\";\n\nimport { cn } from \"../lib/utils\";\nimport { Button } from \"../ui/button\";\nimport { type EmptyGhost, EmptyGhostScope, EmptyState } from \"../ui/empty\";\nimport type { IconSource } from \"../ui/icon\";\nimport { Input } from \"../ui/input\";\nimport { Media, Tile } from \"../ui/item\";\n\nimport styles from \"./tile-picker.module.css\";\n\nexport type TilePickerItem = {\n value: string;\n title: string;\n description?: string;\n /** A short group name, such as AWS or CI/CD, shown across from the media. */\n eyebrow?: string;\n icon?: IconSource;\n /** A logo or image, framed like an icon. Ignored when icon is set. */\n media?: React.ReactNode;\n /** Also listed under the popular section while the search is empty. */\n popular?: boolean;\n disabledReason?: string;\n /** Extra words the search matches, such as a vendor's other product names. */\n keywords?: readonly string[];\n /** Makes the tile a link that navigates instead of calling onSelect. */\n href?: string;\n /** Opens href in a new tab and marks the tile as external. */\n external?: boolean;\n};\n\nexport type TilePickerProps = Omit<React.ComponentPropsWithoutRef<\"div\">, \"onSelect\"> & {\n items: readonly TilePickerItem[];\n /** Called with a picked item's value. Items with an href navigate instead. */\n onSelect?: (value: string) => void;\n searchLabel?: string;\n searchPlaceholder?: string;\n popularLabel?: string;\n /** Heads the full list when popular items are shown above it. */\n allLabel?: string;\n /** Names what the search found nothing of, as in No items match. */\n noun?: string;\n /** Shown in place of the grid when there are no items at all, such as an EmptyState. */\n empty?: React.ReactNode;\n /** The ghost behind an Empty in the empty slot. Defaults to cards; a search that finds nothing never draws one. */\n ghost?: EmptyGhost;\n};\n\nconst matches = (item: TilePickerItem, query: string) =>\n [item.title, item.eyebrow, item.description, ...(item.keywords ?? [])].some((text) =>\n text?.toLowerCase().includes(query)\n );\n\n/**\n * Search plus a responsive grid of stacked Tiles. With an empty search, popular items come first\n * under their own label and every item follows; a search lists its matches flat, and finding\n * nothing offers to clear it. The grid adds columns as the container widens, so it fits a sheet\n * or a page without a frame of its own.\n */\nexport function TilePicker({\n items,\n onSelect,\n searchLabel = \"Search\",\n searchPlaceholder,\n popularLabel = \"Popular\",\n allLabel = \"All\",\n noun = \"items\",\n empty,\n ghost,\n className,\n ref,\n ...props\n}: TilePickerProps & { ref?: React.Ref<HTMLDivElement> }) {\n const [search, setSearch] = React.useState(\"\");\n const inputRef = React.useRef<HTMLInputElement>(null);\n const query = search.trim().toLowerCase();\n const popular = query ? [] : items.filter((item) => item.popular);\n const grid = (list: readonly TilePickerItem[]) => (\n <div className={styles.grid}>\n {list.map((item) => {\n const shared = {\n layout: \"stacked\" as const,\n title: item.title,\n description: item.description,\n eyebrow: item.eyebrow,\n disabledReason: item.disabledReason,\n media: (item.icon || item.media) && <Media icon={item.icon}>{item.media}</Media>\n };\n return item.href ? (\n <Tile key={item.value} {...shared} href={item.href} external={item.external} />\n ) : (\n <Tile key={item.value} {...shared} onClick={() => onSelect?.(item.value)} />\n );\n })}\n </div>\n );\n const section = (label: string, list: readonly TilePickerItem[]) => (\n <section className={styles.section} aria-label={label}>\n <h3 className={styles.label}>{label}</h3>\n {grid(list)}\n </section>\n );\n const found = query ? items.filter((item) => matches(item, query)) : items;\n let body: React.ReactNode;\n if (items.length === 0 && empty !== undefined)\n body = <EmptyGhostScope ghost={ghost ?? \"cards\"}>{empty}</EmptyGhostScope>;\n else if (query && found.length === 0)\n body = (\n <EmptyState\n ghost={false}\n size=\"sm\"\n media=\"bare\"\n icon=\"search\"\n title={`No ${noun} match \"${search.trim()}\"`}\n actions={\n <Button\n variant=\"outline\"\n onClick={() => {\n setSearch(\"\");\n inputRef.current?.focus();\n }}\n >\n Clear search\n </Button>\n }\n />\n );\n else if (popular.length > 0)\n body = (\n <>\n {section(popularLabel, popular)}\n {section(allLabel, items)}\n </>\n );\n else body = grid(found);\n return (\n <div ref={ref} data-slot=\"tile-picker\" className={cn(styles.picker, className)} {...props}>\n <Input\n ref={inputRef}\n icon=\"search\"\n aria-label={searchLabel}\n placeholder={searchPlaceholder ?? searchLabel}\n value={search}\n data-cipher-escape-owner={search ? \"\" : undefined}\n onChange={(event) => setSearch(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === \"Escape\" && search) {\n event.preventDefault();\n event.stopPropagation();\n setSearch(\"\");\n }\n }}\n />\n {body}\n </div>\n );\n}\nTilePicker.displayName = \"TilePicker\";\n"
},
{
"path": "src/components/cipher/patterns/tile-picker.module.css",
Expand Down
2 changes: 1 addition & 1 deletion r/toast-stack.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 @@ -949,6 +949,10 @@
"title": "A few providers",
"module": "tile-picker/few"
},
{
"title": "Links: items with an href navigate, external ones open a new tab",
"module": "tile-picker/links"
},
{
"title": "Long names and disabled providers",
"module": "tile-picker/stressed"
Expand Down Expand Up @@ -1168,6 +1172,10 @@
{
"title": "Selectable tile and media",
"module": "item/tiles"
},
{
"title": "Tiles as links, internal and external",
"module": "item/tile-links"
}
]
},
Expand Down
51 changes: 51 additions & 0 deletions site/src/examples/item/tile-links.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Media, Tile } from "@infisical/cipher/ui/item";
import { Grid } from "@infisical/cipher/ui/layout";

export default function Example() {
return (
<div className="flex w-full min-w-0 flex-col gap-6">
<div className="flex w-full min-w-0 flex-col gap-3">
<Tile
href="#/organizations/acme/settings/billing"
media={<Media icon="folder" />}
title="Billing"
description="Plan, invoices and payment method"
/>
<Tile
href="https://infisical.com/docs/documentation/getting-started/introduction"
external
media={<Media icon="book-open" />}
title="Documentation"
description="Guides and API reference"
/>
</div>
<Grid columns={3} gap={12}>
<Tile
layout="stacked"
href="#/agent-vault/connections/new/github"
media={<Media icon="git" />}
eyebrow="Source control"
title="GitHub"
description="Repositories, issues and pull requests."
/>
<Tile
layout="stacked"
href="https://modelcontextprotocol.io/docs/getting-started/intro"
external
media={<Media icon="link" />}
eyebrow="Protocol"
title="MCP"
description="Any server that speaks the Model Context Protocol."
/>
<Tile
layout="stacked"
href="https://infisical.com/docs"
external
media={<Media icon="cloud" />}
title="Custom HTTP"
description="Any HTTP API, with headers and auth you define."
/>
</Grid>
</div>
);
}
50 changes: 50 additions & 0 deletions site/src/examples/tile-picker/links.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { TilePicker, type TilePickerItem } from "@infisical/cipher/patterns/tile-picker";

const services: TilePickerItem[] = [
{
value: "github",
title: "GitHub",
description: "Repositories, issues and pull requests.",
eyebrow: "Source control",
icon: "git",
href: "#/agent-vault/connections/new/github",
popular: true
},
{
value: "linear",
title: "Linear",
description: "Issues, projects and cycles.",
eyebrow: "Project management",
icon: "folder",
href: "#/agent-vault/connections/new/linear"
},
{
value: "custom-http",
title: "Custom HTTP",
description: "Any HTTP API, with headers and auth you define.",
eyebrow: "Generic",
icon: "cloud",
href: "https://infisical.com/docs",
external: true
},
{
value: "mcp",
title: "MCP",
description: "Any server that speaks the Model Context Protocol.",
eyebrow: "Protocol",
icon: "link",
href: "https://modelcontextprotocol.io/docs/getting-started/intro",
external: true
}
];

export default function Example() {
return (
<TilePicker
items={services}
searchLabel="Search services"
allLabel="All services"
noun="services"
/>
);
}
34 changes: 21 additions & 13 deletions src/patterns/tile-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export type TilePickerItem = {
disabledReason?: string;
/** Extra words the search matches, such as a vendor's other product names. */
keywords?: readonly string[];
/** Makes the tile a link that navigates instead of calling onSelect. */
href?: string;
/** Opens href in a new tab and marks the tile as external. */
external?: boolean;
};

export type TilePickerProps = Omit<React.ComponentPropsWithoutRef<"div">, "onSelect"> & {
items: readonly TilePickerItem[];
onSelect: (value: string) => void;
/** Called with a picked item's value. Items with an href navigate instead. */
onSelect?: (value: string) => void;
searchLabel?: string;
searchPlaceholder?: string;
popularLabel?: string;
Expand Down Expand Up @@ -72,18 +77,21 @@ export function TilePicker({
const popular = query ? [] : items.filter((item) => item.popular);
const grid = (list: readonly TilePickerItem[]) => (
<div className={styles.grid}>
{list.map((item) => (
<Tile
key={item.value}
layout="stacked"
title={item.title}
description={item.description}
eyebrow={item.eyebrow}
disabledReason={item.disabledReason}
media={(item.icon || item.media) && <Media icon={item.icon}>{item.media}</Media>}
onClick={() => onSelect(item.value)}
/>
))}
{list.map((item) => {
const shared = {
layout: "stacked" as const,
title: item.title,
description: item.description,
eyebrow: item.eyebrow,
disabledReason: item.disabledReason,
media: (item.icon || item.media) && <Media icon={item.icon}>{item.media}</Media>
};
return item.href ? (
<Tile key={item.value} {...shared} href={item.href} external={item.external} />
) : (
<Tile key={item.value} {...shared} onClick={() => onSelect?.(item.value)} />
);
})}
</div>
);
const section = (label: string, list: readonly TilePickerItem[]) => (
Expand Down
21 changes: 18 additions & 3 deletions src/ui/helpers.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
}
.tile {
display: flex;
box-sizing: border-box;
text-decoration: none;
align-items: center;
gap: 12px;
width: 100%;
Expand All @@ -111,10 +113,12 @@
.tile[data-in-frame]:not([aria-disabled="true"]):hover {
background: color-mix(in srgb, var(--cipher-mix-ink) var(--cipher-hover-mix), var(--cipher-tint));
}
.tile[aria-pressed="true"] {
.tile[aria-pressed="true"],
.tile[aria-current="page"] {
border-color: var(--cipher-ink, var(--foreground));
}
.tile:disabled {
.tile:disabled,
.tile[data-disabled] {
cursor: not-allowed;
opacity: 0.5;
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
}
Expand Down Expand Up @@ -146,6 +150,17 @@
min-width: 0;
margin-bottom: var(--cipher-space-8);
}
.tileAside {
display: flex;
align-items: center;
gap: var(--cipher-space-8);
min-width: 0;
margin-inline-start: auto;
color: var(--cipher-muted);
}
.tileAside > :not(.tileEyebrow) {
flex: none;
}
.tileEyebrow {
min-width: 0;
overflow: hidden;
Expand All @@ -159,7 +174,7 @@
letter-spacing: var(--cipher-type-eyebrow-letter-spacing);
text-transform: uppercase;
}
.tile[aria-disabled="true"] > .tileTop {
.tile[aria-disabled="true"]:not([data-disabled]) > .tileTop {
opacity: 0.5;
}
.banner {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/item.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
text-overflow: ellipsis;
white-space: nowrap;
}
[data-slot="tile"][aria-disabled="true"] .tileTitle {
[data-slot="tile"][aria-disabled="true"]:not([data-disabled]) .tileTitle {
opacity: 0.5;
}

Expand Down
Loading
Loading