@voyantjs/extras-ui 0.19.0 → 0.20.0
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.
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CatalogSearchHit } from "@voyantjs/catalog-react";
|
|
2
|
+
export interface ExtraCatalogCardProps {
|
|
3
|
+
hit: CatalogSearchHit;
|
|
4
|
+
onClick?: (hit: CatalogSearchHit) => void;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Search-result card for an extras hit (sub-line-item add-ons attached
|
|
9
|
+
* to bookings). Reads: `name`, `category`, `priceCents`, `currency`,
|
|
10
|
+
* `unit` (per_person | per_booking | per_night), `tags`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ExtraCatalogCard({ hit, onClick, className }: ExtraCatalogCardProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=extra-catalog-card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extra-catalog-card.d.ts","sourceRoot":"","sources":["../../src/components/extra-catalog-card.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAK/D,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,gBAAgB,CAAA;IACrB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAA;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,qBAAqB,2CA4DlF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Badge } from "@voyantjs/ui/components/badge";
|
|
4
|
+
import { Card, CardContent } from "@voyantjs/ui/components/card";
|
|
5
|
+
import { cn } from "@voyantjs/ui/lib/utils";
|
|
6
|
+
/**
|
|
7
|
+
* Search-result card for an extras hit (sub-line-item add-ons attached
|
|
8
|
+
* to bookings). Reads: `name`, `category`, `priceCents`, `currency`,
|
|
9
|
+
* `unit` (per_person | per_booking | per_night), `tags`.
|
|
10
|
+
*/
|
|
11
|
+
export function ExtraCatalogCard({ hit, onClick, className }) {
|
|
12
|
+
const f = hit.document.fields;
|
|
13
|
+
const name = stringOr(f.name, "Untitled extra");
|
|
14
|
+
const category = stringOr(f.category, null);
|
|
15
|
+
const unit = stringOr(f.unit, null);
|
|
16
|
+
const status = stringOr(f.status, null);
|
|
17
|
+
const tags = stringArray(f.tags);
|
|
18
|
+
const price = numberOr(f.priceCents, null);
|
|
19
|
+
const currency = stringOr(f.currency ?? f.sellCurrency, null);
|
|
20
|
+
const priceLabel = price != null && currency
|
|
21
|
+
? new Intl.NumberFormat(undefined, {
|
|
22
|
+
style: "currency",
|
|
23
|
+
currency,
|
|
24
|
+
maximumFractionDigits: 2,
|
|
25
|
+
}).format(price / 100)
|
|
26
|
+
: null;
|
|
27
|
+
return (_jsx(Card, { className: cn("h-full cursor-pointer transition-colors hover:border-primary/40", onClick == null && "cursor-default", className), onClick: onClick ? () => onClick(hit) : undefined, children: _jsxs(CardContent, { className: "flex h-full flex-col gap-2 p-4", children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx("h3", { className: "line-clamp-2 font-medium text-sm", children: name }), status && (_jsx(Badge, { variant: status === "active" ? "default" : "secondary", className: "shrink-0", children: status }))] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2 text-muted-foreground text-xs", children: [category && _jsx("span", { children: category }), priceLabel && (_jsxs("span", { className: "ml-auto font-medium text-foreground", children: [priceLabel, unit && (_jsxs("span", { className: "ml-1 text-muted-foreground", children: ["/ ", unit.replace(/_/g, " ")] }))] }))] }), tags.length > 0 && (_jsx("div", { className: "mt-auto flex flex-wrap gap-1", children: tags.slice(0, 4).map((tag) => (_jsx(Badge, { variant: "outline", className: "text-[10px]", children: tag }, tag))) }))] }) }));
|
|
28
|
+
}
|
|
29
|
+
function stringOr(value, fallback) {
|
|
30
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
31
|
+
}
|
|
32
|
+
function numberOr(value, fallback) {
|
|
33
|
+
if (typeof value === "number")
|
|
34
|
+
return value;
|
|
35
|
+
if (typeof value === "string") {
|
|
36
|
+
const n = Number(value);
|
|
37
|
+
return Number.isFinite(n) ? n : fallback;
|
|
38
|
+
}
|
|
39
|
+
return fallback;
|
|
40
|
+
}
|
|
41
|
+
function stringArray(value) {
|
|
42
|
+
if (!Array.isArray(value))
|
|
43
|
+
return [];
|
|
44
|
+
return value.filter((v) => typeof v === "string" && v.length > 0);
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/extras-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"import": "./dist/index.js",
|
|
16
16
|
"default": "./dist/index.js"
|
|
17
17
|
},
|
|
18
|
+
"./styles.css": {
|
|
19
|
+
"default": "./src/styles.css"
|
|
20
|
+
},
|
|
18
21
|
"./i18n": {
|
|
19
22
|
"types": "./dist/i18n/index.d.ts",
|
|
20
23
|
"import": "./dist/i18n/index.js",
|
|
@@ -43,12 +46,13 @@
|
|
|
43
46
|
"react-dom": "^19.0.0",
|
|
44
47
|
"react-hook-form": "^7.60.0",
|
|
45
48
|
"zod": "^4.3.6",
|
|
46
|
-
"@voyantjs/
|
|
47
|
-
"@voyantjs/
|
|
48
|
-
"@voyantjs/
|
|
49
|
+
"@voyantjs/catalog-react": "0.20.0",
|
|
50
|
+
"@voyantjs/extras-react": "0.20.0",
|
|
51
|
+
"@voyantjs/products-react": "0.20.0",
|
|
52
|
+
"@voyantjs/ui": "0.20.0"
|
|
49
53
|
},
|
|
50
54
|
"dependencies": {
|
|
51
|
-
"@voyantjs/i18n": "0.
|
|
55
|
+
"@voyantjs/i18n": "0.20.0"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
54
58
|
"@tanstack/react-query": "^5.96.2",
|
|
@@ -62,14 +66,16 @@
|
|
|
62
66
|
"typescript": "^6.0.2",
|
|
63
67
|
"vitest": "^4.1.2",
|
|
64
68
|
"zod": "^4.3.6",
|
|
65
|
-
"@voyantjs/
|
|
66
|
-
"@voyantjs/
|
|
67
|
-
"@voyantjs/
|
|
68
|
-
"@voyantjs/
|
|
69
|
-
"@voyantjs/ui": "0.
|
|
69
|
+
"@voyantjs/catalog-react": "0.20.0",
|
|
70
|
+
"@voyantjs/extras-react": "0.20.0",
|
|
71
|
+
"@voyantjs/i18n": "0.20.0",
|
|
72
|
+
"@voyantjs/products-react": "0.20.0",
|
|
73
|
+
"@voyantjs/ui": "0.20.0",
|
|
74
|
+
"@voyantjs/voyant-typescript-config": "0.1.0"
|
|
70
75
|
},
|
|
71
76
|
"files": [
|
|
72
|
-
"dist"
|
|
77
|
+
"dist",
|
|
78
|
+
"src/styles.css"
|
|
73
79
|
],
|
|
74
80
|
"publishConfig": {
|
|
75
81
|
"access": "public"
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* Tailwind v4 source-detection helper.
|
|
2
|
+
*
|
|
3
|
+
* Templates that consume this package should `@import` this CSS so Tailwind
|
|
4
|
+
* scans these component files for utility classes:
|
|
5
|
+
*
|
|
6
|
+
* @import "@voyantjs/<domain>-ui/styles.css";
|
|
7
|
+
*
|
|
8
|
+
* Without it, classes that only appear inside this package (e.g. data-attr
|
|
9
|
+
* variants on primitives) won't be compiled into the final bundle.
|
|
10
|
+
*/
|
|
11
|
+
@source "./components/**/*.{ts,tsx}";
|