@molecule/app-listing-card-vue
Feature · listing-card · App (browser) · v1.2.2 · Apache-2.0
Vue listing/product-card primitives with media, body, actions slots
npm install @molecule/app-listing-card-vueHow it works
@molecule/app-listing-card-vue is a ready-made listing-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 {
ListingCard,
ListingCardActions,
ListingCardBody,
ListingCardMedia,
ListingGrid,
} from '@molecule/app-listing-card-vue'
const App = defineComponent({
setup() {
return () =>
h(
ListingGrid,
{ columns: 3 },
{
default: () => [
h(
ListingCard,
{ onClick: () => navigate(`/listings/${item.id}`) },
{
default: () => [
h(ListingCardMedia, { src: item.imageUrl, aspect: '4/3', alt: item.name }),
h(ListingCardBody, {
title: item.name,
subtitle: item.location,
price: `$${item.price}/night`,
}),
h(ListingCardActions, {
default: () => [
h(
'button',
{
onClick: (event: MouseEvent) => {
event.stopPropagation()
saveListing(item.id)
},
},
'Save',
),
],
}),
],
},
),
],
},
)
},
})
createApp(App).mount('#app')Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue product / property / listing card primitives.
Exports:
<ListingCard>— outer Card shell. Props:children,toggle?,onClick?,className?,dataMolId?.<ListingCardMedia>— top image slot. Props:src?,alt?,children?(custom media node),aspect?('1/1' | '4/3' | '16/9' | '3/2', default'4/3', applied as an inline aspect-ratio style),overlay?(badge / favorite button, absolutely positioned over the media),className?.<ListingCardBody>— stacked text. Props:title,subtitle?,price?,meta?,className?.<ListingCardActions>— action row. Props:children,layout?('horizontal'default |'stacked'),className?.<ListingGrid>— grid container. Props:children,columns?(1–6, default 3),gap?,className?.
This is the Vue counterpart of @molecule/app-listing-card-react: the same
exports, the same props (React names) and the same DOM for the same input.
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 {
ListingCard,
ListingCardActions,
ListingCardBody,
ListingCardMedia,
ListingGrid,
} from '@molecule/app-listing-card-vue'
const App = defineComponent({
setup() {
return () =>
h(
ListingGrid,
{ columns: 3 },
{
default: () => [
h(
ListingCard,
{ onClick: () => navigate(`/listings/${item.id}`) },
{
default: () => [
h(ListingCardMedia, { src: item.imageUrl, aspect: '4/3', alt: item.name }),
h(ListingCardBody, {
title: item.name,
subtitle: item.location,
price: `$${item.price}/night`,
}),
h(ListingCardActions, {
default: () => [
h(
'button',
{
onClick: (event: MouseEvent) => {
event.stopPropagation()
saveListing(item.id)
},
},
'Save',
),
],
}),
],
},
),
],
},
)
},
})
createApp(App).mount('#app')
Type
feature
Installation
npm install @molecule/app-listing-card-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
API
Interfaces
ListingCardToggleProps
A server-backed card action with the total number of people who selected it:
the Vue counterpart of React's ListingCardToggleProps.
interface ListingCardToggleProps extends Omit<OptimisticToggleButtonProps, 'value' | 'commit'> {
/** The pressed state and count from the same loaded record. */
value: { pressed: boolean; count: number }
/** Saves the desired state and returns the server-confirmed state and count together. */
commit: (desired: boolean) => Promise<ListingCardToggleProps['value']>
/** Overrides the button's default `data-mol-id`. */
dataMolId?: string
}
ListingCardProps
Props for ListingCard.
interface ListingCardProps {
/**
* Slots — usually `<ListingCardMedia>` + `<ListingCardBody>` +
* `<ListingCardActions>`. The default slot, or the same-named `children`
* prop; both work.
*/
children?: VNodeChild
/** Renders a counted native toggle after the content, outside any links in the content. */
toggle?: ListingCardToggleProps
/**
* Called on any click on the card — including clicks inside
* `<ListingCardActions>`, which bubble into it unless the action handler
* calls `stopPropagation()`. The DOM click event is passed the way React's
* DOM handler receives it.
*/
onClick?: (event: MouseEvent) => void
/** Extra classes on the outer Card. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
}
ListingCardActionsProps
Props for ListingCardActions.
interface ListingCardActionsProps {
/** Action content — buttons, favorite toggle, etc. The default slot. */
children?: VNodeChild
/** Layout — `'horizontal'` (default) fills width, `'stacked'` is vertical. */
layout?: 'horizontal' | 'stacked'
/** Extra classes. */
className?: string
}
ListingCardBodyProps
Props for ListingCardBody.
interface ListingCardBodyProps {
/** Primary title / name (a node, or its same-named slot). */
title?: VNodeChild
/** Secondary line (subtitle, location, category), a node or its same-named slot. */
subtitle?: VNodeChild
/** Price / metric line, a node or its same-named slot. */
price?: VNodeChild
/** Optional extras row (rating, availability, badges), a node or its same-named slot. */
meta?: VNodeChild
/** Extra classes. */
className?: string
}
ListingCardMediaProps
Props for ListingCardMedia.
interface ListingCardMediaProps {
/** Image URL. */
src?: string
/** Image alternative text (defaults to an empty string). */
alt?: string
/** Override with a node (video, carousel, svg) — the default slot. */
children?: VNodeChild
/** Aspect ratio (`'1/1' | '4/3' | '16/9' | '3/2'`), applied as an inline `aspect-ratio` style. Defaults to `'4/3'`. */
aspect?: '1/1' | '4/3' | '16/9' | '3/2'
/** Optional overlay node (badge, favorite heart) — the same-named slot. */
overlay?: VNodeChild
/** Extra classes. */
className?: string
}
ListingGridProps
Props for ListingGrid.
interface ListingGridProps {
/** Grid content — the cards. The default slot. */
children?: VNodeChild
/** Column count, fixed at every viewport width. Defaults to 3. */
columns?: 1 | 2 | 3 | 4 | 5 | 6
/** Gap between cards. Defaults to `'md'`. */
gap?: 'xs' | 'sm' | 'md' | 'lg'
/** Extra classes. */
className?: string
}
Constants
ListingCard
Product / property / listing card shell. Just a <Card> with vertical
stacking of its children — typically <ListingCardMedia> +
<ListingCardBody> + <ListingCardActions>.
A supplied onClick makes the whole card cursor-pointer, exactly as React's
cm.cursorPointer condition does. A supplied toggle renders the counted
card action after the content, outside any links in it.
const ListingCard: DefineComponent<
ExtractPropTypes<{
children: null
toggle: { type: PropType<ListingCardProps['toggle']>; default: undefined }
onClick: { type: PropType<ListingCardProps['onClick']>; default: undefined }
className: StringConstructor
dataMolId: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
children: null
toggle: { type: PropType<ListingCardProps['toggle']>; default: undefined }
onClick: { type: PropType<ListingCardProps['onClick']>; default: undefined }
className: StringConstructor
dataMolId: StringConstructor
}>
> &
Readonly<{}>,
{
toggle: ListingCardToggleProps | undefined
onClick: ((event: MouseEvent) => void) | undefined
},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeListingCardProps).
Returns: The listing card component.
ListingCardActions
Bottom action row of a <ListingCard> (Add to cart, Save, etc.).
const ListingCardActions: DefineComponent<
ExtractPropTypes<{
children: null
layout: { type: PropType<ListingCardActionsProps['layout']>; default: string }
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
children: null
layout: { type: PropType<ListingCardActionsProps['layout']>; default: string }
className: StringConstructor
}>
> &
Readonly<{}>,
{ layout: 'horizontal' | 'stacked' | undefined },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeListingCardActionsProps).
Returns: The listing card actions component.
ListingCardBody
Body of a <ListingCard> — title / subtitle / price / meta rows stacked.
Every optional row renders only when its prop or same-named slot carries
something, exactly as React's {node && …} conditions do.
const ListingCardBody: DefineComponent<
ExtractPropTypes<{
title: null
subtitle: null
price: null
meta: null
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
title: null
subtitle: null
price: null
meta: null
className: StringConstructor
}>
> &
Readonly<{}>,
{},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeListingCardBodyProps).
Returns: The listing card body component.
ListingCardMedia
Media slot at the top of a <ListingCard>. Locks the aspect ratio via an
inline style, renders the caller's node instead of the <img> fallback, and
puts overlay in an absolutely-positioned inset-0 layer.
const ListingCardMedia: DefineComponent<
ExtractPropTypes<{
src: StringConstructor
alt: StringConstructor
children: null
aspect: { type: PropType<ListingCardMediaProps['aspect']>; default: string }
overlay: null
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
src: StringConstructor
alt: StringConstructor
children: null
aspect: { type: PropType<ListingCardMediaProps['aspect']>; default: string }
overlay: null
className: StringConstructor
}>
> &
Readonly<{}>,
{ aspect: '1/1' | '4/3' | '16/9' | '3/2' | undefined },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeListingCardMediaProps).
Returns: The listing card media component.
ListingGrid
Grid for <ListingCard>s — a fixed columns-column grid at every viewport
width.
const ListingGrid: DefineComponent<
ExtractPropTypes<{
children: null
columns: { type: PropType<ListingGridProps['columns']>; default: number }
gap: { type: PropType<ListingGridProps['gap']>; default: string }
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
children: null
columns: { type: PropType<ListingGridProps['columns']>; default: number }
gap: { type: PropType<ListingGridProps['gap']>; default: string }
className: StringConstructor
}>
> &
Readonly<{}>,
{ columns: 1 | 2 | 3 | 4 | 5 | 6 | undefined; gap: 'xs' | 'sm' | 'md' | 'lg' | undefined },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeListingGridProps).
Returns: The listing grid component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.2.0@molecule/app-vue^3.13.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
-
@molecule/app-ui -
@molecule/app-ui-vue -
@molecule/app-vue -
vue -
ListingCard.onClickis attached to the WHOLE card — clicks on buttons inside<ListingCardActions>bubble into it. Callevent.stopPropagation()in every action handler (as in the example) or the card navigation fires too. The built-intogglehandles that itself. -
Pass
togglefor a server-backed action with a count, such as a vote or endorsement: the card renders the counted button after the content, including zero, and a rejected save puts both fields back together. -
<ListingGrid columns={n}>renders a fixed n-column grid (viacm.grid); overrideclassNamefor a custom grid. -
overlaychildren are rendered inside an absolutely-positioned inset-0 layer; give interactive overlays their own pointer handling and stopPropagation. -
Styling resolves through
getClassMap(); the shell uses<Card>from@molecule/app-ui-vue— wire a ClassMap bond first. -
Node-valued props (
children,title,subtitle,price,meta,overlay) arrive as a prop AND a same-named slot; components accept either.