@molecule/app-related-items-card-vue
Feature · related-items-card · App (browser) · v1.1.2 · Apache-2.0
Card container for cross-linked items: company→deals, contact→notes, ticket→articles
npm install @molecule/app-related-items-card-vueHow it works
@molecule/app-related-items-card-vue 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.
import { createApp, defineComponent, h } from 'vue'
import { RelatedItemsCard } from '@molecule/app-related-items-card-vue'
interface Article {
id: string
title: string
}
const RelatedArticles = defineComponent({
props: { articles: { type: Array as () => Article[], required: true } },
setup(props) {
const open = (article: Article): void => {
// navigate to the article…
}
return () =>
h(
RelatedItemsCard,
{
title: 'Related Articles',
items: props.articles,
viewAllHref: '/articles',
renderItem: (article: Article) => h('span', article.title),
onItemClick: open,
},
{ emptyState: () => [h('p', 'No related articles yet.')] },
)
},
})
createApp(RelatedArticles).mount('#app')Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue card container for cross-linked / related item lists.
Exports <RelatedItemsCard> — the Vue 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 (node), items: T[], renderItem(item, 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
import { createApp, defineComponent, h } from 'vue'
import { RelatedItemsCard } from '@molecule/app-related-items-card-vue'
interface Article {
id: string
title: string
}
const RelatedArticles = defineComponent({
props: { articles: { type: Array as () => Article[], required: true } },
setup(props) {
const open = (article: Article): void => {
// navigate to the article…
}
return () =>
h(
RelatedItemsCard,
{
title: 'Related Articles',
items: props.articles,
viewAllHref: '/articles',
renderItem: (article: Article) => h('span', article.title),
onItemClick: open,
},
{ emptyState: () => [h('p', 'No related articles yet.')] },
)
},
})
createApp(RelatedArticles).mount('#app')
Type
feature
Installation
npm install @molecule/app-related-items-card-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
API
Interfaces
RelatedItemsCardProps
Props accepted by the RelatedItemsCard component.
interface RelatedItemsCardProps<T> {
/**
* Card heading. A string renders as text; a node is passed as the prop or
* as the same-named slot — both work.
*/
title: VNodeChild
/**
* Optional leading icon in the header. A node is passed as the prop or as
* the same-named `icon` slot — both work.
*/
icon?: VNodeChild
/** Items to render. */
items: readonly T[]
/** Render function for each item. */
renderItem: (item: T, index: number) => VNodeChild
/** Called when an item row is clicked (if applicable). */
onItemClick?: (item: T, index: number) => void
/**
* Rendered when `items` is empty. A node is passed as the prop or as the
* same-named `emptyState` slot — both work.
*/
emptyState?: VNodeChild
/** Optional "View all" link rendered in the header. */
viewAllHref?: string
/**
* Optional right-aligned header actions (e.g. "Add new" button). A node is
* passed as the prop or as the same-named `headerActions` slot — both work.
*/
headerActions?: VNodeChild
/** Extra classes on the Card. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
Constants
RelatedItemsCard
Card container for a list of cross-linked / related items.
Common usage: "Company → Deals", "Contact → Notes", "Ticket → Related Articles", "Post → Related Posts". Apps supply the item data and a renderer; the card provides consistent header + list + empty-state + view-all chrome.
Clickable rows (onItemClick): the <li> stays a list item and the card
wraps the row content in an inner role="button" div — focusable, with
Enter/Space running the same handler the click does.
const RelatedItemsCard: DefineComponent<
ExtractPropTypes<{
title: null
icon: null
items: { type: PropType<readonly unknown[]>; required: true }
renderItem: { type: PropType<ItemRenderer>; required: true }
onItemClick: {
type: PropType<((item: unknown, index: number) => void) | undefined>
default: undefined
}
emptyState: null
viewAllHref: { type: PropType<string | undefined>; default: undefined }
headerActions: null
className: { type: PropType<string | undefined>; default: undefined }
dataMolId: { type: PropType<string | undefined>; default: undefined }
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
title: null
icon: null
items: { type: PropType<readonly unknown[]>; required: true }
renderItem: { type: PropType<ItemRenderer>; required: true }
onItemClick: {
type: PropType<((item: unknown, index: number) => void) | undefined>
default: undefined
}
emptyState: null
viewAllHref: { type: PropType<string | undefined>; default: undefined }
headerActions: null
className: { type: PropType<string | undefined>; default: undefined }
dataMolId: { type: PropType<string | undefined>; default: undefined }
}>
> &
Readonly<{}>,
{
onItemClick: ((item: unknown, index: number) => void) | undefined
viewAllHref: string | undefined
className: string | undefined
dataMolId: string | undefined
},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (RelatedItemsCardProps).
Returns: The related items card component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.5.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
-
@molecule/app-ui -
@molecule/app-ui-vue -
@molecule/app-vue -
vue -
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 a prop AND a same-named slot; components accept either.