@molecule/app-listing-card-svelte
Feature · listing-card · App (browser) · v1.2.3 · Apache-2.0
Svelte listing/product-card primitives with media, body, actions slots
npm install @molecule/app-listing-card-svelteHow it works
@molecule/app-listing-card-svelte 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.
<script lang="ts">
import {
ListingCard,
ListingCardActions,
ListingCardBody,
ListingCardMedia,
ListingGrid,
} from '@molecule/app-listing-card-svelte'
let { items }: { items: Listing[] } = $props()
</script>
<ListingGrid columns={3}>
<ListingCard onClick={() => navigate(`/listings/${items[0].id}`)}>
<ListingCardMedia src={items[0].imageUrl} aspect="4/3" alt={items[0].name} />
<ListingCardBody
title={items[0].name}
subtitle={items[0].location}
price={`$${items[0].price}/night`}
/>
<ListingCardActions>
<button
onclick={(event) => {
event.stopPropagation()
saveListing(items[0].id)
}}
>
Save
</button>
</ListingCardActions>
</ListingCard>
</ListingGrid>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte product / property / listing card primitives.
Exports:
ListingCard— outer Card shell. Props:children,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 Svelte counterpart of @molecule/app-listing-card-react: the
same exports, the same props (React names) and the same DOM for the same
input. Node-valued props (title, subtitle, price, meta, overlay)
are snippets or plain text.
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 {
ListingCard,
ListingCardActions,
ListingCardBody,
ListingCardMedia,
ListingGrid,
} from '@molecule/app-listing-card-svelte'
let { items }: { items: Listing[] } = $props()
</script>
<ListingGrid columns={3}>
<ListingCard onClick={() => navigate(`/listings/${items[0].id}`)}>
<ListingCardMedia src={items[0].imageUrl} aspect="4/3" alt={items[0].name} />
<ListingCardBody
title={items[0].name}
subtitle={items[0].location}
price={`$${items[0].price}/night`}
/>
<ListingCardActions>
<button
onclick={(event) => {
event.stopPropagation()
saveListing(items[0].id)
}}
>
Save
</button>
</ListingCardActions>
</ListingCard>
</ListingGrid>
Type
feature
Installation
npm install @molecule/app-listing-card-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
ListingCardToggleProps
Props for the counted toggle a <ListingCard> renders after its content: the
Svelte counterpart of React's ListingCardToggleProps. React's shape is its
button props minus the ones the toggle owns; Svelte's ButtonProps carries an
index signature, so those extras stay typed as pass-through props the way the
package's own OptimisticToggleButtonProps declares them.
interface ListingCardToggleProps {
/** 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<{ pressed: boolean; count: number }>
/** Label when the displayed value is true. */
activeLabel: NodeValue
/** Label when the displayed value is false. */
inactiveLabel: NodeValue
/** Receives a failed save after the controller has restored the last confirmed value. */
onError?: (error: unknown) => void
/** Overrides the button's default `data-mol-id`. */
dataMolId?: string
/** Button variant — defaults to `solid` while pressed and `outline` otherwise. */
variant?: ButtonProps['variant']
/** Any other button prop, passed through as React spreads them. */
[key: string]: unknown
}
ListingCardProps
Props for ListingCard.
interface ListingCardProps {
/** Slots — usually `<ListingCardMedia>` + `<ListingCardBody>` + `<ListingCardActions>`. */
children?: Snippet
/** 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
* stops propagation. 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. */
children?: Snippet
/** Layout — `'horizontal'` (default) fills width, `'stacked'` is vertical. */
layout?: 'horizontal' | 'stacked'
/** Extra classes. */
className?: string
}
ListingCardBodyProps
Props for ListingCardBody.
interface ListingCardBodyProps {
/** Primary title / name. */
title: NodeValue
/** Secondary line (subtitle, location, category). */
subtitle?: NodeValue
/** Price / metric line. */
price?: NodeValue
/** Optional extras row (rating, availability, badges). */
meta?: NodeValue
/** 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 snippet. */
children?: NodeValue
/** 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). */
overlay?: NodeValue
/** Extra classes. */
className?: string
}
ListingGridProps
Props for ListingGrid.
interface ListingGridProps {
/** Grid content — the cards. */
children?: Snippet
/** 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
const ListingCard: LegacyComponentType
ListingCardActions
const ListingCardActions: LegacyComponentType
ListingCardBody
const ListingCardBody: LegacyComponentType
ListingCardMedia
const ListingCardMedia: LegacyComponentType
ListingGrid
const ListingGrid: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.14.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 -
ListingCard'sonClickis attached to the WHOLE card — clicks on buttons insideListingCardActionsbubble into it. Callevent.stopPropagation()in every action handler (as in the example) or the card navigation fires too. -
ListingGridrenders a fixedcolumns-column grid (viacm.grid); overrideclassNamefor a custom grid. -
overlaycontent is rendered inside an absolutely-positioned inset-0 layer; give interactive overlays their own pointer handling and stopPropagation. -
Styling resolves through
getClassMap(); the shell usesCardfrom@molecule/app-ui-svelte— wire a ClassMap bond first.