@processdynamics/components 0.1.8 → 0.1.10
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 +1 -0
- package/dist/index.cjs +215 -0
- package/dist/index.d.cts +124 -3
- package/dist/index.d.ts +124 -3
- package/dist/index.js +213 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -201,6 +201,7 @@ The packages the components import are declared as `peerDependencies` in `packag
|
|
|
201
201
|
- `class-variance-authority` for button variants
|
|
202
202
|
- `cn` for class merging
|
|
203
203
|
- `sonner` for the toaster
|
|
204
|
+
- `next` for the footer navigation's links and current path
|
|
204
205
|
|
|
205
206
|
They are also dev dependencies here so Storybook and the tests can run.
|
|
206
207
|
|
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,8 @@ var index_exports = {};
|
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
DatePicker: () => DatePicker,
|
|
35
35
|
DebouncedInput: () => DebouncedInput,
|
|
36
|
+
DocumentScanner: () => DocumentScanner,
|
|
37
|
+
FooterNavigation: () => FooterNavigation,
|
|
36
38
|
JobCard: () => JobCard,
|
|
37
39
|
PullToRefreshArea: () => PullToRefreshArea,
|
|
38
40
|
Toaster: () => Toaster2,
|
|
@@ -935,10 +937,223 @@ function PullToRefreshArea({
|
|
|
935
937
|
children
|
|
936
938
|
] });
|
|
937
939
|
}
|
|
940
|
+
|
|
941
|
+
// src/components/documentScanner/DocumentScanner.tsx
|
|
942
|
+
var import_react5 = require("react");
|
|
943
|
+
var import_lucide_react5 = require("lucide-react");
|
|
944
|
+
|
|
945
|
+
// src/components/documentScanner/DocumentScannerPages.tsx
|
|
946
|
+
var import_lucide_react4 = require("lucide-react");
|
|
947
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
948
|
+
function DocumentScannerPages({
|
|
949
|
+
pages,
|
|
950
|
+
isLocked,
|
|
951
|
+
removeLabel,
|
|
952
|
+
formatPageCount,
|
|
953
|
+
onRemovePage
|
|
954
|
+
}) {
|
|
955
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("ul", { className: "flex w-full snap-x snap-mandatory gap-3 overflow-x-auto", children: pages.map((page, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
956
|
+
"li",
|
|
957
|
+
{
|
|
958
|
+
className: "relative w-full shrink-0 snap-center overflow-hidden rounded-lg border-2 border-dashed border-border",
|
|
959
|
+
children: [
|
|
960
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
961
|
+
"img",
|
|
962
|
+
{
|
|
963
|
+
src: page.src,
|
|
964
|
+
alt: page.alt ?? `Page ${index + 1}`,
|
|
965
|
+
className: "w-full",
|
|
966
|
+
loading: "lazy"
|
|
967
|
+
}
|
|
968
|
+
),
|
|
969
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "absolute top-3 left-3 rounded bg-primary px-2 py-1 text-xs font-bold text-primary-foreground", children: formatPageCount(index + 1, pages.length) }),
|
|
970
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
971
|
+
Button,
|
|
972
|
+
{
|
|
973
|
+
type: "button",
|
|
974
|
+
variant: "secondary",
|
|
975
|
+
size: "icon-sm",
|
|
976
|
+
className: "absolute top-3 right-3 rounded-full shadow-sm",
|
|
977
|
+
"aria-label": `${removeLabel} ${index + 1}`,
|
|
978
|
+
disabled: isLocked,
|
|
979
|
+
onClick: () => onRemovePage(page.id),
|
|
980
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react4.XIcon, {})
|
|
981
|
+
}
|
|
982
|
+
)
|
|
983
|
+
]
|
|
984
|
+
},
|
|
985
|
+
page.id
|
|
986
|
+
)) });
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// src/components/documentScanner/DocumentScannerResult.tsx
|
|
990
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
991
|
+
function DocumentScannerResult({
|
|
992
|
+
status,
|
|
993
|
+
messages
|
|
994
|
+
}) {
|
|
995
|
+
const isError = status === "error";
|
|
996
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
997
|
+
"div",
|
|
998
|
+
{
|
|
999
|
+
role: isError ? "alert" : "status",
|
|
1000
|
+
className: (0, import_cn6.cn)(
|
|
1001
|
+
"rounded-lg border px-3 py-3 text-sm",
|
|
1002
|
+
isError ? "border-destructive/30 bg-destructive/10 text-destructive" : "border-primary/30 bg-primary/10 text-foreground"
|
|
1003
|
+
),
|
|
1004
|
+
children: messages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("p", { className: index === 0 ? "mb-1 font-semibold" : void 0, children: message }, index))
|
|
1005
|
+
}
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// src/components/documentScanner/DocumentScanner.tsx
|
|
1010
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1011
|
+
var DEFAULT_LABELS = {
|
|
1012
|
+
title: "Scan document",
|
|
1013
|
+
hint: "Photograph the pages, then scan",
|
|
1014
|
+
emptyPrompt: "Tap to photograph the document",
|
|
1015
|
+
emptyHint: "Add several pages one at a time",
|
|
1016
|
+
addPage: "Add page",
|
|
1017
|
+
scan: "Scan",
|
|
1018
|
+
rescan: "Rescan",
|
|
1019
|
+
scanning: "Scanning...",
|
|
1020
|
+
removePage: "Remove page",
|
|
1021
|
+
pageCount: (pageNumber, pageTotal) => `Page ${pageNumber} of ${pageTotal}`
|
|
1022
|
+
};
|
|
1023
|
+
function DocumentScanner({
|
|
1024
|
+
pages,
|
|
1025
|
+
isScanning = false,
|
|
1026
|
+
status = "idle",
|
|
1027
|
+
messages = [],
|
|
1028
|
+
onAddFiles,
|
|
1029
|
+
onRemovePage,
|
|
1030
|
+
onScan,
|
|
1031
|
+
labels,
|
|
1032
|
+
accept = "image/*",
|
|
1033
|
+
capture = "environment",
|
|
1034
|
+
isDisabled = false,
|
|
1035
|
+
className
|
|
1036
|
+
}) {
|
|
1037
|
+
const fileInputRef = (0, import_react5.useRef)(null);
|
|
1038
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
1039
|
+
const isLocked = isScanning || isDisabled;
|
|
1040
|
+
const hasPages = pages.length > 0;
|
|
1041
|
+
const shouldShowResult = status !== "idle" && messages.length > 0;
|
|
1042
|
+
const openFilePicker = () => fileInputRef.current?.click();
|
|
1043
|
+
const handleFilesChosen = (event) => {
|
|
1044
|
+
const chosenFiles = Array.from(event.target.files ?? []);
|
|
1045
|
+
event.target.value = "";
|
|
1046
|
+
if (chosenFiles.length > 0) onAddFiles(chosenFiles);
|
|
1047
|
+
};
|
|
1048
|
+
const scanLabel = isScanning ? text.scanning : status === "idle" ? text.scan : text.rescan;
|
|
1049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: (0, import_cn6.cn)("flex flex-col gap-3", className), children: [
|
|
1050
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("p", { className: "text-xs font-semibold tracking-wider text-muted-foreground uppercase", children: [
|
|
1051
|
+
text.title,
|
|
1052
|
+
" \u2014 ",
|
|
1053
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "font-normal normal-case", children: text.hint })
|
|
1054
|
+
] }),
|
|
1055
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1056
|
+
"input",
|
|
1057
|
+
{
|
|
1058
|
+
ref: fileInputRef,
|
|
1059
|
+
type: "file",
|
|
1060
|
+
multiple: true,
|
|
1061
|
+
accept,
|
|
1062
|
+
capture,
|
|
1063
|
+
className: "hidden",
|
|
1064
|
+
tabIndex: -1,
|
|
1065
|
+
"aria-hidden": "true",
|
|
1066
|
+
"data-slot": "document-scanner-input",
|
|
1067
|
+
onChange: handleFilesChosen
|
|
1068
|
+
}
|
|
1069
|
+
),
|
|
1070
|
+
hasPages ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
1071
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1072
|
+
DocumentScannerPages,
|
|
1073
|
+
{
|
|
1074
|
+
pages,
|
|
1075
|
+
isLocked,
|
|
1076
|
+
removeLabel: text.removePage,
|
|
1077
|
+
formatPageCount: text.pageCount,
|
|
1078
|
+
onRemovePage
|
|
1079
|
+
}
|
|
1080
|
+
),
|
|
1081
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex gap-2", children: [
|
|
1082
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
1083
|
+
Button,
|
|
1084
|
+
{
|
|
1085
|
+
type: "button",
|
|
1086
|
+
variant: "outline",
|
|
1087
|
+
className: "h-10 flex-1 border-dashed",
|
|
1088
|
+
disabled: isLocked,
|
|
1089
|
+
onClick: openFilePicker,
|
|
1090
|
+
children: [
|
|
1091
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react5.CameraIcon, {}),
|
|
1092
|
+
text.addPage
|
|
1093
|
+
]
|
|
1094
|
+
}
|
|
1095
|
+
),
|
|
1096
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
1097
|
+
Button,
|
|
1098
|
+
{
|
|
1099
|
+
type: "button",
|
|
1100
|
+
className: "h-10 flex-1",
|
|
1101
|
+
disabled: isLocked,
|
|
1102
|
+
onClick: onScan,
|
|
1103
|
+
children: [
|
|
1104
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react5.ScanLineIcon, {}),
|
|
1105
|
+
scanLabel
|
|
1106
|
+
]
|
|
1107
|
+
}
|
|
1108
|
+
)
|
|
1109
|
+
] }),
|
|
1110
|
+
shouldShowResult && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DocumentScannerResult, { status, messages })
|
|
1111
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
1112
|
+
"button",
|
|
1113
|
+
{
|
|
1114
|
+
type: "button",
|
|
1115
|
+
disabled: isLocked,
|
|
1116
|
+
onClick: openFilePicker,
|
|
1117
|
+
className: "flex w-full flex-col items-center gap-2 rounded-lg border-2 border-dashed border-border bg-muted/40 py-8 text-sm text-muted-foreground transition-colors hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",
|
|
1118
|
+
children: [
|
|
1119
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react5.CameraIcon, { className: "size-8" }),
|
|
1120
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "font-medium text-foreground", children: text.emptyPrompt }),
|
|
1121
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "text-xs", children: text.emptyHint })
|
|
1122
|
+
]
|
|
1123
|
+
}
|
|
1124
|
+
)
|
|
1125
|
+
] });
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// src/components/footerNavigation/FooterNavigation.tsx
|
|
1129
|
+
var import_link = __toESM(require("next/link"), 1);
|
|
1130
|
+
var import_navigation = require("next/navigation");
|
|
1131
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1132
|
+
function FooterNavigation({ onClick, navItems }) {
|
|
1133
|
+
const pathname = (0, import_navigation.usePathname)();
|
|
1134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("nav", { className: "flex border-t border-gray-200 bg-white shrink-0", children: navItems.map(({ href, icon, label }) => {
|
|
1135
|
+
const isActive = pathname === href;
|
|
1136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
1137
|
+
import_link.default,
|
|
1138
|
+
{
|
|
1139
|
+
href,
|
|
1140
|
+
onClick,
|
|
1141
|
+
className: `flex-1 px-1 py-2.5 flex flex-col items-center gap-0.5 border-none bg-transparent cursor-pointer text-[10px] font-medium border-t-2 transition-colors ${isActive ? "text-primary border-t-primary" : "text-gray-500 border-t-transparent"}`,
|
|
1142
|
+
children: [
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "text-xl leading-none", children: icon }),
|
|
1144
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { children: label })
|
|
1145
|
+
]
|
|
1146
|
+
},
|
|
1147
|
+
href
|
|
1148
|
+
);
|
|
1149
|
+
}) });
|
|
1150
|
+
}
|
|
938
1151
|
// Annotate the CommonJS export names for ESM import in node:
|
|
939
1152
|
0 && (module.exports = {
|
|
940
1153
|
DatePicker,
|
|
941
1154
|
DebouncedInput,
|
|
1155
|
+
DocumentScanner,
|
|
1156
|
+
FooterNavigation,
|
|
942
1157
|
JobCard,
|
|
943
1158
|
PullToRefreshArea,
|
|
944
1159
|
Toaster,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties } from 'react';
|
|
2
|
+
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties, MouseEventHandler } from 'react';
|
|
3
3
|
import { ToasterProps as ToasterProps$1 } from 'sonner';
|
|
4
4
|
export { toast } from 'sonner';
|
|
5
5
|
|
|
@@ -305,5 +305,126 @@ interface PullToRefreshAreaProps {
|
|
|
305
305
|
*/
|
|
306
306
|
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
/** Whether the last scan has not run yet, worked, or failed. */
|
|
309
|
+
type DocumentScannerStatus = "idle" | "success" | "error";
|
|
310
|
+
/** One staged page of the document. */
|
|
311
|
+
interface DocumentScannerPage {
|
|
312
|
+
/** A stable id for the page, passed back to `onRemovePage`. */
|
|
313
|
+
id: string;
|
|
314
|
+
/** The image address to show. A local preview address works. */
|
|
315
|
+
src: string;
|
|
316
|
+
/** Text for screen readers. Defaults to "Page" and its number. */
|
|
317
|
+
alt?: string;
|
|
318
|
+
}
|
|
319
|
+
/** Every piece of text the component shows, so an app can reword or translate it. */
|
|
320
|
+
interface DocumentScannerLabels {
|
|
321
|
+
/** The heading above the scanner. */
|
|
322
|
+
title: string;
|
|
323
|
+
/** The line next to the heading saying what a scan does. */
|
|
324
|
+
hint: string;
|
|
325
|
+
/** The main text of the empty state's photo button. */
|
|
326
|
+
emptyPrompt: string;
|
|
327
|
+
/** The smaller line under the empty state's prompt. */
|
|
328
|
+
emptyHint: string;
|
|
329
|
+
/** The button that adds another page. */
|
|
330
|
+
addPage: string;
|
|
331
|
+
/** The scan button before any scan has run. */
|
|
332
|
+
scan: string;
|
|
333
|
+
/** The scan button once a scan has run. */
|
|
334
|
+
rescan: string;
|
|
335
|
+
/** The scan button while a scan is running. */
|
|
336
|
+
scanning: string;
|
|
337
|
+
/** The start of each remove button's name. The page number follows it. */
|
|
338
|
+
removePage: string;
|
|
339
|
+
/** Builds the "Page 1 of 3" badge on each page. */
|
|
340
|
+
pageCount: (pageNumber: number, pageTotal: number) => string;
|
|
341
|
+
}
|
|
342
|
+
interface DocumentScannerProps {
|
|
343
|
+
/**
|
|
344
|
+
* The pages staged so far, in order. Controlled: the component only shows
|
|
345
|
+
* them, so add and remove them from `onAddFiles` and `onRemovePage`, or
|
|
346
|
+
* nothing will change on screen.
|
|
347
|
+
*/
|
|
348
|
+
pages: DocumentScannerPage[];
|
|
349
|
+
/**
|
|
350
|
+
* True while a scan is running. The scan, add and remove buttons are
|
|
351
|
+
* disabled and the scan button says "Scanning...". Defaults to false.
|
|
352
|
+
*/
|
|
353
|
+
isScanning?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* How the last scan went. Defaults to "idle", which shows no result and
|
|
356
|
+
* labels the scan button "Scan". "success" and "error" show the result
|
|
357
|
+
* panel (when there are messages) and label the button "Rescan".
|
|
358
|
+
*/
|
|
359
|
+
status?: DocumentScannerStatus;
|
|
360
|
+
/**
|
|
361
|
+
* The lines to show in the result panel. The first is the headline and the
|
|
362
|
+
* rest are detail. The panel is hidden when this is empty or the status is
|
|
363
|
+
* "idle". Defaults to none.
|
|
364
|
+
*/
|
|
365
|
+
messages?: string[];
|
|
366
|
+
/**
|
|
367
|
+
* Called with the images the person chose, from the camera or the file
|
|
368
|
+
* picker. The component does not read, resize or upload them: do that here
|
|
369
|
+
* and add the result to `pages`. Never called with an empty list.
|
|
370
|
+
*/
|
|
371
|
+
onAddFiles: (files: File[]) => void;
|
|
372
|
+
/** Called with the id of the page whose remove button was pressed. */
|
|
373
|
+
onRemovePage: (pageId: string) => void;
|
|
374
|
+
/**
|
|
375
|
+
* Called when the scan button is pressed. What a scan does is up to the app:
|
|
376
|
+
* the component makes no network call and holds no keys. Set `isScanning`
|
|
377
|
+
* while it runs and `status` and `messages` when it finishes.
|
|
378
|
+
*/
|
|
379
|
+
onScan: () => void;
|
|
380
|
+
/** Reword any text. Anything left out keeps its default. */
|
|
381
|
+
labels?: Partial<DocumentScannerLabels>;
|
|
382
|
+
/**
|
|
383
|
+
* The kinds of file the picker offers. Defaults to "image/*".
|
|
384
|
+
*/
|
|
385
|
+
accept?: string;
|
|
386
|
+
/**
|
|
387
|
+
* Which camera a phone opens straight away: "environment" is the rear one.
|
|
388
|
+
* Defaults to "environment". Pass `false` for the normal file picker, which
|
|
389
|
+
* also lets the person choose a saved photo. Desktop browsers ignore it.
|
|
390
|
+
*/
|
|
391
|
+
capture?: "environment" | "user" | false;
|
|
392
|
+
/** Disables every control, for when the form around it is locked. Defaults to false. */
|
|
393
|
+
isDisabled?: boolean;
|
|
394
|
+
/** Extra classes for the outer element. */
|
|
395
|
+
className?: string;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Stages photos of a document and asks the app to scan them.
|
|
399
|
+
*
|
|
400
|
+
* It is a screen part only. It keeps no state of its own about the pages or
|
|
401
|
+
* the scan, makes no network calls and holds no keys, so the app decides how
|
|
402
|
+
* images are stored and what does the reading. That also keeps it safe to use
|
|
403
|
+
* in the browser: anything passed to it ends up in the page.
|
|
404
|
+
*/
|
|
405
|
+
declare function DocumentScanner({ pages, isScanning, status, messages, onAddFiles, onRemovePage, onScan, labels, accept, capture, isDisabled, className, }: DocumentScannerProps): react.JSX.Element;
|
|
406
|
+
|
|
407
|
+
/** One tab in the footer navigation. */
|
|
408
|
+
type FooterNavigationItem = {
|
|
409
|
+
/** Where the tab links to. The tab is active when this matches the current path exactly. */
|
|
410
|
+
href: string;
|
|
411
|
+
/** What shows above the label: an emoji or text, or any element such as an icon. */
|
|
412
|
+
icon: string | ReactNode;
|
|
413
|
+
/** The tab's text, shown under the icon. */
|
|
414
|
+
label: string;
|
|
415
|
+
};
|
|
416
|
+
interface FooterNavigationProps {
|
|
417
|
+
/** The tabs, in the order they show. Each `href` should be unique, because it is the React key. */
|
|
418
|
+
navItems: FooterNavigationItem[];
|
|
419
|
+
/** Called when any tab is clicked, before the navigation happens. Not controlled: the link still navigates. */
|
|
420
|
+
onClick: MouseEventHandler<HTMLAnchorElement>;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* A row of equal-width tabs for the foot of a phone-sized screen. The tab whose
|
|
424
|
+
* `href` matches the current path is highlighted with the primary colour.
|
|
425
|
+
* It reads the path from the Next router, so it must render inside a Next app.
|
|
426
|
+
*/
|
|
427
|
+
declare function FooterNavigation({ onClick, navItems }: FooterNavigationProps): react.JSX.Element;
|
|
428
|
+
|
|
429
|
+
export { DatePicker, DebouncedInput, DocumentScanner, FooterNavigation, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
430
|
+
export type { DebouncedInputProps, DocumentScannerLabels, DocumentScannerPage, DocumentScannerProps, DocumentScannerStatus, FooterNavigationItem, FooterNavigationProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties } from 'react';
|
|
2
|
+
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties, MouseEventHandler } from 'react';
|
|
3
3
|
import { ToasterProps as ToasterProps$1 } from 'sonner';
|
|
4
4
|
export { toast } from 'sonner';
|
|
5
5
|
|
|
@@ -305,5 +305,126 @@ interface PullToRefreshAreaProps {
|
|
|
305
305
|
*/
|
|
306
306
|
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
/** Whether the last scan has not run yet, worked, or failed. */
|
|
309
|
+
type DocumentScannerStatus = "idle" | "success" | "error";
|
|
310
|
+
/** One staged page of the document. */
|
|
311
|
+
interface DocumentScannerPage {
|
|
312
|
+
/** A stable id for the page, passed back to `onRemovePage`. */
|
|
313
|
+
id: string;
|
|
314
|
+
/** The image address to show. A local preview address works. */
|
|
315
|
+
src: string;
|
|
316
|
+
/** Text for screen readers. Defaults to "Page" and its number. */
|
|
317
|
+
alt?: string;
|
|
318
|
+
}
|
|
319
|
+
/** Every piece of text the component shows, so an app can reword or translate it. */
|
|
320
|
+
interface DocumentScannerLabels {
|
|
321
|
+
/** The heading above the scanner. */
|
|
322
|
+
title: string;
|
|
323
|
+
/** The line next to the heading saying what a scan does. */
|
|
324
|
+
hint: string;
|
|
325
|
+
/** The main text of the empty state's photo button. */
|
|
326
|
+
emptyPrompt: string;
|
|
327
|
+
/** The smaller line under the empty state's prompt. */
|
|
328
|
+
emptyHint: string;
|
|
329
|
+
/** The button that adds another page. */
|
|
330
|
+
addPage: string;
|
|
331
|
+
/** The scan button before any scan has run. */
|
|
332
|
+
scan: string;
|
|
333
|
+
/** The scan button once a scan has run. */
|
|
334
|
+
rescan: string;
|
|
335
|
+
/** The scan button while a scan is running. */
|
|
336
|
+
scanning: string;
|
|
337
|
+
/** The start of each remove button's name. The page number follows it. */
|
|
338
|
+
removePage: string;
|
|
339
|
+
/** Builds the "Page 1 of 3" badge on each page. */
|
|
340
|
+
pageCount: (pageNumber: number, pageTotal: number) => string;
|
|
341
|
+
}
|
|
342
|
+
interface DocumentScannerProps {
|
|
343
|
+
/**
|
|
344
|
+
* The pages staged so far, in order. Controlled: the component only shows
|
|
345
|
+
* them, so add and remove them from `onAddFiles` and `onRemovePage`, or
|
|
346
|
+
* nothing will change on screen.
|
|
347
|
+
*/
|
|
348
|
+
pages: DocumentScannerPage[];
|
|
349
|
+
/**
|
|
350
|
+
* True while a scan is running. The scan, add and remove buttons are
|
|
351
|
+
* disabled and the scan button says "Scanning...". Defaults to false.
|
|
352
|
+
*/
|
|
353
|
+
isScanning?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* How the last scan went. Defaults to "idle", which shows no result and
|
|
356
|
+
* labels the scan button "Scan". "success" and "error" show the result
|
|
357
|
+
* panel (when there are messages) and label the button "Rescan".
|
|
358
|
+
*/
|
|
359
|
+
status?: DocumentScannerStatus;
|
|
360
|
+
/**
|
|
361
|
+
* The lines to show in the result panel. The first is the headline and the
|
|
362
|
+
* rest are detail. The panel is hidden when this is empty or the status is
|
|
363
|
+
* "idle". Defaults to none.
|
|
364
|
+
*/
|
|
365
|
+
messages?: string[];
|
|
366
|
+
/**
|
|
367
|
+
* Called with the images the person chose, from the camera or the file
|
|
368
|
+
* picker. The component does not read, resize or upload them: do that here
|
|
369
|
+
* and add the result to `pages`. Never called with an empty list.
|
|
370
|
+
*/
|
|
371
|
+
onAddFiles: (files: File[]) => void;
|
|
372
|
+
/** Called with the id of the page whose remove button was pressed. */
|
|
373
|
+
onRemovePage: (pageId: string) => void;
|
|
374
|
+
/**
|
|
375
|
+
* Called when the scan button is pressed. What a scan does is up to the app:
|
|
376
|
+
* the component makes no network call and holds no keys. Set `isScanning`
|
|
377
|
+
* while it runs and `status` and `messages` when it finishes.
|
|
378
|
+
*/
|
|
379
|
+
onScan: () => void;
|
|
380
|
+
/** Reword any text. Anything left out keeps its default. */
|
|
381
|
+
labels?: Partial<DocumentScannerLabels>;
|
|
382
|
+
/**
|
|
383
|
+
* The kinds of file the picker offers. Defaults to "image/*".
|
|
384
|
+
*/
|
|
385
|
+
accept?: string;
|
|
386
|
+
/**
|
|
387
|
+
* Which camera a phone opens straight away: "environment" is the rear one.
|
|
388
|
+
* Defaults to "environment". Pass `false` for the normal file picker, which
|
|
389
|
+
* also lets the person choose a saved photo. Desktop browsers ignore it.
|
|
390
|
+
*/
|
|
391
|
+
capture?: "environment" | "user" | false;
|
|
392
|
+
/** Disables every control, for when the form around it is locked. Defaults to false. */
|
|
393
|
+
isDisabled?: boolean;
|
|
394
|
+
/** Extra classes for the outer element. */
|
|
395
|
+
className?: string;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Stages photos of a document and asks the app to scan them.
|
|
399
|
+
*
|
|
400
|
+
* It is a screen part only. It keeps no state of its own about the pages or
|
|
401
|
+
* the scan, makes no network calls and holds no keys, so the app decides how
|
|
402
|
+
* images are stored and what does the reading. That also keeps it safe to use
|
|
403
|
+
* in the browser: anything passed to it ends up in the page.
|
|
404
|
+
*/
|
|
405
|
+
declare function DocumentScanner({ pages, isScanning, status, messages, onAddFiles, onRemovePage, onScan, labels, accept, capture, isDisabled, className, }: DocumentScannerProps): react.JSX.Element;
|
|
406
|
+
|
|
407
|
+
/** One tab in the footer navigation. */
|
|
408
|
+
type FooterNavigationItem = {
|
|
409
|
+
/** Where the tab links to. The tab is active when this matches the current path exactly. */
|
|
410
|
+
href: string;
|
|
411
|
+
/** What shows above the label: an emoji or text, or any element such as an icon. */
|
|
412
|
+
icon: string | ReactNode;
|
|
413
|
+
/** The tab's text, shown under the icon. */
|
|
414
|
+
label: string;
|
|
415
|
+
};
|
|
416
|
+
interface FooterNavigationProps {
|
|
417
|
+
/** The tabs, in the order they show. Each `href` should be unique, because it is the React key. */
|
|
418
|
+
navItems: FooterNavigationItem[];
|
|
419
|
+
/** Called when any tab is clicked, before the navigation happens. Not controlled: the link still navigates. */
|
|
420
|
+
onClick: MouseEventHandler<HTMLAnchorElement>;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* A row of equal-width tabs for the foot of a phone-sized screen. The tab whose
|
|
424
|
+
* `href` matches the current path is highlighted with the primary colour.
|
|
425
|
+
* It reads the path from the Next router, so it must render inside a Next app.
|
|
426
|
+
*/
|
|
427
|
+
declare function FooterNavigation({ onClick, navItems }: FooterNavigationProps): react.JSX.Element;
|
|
428
|
+
|
|
429
|
+
export { DatePicker, DebouncedInput, DocumentScanner, FooterNavigation, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
430
|
+
export type { DebouncedInputProps, DocumentScannerLabels, DocumentScannerPage, DocumentScannerProps, DocumentScannerStatus, FooterNavigationItem, FooterNavigationProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.js
CHANGED
|
@@ -901,9 +901,222 @@ function PullToRefreshArea({
|
|
|
901
901
|
children
|
|
902
902
|
] });
|
|
903
903
|
}
|
|
904
|
+
|
|
905
|
+
// src/components/documentScanner/DocumentScanner.tsx
|
|
906
|
+
import { useRef as useRef5 } from "react";
|
|
907
|
+
import { CameraIcon, ScanLineIcon } from "lucide-react";
|
|
908
|
+
|
|
909
|
+
// src/components/documentScanner/DocumentScannerPages.tsx
|
|
910
|
+
import { XIcon } from "lucide-react";
|
|
911
|
+
import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
912
|
+
function DocumentScannerPages({
|
|
913
|
+
pages,
|
|
914
|
+
isLocked,
|
|
915
|
+
removeLabel,
|
|
916
|
+
formatPageCount,
|
|
917
|
+
onRemovePage
|
|
918
|
+
}) {
|
|
919
|
+
return /* @__PURE__ */ jsx14("ul", { className: "flex w-full snap-x snap-mandatory gap-3 overflow-x-auto", children: pages.map((page, index) => /* @__PURE__ */ jsxs7(
|
|
920
|
+
"li",
|
|
921
|
+
{
|
|
922
|
+
className: "relative w-full shrink-0 snap-center overflow-hidden rounded-lg border-2 border-dashed border-border",
|
|
923
|
+
children: [
|
|
924
|
+
/* @__PURE__ */ jsx14(
|
|
925
|
+
"img",
|
|
926
|
+
{
|
|
927
|
+
src: page.src,
|
|
928
|
+
alt: page.alt ?? `Page ${index + 1}`,
|
|
929
|
+
className: "w-full",
|
|
930
|
+
loading: "lazy"
|
|
931
|
+
}
|
|
932
|
+
),
|
|
933
|
+
/* @__PURE__ */ jsx14("span", { className: "absolute top-3 left-3 rounded bg-primary px-2 py-1 text-xs font-bold text-primary-foreground", children: formatPageCount(index + 1, pages.length) }),
|
|
934
|
+
/* @__PURE__ */ jsx14(
|
|
935
|
+
Button,
|
|
936
|
+
{
|
|
937
|
+
type: "button",
|
|
938
|
+
variant: "secondary",
|
|
939
|
+
size: "icon-sm",
|
|
940
|
+
className: "absolute top-3 right-3 rounded-full shadow-sm",
|
|
941
|
+
"aria-label": `${removeLabel} ${index + 1}`,
|
|
942
|
+
disabled: isLocked,
|
|
943
|
+
onClick: () => onRemovePage(page.id),
|
|
944
|
+
children: /* @__PURE__ */ jsx14(XIcon, {})
|
|
945
|
+
}
|
|
946
|
+
)
|
|
947
|
+
]
|
|
948
|
+
},
|
|
949
|
+
page.id
|
|
950
|
+
)) });
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// src/components/documentScanner/DocumentScannerResult.tsx
|
|
954
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
955
|
+
function DocumentScannerResult({
|
|
956
|
+
status,
|
|
957
|
+
messages
|
|
958
|
+
}) {
|
|
959
|
+
const isError = status === "error";
|
|
960
|
+
return /* @__PURE__ */ jsx15(
|
|
961
|
+
"div",
|
|
962
|
+
{
|
|
963
|
+
role: isError ? "alert" : "status",
|
|
964
|
+
className: cn6(
|
|
965
|
+
"rounded-lg border px-3 py-3 text-sm",
|
|
966
|
+
isError ? "border-destructive/30 bg-destructive/10 text-destructive" : "border-primary/30 bg-primary/10 text-foreground"
|
|
967
|
+
),
|
|
968
|
+
children: messages.map((message, index) => /* @__PURE__ */ jsx15("p", { className: index === 0 ? "mb-1 font-semibold" : void 0, children: message }, index))
|
|
969
|
+
}
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// src/components/documentScanner/DocumentScanner.tsx
|
|
974
|
+
import { Fragment, jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
975
|
+
var DEFAULT_LABELS = {
|
|
976
|
+
title: "Scan document",
|
|
977
|
+
hint: "Photograph the pages, then scan",
|
|
978
|
+
emptyPrompt: "Tap to photograph the document",
|
|
979
|
+
emptyHint: "Add several pages one at a time",
|
|
980
|
+
addPage: "Add page",
|
|
981
|
+
scan: "Scan",
|
|
982
|
+
rescan: "Rescan",
|
|
983
|
+
scanning: "Scanning...",
|
|
984
|
+
removePage: "Remove page",
|
|
985
|
+
pageCount: (pageNumber, pageTotal) => `Page ${pageNumber} of ${pageTotal}`
|
|
986
|
+
};
|
|
987
|
+
function DocumentScanner({
|
|
988
|
+
pages,
|
|
989
|
+
isScanning = false,
|
|
990
|
+
status = "idle",
|
|
991
|
+
messages = [],
|
|
992
|
+
onAddFiles,
|
|
993
|
+
onRemovePage,
|
|
994
|
+
onScan,
|
|
995
|
+
labels,
|
|
996
|
+
accept = "image/*",
|
|
997
|
+
capture = "environment",
|
|
998
|
+
isDisabled = false,
|
|
999
|
+
className
|
|
1000
|
+
}) {
|
|
1001
|
+
const fileInputRef = useRef5(null);
|
|
1002
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
1003
|
+
const isLocked = isScanning || isDisabled;
|
|
1004
|
+
const hasPages = pages.length > 0;
|
|
1005
|
+
const shouldShowResult = status !== "idle" && messages.length > 0;
|
|
1006
|
+
const openFilePicker = () => fileInputRef.current?.click();
|
|
1007
|
+
const handleFilesChosen = (event) => {
|
|
1008
|
+
const chosenFiles = Array.from(event.target.files ?? []);
|
|
1009
|
+
event.target.value = "";
|
|
1010
|
+
if (chosenFiles.length > 0) onAddFiles(chosenFiles);
|
|
1011
|
+
};
|
|
1012
|
+
const scanLabel = isScanning ? text.scanning : status === "idle" ? text.scan : text.rescan;
|
|
1013
|
+
return /* @__PURE__ */ jsxs8("div", { className: cn6("flex flex-col gap-3", className), children: [
|
|
1014
|
+
/* @__PURE__ */ jsxs8("p", { className: "text-xs font-semibold tracking-wider text-muted-foreground uppercase", children: [
|
|
1015
|
+
text.title,
|
|
1016
|
+
" \u2014 ",
|
|
1017
|
+
/* @__PURE__ */ jsx16("span", { className: "font-normal normal-case", children: text.hint })
|
|
1018
|
+
] }),
|
|
1019
|
+
/* @__PURE__ */ jsx16(
|
|
1020
|
+
"input",
|
|
1021
|
+
{
|
|
1022
|
+
ref: fileInputRef,
|
|
1023
|
+
type: "file",
|
|
1024
|
+
multiple: true,
|
|
1025
|
+
accept,
|
|
1026
|
+
capture,
|
|
1027
|
+
className: "hidden",
|
|
1028
|
+
tabIndex: -1,
|
|
1029
|
+
"aria-hidden": "true",
|
|
1030
|
+
"data-slot": "document-scanner-input",
|
|
1031
|
+
onChange: handleFilesChosen
|
|
1032
|
+
}
|
|
1033
|
+
),
|
|
1034
|
+
hasPages ? /* @__PURE__ */ jsxs8(Fragment, { children: [
|
|
1035
|
+
/* @__PURE__ */ jsx16(
|
|
1036
|
+
DocumentScannerPages,
|
|
1037
|
+
{
|
|
1038
|
+
pages,
|
|
1039
|
+
isLocked,
|
|
1040
|
+
removeLabel: text.removePage,
|
|
1041
|
+
formatPageCount: text.pageCount,
|
|
1042
|
+
onRemovePage
|
|
1043
|
+
}
|
|
1044
|
+
),
|
|
1045
|
+
/* @__PURE__ */ jsxs8("div", { className: "flex gap-2", children: [
|
|
1046
|
+
/* @__PURE__ */ jsxs8(
|
|
1047
|
+
Button,
|
|
1048
|
+
{
|
|
1049
|
+
type: "button",
|
|
1050
|
+
variant: "outline",
|
|
1051
|
+
className: "h-10 flex-1 border-dashed",
|
|
1052
|
+
disabled: isLocked,
|
|
1053
|
+
onClick: openFilePicker,
|
|
1054
|
+
children: [
|
|
1055
|
+
/* @__PURE__ */ jsx16(CameraIcon, {}),
|
|
1056
|
+
text.addPage
|
|
1057
|
+
]
|
|
1058
|
+
}
|
|
1059
|
+
),
|
|
1060
|
+
/* @__PURE__ */ jsxs8(
|
|
1061
|
+
Button,
|
|
1062
|
+
{
|
|
1063
|
+
type: "button",
|
|
1064
|
+
className: "h-10 flex-1",
|
|
1065
|
+
disabled: isLocked,
|
|
1066
|
+
onClick: onScan,
|
|
1067
|
+
children: [
|
|
1068
|
+
/* @__PURE__ */ jsx16(ScanLineIcon, {}),
|
|
1069
|
+
scanLabel
|
|
1070
|
+
]
|
|
1071
|
+
}
|
|
1072
|
+
)
|
|
1073
|
+
] }),
|
|
1074
|
+
shouldShowResult && /* @__PURE__ */ jsx16(DocumentScannerResult, { status, messages })
|
|
1075
|
+
] }) : /* @__PURE__ */ jsxs8(
|
|
1076
|
+
"button",
|
|
1077
|
+
{
|
|
1078
|
+
type: "button",
|
|
1079
|
+
disabled: isLocked,
|
|
1080
|
+
onClick: openFilePicker,
|
|
1081
|
+
className: "flex w-full flex-col items-center gap-2 rounded-lg border-2 border-dashed border-border bg-muted/40 py-8 text-sm text-muted-foreground transition-colors hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",
|
|
1082
|
+
children: [
|
|
1083
|
+
/* @__PURE__ */ jsx16(CameraIcon, { className: "size-8" }),
|
|
1084
|
+
/* @__PURE__ */ jsx16("span", { className: "font-medium text-foreground", children: text.emptyPrompt }),
|
|
1085
|
+
/* @__PURE__ */ jsx16("span", { className: "text-xs", children: text.emptyHint })
|
|
1086
|
+
]
|
|
1087
|
+
}
|
|
1088
|
+
)
|
|
1089
|
+
] });
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// src/components/footerNavigation/FooterNavigation.tsx
|
|
1093
|
+
import Link from "next/link";
|
|
1094
|
+
import { usePathname } from "next/navigation";
|
|
1095
|
+
import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1096
|
+
function FooterNavigation({ onClick, navItems }) {
|
|
1097
|
+
const pathname = usePathname();
|
|
1098
|
+
return /* @__PURE__ */ jsx17("nav", { className: "flex border-t border-gray-200 bg-white shrink-0", children: navItems.map(({ href, icon, label }) => {
|
|
1099
|
+
const isActive = pathname === href;
|
|
1100
|
+
return /* @__PURE__ */ jsxs9(
|
|
1101
|
+
Link,
|
|
1102
|
+
{
|
|
1103
|
+
href,
|
|
1104
|
+
onClick,
|
|
1105
|
+
className: `flex-1 px-1 py-2.5 flex flex-col items-center gap-0.5 border-none bg-transparent cursor-pointer text-[10px] font-medium border-t-2 transition-colors ${isActive ? "text-primary border-t-primary" : "text-gray-500 border-t-transparent"}`,
|
|
1106
|
+
children: [
|
|
1107
|
+
/* @__PURE__ */ jsx17("span", { className: "text-xl leading-none", children: icon }),
|
|
1108
|
+
/* @__PURE__ */ jsx17("span", { children: label })
|
|
1109
|
+
]
|
|
1110
|
+
},
|
|
1111
|
+
href
|
|
1112
|
+
);
|
|
1113
|
+
}) });
|
|
1114
|
+
}
|
|
904
1115
|
export {
|
|
905
1116
|
DatePicker,
|
|
906
1117
|
DebouncedInput,
|
|
1118
|
+
DocumentScanner,
|
|
1119
|
+
FooterNavigation,
|
|
907
1120
|
JobCard,
|
|
908
1121
|
PullToRefreshArea,
|
|
909
1122
|
Toaster2 as Toaster,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@processdynamics/components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Process Dynamics React component library, built on shadcn (Radix) and Tailwind CSS v4.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"cn": "^0.5.2",
|
|
100
100
|
"date-fns": "^4.4.0",
|
|
101
101
|
"lucide-react": "^1.66.0",
|
|
102
|
+
"next": "^16.0.0",
|
|
102
103
|
"radix-ui": "^1.8.1",
|
|
103
104
|
"react": "^19.0.0",
|
|
104
105
|
"react-day-picker": "^10.0.2",
|