@molecule/app-related-items-card-svelte
Feature · related-items-card · App (browser) · v1.1.3 · Apache-2.0
Card container for cross-linked items: company→deals, contact→notes, ticket→articles
npm install @molecule/app-related-items-card-svelteHow it works
@molecule/app-related-items-card-svelte is a ready-made related-items-card feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { RelatedItemsCard } from '@molecule/app-related-items-card-svelte'
interface Article {
id: string
title: string
}
let { articles, onOpen }: { articles: Article[]; onOpen: (id: string) => void } = $props()
</script>
<RelatedItemsCard
title="Related Articles"
items={articles}
viewAllHref="/articles"
onItemClick={(article) => onOpen(article.id)}
>
{#snippet renderItem(article)}
<span>{article.title}</span>
{/snippet}
{#snippet emptyState()}
<p>No related articles yet.</p>
{/snippet}
</RelatedItemsCard>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte card container for cross-linked / related item lists.
Exports RelatedItemsCard — the Svelte counterpart of
@molecule/app-related-items-card-react: a titled Card with header + list +
empty state + "View all" link, with the same props (React names) and the
same DOM for the same input. Use for "Company → Deals", "Contact → Notes",
"Ticket → Related Articles" panels.
Props: title (snippet or string), items: T[], renderItem(item, index)
(a snippet with the item and its index), icon?, onItemClick?(item, index)
(rows become clickable), emptyState? (rendered when items is empty),
viewAllHref? (header "View all" link), headerActions? (right-aligned
header slot), className?, dataMolId?.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { RelatedItemsCard } from '@molecule/app-related-items-card-svelte'
interface Article {
id: string
title: string
}
let { articles, onOpen }: { articles: Article[]; onOpen: (id: string) => void } = $props()
</script>
<RelatedItemsCard
title="Related Articles"
items={articles}
viewAllHref="/articles"
onItemClick={(article) => onOpen(article.id)}
>
{#snippet renderItem(article)}
<span>{article.title}</span>
{/snippet}
{#snippet emptyState()}
<p>No related articles yet.</p>
{/snippet}
</RelatedItemsCard>
Type
feature
Installation
npm install @molecule/app-related-items-card-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
RelatedItemsCardProps
Props accepted by the RelatedItemsCard component.
interface RelatedItemsCardProps<T> {
/** Card heading. A string renders as text; a node arrives as the same-named snippet. */
title: ReactNodeProp
/** Optional leading icon in the header; arrives as the same-named snippet. */
icon?: ReactNodeProp
/** Items to render. */
items: readonly T[]
/** Render function for each item; arrives as a snippet with the item and its index. */
renderItem: Snippet<[T, number]>
/** Called when an item row is clicked (if applicable). */
onItemClick?: (item: T, index: number) => void
/** Rendered when `items` is empty; arrives as the same-named snippet. */
emptyState?: ReactNodeProp
/** Optional "View all" link rendered in the header. */
viewAllHref?: string
/** Optional right-aligned header actions; arrives as the same-named snippet. */
headerActions?: ReactNodeProp
/** Extra classes on the Card. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
Constants
RelatedItemsCard
const RelatedItemsCard: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
-
@molecule/app-svelte -
@molecule/app-ui -
@molecule/app-ui-svelte -
svelte -
Requires a bonded ClassMap — call
setClassMap()(e.g. with@molecule/app-ui-tailwind) at startup or rendering throws. -
The "View all" label is hardcoded English in the React reference (not routed through i18n) and is the same literal here; pass a translated link via
headerActionsin localized apps. -
onItemClickrows stay<li>list items: the card wraps each row's content in an innerrole="button"control (focusable, Enter/Space activate it) so the click works from the keyboard too. A real<button>/<a>insiderenderItemstill takes its own clicks and focus. -
viewAllHrefrenders a plain<a href>(full page load in SPA routers); useheaderActionswith your router's Link for client-side navigation. -
Node-valued props (
title,icon,emptyState,headerActions) arrive as snippets; strings render as text.