@molecule/app-listing-card-react 4.0.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -22
- package/dist/ListingCard.d.ts +16 -1
- package/dist/ListingCard.d.ts.map +1 -1
- package/dist/ListingCard.js +27 -4
- package/dist/ListingCardBody.d.ts +1 -1
- package/dist/ListingCardBody.d.ts.map +1 -1
- package/dist/ListingCardBody.js +5 -1
- package/dist/ListingCardMedia.d.ts +1 -1
- package/dist/ListingCardMedia.d.ts.map +1 -1
- package/dist/ListingCardMedia.js +4 -1
- package/dist/index.d.ts +22 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-24T08:58:59.282Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-listing-card-react
|
|
@@ -12,7 +12,7 @@ React product / property / listing card primitives.
|
|
|
12
12
|
|
|
13
13
|
Exports:
|
|
14
14
|
|
|
15
|
-
- `<ListingCard>` — outer Card shell. Props: `children`, `onClick?`,
|
|
15
|
+
- `<ListingCard>` — outer Card shell. Props: `children`, `toggle?`, `onClick?`,
|
|
16
16
|
`className?`, `dataMolId?`.
|
|
17
17
|
- `<ListingCardMedia>` — top image slot. Props: `src?`, `alt?`, `children?`
|
|
18
18
|
(custom media node), `aspect?` (`'1/1' | '4/3' | '16/9' | '3/2'`, default
|
|
@@ -36,24 +36,27 @@ import {
|
|
|
36
36
|
ListingCard,
|
|
37
37
|
ListingCardMedia,
|
|
38
38
|
ListingCardBody,
|
|
39
|
-
ListingCardActions,
|
|
40
39
|
ListingGrid,
|
|
41
40
|
} from '@molecule/app-listing-card-react'
|
|
42
41
|
|
|
43
42
|
;<ListingGrid columns={3}>
|
|
44
|
-
<ListingCard
|
|
43
|
+
<ListingCard
|
|
44
|
+
key={item.id}
|
|
45
|
+
onClick={() => navigate(`/listings/${item.id}`)}
|
|
46
|
+
toggle={{
|
|
47
|
+
value: { pressed: item.recommended, count: item.recommendations },
|
|
48
|
+
commit: async (desired) => {
|
|
49
|
+
const saved = await setRecommendation(item.id, desired)
|
|
50
|
+
return { pressed: saved.recommended, count: saved.recommendations }
|
|
51
|
+
},
|
|
52
|
+
activeLabel: t('listing.undoRecommendation', undefined, {
|
|
53
|
+
defaultValue: 'Undo recommendation',
|
|
54
|
+
}),
|
|
55
|
+
inactiveLabel: t('listing.recommend', undefined, { defaultValue: 'Recommend' }),
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
45
58
|
<ListingCardMedia src={item.imageUrl} aspect="4/3" alt={item.name} />
|
|
46
59
|
<ListingCardBody title={item.name} subtitle={item.location} price={`$${item.price}/night`} />
|
|
47
|
-
<ListingCardActions>
|
|
48
|
-
<button
|
|
49
|
-
onClick={(e) => {
|
|
50
|
-
e.stopPropagation()
|
|
51
|
-
saveListing(item.id)
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
Save
|
|
55
|
-
</button>
|
|
56
|
-
</ListingCardActions>
|
|
57
60
|
</ListingCard>
|
|
58
61
|
</ListingGrid>
|
|
59
62
|
```
|
|
@@ -73,6 +76,21 @@ npm install -D @types/react
|
|
|
73
76
|
|
|
74
77
|
### Interfaces
|
|
75
78
|
|
|
79
|
+
#### `ListingCardToggleProps`
|
|
80
|
+
|
|
81
|
+
A server-backed card action with the total number of people who selected it.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface ListingCardToggleProps extends Omit<OptimisticToggleButtonProps, 'value' | 'commit'> {
|
|
85
|
+
/** The pressed state and count from the same loaded record. */
|
|
86
|
+
value: { pressed: boolean; count: number }
|
|
87
|
+
/** Saves the desired state and returns the server-confirmed state and count together. */
|
|
88
|
+
commit: (desired: boolean) => Promise<ListingCardToggleProps['value']>
|
|
89
|
+
/** Overrides the button's default `data-mol-id`. */
|
|
90
|
+
dataMolId?: string
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
76
94
|
#### `ListingCardProps`
|
|
77
95
|
|
|
78
96
|
Props for {@link ListingCard}.
|
|
@@ -81,6 +99,8 @@ Props for {@link ListingCard}.
|
|
|
81
99
|
interface ListingCardProps {
|
|
82
100
|
/** Slots — usually `<ListingCardMedia>` + `<ListingCardBody>` + `<ListingCardActions>`. */
|
|
83
101
|
children: ReactNode
|
|
102
|
+
/** Renders a counted native toggle after the content, outside any links in the content. */
|
|
103
|
+
toggle?: ListingCardToggleProps
|
|
84
104
|
/**
|
|
85
105
|
* Called on any click on the card — including clicks inside
|
|
86
106
|
* `<ListingCardActions>`, which bubble into it unless the action handler
|
|
@@ -174,7 +194,13 @@ Use for product tiles, property cards, course cards, listings,
|
|
|
174
194
|
and similar content-card layouts.
|
|
175
195
|
|
|
176
196
|
```typescript
|
|
177
|
-
function ListingCard({
|
|
197
|
+
function ListingCard({
|
|
198
|
+
children,
|
|
199
|
+
toggle,
|
|
200
|
+
onClick,
|
|
201
|
+
className,
|
|
202
|
+
dataMolId,
|
|
203
|
+
}: ListingCardProps): JSX.Element
|
|
178
204
|
```
|
|
179
205
|
|
|
180
206
|
- `props` — Component props (see {@link ListingCardProps}).
|
|
@@ -200,9 +226,9 @@ Body of a `<ListingCard>` — title / subtitle / price / meta rows stacked.
|
|
|
200
226
|
```typescript
|
|
201
227
|
function ListingCardBody({
|
|
202
228
|
title,
|
|
203
|
-
subtitle,
|
|
204
|
-
price,
|
|
205
|
-
meta,
|
|
229
|
+
subtitle: subtitleProp,
|
|
230
|
+
price: priceProp,
|
|
231
|
+
meta: metaProp,
|
|
206
232
|
className,
|
|
207
233
|
}: ListingCardBodyProps): JSX.Element
|
|
208
234
|
```
|
|
@@ -218,9 +244,9 @@ inline style so apps get consistent card sizing without custom CSS.
|
|
|
218
244
|
function ListingCardMedia({
|
|
219
245
|
src,
|
|
220
246
|
alt,
|
|
221
|
-
children,
|
|
247
|
+
children: childrenProp,
|
|
222
248
|
aspect = '4/3',
|
|
223
|
-
overlay,
|
|
249
|
+
overlay: overlayProp,
|
|
224
250
|
className,
|
|
225
251
|
}: ListingCardMediaProps): JSX.Element
|
|
226
252
|
```
|
|
@@ -250,7 +276,7 @@ function ListingGrid({
|
|
|
250
276
|
|
|
251
277
|
Peer dependencies:
|
|
252
278
|
|
|
253
|
-
- `@molecule/app-react` ^4.
|
|
279
|
+
- `@molecule/app-react` ^4.13.0
|
|
254
280
|
- `@molecule/app-ui` ^1.0.1
|
|
255
281
|
- `@molecule/app-ui-react` ^4.0.0
|
|
256
282
|
- `react` ^18.0.0 || ^19.0.0
|
|
@@ -264,7 +290,13 @@ Peer dependencies:
|
|
|
264
290
|
|
|
265
291
|
- `ListingCard.onClick` is attached to the WHOLE card — clicks on buttons inside
|
|
266
292
|
`<ListingCardActions>` bubble into it. Call `e.stopPropagation()` in every
|
|
267
|
-
action handler
|
|
293
|
+
custom action handler or the card navigation fires too. The built-in
|
|
294
|
+
`toggle` handles that itself.
|
|
295
|
+
- Pass `toggle` for a server-backed action with a count, such as a vote or
|
|
296
|
+
endorsement. The card renders the button and count together, including zero.
|
|
297
|
+
Pass the loaded `{ pressed, count }` and return both saved fields from
|
|
298
|
+
`commit(desired)`. Keep the card mounted and keyed by record ID. Omit
|
|
299
|
+
`toggle` for cards without that action.
|
|
268
300
|
- `<ListingGrid columns={n}>` renders a responsive n-column grid (via `cm.grid`):
|
|
269
301
|
1 column on phones, stepping up to `n` at larger breakpoints, so listings
|
|
270
302
|
don't overflow on mobile. Override `className` for a fixed grid.
|
package/dist/ListingCard.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { JSX, ReactNode } from 'react';
|
|
2
|
+
import { type OptimisticToggleButtonProps } from '@molecule/app-ui-react';
|
|
3
|
+
/** A server-backed card action with the total number of people who selected it. */
|
|
4
|
+
export interface ListingCardToggleProps extends Omit<OptimisticToggleButtonProps, 'value' | 'commit'> {
|
|
5
|
+
/** The pressed state and count from the same loaded record. */
|
|
6
|
+
value: {
|
|
7
|
+
pressed: boolean;
|
|
8
|
+
count: number;
|
|
9
|
+
};
|
|
10
|
+
/** Saves the desired state and returns the server-confirmed state and count together. */
|
|
11
|
+
commit: (desired: boolean) => Promise<ListingCardToggleProps['value']>;
|
|
12
|
+
/** Overrides the button's default `data-mol-id`. */
|
|
13
|
+
dataMolId?: string;
|
|
14
|
+
}
|
|
2
15
|
/** Props for {@link ListingCard}. */
|
|
3
16
|
export interface ListingCardProps {
|
|
4
17
|
/** Slots — usually `<ListingCardMedia>` + `<ListingCardBody>` + `<ListingCardActions>`. */
|
|
5
18
|
children: ReactNode;
|
|
19
|
+
/** Renders a counted native toggle after the content, outside any links in the content. */
|
|
20
|
+
toggle?: ListingCardToggleProps;
|
|
6
21
|
/**
|
|
7
22
|
* Called on any click on the card — including clicks inside
|
|
8
23
|
* `<ListingCardActions>`, which bubble into it unless the action handler
|
|
@@ -39,5 +54,5 @@ export interface ListingCardProps {
|
|
|
39
54
|
* </ListingCard>
|
|
40
55
|
* ```
|
|
41
56
|
*/
|
|
42
|
-
export declare function ListingCard({ children, onClick, className, dataMolId, }: ListingCardProps): JSX.Element;
|
|
57
|
+
export declare function ListingCard({ children, toggle, onClick, className, dataMolId, }: ListingCardProps): JSX.Element;
|
|
43
58
|
//# sourceMappingURL=ListingCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListingCard.d.ts","sourceRoot":"","sources":["../src/ListingCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"ListingCard.d.ts","sourceRoot":"","sources":["../src/ListingCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAI3C,OAAO,EAAgB,KAAK,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AAIvF,mFAAmF;AACnF,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAClD,2BAA2B,EAC3B,OAAO,GAAG,QAAQ,CACnB;IACC,+DAA+D;IAC/D,KAAK,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1C,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAA;IACtE,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,QAAQ,EAAE,SAAS,CAAA;IACnB,2FAA2F;IAC3F,MAAM,CAAC,EAAE,sBAAsB,CAAA;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAgDD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,GACV,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAchC"}
|
package/dist/ListingCard.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useOptimisticValue } from '@molecule/app-react';
|
|
2
3
|
import { getClassMap } from '@molecule/app-ui';
|
|
3
|
-
import { Card } from '@molecule/app-ui-react';
|
|
4
|
+
import { Button, Card } from '@molecule/app-ui-react';
|
|
5
|
+
import { ListingCardActions } from './ListingCardActions.js';
|
|
6
|
+
/**
|
|
7
|
+
* Shows both fields of a card action and saves the person's latest selection.
|
|
8
|
+
*
|
|
9
|
+
* @param props - Loaded value, save function, labels and button props.
|
|
10
|
+
* @returns The card action row.
|
|
11
|
+
*/
|
|
12
|
+
function ListingCardToggle({ value, commit, onError, activeLabel, inactiveLabel, dataMolId = 'listing-card-toggle', variant, ...buttonProps }) {
|
|
13
|
+
const toggle = useOptimisticValue({
|
|
14
|
+
value,
|
|
15
|
+
commit: (next) => commit(next.pressed),
|
|
16
|
+
onError: (error) => onError?.(error),
|
|
17
|
+
});
|
|
18
|
+
const { pressed, count } = toggle.value;
|
|
19
|
+
return (_jsx(ListingCardActions, { children: _jsxs(Button, { "data-mol-id": dataMolId, ...buttonProps, type: "button", variant: variant ?? (pressed ? 'solid' : 'outline'), "aria-pressed": pressed, "aria-busy": toggle.pending, onClick: (event) => {
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
toggle.update((current) => ({
|
|
22
|
+
pressed: !current.pressed,
|
|
23
|
+
count: Math.max(0, current.count + (current.pressed ? -1 : 1)),
|
|
24
|
+
}));
|
|
25
|
+
}, children: [pressed ? activeLabel : inactiveLabel, " ", _jsx("span", { children: count })] }) }));
|
|
26
|
+
}
|
|
4
27
|
/**
|
|
5
28
|
* Product / property / listing card shell. Just a `<Card>` with vertical
|
|
6
29
|
* stacking of its children — typically `<ListingCardMedia>` +
|
|
@@ -26,7 +49,7 @@ import { Card } from '@molecule/app-ui-react';
|
|
|
26
49
|
* </ListingCard>
|
|
27
50
|
* ```
|
|
28
51
|
*/
|
|
29
|
-
export function ListingCard({ children, onClick, className, dataMolId, }) {
|
|
52
|
+
export function ListingCard({ children, toggle, onClick, className, dataMolId, }) {
|
|
30
53
|
const cm = getClassMap();
|
|
31
|
-
return (_jsx(Card, { "data-mol-id": dataMolId, onClick: onClick, className: cm.cn(onClick ? cm.cursorPointer : undefined, className), children:
|
|
54
|
+
return (_jsx(Card, { "data-mol-id": dataMolId, onClick: onClick, className: cm.cn(onClick ? cm.cursorPointer : undefined, className), children: _jsxs("div", { className: cm.stack(0), children: [children, toggle && _jsx(ListingCardToggle, { ...toggle })] }) }));
|
|
32
55
|
}
|
|
@@ -16,5 +16,5 @@ export interface ListingCardBodyProps {
|
|
|
16
16
|
* Body of a `<ListingCard>` — title / subtitle / price / meta rows stacked.
|
|
17
17
|
* @param props - Component props (see {@link ListingCardBodyProps}).
|
|
18
18
|
*/
|
|
19
|
-
export declare function ListingCardBody({ title, subtitle, price, meta, className, }: ListingCardBodyProps): JSX.Element;
|
|
19
|
+
export declare function ListingCardBody({ title, subtitle: subtitleProp, price: priceProp, meta: metaProp, className, }: ListingCardBodyProps): JSX.Element;
|
|
20
20
|
//# sourceMappingURL=ListingCardBody.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListingCardBody.d.ts","sourceRoot":"","sources":["../src/ListingCardBody.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"ListingCardBody.d.ts","sourceRoot":"","sources":["../src/ListingCardBody.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAK3C,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,4BAA4B;IAC5B,KAAK,EAAE,SAAS,CAAA;IAChB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,QAAQ,EACd,SAAS,GACV,EAAE,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAapC"}
|
package/dist/ListingCardBody.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { slot } from '@molecule/app-react/render';
|
|
2
3
|
import { getClassMap } from '@molecule/app-ui';
|
|
3
4
|
/**
|
|
4
5
|
* Body of a `<ListingCard>` — title / subtitle / price / meta rows stacked.
|
|
5
6
|
* @param props - Component props (see {@link ListingCardBodyProps}).
|
|
6
7
|
*/
|
|
7
|
-
export function ListingCardBody({ title, subtitle, price, meta, className, }) {
|
|
8
|
+
export function ListingCardBody({ title, subtitle: subtitleProp, price: priceProp, meta: metaProp, className, }) {
|
|
9
|
+
const subtitle = slot(subtitleProp);
|
|
10
|
+
const price = slot(priceProp);
|
|
11
|
+
const meta = slot(metaProp);
|
|
8
12
|
const cm = getClassMap();
|
|
9
13
|
return (_jsxs("div", { className: cm.cn(cm.stack(1), cm.sp('p', 3), className), children: [_jsx("h3", { className: cm.cn(cm.textSize('base'), cm.fontWeight('semibold')), children: title }), subtitle && _jsx("p", { className: cm.textSize('sm'), children: subtitle }), price && _jsx("p", { className: cm.cn(cm.textSize('lg'), cm.fontWeight('bold')), children: price }), meta && _jsx("div", { className: cm.flex({ align: 'center', gap: 'sm', wrap: 'wrap' }), children: meta })] }));
|
|
10
14
|
}
|
|
@@ -18,5 +18,5 @@ export interface ListingCardMediaProps {
|
|
|
18
18
|
* inline style so apps get consistent card sizing without custom CSS.
|
|
19
19
|
* @param props - Component props (see {@link ListingCardMediaProps}).
|
|
20
20
|
*/
|
|
21
|
-
export declare function ListingCardMedia({ src, alt, children, aspect, overlay, className, }: ListingCardMediaProps): JSX.Element;
|
|
21
|
+
export declare function ListingCardMedia({ src, alt, children: childrenProp, aspect, overlay: overlayProp, className, }: ListingCardMediaProps): JSX.Element;
|
|
22
22
|
//# sourceMappingURL=ListingCardMedia.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListingCardMedia.d.ts","sourceRoot":"","sources":["../src/ListingCardMedia.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"ListingCardMedia.d.ts","sourceRoot":"","sources":["../src/ListingCardMedia.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAK3C,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,uHAAuH;IACvH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAA;IACvC,qDAAqD;IACrD,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,GAAG,EACH,QAAQ,EAAE,YAAY,EACtB,MAAc,EACd,OAAO,EAAE,WAAW,EACpB,SAAS,GACV,EAAE,qBAAqB,GAAG,GAAG,CAAC,OAAO,CAoBrC"}
|
package/dist/ListingCardMedia.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { slot } from '@molecule/app-react/render';
|
|
2
3
|
import { getClassMap } from '@molecule/app-ui';
|
|
3
4
|
/**
|
|
4
5
|
* Media slot at the top of a `<ListingCard>`. Locks aspect ratio via
|
|
5
6
|
* inline style so apps get consistent card sizing without custom CSS.
|
|
6
7
|
* @param props - Component props (see {@link ListingCardMediaProps}).
|
|
7
8
|
*/
|
|
8
|
-
export function ListingCardMedia({ src, alt, children, aspect = '4/3', overlay, className, }) {
|
|
9
|
+
export function ListingCardMedia({ src, alt, children: childrenProp, aspect = '4/3', overlay: overlayProp, className, }) {
|
|
10
|
+
const children = slot(childrenProp);
|
|
11
|
+
const overlay = slot(overlayProp);
|
|
9
12
|
const cm = getClassMap();
|
|
10
13
|
return (_jsxs("div", { className: cm.cn(cm.position('relative'), className), style: { aspectRatio: aspect.replace('/', ' / ') }, children: [children ??
|
|
11
14
|
(src && (_jsx("img", { src: src, alt: alt ?? '', style: { width: '100%', height: '100%', objectFit: 'cover' } }))), overlay && _jsx("div", { className: cm.cn(cm.position('absolute'), cm.inset0), children: overlay })] }));
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* React product / property / listing card primitives.
|
|
3
3
|
*
|
|
4
4
|
* Exports:
|
|
5
|
-
* - `<ListingCard>` — outer Card shell. Props: `children`, `onClick?`,
|
|
5
|
+
* - `<ListingCard>` — outer Card shell. Props: `children`, `toggle?`, `onClick?`,
|
|
6
6
|
* `className?`, `dataMolId?`.
|
|
7
7
|
* - `<ListingCardMedia>` — top image slot. Props: `src?`, `alt?`, `children?`
|
|
8
8
|
* (custom media node), `aspect?` (`'1/1' | '4/3' | '16/9' | '3/2'`, default
|
|
@@ -18,7 +18,13 @@
|
|
|
18
18
|
* @remarks
|
|
19
19
|
* - `ListingCard.onClick` is attached to the WHOLE card — clicks on buttons inside
|
|
20
20
|
* `<ListingCardActions>` bubble into it. Call `e.stopPropagation()` in every
|
|
21
|
-
* action handler
|
|
21
|
+
* custom action handler or the card navigation fires too. The built-in
|
|
22
|
+
* `toggle` handles that itself.
|
|
23
|
+
* - Pass `toggle` for a server-backed action with a count, such as a vote or
|
|
24
|
+
* endorsement. The card renders the button and count together, including zero.
|
|
25
|
+
* Pass the loaded `{ pressed, count }` and return both saved fields from
|
|
26
|
+
* `commit(desired)`. Keep the card mounted and keyed by record ID. Omit
|
|
27
|
+
* `toggle` for cards without that action.
|
|
22
28
|
* - `<ListingGrid columns={n}>` renders a responsive n-column grid (via `cm.grid`):
|
|
23
29
|
* 1 column on phones, stepping up to `n` at larger breakpoints, so listings
|
|
24
30
|
* don't overflow on mobile. Override `className` for a fixed grid.
|
|
@@ -29,15 +35,24 @@
|
|
|
29
35
|
*
|
|
30
36
|
* @example
|
|
31
37
|
* ```tsx
|
|
32
|
-
* import { ListingCard, ListingCardMedia, ListingCardBody,
|
|
38
|
+
* import { ListingCard, ListingCardMedia, ListingCardBody, ListingGrid } from '@molecule/app-listing-card-react'
|
|
33
39
|
*
|
|
34
40
|
* <ListingGrid columns={3}>
|
|
35
|
-
* <ListingCard
|
|
41
|
+
* <ListingCard
|
|
42
|
+
* key={item.id}
|
|
43
|
+
* onClick={() => navigate(`/listings/${item.id}`)}
|
|
44
|
+
* toggle={{
|
|
45
|
+
* value: { pressed: item.recommended, count: item.recommendations },
|
|
46
|
+
* commit: async (desired) => {
|
|
47
|
+
* const saved = await setRecommendation(item.id, desired)
|
|
48
|
+
* return { pressed: saved.recommended, count: saved.recommendations }
|
|
49
|
+
* },
|
|
50
|
+
* activeLabel: t('listing.undoRecommendation', undefined, { defaultValue: 'Undo recommendation' }),
|
|
51
|
+
* inactiveLabel: t('listing.recommend', undefined, { defaultValue: 'Recommend' }),
|
|
52
|
+
* }}
|
|
53
|
+
* >
|
|
36
54
|
* <ListingCardMedia src={item.imageUrl} aspect="4/3" alt={item.name} />
|
|
37
55
|
* <ListingCardBody title={item.name} subtitle={item.location} price={`$${item.price}/night`} />
|
|
38
|
-
* <ListingCardActions>
|
|
39
|
-
* <button onClick={(e) => { e.stopPropagation(); saveListing(item.id) }}>Save</button>
|
|
40
|
-
* </ListingCardActions>
|
|
41
56
|
* </ListingCard>
|
|
42
57
|
* </ListingGrid>
|
|
43
58
|
* ```
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* React product / property / listing card primitives.
|
|
3
3
|
*
|
|
4
4
|
* Exports:
|
|
5
|
-
* - `<ListingCard>` — outer Card shell. Props: `children`, `onClick?`,
|
|
5
|
+
* - `<ListingCard>` — outer Card shell. Props: `children`, `toggle?`, `onClick?`,
|
|
6
6
|
* `className?`, `dataMolId?`.
|
|
7
7
|
* - `<ListingCardMedia>` — top image slot. Props: `src?`, `alt?`, `children?`
|
|
8
8
|
* (custom media node), `aspect?` (`'1/1' | '4/3' | '16/9' | '3/2'`, default
|
|
@@ -18,7 +18,13 @@
|
|
|
18
18
|
* @remarks
|
|
19
19
|
* - `ListingCard.onClick` is attached to the WHOLE card — clicks on buttons inside
|
|
20
20
|
* `<ListingCardActions>` bubble into it. Call `e.stopPropagation()` in every
|
|
21
|
-
* action handler
|
|
21
|
+
* custom action handler or the card navigation fires too. The built-in
|
|
22
|
+
* `toggle` handles that itself.
|
|
23
|
+
* - Pass `toggle` for a server-backed action with a count, such as a vote or
|
|
24
|
+
* endorsement. The card renders the button and count together, including zero.
|
|
25
|
+
* Pass the loaded `{ pressed, count }` and return both saved fields from
|
|
26
|
+
* `commit(desired)`. Keep the card mounted and keyed by record ID. Omit
|
|
27
|
+
* `toggle` for cards without that action.
|
|
22
28
|
* - `<ListingGrid columns={n}>` renders a responsive n-column grid (via `cm.grid`):
|
|
23
29
|
* 1 column on phones, stepping up to `n` at larger breakpoints, so listings
|
|
24
30
|
* don't overflow on mobile. Override `className` for a fixed grid.
|
|
@@ -29,15 +35,24 @@
|
|
|
29
35
|
*
|
|
30
36
|
* @example
|
|
31
37
|
* ```tsx
|
|
32
|
-
* import { ListingCard, ListingCardMedia, ListingCardBody,
|
|
38
|
+
* import { ListingCard, ListingCardMedia, ListingCardBody, ListingGrid } from '@molecule/app-listing-card-react'
|
|
33
39
|
*
|
|
34
40
|
* <ListingGrid columns={3}>
|
|
35
|
-
* <ListingCard
|
|
41
|
+
* <ListingCard
|
|
42
|
+
* key={item.id}
|
|
43
|
+
* onClick={() => navigate(`/listings/${item.id}`)}
|
|
44
|
+
* toggle={{
|
|
45
|
+
* value: { pressed: item.recommended, count: item.recommendations },
|
|
46
|
+
* commit: async (desired) => {
|
|
47
|
+
* const saved = await setRecommendation(item.id, desired)
|
|
48
|
+
* return { pressed: saved.recommended, count: saved.recommendations }
|
|
49
|
+
* },
|
|
50
|
+
* activeLabel: t('listing.undoRecommendation', undefined, { defaultValue: 'Undo recommendation' }),
|
|
51
|
+
* inactiveLabel: t('listing.recommend', undefined, { defaultValue: 'Recommend' }),
|
|
52
|
+
* }}
|
|
53
|
+
* >
|
|
36
54
|
* <ListingCardMedia src={item.imageUrl} aspect="4/3" alt={item.name} />
|
|
37
55
|
* <ListingCardBody title={item.name} subtitle={item.location} price={`$${item.price}/night`} />
|
|
38
|
-
* <ListingCardActions>
|
|
39
|
-
* <button onClick={(e) => { e.stopPropagation(); saveListing(item.id) }}>Save</button>
|
|
40
|
-
* </ListingCardActions>
|
|
41
56
|
* </ListingCard>
|
|
42
57
|
* </ListingGrid>
|
|
43
58
|
* ```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-listing-card-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "React listing/product-card primitives with media, body, actions slots",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-listing-card-react",
|
|
6
6
|
"type": "module",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"directory": "packages/app/features/listing-card-react"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@molecule/app-react": "^4.
|
|
36
|
+
"@molecule/app-react": "^4.13.0",
|
|
37
37
|
"@molecule/app-ui": "^1.0.1",
|
|
38
38
|
"@molecule/app-ui-react": "^4.0.0",
|
|
39
39
|
"react": "^18.0.0 || ^19.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@molecule/app-react": "4.
|
|
43
|
-
"@molecule/app-ui": "1.
|
|
44
|
-
"@molecule/app-ui-react": "4.
|
|
42
|
+
"@molecule/app-react": "4.13.0",
|
|
43
|
+
"@molecule/app-ui": "1.5.0",
|
|
44
|
+
"@molecule/app-ui-react": "4.3.2",
|
|
45
45
|
"@types/node": "26.6.5",
|
|
46
46
|
"@types/react": "19.3.0",
|
|
47
47
|
"@types/react-dom": "19.3.0",
|