@discuss-ds/ui 0.19.1 → 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.
package/dist/index.d.cts CHANGED
@@ -335,6 +335,16 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
335
335
  /** Use a textarea. Enter inserts a line break; Cmd/Ctrl+Enter commits. */
336
336
  multiline?: boolean;
337
337
  maxLength?: number;
338
+ /**
339
+ * Shortest value (in characters, ignoring surrounding spaces) that may be saved. An edit that is too short is not saved:
340
+ * the field stays open with an error message, and Escape still reverts.
341
+ */
342
+ minLength?: number;
343
+ /**
344
+ * Checks an edit before it is saved (on Enter or blur). Return a message to refuse it: the field stays open showing the
345
+ * message and `onValueChange` is not called. Return nothing (or `null`) to accept. Runs after `minLength`.
346
+ */
347
+ validate?: (value: string) => string | null | undefined;
338
348
  disabled?: boolean;
339
349
  /** Called when editing starts or ends. */
340
350
  onEditingChange?: (editing: boolean) => void;
package/dist/index.d.ts CHANGED
@@ -335,6 +335,16 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
335
335
  /** Use a textarea. Enter inserts a line break; Cmd/Ctrl+Enter commits. */
336
336
  multiline?: boolean;
337
337
  maxLength?: number;
338
+ /**
339
+ * Shortest value (in characters, ignoring surrounding spaces) that may be saved. An edit that is too short is not saved:
340
+ * the field stays open with an error message, and Escape still reverts.
341
+ */
342
+ minLength?: number;
343
+ /**
344
+ * Checks an edit before it is saved (on Enter or blur). Return a message to refuse it: the field stays open showing the
345
+ * message and `onValueChange` is not called. Return nothing (or `null`) to accept. Runs after `minLength`.
346
+ */
347
+ validate?: (value: string) => string | null | undefined;
338
348
  disabled?: boolean;
339
349
  /** Called when editing starts or ends. */
340
350
  onEditingChange?: (editing: boolean) => void;
package/dist/index.js CHANGED
@@ -1386,8 +1386,8 @@ FormMessage.displayName = "FormMessage";
1386
1386
 
1387
1387
  // src/components/Forms & Data Entry/InlineEdit.tsx
1388
1388
  import * as React24 from "react";
1389
- import { PencilSimple } from "@phosphor-icons/react";
1390
- import { jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
1389
+ import { PencilSimple, WarningCircle as WarningCircle2 } from "@phosphor-icons/react";
1390
+ import { Fragment as Fragment4, jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
1391
1391
  var InlineEdit = React24.forwardRef(
1392
1392
  ({
1393
1393
  className,
@@ -1398,6 +1398,8 @@ var InlineEdit = React24.forwardRef(
1398
1398
  placeholder = "Click to edit",
1399
1399
  multiline,
1400
1400
  maxLength,
1401
+ minLength,
1402
+ validate,
1401
1403
  disabled,
1402
1404
  onEditingChange,
1403
1405
  onDraftChange,
@@ -1410,6 +1412,8 @@ var InlineEdit = React24.forwardRef(
1410
1412
  const value = valueProp ?? internal;
1411
1413
  const [editing, setEditing] = React24.useState(false);
1412
1414
  const [draft, setDraft] = React24.useState(value);
1415
+ const [error, setError] = React24.useState(null);
1416
+ const errorId = React24.useId();
1413
1417
  const fieldRef = React24.useRef(null);
1414
1418
  const readRef = React24.useRef(null);
1415
1419
  const cancelled = React24.useRef(false);
@@ -1423,14 +1427,29 @@ var InlineEdit = React24.forwardRef(
1423
1427
  readRef.current?.focus();
1424
1428
  }
1425
1429
  }, [editing]);
1430
+ const problemWith = (text) => {
1431
+ if (minLength !== void 0 && text.trim().length < minLength) {
1432
+ return `Enter at least ${minLength} characters (${text.trim().length} now).`;
1433
+ }
1434
+ return validate?.(text) ?? null;
1435
+ };
1426
1436
  const start = () => {
1427
1437
  if (disabled) return;
1428
1438
  setDraft(value);
1439
+ setError(null);
1429
1440
  cancelled.current = false;
1430
1441
  setEditing(true);
1431
1442
  onEditingChange?.(true);
1432
1443
  };
1433
1444
  const finish = (commit, refocus) => {
1445
+ if (commit && draft !== value) {
1446
+ const problem = problemWith(draft);
1447
+ if (problem) {
1448
+ setError(problem);
1449
+ return;
1450
+ }
1451
+ }
1452
+ setError(null);
1434
1453
  restoreFocus.current = refocus;
1435
1454
  if (commit && draft !== value) {
1436
1455
  if (valueProp === void 0) setInternal(draft);
@@ -1443,66 +1462,84 @@ var InlineEdit = React24.forwardRef(
1443
1462
  const textClasses = cn("text-ui-input-value text-surface-foreground", textClassName);
1444
1463
  const question = variant === "question";
1445
1464
  const fill = multiline || question;
1446
- return /* @__PURE__ */ jsx25("div", { ref, className: cn(fill ? "flex w-full min-w-0" : "inline-flex min-w-0 max-w-full", className), ...props, children: editing ? React24.createElement(multiline ? "textarea" : "input", {
1447
- ref: fieldRef,
1448
- value: draft,
1449
- maxLength,
1450
- "aria-label": ariaLabel,
1451
- ...multiline ? { rows: 1 } : { type: "text" },
1452
- className: cn(
1453
- "w-full px-3 py-1 outline-none",
1454
- multiline && "field-sizing-content resize-none",
1455
- question ? "rounded-none border-0 border-b-2 border-accent-foreground bg-transparent" : cn("rounded-md focus-visible:border-input-accent", fieldSurfaceClasses("default")),
1456
- textClasses
1457
- ),
1458
- onChange: (event) => {
1459
- setDraft(event.target.value);
1460
- onDraftChange?.(event.target.value);
1461
- },
1462
- onKeyDown: (event) => {
1463
- if (event.key === "Escape") {
1464
- cancelled.current = true;
1465
- finish(false, true);
1466
- } else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
1467
- event.preventDefault();
1468
- finish(true, true);
1469
- }
1470
- },
1471
- onBlur: () => {
1472
- if (!cancelled.current) finish(true, false);
1473
- }
1474
- }) : /* @__PURE__ */ jsxs16(
1475
- "button",
1465
+ return /* @__PURE__ */ jsx25(
1466
+ "div",
1476
1467
  {
1477
- ref: readRef,
1478
- type: "button",
1479
- disabled,
1480
- "aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
1481
- onClick: start,
1482
- className: cn(
1483
- "group inline-flex min-w-0 max-w-full items-center gap-2 px-3 text-left outline-none",
1484
- fill && "w-full",
1485
- question ? (
1486
- // Hover and focus show a 1px bottom border in the input colour; only a selected question gets the 2px accent
1487
- // one. The extra 1px of bottom padding keeps the height identical so the text never jumps.
1488
- selected ? "rounded-none border-b-2 border-accent-foreground py-1" : "rounded-none border-b border-transparent pb-1.25 pt-1 enabled:hover:border-input-muted enabled:focus-visible:border-input-muted"
1489
- ) : "rounded-md border border-transparent py-1 enabled:focus-visible:border-input-accent",
1490
- "enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1491
- textClasses
1492
- ),
1493
- children: [
1494
- /* @__PURE__ */ jsx25("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && "text-muted-foreground"), children: value || placeholder }),
1495
- !fill && /* @__PURE__ */ jsx25(
1496
- PencilSimple,
1497
- {
1498
- size: 16,
1499
- "aria-hidden": true,
1500
- className: "shrink-0 text-secondary-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
1468
+ ref,
1469
+ className: cn(fill ? "flex w-full min-w-0" : "inline-flex min-w-0 max-w-full", editing && error && "flex-col gap-1.5", className),
1470
+ ...props,
1471
+ children: editing ? /* @__PURE__ */ jsxs16(Fragment4, { children: [
1472
+ React24.createElement(multiline ? "textarea" : "input", {
1473
+ ref: fieldRef,
1474
+ value: draft,
1475
+ maxLength,
1476
+ "aria-label": ariaLabel,
1477
+ "aria-invalid": error ? true : void 0,
1478
+ "aria-describedby": error ? errorId : void 0,
1479
+ ...multiline ? { rows: 1 } : { type: "text" },
1480
+ className: cn(
1481
+ "w-full px-3 py-1 outline-none",
1482
+ multiline && "field-sizing-content resize-none",
1483
+ question ? cn("rounded-none border-0 border-b-2 bg-transparent", error ? "border-destructive" : "border-accent-foreground") : cn("rounded-md", !error && "focus-visible:border-input-accent", fieldSurfaceClasses(error ? "error" : "default")),
1484
+ textClasses
1485
+ ),
1486
+ onChange: (event) => {
1487
+ setDraft(event.target.value);
1488
+ if (error) setError(problemWith(event.target.value));
1489
+ onDraftChange?.(event.target.value);
1490
+ },
1491
+ onKeyDown: (event) => {
1492
+ if (event.key === "Escape") {
1493
+ cancelled.current = true;
1494
+ setError(null);
1495
+ finish(false, true);
1496
+ } else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
1497
+ event.preventDefault();
1498
+ finish(true, true);
1499
+ }
1500
+ },
1501
+ onBlur: () => {
1502
+ if (!cancelled.current) finish(true, false);
1501
1503
  }
1502
- )
1503
- ]
1504
+ }),
1505
+ error && /* @__PURE__ */ jsxs16("p", { id: errorId, role: "alert", className: "flex items-start gap-2 px-3 text-ui-caption text-destructive", children: [
1506
+ /* @__PURE__ */ jsx25(WarningCircle2, { size: 16, "aria-hidden": true, className: "shrink-0" }),
1507
+ error
1508
+ ] })
1509
+ ] }) : /* @__PURE__ */ jsxs16(
1510
+ "button",
1511
+ {
1512
+ ref: readRef,
1513
+ type: "button",
1514
+ disabled,
1515
+ "aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
1516
+ onClick: start,
1517
+ className: cn(
1518
+ "group inline-flex min-w-0 max-w-full items-center gap-2 px-3 text-left outline-none",
1519
+ fill && "w-full",
1520
+ question ? (
1521
+ // Hover and focus show a 1px bottom border in the input colour; only a selected question gets the 2px accent
1522
+ // one. The extra 1px of bottom padding keeps the height identical so the text never jumps.
1523
+ selected ? "rounded-none border-b-2 border-accent-foreground py-1" : "rounded-none border-b border-transparent pb-1.25 pt-1 enabled:hover:border-input-muted enabled:focus-visible:border-input-muted"
1524
+ ) : "rounded-md border border-transparent py-1 enabled:focus-visible:border-input-accent",
1525
+ "enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1526
+ textClasses
1527
+ ),
1528
+ children: [
1529
+ /* @__PURE__ */ jsx25("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && "text-muted-foreground"), children: value || placeholder }),
1530
+ !fill && /* @__PURE__ */ jsx25(
1531
+ PencilSimple,
1532
+ {
1533
+ size: 16,
1534
+ "aria-hidden": true,
1535
+ className: "shrink-0 text-secondary-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
1536
+ }
1537
+ )
1538
+ ]
1539
+ }
1540
+ )
1504
1541
  }
1505
- ) });
1542
+ );
1506
1543
  }
1507
1544
  );
1508
1545
  InlineEdit.displayName = "InlineEdit";
@@ -1975,7 +2012,7 @@ var DialogFooter = ({ className, ...props }) => /* @__PURE__ */ jsx33("div", { c
1975
2012
 
1976
2013
  // src/components/Overlays & Feedback/Toast.tsx
1977
2014
  import * as React33 from "react";
1978
- import { CheckCircle as CheckCircle2, Info, Warning, WarningCircle as WarningCircle2, X as X4 } from "@phosphor-icons/react";
2015
+ import { CheckCircle as CheckCircle2, Info, Warning, WarningCircle as WarningCircle3, X as X4 } from "@phosphor-icons/react";
1979
2016
  import { cva as cva4 } from "class-variance-authority";
1980
2017
  import { Toast as ToastPrimitive } from "radix-ui";
1981
2018
  import { jsx as jsx34, jsxs as jsxs23 } from "react/jsx-runtime";
@@ -2006,7 +2043,7 @@ function VariantIcon({ variant, size }) {
2006
2043
  const props = { size, "aria-hidden": true, className: cn("shrink-0", iconColour[variant]) };
2007
2044
  if (variant === "success") return /* @__PURE__ */ jsx34(CheckCircle2, { ...props });
2008
2045
  if (variant === "warning") return /* @__PURE__ */ jsx34(Warning, { ...props });
2009
- if (variant === "destructive") return /* @__PURE__ */ jsx34(WarningCircle2, { ...props });
2046
+ if (variant === "destructive") return /* @__PURE__ */ jsx34(WarningCircle3, { ...props });
2010
2047
  return /* @__PURE__ */ jsx34(Info, { ...props });
2011
2048
  }
2012
2049
  var ToastProvider = ToastPrimitive.Provider;
@@ -2077,7 +2114,7 @@ ToastInline.displayName = "ToastInline";
2077
2114
  // src/components/Overlays & Feedback/Tooltip.tsx
2078
2115
  import * as React34 from "react";
2079
2116
  import { Tooltip as TooltipPrimitive } from "radix-ui";
2080
- import { Fragment as Fragment4, jsx as jsx35, jsxs as jsxs24 } from "react/jsx-runtime";
2117
+ import { Fragment as Fragment5, jsx as jsx35, jsxs as jsxs24 } from "react/jsx-runtime";
2081
2118
  var TooltipProvider = TooltipPrimitive.Provider;
2082
2119
  var Tooltip = TooltipPrimitive.Root;
2083
2120
  var TooltipTrigger = TooltipPrimitive.Trigger;
@@ -2098,7 +2135,7 @@ var TooltipContent = React34.forwardRef(
2098
2135
  ),
2099
2136
  ...props,
2100
2137
  children: [
2101
- detailed ? /* @__PURE__ */ jsxs24(Fragment4, { children: [
2138
+ detailed ? /* @__PURE__ */ jsxs24(Fragment5, { children: [
2102
2139
  title != null && /* @__PURE__ */ jsx35("p", { className: "text-xs leading-4 font-semibold text-label", children: title }),
2103
2140
  description != null && /* @__PURE__ */ jsx35("p", { className: "text-xs leading-4.5 text-plum-200", children: description }),
2104
2141
  action != null && /* @__PURE__ */ jsx35("div", { className: "mt-1 text-ui-caption text-plum-300 underline *:underline", children: action })
@@ -2157,7 +2194,7 @@ var StatusTag = React35.forwardRef(
2157
2194
  StatusTag.displayName = "StatusTag";
2158
2195
 
2159
2196
  // src/components/Question Types/FileUpload.tsx
2160
- import { Fragment as Fragment5, jsx as jsx37, jsxs as jsxs26 } from "react/jsx-runtime";
2197
+ import { Fragment as Fragment6, jsx as jsx37, jsxs as jsxs26 } from "react/jsx-runtime";
2161
2198
  var FileUploadZone = React36.forwardRef(
2162
2199
  ({ className, title = "Upload document", hint, icon, onFiles, ...props }, ref) => {
2163
2200
  const [over, setOver] = React36.useState(false);
@@ -2224,7 +2261,7 @@ var FileUploadItem = React36.forwardRef(
2224
2261
  size,
2225
2262
  status === "complete" && /* @__PURE__ */ jsx37(Tag, { variant: "success", children: "Complete" }),
2226
2263
  status === "error" && /* @__PURE__ */ jsx37(Tag, { variant: "destructive", children: "Error" }),
2227
- uploading && timeLeft && /* @__PURE__ */ jsxs26(Fragment5, { children: [
2264
+ uploading && timeLeft && /* @__PURE__ */ jsxs26(Fragment6, { children: [
2228
2265
  /* @__PURE__ */ jsx37("span", { "aria-hidden": "true", className: "size-0.5 rounded-full bg-secondary-muted-foreground" }),
2229
2266
  timeLeft
2230
2267
  ] })
@@ -2624,7 +2661,7 @@ var QuestionHeader = React40.forwardRef(
2624
2661
  QuestionHeader.displayName = "QuestionHeader";
2625
2662
 
2626
2663
  // src/components/Question Types/QuestionEditorCard.tsx
2627
- import { Fragment as Fragment7, jsx as jsx42, jsxs as jsxs29 } from "react/jsx-runtime";
2664
+ import { Fragment as Fragment8, jsx as jsx42, jsxs as jsxs29 } from "react/jsx-runtime";
2628
2665
  var QuestionEditorCard = React41.forwardRef(
2629
2666
  ({
2630
2667
  className,
@@ -2680,7 +2717,7 @@ var QuestionEditorCard = React41.forwardRef(
2680
2717
  showDragHandle,
2681
2718
  meta,
2682
2719
  maxLength,
2683
- actions: actions ?? /* @__PURE__ */ jsxs29(Fragment7, { children: [
2720
+ actions: actions ?? /* @__PURE__ */ jsxs29(Fragment8, { children: [
2684
2721
  /* @__PURE__ */ jsx42(
2685
2722
  Button,
2686
2723
  {
@@ -2835,7 +2872,7 @@ QuestionNavItem.displayName = "QuestionNavItem";
2835
2872
  // src/components/Question Types/QuestionOption.tsx
2836
2873
  import * as React44 from "react";
2837
2874
  import { Check as Check4, DotsSixVertical as DotsSixVertical3, Plus as Plus4, Trash as Trash4 } from "@phosphor-icons/react";
2838
- import { Fragment as Fragment8, jsx as jsx45, jsxs as jsxs31 } from "react/jsx-runtime";
2875
+ import { Fragment as Fragment9, jsx as jsx45, jsxs as jsxs31 } from "react/jsx-runtime";
2839
2876
  var optionClasses = "flex w-full max-w-150 cursor-pointer items-center gap-2 rounded-md border border-border bg-surface px-4 py-2 text-body-base text-surface-foreground transition-colors hover:bg-accent-soft hover:shadow-md has-[[data-state=checked]]:border-accent-foreground has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50";
2840
2877
  function QuestionOption(props) {
2841
2878
  const id = React44.useId();
@@ -2909,7 +2946,7 @@ function QuestionOptionEditor({ label, onLabelChange, onRemove, onAdd, className
2909
2946
  ) : "border-border hover:border-input-muted hover:shadow-md"
2910
2947
  ),
2911
2948
  children: [
2912
- kind === "rank" ? /* @__PURE__ */ jsxs31(Fragment8, { children: [
2949
+ kind === "rank" ? /* @__PURE__ */ jsxs31(Fragment9, { children: [
2913
2950
  !locked && grip,
2914
2951
  /* @__PURE__ */ jsx45(
2915
2952
  "span",
@@ -2974,7 +3011,7 @@ function QuestionOptionEditor({ label, onLabelChange, onRemove, onAdd, className
2974
3011
  // src/components/Question Types/RankList.tsx
2975
3012
  import * as React45 from "react";
2976
3013
  import { DotsSixVertical as DotsSixVertical4 } from "@phosphor-icons/react";
2977
- import { Fragment as Fragment9, jsx as jsx46, jsxs as jsxs32 } from "react/jsx-runtime";
3014
+ import { Fragment as Fragment10, jsx as jsx46, jsxs as jsxs32 } from "react/jsx-runtime";
2978
3015
  function move(list, from, to) {
2979
3016
  if (from === to || to < 0 || to >= list.length) return list;
2980
3017
  const next = list.slice();
@@ -3001,7 +3038,7 @@ var RankList = React45.forwardRef(
3001
3038
  setAnnouncement(`Moved to position ${to + 1} of ${items.length}`);
3002
3039
  onItemsChange(next);
3003
3040
  };
3004
- return /* @__PURE__ */ jsxs32(Fragment9, { children: [
3041
+ return /* @__PURE__ */ jsxs32(Fragment10, { children: [
3005
3042
  /* @__PURE__ */ jsx46("ol", { ref, className: cn("flex w-full max-w-150 flex-col gap-4", className), ...props, children: items.map((item, index) => /* @__PURE__ */ jsxs32(
3006
3043
  "li",
3007
3044
  {