@discuss-ds/ui 0.19.1 → 0.21.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 +114 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +128 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @discuss-ds/ui
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#84](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/84) [`da5c71d`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/da5c71d53726b8ba0f5836fadc8bb4f77dd18b47) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `InlineEdit`: new optional `showLimits` prop. While editing it shows the allowed length under the field (for example "150–500 characters", from `minLength` and `maxLength`) with a live character counter. After a refused save that same line turns into the error state (error colour and icon). Off by default, so nothing changes unless it is set.
|
|
8
|
+
|
|
9
|
+
## 0.20.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#82](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/82) [`3a419e5`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/3a419e592a9831322bd08df205a9edb01156d61c) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `InlineEdit`: new optional `minLength` and `validate` props. An edit that is too short, or that `validate` rejects (by returning a message), is not saved on Enter or blur: the field stays open with an error border and message, `onValueChange` is not called, and the message follows what is typed. Escape still reverts. Without the props nothing changes.
|
|
14
|
+
|
|
3
15
|
## 0.19.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1542,6 +1542,12 @@ FormMessage.displayName = "FormMessage";
|
|
|
1542
1542
|
var React24 = __toESM(require("react"), 1);
|
|
1543
1543
|
var import_react11 = require("@phosphor-icons/react");
|
|
1544
1544
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
1545
|
+
function limitsText(min, max) {
|
|
1546
|
+
if (min !== void 0 && max !== void 0) return `${min}\u2013${max} characters`;
|
|
1547
|
+
if (min !== void 0) return `At least ${min} characters`;
|
|
1548
|
+
if (max !== void 0) return `Up to ${max} characters`;
|
|
1549
|
+
return "";
|
|
1550
|
+
}
|
|
1545
1551
|
var InlineEdit = React24.forwardRef(
|
|
1546
1552
|
({
|
|
1547
1553
|
className,
|
|
@@ -1552,6 +1558,9 @@ var InlineEdit = React24.forwardRef(
|
|
|
1552
1558
|
placeholder = "Click to edit",
|
|
1553
1559
|
multiline,
|
|
1554
1560
|
maxLength,
|
|
1561
|
+
minLength,
|
|
1562
|
+
validate,
|
|
1563
|
+
showLimits,
|
|
1555
1564
|
disabled,
|
|
1556
1565
|
onEditingChange,
|
|
1557
1566
|
onDraftChange,
|
|
@@ -1564,6 +1573,8 @@ var InlineEdit = React24.forwardRef(
|
|
|
1564
1573
|
const value = valueProp ?? internal;
|
|
1565
1574
|
const [editing, setEditing] = React24.useState(false);
|
|
1566
1575
|
const [draft, setDraft] = React24.useState(value);
|
|
1576
|
+
const [error, setError] = React24.useState(null);
|
|
1577
|
+
const errorId = React24.useId();
|
|
1567
1578
|
const fieldRef = React24.useRef(null);
|
|
1568
1579
|
const readRef = React24.useRef(null);
|
|
1569
1580
|
const cancelled = React24.useRef(false);
|
|
@@ -1577,14 +1588,29 @@ var InlineEdit = React24.forwardRef(
|
|
|
1577
1588
|
readRef.current?.focus();
|
|
1578
1589
|
}
|
|
1579
1590
|
}, [editing]);
|
|
1591
|
+
const problemWith = (text) => {
|
|
1592
|
+
if (minLength !== void 0 && text.trim().length < minLength) {
|
|
1593
|
+
return `Enter at least ${minLength} characters (${text.trim().length} now).`;
|
|
1594
|
+
}
|
|
1595
|
+
return validate?.(text) ?? null;
|
|
1596
|
+
};
|
|
1580
1597
|
const start = () => {
|
|
1581
1598
|
if (disabled) return;
|
|
1582
1599
|
setDraft(value);
|
|
1600
|
+
setError(null);
|
|
1583
1601
|
cancelled.current = false;
|
|
1584
1602
|
setEditing(true);
|
|
1585
1603
|
onEditingChange?.(true);
|
|
1586
1604
|
};
|
|
1587
1605
|
const finish = (commit, refocus) => {
|
|
1606
|
+
if (commit && draft !== value) {
|
|
1607
|
+
const problem = problemWith(draft);
|
|
1608
|
+
if (problem) {
|
|
1609
|
+
setError(problem);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
setError(null);
|
|
1588
1614
|
restoreFocus.current = refocus;
|
|
1589
1615
|
if (commit && draft !== value) {
|
|
1590
1616
|
if (valueProp === void 0) setInternal(draft);
|
|
@@ -1597,66 +1623,99 @@ var InlineEdit = React24.forwardRef(
|
|
|
1597
1623
|
const textClasses = cn("text-ui-input-value text-surface-foreground", textClassName);
|
|
1598
1624
|
const question = variant === "question";
|
|
1599
1625
|
const fill = multiline || question;
|
|
1600
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
1601
|
-
|
|
1602
|
-
value: draft,
|
|
1603
|
-
maxLength,
|
|
1604
|
-
"aria-label": ariaLabel,
|
|
1605
|
-
...multiline ? { rows: 1 } : { type: "text" },
|
|
1606
|
-
className: cn(
|
|
1607
|
-
"w-full px-3 py-1 outline-none",
|
|
1608
|
-
multiline && "field-sizing-content resize-none",
|
|
1609
|
-
question ? "rounded-none border-0 border-b-2 border-accent-foreground bg-transparent" : cn("rounded-md focus-visible:border-input-accent", fieldSurfaceClasses("default")),
|
|
1610
|
-
textClasses
|
|
1611
|
-
),
|
|
1612
|
-
onChange: (event) => {
|
|
1613
|
-
setDraft(event.target.value);
|
|
1614
|
-
onDraftChange?.(event.target.value);
|
|
1615
|
-
},
|
|
1616
|
-
onKeyDown: (event) => {
|
|
1617
|
-
if (event.key === "Escape") {
|
|
1618
|
-
cancelled.current = true;
|
|
1619
|
-
finish(false, true);
|
|
1620
|
-
} else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
|
|
1621
|
-
event.preventDefault();
|
|
1622
|
-
finish(true, true);
|
|
1623
|
-
}
|
|
1624
|
-
},
|
|
1625
|
-
onBlur: () => {
|
|
1626
|
-
if (!cancelled.current) finish(true, false);
|
|
1627
|
-
}
|
|
1628
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
1629
|
-
"button",
|
|
1626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
1627
|
+
"div",
|
|
1630
1628
|
{
|
|
1631
|
-
ref
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1629
|
+
ref,
|
|
1630
|
+
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),
|
|
1631
|
+
...props,
|
|
1632
|
+
children: editing ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
|
|
1633
|
+
React24.createElement(multiline ? "textarea" : "input", {
|
|
1634
|
+
ref: fieldRef,
|
|
1635
|
+
value: draft,
|
|
1636
|
+
maxLength,
|
|
1637
|
+
"aria-label": ariaLabel,
|
|
1638
|
+
"aria-invalid": error ? true : void 0,
|
|
1639
|
+
"aria-describedby": error || showLimits ? errorId : void 0,
|
|
1640
|
+
...multiline ? { rows: 1 } : { type: "text" },
|
|
1641
|
+
className: cn(
|
|
1642
|
+
"w-full px-3 py-1 outline-none",
|
|
1643
|
+
multiline && "field-sizing-content resize-none",
|
|
1644
|
+
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")),
|
|
1645
|
+
textClasses
|
|
1646
|
+
),
|
|
1647
|
+
onChange: (event) => {
|
|
1648
|
+
setDraft(event.target.value);
|
|
1649
|
+
if (error) setError(problemWith(event.target.value));
|
|
1650
|
+
onDraftChange?.(event.target.value);
|
|
1651
|
+
},
|
|
1652
|
+
onKeyDown: (event) => {
|
|
1653
|
+
if (event.key === "Escape") {
|
|
1654
|
+
cancelled.current = true;
|
|
1655
|
+
setError(null);
|
|
1656
|
+
finish(false, true);
|
|
1657
|
+
} else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
|
|
1658
|
+
event.preventDefault();
|
|
1659
|
+
finish(true, true);
|
|
1660
|
+
}
|
|
1661
|
+
},
|
|
1662
|
+
onBlur: () => {
|
|
1663
|
+
if (!cancelled.current) finish(true, false);
|
|
1664
|
+
}
|
|
1665
|
+
}),
|
|
1666
|
+
(error || showLimits) && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
1667
|
+
"p",
|
|
1651
1668
|
{
|
|
1652
|
-
|
|
1653
|
-
"
|
|
1654
|
-
className: "
|
|
1669
|
+
id: errorId,
|
|
1670
|
+
role: error ? "alert" : void 0,
|
|
1671
|
+
className: cn("flex items-start justify-between gap-2 px-3 text-ui-caption", error ? "text-destructive" : "text-secondary-muted-foreground"),
|
|
1672
|
+
children: [
|
|
1673
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { className: "flex items-start gap-2", children: [
|
|
1674
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react11.WarningCircle, { size: 16, "aria-hidden": true, className: "shrink-0" }),
|
|
1675
|
+
showLimits ? limitsText(minLength, maxLength) : error,
|
|
1676
|
+
showLimits && error && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "sr-only", children: error })
|
|
1677
|
+
] }),
|
|
1678
|
+
showLimits && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { "aria-hidden": true, className: "shrink-0 tabular-nums", children: [
|
|
1679
|
+
draft.length,
|
|
1680
|
+
maxLength !== void 0 && `/${maxLength}`
|
|
1681
|
+
] })
|
|
1682
|
+
]
|
|
1655
1683
|
}
|
|
1656
1684
|
)
|
|
1657
|
-
]
|
|
1685
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
1686
|
+
"button",
|
|
1687
|
+
{
|
|
1688
|
+
ref: readRef,
|
|
1689
|
+
type: "button",
|
|
1690
|
+
disabled,
|
|
1691
|
+
"aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
|
|
1692
|
+
onClick: start,
|
|
1693
|
+
className: cn(
|
|
1694
|
+
"group inline-flex min-w-0 max-w-full items-center gap-2 px-3 text-left outline-none",
|
|
1695
|
+
fill && "w-full",
|
|
1696
|
+
question ? (
|
|
1697
|
+
// Hover and focus show a 1px bottom border in the input colour; only a selected question gets the 2px accent
|
|
1698
|
+
// one. The extra 1px of bottom padding keeps the height identical so the text never jumps.
|
|
1699
|
+
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"
|
|
1700
|
+
) : "rounded-md border border-transparent py-1 enabled:focus-visible:border-input-accent",
|
|
1701
|
+
"enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
|
|
1702
|
+
textClasses
|
|
1703
|
+
),
|
|
1704
|
+
children: [
|
|
1705
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && "text-muted-foreground"), children: value || placeholder }),
|
|
1706
|
+
!fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
1707
|
+
import_react11.PencilSimple,
|
|
1708
|
+
{
|
|
1709
|
+
size: 16,
|
|
1710
|
+
"aria-hidden": true,
|
|
1711
|
+
className: "shrink-0 text-secondary-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
|
|
1712
|
+
}
|
|
1713
|
+
)
|
|
1714
|
+
]
|
|
1715
|
+
}
|
|
1716
|
+
)
|
|
1658
1717
|
}
|
|
1659
|
-
)
|
|
1718
|
+
);
|
|
1660
1719
|
}
|
|
1661
1720
|
);
|
|
1662
1721
|
InlineEdit.displayName = "InlineEdit";
|