@processdynamics/components 0.1.5 → 0.1.6

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/index.cjs CHANGED
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
  var index_exports = {};
33
33
  __export(index_exports, {
34
34
  DatePicker: () => DatePicker,
35
+ DebouncedInput: () => DebouncedInput,
35
36
  JobCard: () => JobCard
36
37
  });
37
38
  module.exports = __toCommonJS(index_exports);
@@ -423,15 +424,103 @@ var DatePicker = ({
423
424
  );
424
425
  };
425
426
 
427
+ // src/components/debounceInput/DebouncedInput.tsx
428
+ var import_react2 = require("react");
429
+
430
+ // src/lib/debounce.ts
431
+ function debounce(fn, delayMs) {
432
+ let timeout = null;
433
+ let latestArgs = null;
434
+ const run = () => {
435
+ const args = latestArgs;
436
+ timeout = null;
437
+ latestArgs = null;
438
+ if (args) fn(...args);
439
+ };
440
+ const debounced = (...args) => {
441
+ latestArgs = args;
442
+ if (timeout) clearTimeout(timeout);
443
+ timeout = setTimeout(run, delayMs);
444
+ };
445
+ debounced.cancel = () => {
446
+ if (timeout) clearTimeout(timeout);
447
+ timeout = null;
448
+ latestArgs = null;
449
+ };
450
+ debounced.flush = () => {
451
+ if (!timeout) return;
452
+ clearTimeout(timeout);
453
+ run();
454
+ };
455
+ return debounced;
456
+ }
457
+
458
+ // src/components/debounceInput/DebouncedInput.tsx
459
+ var import_jsx_runtime6 = require("react/jsx-runtime");
460
+ function DebouncedInput({
461
+ value,
462
+ onValueChange,
463
+ delay = 250,
464
+ onFocus,
465
+ onBlur,
466
+ ...inputProps
467
+ }) {
468
+ const [text, setText] = (0, import_react2.useState)(value);
469
+ const [isFocused, setIsFocused] = (0, import_react2.useState)(false);
470
+ const onValueChangeRef = (0, import_react2.useRef)(onValueChange);
471
+ (0, import_react2.useEffect)(() => {
472
+ onValueChangeRef.current = onValueChange;
473
+ });
474
+ const commitTextRef = (0, import_react2.useRef)(null);
475
+ (0, import_react2.useEffect)(() => {
476
+ const commitText = debounce(
477
+ (next) => onValueChangeRef.current(next),
478
+ delay
479
+ );
480
+ commitTextRef.current = commitText;
481
+ const flushWaitingText = () => commitText.flush();
482
+ document.addEventListener("pointerdown", flushWaitingText, true);
483
+ return () => {
484
+ document.removeEventListener("pointerdown", flushWaitingText, true);
485
+ commitText.flush();
486
+ commitTextRef.current = null;
487
+ };
488
+ }, [delay]);
489
+ if (!isFocused && text !== value) {
490
+ setText(value);
491
+ }
492
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
493
+ Input,
494
+ {
495
+ ...inputProps,
496
+ type: "text",
497
+ value: text,
498
+ onChange: (e) => {
499
+ setText(e.target.value);
500
+ commitTextRef.current?.(e.target.value);
501
+ },
502
+ onFocus: (e) => {
503
+ setIsFocused(true);
504
+ onFocus?.(e);
505
+ },
506
+ onBlur: (e) => {
507
+ commitTextRef.current?.flush();
508
+ setIsFocused(false);
509
+ onBlur?.(e);
510
+ }
511
+ }
512
+ );
513
+ }
514
+
426
515
  // src/components/ui/card.tsx
427
516
  var import_cn5 = require("cn");
428
- var import_jsx_runtime6 = require("react/jsx-runtime");
517
+ var import_jsx_runtime7 = require("react/jsx-runtime");
429
518
  function Card({
430
519
  className,
431
520
  size = "default",
432
521
  ...props
433
522
  }) {
434
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
523
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
435
524
  "div",
436
525
  {
437
526
  "data-slot": "card",
@@ -445,7 +534,7 @@ function Card({
445
534
  );
446
535
  }
447
536
  function CardContent({ className, ...props }) {
448
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
537
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
449
538
  "div",
450
539
  {
451
540
  "data-slot": "card-content",
@@ -459,14 +548,14 @@ function CardContent({ className, ...props }) {
459
548
  var import_cn6 = require("cn");
460
549
 
461
550
  // src/components/jobCard/JobCardBannerBar.tsx
462
- var import_jsx_runtime7 = require("react/jsx-runtime");
463
- var JobCardBannerBar = ({ banner }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "mt-3 flex items-center gap-2 rounded border border-blue-300 bg-blue-50 px-3 py-1.5 text-xs text-gray-600 shadow [&>svg]:h-4 [&>svg]:w-4", children: [
551
+ var import_jsx_runtime8 = require("react/jsx-runtime");
552
+ var JobCardBannerBar = ({ banner }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "mt-3 flex items-center gap-2 rounded border border-blue-300 bg-blue-50 px-3 py-1.5 text-xs text-gray-600 shadow [&>svg]:h-4 [&>svg]:w-4", children: [
464
553
  banner.icon,
465
554
  banner.label
466
555
  ] });
467
556
 
468
557
  // src/components/jobCard/JobCardParts.tsx
469
- var import_jsx_runtime8 = require("react/jsx-runtime");
558
+ var import_jsx_runtime9 = require("react/jsx-runtime");
470
559
  var DEFAULT_STAGE_COLOR = "#6b7280";
471
560
  var BADGE_COLOR_CLASSES = {
472
561
  gray: "bg-gray-300",
@@ -477,45 +566,45 @@ var BADGE_COLOR_CLASSES = {
477
566
  blue: "bg-blue-300",
478
567
  purple: "bg-purple-300"
479
568
  };
480
- var JobCardHeading = ({ title, stage, leadingContent }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex items-center gap-2 mb-1", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex justify-between w-full", children: [
481
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "flex items-center gap-2 font-bold text-base", children: [
569
+ var JobCardHeading = ({ title, stage, leadingContent }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex items-center gap-2 mb-1", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex justify-between w-full", children: [
570
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "flex items-center gap-2 font-bold text-base", children: [
482
571
  leadingContent,
483
572
  title
484
573
  ] }),
485
- stage && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-2 text-xs", children: [
486
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
574
+ stage && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex items-center gap-2 text-xs", children: [
575
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
487
576
  "span",
488
577
  {
489
578
  className: "w-2 h-2 rounded-full",
490
579
  style: { backgroundColor: stage.color ?? DEFAULT_STAGE_COLOR }
491
580
  }
492
581
  ),
493
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-gray-900", children: stage.label })
582
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-gray-900", children: stage.label })
494
583
  ] })
495
584
  ] }) });
496
- var JobCardDetails = ({ details }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex flex-col gap-1", children: details.map((detail, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "text-xs text-gray-500", children: detail }, `${index}-${detail}`)) });
497
- var JobCardCallouts = ({ callouts }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex justify-between w-full", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "text-xs my-1 w-full space-y-1", children: callouts.map((callout, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
585
+ var JobCardDetails = ({ details }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex flex-col gap-1", children: details.map((detail, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-xs text-gray-500", children: detail }, `${index}-${detail}`)) });
586
+ var JobCardCallouts = ({ callouts }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex justify-between w-full", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-xs my-1 w-full space-y-1", children: callouts.map((callout, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
498
587
  "div",
499
588
  {
500
589
  className: "flex gap-2 items-center border p-2 rounded bg-white shadow",
501
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: callout })
590
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: callout })
502
591
  },
503
592
  `${index}-${callout}`
504
593
  )) }) });
505
594
  var JobCardSummary = ({
506
595
  job,
507
596
  leadingContent
508
- }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "w-full", children: [
509
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(JobCardHeading, { title: job.title, stage: job.stage, leadingContent }),
510
- job.subtitle && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "text-[13px] text-gray-600 mb-1", children: job.subtitle }),
511
- job.details && job.details.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(JobCardDetails, { details: job.details }),
512
- job.description && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "text-sm text-gray-700 italic mt-1", children: job.description }),
513
- job.callouts && job.callouts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(JobCardCallouts, { callouts: job.callouts })
597
+ }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "w-full", children: [
598
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(JobCardHeading, { title: job.title, stage: job.stage, leadingContent }),
599
+ job.subtitle && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-[13px] text-gray-600 mb-1", children: job.subtitle }),
600
+ job.details && job.details.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(JobCardDetails, { details: job.details }),
601
+ job.description && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "text-sm text-gray-700 italic mt-1", children: job.description }),
602
+ job.callouts && job.callouts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(JobCardCallouts, { callouts: job.callouts })
514
603
  ] });
515
604
  var JobCardBadgeBlock = ({
516
605
  badge,
517
606
  hasPills
518
- }) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `flex pr-4 w-20 ${hasPills ? "border-r" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
607
+ }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: `flex pr-4 w-20 ${hasPills ? "border-r" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
519
608
  "span",
520
609
  {
521
610
  className: `flex items-center shadow border rounded px-4 py-1 text-center text-wrap ${BADGE_COLOR_CLASSES[badge.color]} ${hasPills ? "border-r" : ""}`,
@@ -524,7 +613,7 @@ var JobCardBadgeBlock = ({
524
613
  ) });
525
614
 
526
615
  // src/components/jobCard/JobCardPills.tsx
527
- var import_jsx_runtime9 = require("react/jsx-runtime");
616
+ var import_jsx_runtime10 = require("react/jsx-runtime");
528
617
  var PILL_BASE = "flex items-center gap-1 h-5 rounded-full text-center text-[10px] md:text-xs [&>svg]:w-3 [&>svg]:h-3";
529
618
  var PILL_TONE_CLASSES = {
530
619
  critical: "px-3 bg-red-500 text-white font-bold shadow-md shadow-red-900/70",
@@ -538,27 +627,27 @@ var PILL_TONE_CLASSES = {
538
627
  outline: "px-3 border border-gray-300 bg-white text-gray-600",
539
628
  dashed: "px-3 border border-dashed border-gray-400 bg-white text-gray-600"
540
629
  };
541
- var JobCardPillItem = ({ pill }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: `${PILL_BASE} ${PILL_TONE_CLASSES[pill.tone]}`, children: [
630
+ var JobCardPillItem = ({ pill }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: `${PILL_BASE} ${PILL_TONE_CLASSES[pill.tone]}`, children: [
542
631
  pill.icon,
543
632
  pill.label
544
633
  ] });
545
634
  var JobCardPillList = ({ pills }) => {
546
635
  const priorityPills = pills.filter((pill) => pill.priority);
547
636
  const otherPills = pills.filter((pill) => !pill.priority);
548
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex gap-2 flex-wrap", children: [
549
- priorityPills.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
637
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex gap-2 flex-wrap", children: [
638
+ priorityPills.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
550
639
  "div",
551
640
  {
552
641
  className: `flex gap-2 w-full ${otherPills.length > 0 ? "pb-2 border-b" : ""}`,
553
- children: priorityPills.map((pill) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(JobCardPillItem, { pill }, pill.label))
642
+ children: priorityPills.map((pill) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardPillItem, { pill }, pill.label))
554
643
  }
555
644
  ),
556
- otherPills.map((pill) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(JobCardPillItem, { pill }, pill.label))
645
+ otherPills.map((pill) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardPillItem, { pill }, pill.label))
557
646
  ] });
558
647
  };
559
648
 
560
649
  // src/components/jobCard/JobCard.tsx
561
- var import_jsx_runtime10 = require("react/jsx-runtime");
650
+ var import_jsx_runtime11 = require("react/jsx-runtime");
562
651
  var CARD_TONE_CLASSES = {
563
652
  success: "border-green-400 bg-green-50",
564
653
  warning: "border-orange-400 bg-orange-50",
@@ -574,7 +663,7 @@ var JobCard = ({
574
663
  className
575
664
  }) => {
576
665
  const hasPills = Boolean(job.pills && job.pills.length > 0);
577
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
666
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
578
667
  Card,
579
668
  {
580
669
  onClick,
@@ -588,14 +677,14 @@ var JobCard = ({
588
677
  CARD_TONE_CLASSES[job.tone ?? "neutral"],
589
678
  className
590
679
  ),
591
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(CardContent, { className: "p-3.5", children: [
592
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "flex justify-between items-start mb-2", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardSummary, { job, leadingContent }) }),
593
- (job.badge || hasPills) && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex gap-2 text-xs", children: [
594
- job.badge && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardBadgeBlock, { badge: job.badge, hasPills }),
595
- hasPills && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardPillList, { pills: job.pills ?? [] })
680
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(CardContent, { className: "p-3.5", children: [
681
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "flex justify-between items-start mb-2", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(JobCardSummary, { job, leadingContent }) }),
682
+ (job.badge || hasPills) && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex gap-2 text-xs", children: [
683
+ job.badge && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(JobCardBadgeBlock, { badge: job.badge, hasPills }),
684
+ hasPills && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(JobCardPillList, { pills: job.pills ?? [] })
596
685
  ] }),
597
- job.banner && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(JobCardBannerBar, { banner: job.banner }),
598
- action && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
686
+ job.banner && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(JobCardBannerBar, { banner: job.banner }),
687
+ action && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
599
688
  Button,
600
689
  {
601
690
  onClick: (event) => {
@@ -608,7 +697,7 @@ var JobCard = ({
608
697
  children: action.label
609
698
  }
610
699
  ),
611
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { children: expandedContent })
700
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children: expandedContent })
612
701
  ] })
613
702
  }
614
703
  );
@@ -616,5 +705,6 @@ var JobCard = ({
616
705
  // Annotate the CommonJS export names for ESM import in node:
617
706
  0 && (module.exports = {
618
707
  DatePicker,
708
+ DebouncedInput,
619
709
  JobCard
620
710
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
2
+ import { ComponentProps, FocusEventHandler, ReactNode } from 'react';
3
3
 
4
4
  interface IDatePicker {
5
5
  /**
@@ -38,6 +38,49 @@ interface IDatePicker {
38
38
  */
39
39
  declare const DatePicker: ({ onSelect, date, dateFormat, }: IDatePicker) => react.JSX.Element;
40
40
 
41
+ declare function Input({ className, type, ...props }: react.ComponentProps<"input">): react.JSX.Element;
42
+
43
+ interface DebouncedInputProps extends Omit<ComponentProps<typeof Input>, "type" | "value" | "defaultValue" | "onChange"> {
44
+ /**
45
+ * The text the owner holds. Controlled: the box shows what is typed at once,
46
+ * and follows this value when it changes from elsewhere (opening a saved job,
47
+ * resetting the form). While the box has focus, outside changes are ignored
48
+ * so they cannot overwrite characters typed since.
49
+ */
50
+ value: string;
51
+ /**
52
+ * Called with the latest text once typing has paused for `delay`, and not on
53
+ * every keystroke. The waiting text is also passed through at once when the
54
+ * box loses focus, when it unmounts, and on the next press anywhere on the
55
+ * page. The owner should store it and pass it back as `value`.
56
+ */
57
+ onValueChange: (value: string) => void;
58
+ /** How long typing must pause before `onValueChange` is called. */
59
+ delay?: number;
60
+ /**
61
+ * Called when the box gains focus. Typing is not reported by this: it only
62
+ * says the box was entered, and the value is unchanged.
63
+ */
64
+ onFocus?: FocusEventHandler<HTMLInputElement>;
65
+ /**
66
+ * Called when the box loses focus. Any text still waiting for the pause is
67
+ * passed to `onValueChange` first, so by the time this runs the owner already
68
+ * holds what was typed.
69
+ */
70
+ onBlur?: FocusEventHandler<HTMLInputElement>;
71
+ }
72
+ /**
73
+ * Text input that tells its owner about a change only after typing pauses.
74
+ *
75
+ * The typed text lives locally so every keystroke shows at once, while the
76
+ * owner (a store that re-renders a whole form) is written to once per pause.
77
+ * The waiting text is pushed through straight away on blur, on unmount, and on
78
+ * the next press anywhere on the page. The press covers a Save tapped soon
79
+ * after typing: iOS Safari does not blur a focused input when a button is
80
+ * tapped, so blur alone could let Save read the old value.
81
+ */
82
+ declare function DebouncedInput({ value, onValueChange, delay, onFocus, onBlur, ...inputProps }: DebouncedInputProps): react.JSX.Element;
83
+
41
84
  /**
42
85
  * How the whole card is coloured. `success` is green, `warning` orange,
43
86
  * `danger` red and `neutral` grey. What each one means is up to the using app,
@@ -166,5 +209,5 @@ interface JobCardProps {
166
209
  */
167
210
  declare const JobCard: ({ job, onClick, action, leadingContent, expandedContent, className, }: JobCardProps) => react.JSX.Element;
168
211
 
169
- export { DatePicker, JobCard };
170
- export type { JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone };
212
+ export { DatePicker, DebouncedInput, JobCard };
213
+ export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode } from 'react';
2
+ import { ComponentProps, FocusEventHandler, ReactNode } from 'react';
3
3
 
4
4
  interface IDatePicker {
5
5
  /**
@@ -38,6 +38,49 @@ interface IDatePicker {
38
38
  */
39
39
  declare const DatePicker: ({ onSelect, date, dateFormat, }: IDatePicker) => react.JSX.Element;
40
40
 
41
+ declare function Input({ className, type, ...props }: react.ComponentProps<"input">): react.JSX.Element;
42
+
43
+ interface DebouncedInputProps extends Omit<ComponentProps<typeof Input>, "type" | "value" | "defaultValue" | "onChange"> {
44
+ /**
45
+ * The text the owner holds. Controlled: the box shows what is typed at once,
46
+ * and follows this value when it changes from elsewhere (opening a saved job,
47
+ * resetting the form). While the box has focus, outside changes are ignored
48
+ * so they cannot overwrite characters typed since.
49
+ */
50
+ value: string;
51
+ /**
52
+ * Called with the latest text once typing has paused for `delay`, and not on
53
+ * every keystroke. The waiting text is also passed through at once when the
54
+ * box loses focus, when it unmounts, and on the next press anywhere on the
55
+ * page. The owner should store it and pass it back as `value`.
56
+ */
57
+ onValueChange: (value: string) => void;
58
+ /** How long typing must pause before `onValueChange` is called. */
59
+ delay?: number;
60
+ /**
61
+ * Called when the box gains focus. Typing is not reported by this: it only
62
+ * says the box was entered, and the value is unchanged.
63
+ */
64
+ onFocus?: FocusEventHandler<HTMLInputElement>;
65
+ /**
66
+ * Called when the box loses focus. Any text still waiting for the pause is
67
+ * passed to `onValueChange` first, so by the time this runs the owner already
68
+ * holds what was typed.
69
+ */
70
+ onBlur?: FocusEventHandler<HTMLInputElement>;
71
+ }
72
+ /**
73
+ * Text input that tells its owner about a change only after typing pauses.
74
+ *
75
+ * The typed text lives locally so every keystroke shows at once, while the
76
+ * owner (a store that re-renders a whole form) is written to once per pause.
77
+ * The waiting text is pushed through straight away on blur, on unmount, and on
78
+ * the next press anywhere on the page. The press covers a Save tapped soon
79
+ * after typing: iOS Safari does not blur a focused input when a button is
80
+ * tapped, so blur alone could let Save read the old value.
81
+ */
82
+ declare function DebouncedInput({ value, onValueChange, delay, onFocus, onBlur, ...inputProps }: DebouncedInputProps): react.JSX.Element;
83
+
41
84
  /**
42
85
  * How the whole card is coloured. `success` is green, `warning` orange,
43
86
  * `danger` red and `neutral` grey. What each one means is up to the using app,
@@ -166,5 +209,5 @@ interface JobCardProps {
166
209
  */
167
210
  declare const JobCard: ({ job, onClick, action, leadingContent, expandedContent, className, }: JobCardProps) => react.JSX.Element;
168
211
 
169
- export { DatePicker, JobCard };
170
- export type { JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone };
212
+ export { DatePicker, DebouncedInput, JobCard };
213
+ export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone };
package/dist/index.js CHANGED
@@ -390,15 +390,107 @@ var DatePicker = ({
390
390
  );
391
391
  };
392
392
 
393
+ // src/components/debounceInput/DebouncedInput.tsx
394
+ import {
395
+ useEffect as useEffect2,
396
+ useRef as useRef2,
397
+ useState as useState2
398
+ } from "react";
399
+
400
+ // src/lib/debounce.ts
401
+ function debounce(fn, delayMs) {
402
+ let timeout = null;
403
+ let latestArgs = null;
404
+ const run = () => {
405
+ const args = latestArgs;
406
+ timeout = null;
407
+ latestArgs = null;
408
+ if (args) fn(...args);
409
+ };
410
+ const debounced = (...args) => {
411
+ latestArgs = args;
412
+ if (timeout) clearTimeout(timeout);
413
+ timeout = setTimeout(run, delayMs);
414
+ };
415
+ debounced.cancel = () => {
416
+ if (timeout) clearTimeout(timeout);
417
+ timeout = null;
418
+ latestArgs = null;
419
+ };
420
+ debounced.flush = () => {
421
+ if (!timeout) return;
422
+ clearTimeout(timeout);
423
+ run();
424
+ };
425
+ return debounced;
426
+ }
427
+
428
+ // src/components/debounceInput/DebouncedInput.tsx
429
+ import { jsx as jsx6 } from "react/jsx-runtime";
430
+ function DebouncedInput({
431
+ value,
432
+ onValueChange,
433
+ delay = 250,
434
+ onFocus,
435
+ onBlur,
436
+ ...inputProps
437
+ }) {
438
+ const [text, setText] = useState2(value);
439
+ const [isFocused, setIsFocused] = useState2(false);
440
+ const onValueChangeRef = useRef2(onValueChange);
441
+ useEffect2(() => {
442
+ onValueChangeRef.current = onValueChange;
443
+ });
444
+ const commitTextRef = useRef2(null);
445
+ useEffect2(() => {
446
+ const commitText = debounce(
447
+ (next) => onValueChangeRef.current(next),
448
+ delay
449
+ );
450
+ commitTextRef.current = commitText;
451
+ const flushWaitingText = () => commitText.flush();
452
+ document.addEventListener("pointerdown", flushWaitingText, true);
453
+ return () => {
454
+ document.removeEventListener("pointerdown", flushWaitingText, true);
455
+ commitText.flush();
456
+ commitTextRef.current = null;
457
+ };
458
+ }, [delay]);
459
+ if (!isFocused && text !== value) {
460
+ setText(value);
461
+ }
462
+ return /* @__PURE__ */ jsx6(
463
+ Input,
464
+ {
465
+ ...inputProps,
466
+ type: "text",
467
+ value: text,
468
+ onChange: (e) => {
469
+ setText(e.target.value);
470
+ commitTextRef.current?.(e.target.value);
471
+ },
472
+ onFocus: (e) => {
473
+ setIsFocused(true);
474
+ onFocus?.(e);
475
+ },
476
+ onBlur: (e) => {
477
+ commitTextRef.current?.flush();
478
+ setIsFocused(false);
479
+ onBlur?.(e);
480
+ }
481
+ }
482
+ );
483
+ }
484
+
393
485
  // src/components/ui/card.tsx
394
486
  import { cn as cn5 } from "cn";
395
- import { jsx as jsx6 } from "react/jsx-runtime";
487
+ import { jsx as jsx7 } from "react/jsx-runtime";
396
488
  function Card({
397
489
  className,
398
490
  size = "default",
399
491
  ...props
400
492
  }) {
401
- return /* @__PURE__ */ jsx6(
493
+ return /* @__PURE__ */ jsx7(
402
494
  "div",
403
495
  {
404
496
  "data-slot": "card",
@@ -412,7 +504,7 @@ function Card({
412
504
  );
413
505
  }
414
506
  function CardContent({ className, ...props }) {
415
- return /* @__PURE__ */ jsx6(
507
+ return /* @__PURE__ */ jsx7(
416
508
  "div",
417
509
  {
418
510
  "data-slot": "card-content",
@@ -433,7 +525,7 @@ var JobCardBannerBar = ({ banner }) => /* @__PURE__ */ jsxs2("div", { className:
433
525
  ] });
434
526
 
435
527
  // src/components/jobCard/JobCardParts.tsx
436
- import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
528
+ import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
437
529
  var DEFAULT_STAGE_COLOR = "#6b7280";
438
530
  var BADGE_COLOR_CLASSES = {
439
531
  gray: "bg-gray-300",
@@ -444,28 +536,28 @@ var BADGE_COLOR_CLASSES = {
444
536
  blue: "bg-blue-300",
445
537
  purple: "bg-purple-300"
446
538
  };
447
- var JobCardHeading = ({ title, stage, leadingContent }) => /* @__PURE__ */ jsx7("div", { className: "flex items-center gap-2 mb-1", children: /* @__PURE__ */ jsxs3("div", { className: "flex justify-between w-full", children: [
539
+ var JobCardHeading = ({ title, stage, leadingContent }) => /* @__PURE__ */ jsx8("div", { className: "flex items-center gap-2 mb-1", children: /* @__PURE__ */ jsxs3("div", { className: "flex justify-between w-full", children: [
448
540
  /* @__PURE__ */ jsxs3("span", { className: "flex items-center gap-2 font-bold text-base", children: [
449
541
  leadingContent,
450
542
  title
451
543
  ] }),
452
544
  stage && /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2 text-xs", children: [
453
- /* @__PURE__ */ jsx7(
545
+ /* @__PURE__ */ jsx8(
454
546
  "span",
455
547
  {
456
548
  className: "w-2 h-2 rounded-full",
457
549
  style: { backgroundColor: stage.color ?? DEFAULT_STAGE_COLOR }
458
550
  }
459
551
  ),
460
- /* @__PURE__ */ jsx7("span", { className: "text-gray-900", children: stage.label })
552
+ /* @__PURE__ */ jsx8("span", { className: "text-gray-900", children: stage.label })
461
553
  ] })
462
554
  ] }) });
463
- var JobCardDetails = ({ details }) => /* @__PURE__ */ jsx7("div", { className: "flex flex-col gap-1", children: details.map((detail, index) => /* @__PURE__ */ jsx7("div", { className: "text-xs text-gray-500", children: detail }, `${index}-${detail}`)) });
464
- var JobCardCallouts = ({ callouts }) => /* @__PURE__ */ jsx7("div", { className: "flex justify-between w-full", children: /* @__PURE__ */ jsx7("div", { className: "text-xs my-1 w-full space-y-1", children: callouts.map((callout, index) => /* @__PURE__ */ jsx7(
555
+ var JobCardDetails = ({ details }) => /* @__PURE__ */ jsx8("div", { className: "flex flex-col gap-1", children: details.map((detail, index) => /* @__PURE__ */ jsx8("div", { className: "text-xs text-gray-500", children: detail }, `${index}-${detail}`)) });
556
+ var JobCardCallouts = ({ callouts }) => /* @__PURE__ */ jsx8("div", { className: "flex justify-between w-full", children: /* @__PURE__ */ jsx8("div", { className: "text-xs my-1 w-full space-y-1", children: callouts.map((callout, index) => /* @__PURE__ */ jsx8(
465
557
  "div",
466
558
  {
467
559
  className: "flex gap-2 items-center border p-2 rounded bg-white shadow",
468
- children: /* @__PURE__ */ jsx7("span", { children: callout })
560
+ children: /* @__PURE__ */ jsx8("span", { children: callout })
469
561
  },
470
562
  `${index}-${callout}`
471
563
  )) }) });
@@ -473,16 +565,16 @@ var JobCardSummary = ({
473
565
  job,
474
566
  leadingContent
475
567
  }) => /* @__PURE__ */ jsxs3("div", { className: "w-full", children: [
476
- /* @__PURE__ */ jsx7(JobCardHeading, { title: job.title, stage: job.stage, leadingContent }),
477
- job.subtitle && /* @__PURE__ */ jsx7("div", { className: "text-[13px] text-gray-600 mb-1", children: job.subtitle }),
478
- job.details && job.details.length > 0 && /* @__PURE__ */ jsx7(JobCardDetails, { details: job.details }),
479
- job.description && /* @__PURE__ */ jsx7("div", { className: "text-sm text-gray-700 italic mt-1", children: job.description }),
480
- job.callouts && job.callouts.length > 0 && /* @__PURE__ */ jsx7(JobCardCallouts, { callouts: job.callouts })
568
+ /* @__PURE__ */ jsx8(JobCardHeading, { title: job.title, stage: job.stage, leadingContent }),
569
+ job.subtitle && /* @__PURE__ */ jsx8("div", { className: "text-[13px] text-gray-600 mb-1", children: job.subtitle }),
570
+ job.details && job.details.length > 0 && /* @__PURE__ */ jsx8(JobCardDetails, { details: job.details }),
571
+ job.description && /* @__PURE__ */ jsx8("div", { className: "text-sm text-gray-700 italic mt-1", children: job.description }),
572
+ job.callouts && job.callouts.length > 0 && /* @__PURE__ */ jsx8(JobCardCallouts, { callouts: job.callouts })
481
573
  ] });
482
574
  var JobCardBadgeBlock = ({
483
575
  badge,
484
576
  hasPills
485
- }) => /* @__PURE__ */ jsx7("div", { className: `flex pr-4 w-20 ${hasPills ? "border-r" : ""}`, children: /* @__PURE__ */ jsx7(
577
+ }) => /* @__PURE__ */ jsx8("div", { className: `flex pr-4 w-20 ${hasPills ? "border-r" : ""}`, children: /* @__PURE__ */ jsx8(
486
578
  "span",
487
579
  {
488
580
  className: `flex items-center shadow border rounded px-4 py-1 text-center text-wrap ${BADGE_COLOR_CLASSES[badge.color]} ${hasPills ? "border-r" : ""}`,
@@ -491,7 +583,7 @@ var JobCardBadgeBlock = ({
491
583
  ) });
492
584
 
493
585
  // src/components/jobCard/JobCardPills.tsx
494
- import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
586
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
495
587
  var PILL_BASE = "flex items-center gap-1 h-5 rounded-full text-center text-[10px] md:text-xs [&>svg]:w-3 [&>svg]:h-3";
496
588
  var PILL_TONE_CLASSES = {
497
589
  critical: "px-3 bg-red-500 text-white font-bold shadow-md shadow-red-900/70",
@@ -513,19 +605,19 @@ var JobCardPillList = ({ pills }) => {
513
605
  const priorityPills = pills.filter((pill) => pill.priority);
514
606
  const otherPills = pills.filter((pill) => !pill.priority);
515
607
  return /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 flex-wrap", children: [
516
- priorityPills.length > 0 && /* @__PURE__ */ jsx8(
608
+ priorityPills.length > 0 && /* @__PURE__ */ jsx9(
517
609
  "div",
518
610
  {
519
611
  className: `flex gap-2 w-full ${otherPills.length > 0 ? "pb-2 border-b" : ""}`,
520
- children: priorityPills.map((pill) => /* @__PURE__ */ jsx8(JobCardPillItem, { pill }, pill.label))
612
+ children: priorityPills.map((pill) => /* @__PURE__ */ jsx9(JobCardPillItem, { pill }, pill.label))
521
613
  }
522
614
  ),
523
- otherPills.map((pill) => /* @__PURE__ */ jsx8(JobCardPillItem, { pill }, pill.label))
615
+ otherPills.map((pill) => /* @__PURE__ */ jsx9(JobCardPillItem, { pill }, pill.label))
524
616
  ] });
525
617
  };
526
618
 
527
619
  // src/components/jobCard/JobCard.tsx
528
- import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
620
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
529
621
  var CARD_TONE_CLASSES = {
530
622
  success: "border-green-400 bg-green-50",
531
623
  warning: "border-orange-400 bg-orange-50",
@@ -541,7 +633,7 @@ var JobCard = ({
541
633
  className
542
634
  }) => {
543
635
  const hasPills = Boolean(job.pills && job.pills.length > 0);
544
- return /* @__PURE__ */ jsx9(
636
+ return /* @__PURE__ */ jsx10(
545
637
  Card,
546
638
  {
547
639
  onClick,
@@ -556,13 +648,13 @@ var JobCard = ({
556
648
  className
557
649
  ),
558
650
  children: /* @__PURE__ */ jsxs5(CardContent, { className: "p-3.5", children: [
559
- /* @__PURE__ */ jsx9("div", { className: "flex justify-between items-start mb-2", children: /* @__PURE__ */ jsx9(JobCardSummary, { job, leadingContent }) }),
651
+ /* @__PURE__ */ jsx10("div", { className: "flex justify-between items-start mb-2", children: /* @__PURE__ */ jsx10(JobCardSummary, { job, leadingContent }) }),
560
652
  (job.badge || hasPills) && /* @__PURE__ */ jsxs5("div", { className: "flex gap-2 text-xs", children: [
561
- job.badge && /* @__PURE__ */ jsx9(JobCardBadgeBlock, { badge: job.badge, hasPills }),
562
- hasPills && /* @__PURE__ */ jsx9(JobCardPillList, { pills: job.pills ?? [] })
653
+ job.badge && /* @__PURE__ */ jsx10(JobCardBadgeBlock, { badge: job.badge, hasPills }),
654
+ hasPills && /* @__PURE__ */ jsx10(JobCardPillList, { pills: job.pills ?? [] })
563
655
  ] }),
564
- job.banner && /* @__PURE__ */ jsx9(JobCardBannerBar, { banner: job.banner }),
565
- action && /* @__PURE__ */ jsx9(
656
+ job.banner && /* @__PURE__ */ jsx10(JobCardBannerBar, { banner: job.banner }),
657
+ action && /* @__PURE__ */ jsx10(
566
658
  Button,
567
659
  {
568
660
  onClick: (event) => {
@@ -575,12 +667,13 @@ var JobCard = ({
575
667
  children: action.label
576
668
  }
577
669
  ),
578
- /* @__PURE__ */ jsx9("div", { children: expandedContent })
670
+ /* @__PURE__ */ jsx10("div", { children: expandedContent })
579
671
  ] })
580
672
  }
581
673
  );
582
674
  };
583
675
  export {
584
676
  DatePicker,
677
+ DebouncedInput,
585
678
  JobCard
586
679
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processdynamics/components",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Process Dynamics React component library, built on shadcn (Radix) and Tailwind CSS v4.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -59,6 +59,10 @@
59
59
  "@storybook/nextjs-vite": "^10.6.5",
60
60
  "@tailwindcss/turbopack": "^4",
61
61
  "@tailwindcss/vite": "^4.3.3",
62
+ "@testing-library/dom": "^10.4.2",
63
+ "@testing-library/jest-dom": "^7.0.1",
64
+ "@testing-library/react": "^16.3.3",
65
+ "@testing-library/user-event": "^14.6.8",
62
66
  "@types/node": "^20",
63
67
  "@types/react": "^19",
64
68
  "@types/react-dom": "^19",
@@ -71,6 +75,7 @@
71
75
  "eslint-config-next": "16.4.3",
72
76
  "eslint-plugin-storybook": "^10.6.5",
73
77
  "husky": "^9.1.7",
78
+ "jsdom": "^30.1.3",
74
79
  "lucide-react": "^1.66.0",
75
80
  "next": "16.4.3",
76
81
  "playwright": "latest",