@kybernesis/cards-react 0.2.0 → 0.3.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.
- package/dist/AskView.d.ts +6 -0
- package/dist/AskView.js +37 -1
- package/package.json +3 -3
package/dist/AskView.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ import { type CardContext } from "./CardView.js";
|
|
|
10
10
|
* buttons and, when it takes words, a box to type them. The host sends the
|
|
11
11
|
* answer the way it answers anything (`onAnswer`); a pressed question then
|
|
12
12
|
* shows what was said, so it is still on record.
|
|
13
|
+
*
|
|
14
|
+
* In a shared conversation a question can be someone else's. `waitingOn`
|
|
15
|
+
* draws it without buttons, saying whose answer it waits for, and a question
|
|
16
|
+
* that carries `settled` shows how it ended for everyone who sees it.
|
|
13
17
|
*/
|
|
14
18
|
export interface AskReply {
|
|
15
19
|
optionId?: string;
|
|
@@ -26,6 +30,8 @@ export interface AskViewProps {
|
|
|
26
30
|
error?: string;
|
|
27
31
|
/** True while an answer is on its way. */
|
|
28
32
|
sending?: boolean;
|
|
33
|
+
/** Someone else's question: drawn without buttons, waiting on this name. */
|
|
34
|
+
waitingOn?: string;
|
|
29
35
|
onAnswer(reply: AskReply): void;
|
|
30
36
|
}
|
|
31
37
|
export declare function AskView(props: AskViewProps): ReactNode;
|
package/dist/AskView.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { cardTitle, formAnswer, isKnownCard, money } from "@kybernesis/cards";
|
|
2
|
+
import { cardTitle, formAnswer, isKnownCard, money, settledLabel, settledLine } from "@kybernesis/cards";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { ApprovalBody, CardView } from "./CardView.js";
|
|
5
5
|
function host(url) {
|
|
@@ -78,9 +78,45 @@ function outcome(reply) {
|
|
|
78
78
|
return { label: /changes/i.test(reply.label) ? "Sent back" : "Declined", good: false };
|
|
79
79
|
return { label: reply.optionId === "approve" || reply.optionId === "approved" ? "Approved" : "Answered", good: true };
|
|
80
80
|
}
|
|
81
|
+
function askTitle(ask) {
|
|
82
|
+
const card = ask.card && isKnownCard(ask.card) ? ask.card : undefined;
|
|
83
|
+
if (card?.card === "approval")
|
|
84
|
+
return cardTitle(card) ?? card.data.action;
|
|
85
|
+
if (card?.card === "form")
|
|
86
|
+
return card.title ?? "A few details";
|
|
87
|
+
if (ask.spend)
|
|
88
|
+
return "Purchase approval";
|
|
89
|
+
return ask.text.split("\n")[0].slice(0, 120) || "Question";
|
|
90
|
+
}
|
|
91
|
+
/** What the question asks, without anything to press: the email, the amount, or the sentence. */
|
|
92
|
+
function AskBody({ ask }) {
|
|
93
|
+
const card = ask.card && isKnownCard(ask.card) ? ask.card : undefined;
|
|
94
|
+
if (card?.card === "approval")
|
|
95
|
+
return _jsx(ApprovalBody, { data: card.data });
|
|
96
|
+
if (ask.spend) {
|
|
97
|
+
const s = ask.spend;
|
|
98
|
+
return (_jsxs("div", { className: "kask__amount", children: [_jsx("span", { className: "kask__total", children: money(s.amount, s.currency) }), _jsxs("span", { className: "kask__note", children: ["at ", s.merchant ?? (s.merchant_url ? host(s.merchant_url) : "a merchant")] })] }));
|
|
99
|
+
}
|
|
100
|
+
return ask.text ? _jsx("div", { className: "kask__text", children: ask.text }) : null;
|
|
101
|
+
}
|
|
102
|
+
/** A question answered or let go, as everyone in the conversation sees it. */
|
|
103
|
+
function Settled({ ask }) {
|
|
104
|
+
const outcome = ask.settled.outcome;
|
|
105
|
+
const good = outcome === "approved" || outcome === "answered";
|
|
106
|
+
const card = ask.card && isKnownCard(ask.card) ? ask.card : undefined;
|
|
107
|
+
return (_jsxs("div", { className: "kcard kask is-done", children: [_jsxs("div", { className: "kcard__head", children: [_jsx("span", { className: "kcard__title", children: askTitle(ask) }), _jsx("span", { className: `kpill${good ? " is-good" : ""}`, children: settledLabel(ask) })] }), card?.card === "approval" && card.data.subject ? _jsx("div", { className: "kcard__text", children: card.data.subject }) : null, _jsx("div", { className: "kask__note", children: settledLine(ask) })] }));
|
|
108
|
+
}
|
|
109
|
+
/** Someone else's question, open: what it asks, and whose answer it waits for. */
|
|
110
|
+
function Waiting({ ask, name }) {
|
|
111
|
+
return (_jsxs("div", { className: "kcard kask", children: [_jsxs("div", { className: "kcard__head", children: [_jsx("span", { className: "kcard__title", children: askTitle(ask) }), _jsxs("span", { className: "kpill", children: ["Waiting on ", name] })] }), _jsx(AskBody, { ask: ask })] }));
|
|
112
|
+
}
|
|
81
113
|
export function AskView(props) {
|
|
82
114
|
const { ask, ctx, answered } = props;
|
|
83
115
|
const card = ask.card && isKnownCard(ask.card) ? ask.card : undefined;
|
|
116
|
+
if (ask.settled)
|
|
117
|
+
return _jsx(Settled, { ask: ask });
|
|
118
|
+
if (props.waitingOn && !answered)
|
|
119
|
+
return _jsx(Waiting, { ask: ask, name: props.waitingOn });
|
|
84
120
|
if (card?.card === "approval") {
|
|
85
121
|
const title = cardTitle(card) ?? card.data.action;
|
|
86
122
|
if (answered) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kybernesis/cards-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React components that draw Kybernesis cards: one frame and one body per card type, themed by CSS variables, with the host's own way to open links, artifacts and files.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"test": "node --test \"test/**/*.test.mjs\""
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@kybernesis/cards": "^0.
|
|
34
|
+
"@kybernesis/cards": "^0.6.0",
|
|
35
35
|
"react": ">=18"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kybernesis/cards": "^0.
|
|
38
|
+
"@kybernesis/cards": "^0.6.0",
|
|
39
39
|
"@types/node": "^24.0.0",
|
|
40
40
|
"@types/react": "^19.0.0",
|
|
41
41
|
"react": "^19.0.0",
|