@discuss-ds/ui 0.20.0 → 0.22.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/CHANGELOG.md +12 -0
- package/dist/index.cjs +30 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +30 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -345,6 +345,17 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
|
|
|
345
345
|
* message and `onValueChange` is not called. Return nothing (or `null`) to accept. Runs after `minLength`.
|
|
346
346
|
*/
|
|
347
347
|
validate?: (value: string) => string | null | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* While editing, shows the allowed length under the field (from `minLength` and `maxLength`) with a live character
|
|
350
|
+
* counter. After a refused save the same line turns into the error state (error colour and icon) instead of a
|
|
351
|
+
* different message appears.
|
|
352
|
+
*/
|
|
353
|
+
showLimits?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Multiline only: Enter saves (like a single-line field) and Shift+Enter inserts a line break. Cmd/Ctrl+Enter keeps
|
|
356
|
+
* saving too. The `question` variant already works this way.
|
|
357
|
+
*/
|
|
358
|
+
submitOnEnter?: boolean;
|
|
348
359
|
disabled?: boolean;
|
|
349
360
|
/** Called when editing starts or ends. */
|
|
350
361
|
onEditingChange?: (editing: boolean) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -345,6 +345,17 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
|
|
|
345
345
|
* message and `onValueChange` is not called. Return nothing (or `null`) to accept. Runs after `minLength`.
|
|
346
346
|
*/
|
|
347
347
|
validate?: (value: string) => string | null | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* While editing, shows the allowed length under the field (from `minLength` and `maxLength`) with a live character
|
|
350
|
+
* counter. After a refused save the same line turns into the error state (error colour and icon) instead of a
|
|
351
|
+
* different message appears.
|
|
352
|
+
*/
|
|
353
|
+
showLimits?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Multiline only: Enter saves (like a single-line field) and Shift+Enter inserts a line break. Cmd/Ctrl+Enter keeps
|
|
356
|
+
* saving too. The `question` variant already works this way.
|
|
357
|
+
*/
|
|
358
|
+
submitOnEnter?: boolean;
|
|
348
359
|
disabled?: boolean;
|
|
349
360
|
/** Called when editing starts or ends. */
|
|
350
361
|
onEditingChange?: (editing: boolean) => void;
|
package/dist/index.js
CHANGED
|
@@ -1388,6 +1388,12 @@ FormMessage.displayName = "FormMessage";
|
|
|
1388
1388
|
import * as React24 from "react";
|
|
1389
1389
|
import { PencilSimple, WarningCircle as WarningCircle2 } from "@phosphor-icons/react";
|
|
1390
1390
|
import { Fragment as Fragment4, jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1391
|
+
function limitsText(min, max) {
|
|
1392
|
+
if (min !== void 0 && max !== void 0) return `${min}\u2013${max} characters`;
|
|
1393
|
+
if (min !== void 0) return `At least ${min} characters`;
|
|
1394
|
+
if (max !== void 0) return `Up to ${max} characters`;
|
|
1395
|
+
return "";
|
|
1396
|
+
}
|
|
1391
1397
|
var InlineEdit = React24.forwardRef(
|
|
1392
1398
|
({
|
|
1393
1399
|
className,
|
|
@@ -1400,6 +1406,8 @@ var InlineEdit = React24.forwardRef(
|
|
|
1400
1406
|
maxLength,
|
|
1401
1407
|
minLength,
|
|
1402
1408
|
validate,
|
|
1409
|
+
showLimits,
|
|
1410
|
+
submitOnEnter,
|
|
1403
1411
|
disabled,
|
|
1404
1412
|
onEditingChange,
|
|
1405
1413
|
onDraftChange,
|
|
@@ -1466,7 +1474,7 @@ var InlineEdit = React24.forwardRef(
|
|
|
1466
1474
|
"div",
|
|
1467
1475
|
{
|
|
1468
1476
|
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),
|
|
1477
|
+
className: cn(fill ? "flex w-full min-w-0" : "inline-flex min-w-0 max-w-full", editing && (error || showLimits) && "flex-col gap-1.5", className),
|
|
1470
1478
|
...props,
|
|
1471
1479
|
children: editing ? /* @__PURE__ */ jsxs16(Fragment4, { children: [
|
|
1472
1480
|
React24.createElement(multiline ? "textarea" : "input", {
|
|
@@ -1475,7 +1483,7 @@ var InlineEdit = React24.forwardRef(
|
|
|
1475
1483
|
maxLength,
|
|
1476
1484
|
"aria-label": ariaLabel,
|
|
1477
1485
|
"aria-invalid": error ? true : void 0,
|
|
1478
|
-
"aria-describedby": error ? errorId : void 0,
|
|
1486
|
+
"aria-describedby": error || showLimits ? errorId : void 0,
|
|
1479
1487
|
...multiline ? { rows: 1 } : { type: "text" },
|
|
1480
1488
|
className: cn(
|
|
1481
1489
|
"w-full px-3 py-1 outline-none",
|
|
@@ -1493,7 +1501,7 @@ var InlineEdit = React24.forwardRef(
|
|
|
1493
1501
|
cancelled.current = true;
|
|
1494
1502
|
setError(null);
|
|
1495
1503
|
finish(false, true);
|
|
1496
|
-
} else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
|
|
1504
|
+
} else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || (question || submitOnEnter) && !event.shiftKey)) {
|
|
1497
1505
|
event.preventDefault();
|
|
1498
1506
|
finish(true, true);
|
|
1499
1507
|
}
|
|
@@ -1502,10 +1510,25 @@ var InlineEdit = React24.forwardRef(
|
|
|
1502
1510
|
if (!cancelled.current) finish(true, false);
|
|
1503
1511
|
}
|
|
1504
1512
|
}),
|
|
1505
|
-
error && /* @__PURE__ */ jsxs16(
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1513
|
+
(error || showLimits) && /* @__PURE__ */ jsxs16(
|
|
1514
|
+
"p",
|
|
1515
|
+
{
|
|
1516
|
+
id: errorId,
|
|
1517
|
+
role: error ? "alert" : void 0,
|
|
1518
|
+
className: cn("flex items-start justify-between gap-2 px-3 text-ui-caption", error ? "text-destructive" : "text-secondary-muted-foreground"),
|
|
1519
|
+
children: [
|
|
1520
|
+
/* @__PURE__ */ jsxs16("span", { className: "flex items-start gap-2", children: [
|
|
1521
|
+
error && /* @__PURE__ */ jsx25(WarningCircle2, { size: 16, "aria-hidden": true, className: "shrink-0" }),
|
|
1522
|
+
showLimits ? limitsText(minLength, maxLength) : error,
|
|
1523
|
+
showLimits && error && /* @__PURE__ */ jsx25("span", { className: "sr-only", children: error })
|
|
1524
|
+
] }),
|
|
1525
|
+
showLimits && /* @__PURE__ */ jsxs16("span", { "aria-hidden": true, className: "shrink-0 tabular-nums", children: [
|
|
1526
|
+
draft.length,
|
|
1527
|
+
maxLength !== void 0 && `/${maxLength}`
|
|
1528
|
+
] })
|
|
1529
|
+
]
|
|
1530
|
+
}
|
|
1531
|
+
)
|
|
1509
1532
|
] }) : /* @__PURE__ */ jsxs16(
|
|
1510
1533
|
"button",
|
|
1511
1534
|
{
|