@discuss-ds/ui 0.20.0 → 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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 0.20.0
4
10
 
5
11
  ### Minor 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,
@@ -1554,6 +1560,7 @@ var InlineEdit = React24.forwardRef(
1554
1560
  maxLength,
1555
1561
  minLength,
1556
1562
  validate,
1563
+ showLimits,
1557
1564
  disabled,
1558
1565
  onEditingChange,
1559
1566
  onDraftChange,
@@ -1620,7 +1627,7 @@ var InlineEdit = React24.forwardRef(
1620
1627
  "div",
1621
1628
  {
1622
1629
  ref,
1623
- 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),
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),
1624
1631
  ...props,
1625
1632
  children: editing ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
1626
1633
  React24.createElement(multiline ? "textarea" : "input", {
@@ -1629,7 +1636,7 @@ var InlineEdit = React24.forwardRef(
1629
1636
  maxLength,
1630
1637
  "aria-label": ariaLabel,
1631
1638
  "aria-invalid": error ? true : void 0,
1632
- "aria-describedby": error ? errorId : void 0,
1639
+ "aria-describedby": error || showLimits ? errorId : void 0,
1633
1640
  ...multiline ? { rows: 1 } : { type: "text" },
1634
1641
  className: cn(
1635
1642
  "w-full px-3 py-1 outline-none",
@@ -1656,10 +1663,25 @@ var InlineEdit = React24.forwardRef(
1656
1663
  if (!cancelled.current) finish(true, false);
1657
1664
  }
1658
1665
  }),
1659
- error && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("p", { id: errorId, role: "alert", className: "flex items-start gap-2 px-3 text-ui-caption text-destructive", children: [
1660
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_react11.WarningCircle, { size: 16, "aria-hidden": true, className: "shrink-0" }),
1661
- error
1662
- ] })
1666
+ (error || showLimits) && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
1667
+ "p",
1668
+ {
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
+ ]
1683
+ }
1684
+ )
1663
1685
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
1664
1686
  "button",
1665
1687
  {