@discuss-ds/ui 0.19.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @discuss-ds/ui
2
2
 
3
+ ## 0.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
9
+ ## 0.19.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#80](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/80) [`d84a221`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/d84a221292b9b197c2eaf8d3ee671ed1896866f8) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `ChatInput`: the send button is now round (it was a rounded square), matching the Figma chat input.
14
+
3
15
  ## 0.19.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -714,7 +714,7 @@ var ChatInput = React11.forwardRef(
714
714
  "aria-label": sendLabel,
715
715
  disabled: disabled || !filled,
716
716
  onClick: submit,
717
- className: cn(!filled && "disabled:opacity-100 disabled:border-border disabled:text-muted-foreground"),
717
+ className: cn("rounded-full", !filled && "disabled:opacity-100 disabled:border-border disabled:text-muted-foreground"),
718
718
  children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react3.ArrowUp, { size: 16, "aria-hidden": true })
719
719
  }
720
720
  )
@@ -1552,6 +1552,8 @@ var InlineEdit = React24.forwardRef(
1552
1552
  placeholder = "Click to edit",
1553
1553
  multiline,
1554
1554
  maxLength,
1555
+ minLength,
1556
+ validate,
1555
1557
  disabled,
1556
1558
  onEditingChange,
1557
1559
  onDraftChange,
@@ -1564,6 +1566,8 @@ var InlineEdit = React24.forwardRef(
1564
1566
  const value = valueProp ?? internal;
1565
1567
  const [editing, setEditing] = React24.useState(false);
1566
1568
  const [draft, setDraft] = React24.useState(value);
1569
+ const [error, setError] = React24.useState(null);
1570
+ const errorId = React24.useId();
1567
1571
  const fieldRef = React24.useRef(null);
1568
1572
  const readRef = React24.useRef(null);
1569
1573
  const cancelled = React24.useRef(false);
@@ -1577,14 +1581,29 @@ var InlineEdit = React24.forwardRef(
1577
1581
  readRef.current?.focus();
1578
1582
  }
1579
1583
  }, [editing]);
1584
+ const problemWith = (text) => {
1585
+ if (minLength !== void 0 && text.trim().length < minLength) {
1586
+ return `Enter at least ${minLength} characters (${text.trim().length} now).`;
1587
+ }
1588
+ return validate?.(text) ?? null;
1589
+ };
1580
1590
  const start = () => {
1581
1591
  if (disabled) return;
1582
1592
  setDraft(value);
1593
+ setError(null);
1583
1594
  cancelled.current = false;
1584
1595
  setEditing(true);
1585
1596
  onEditingChange?.(true);
1586
1597
  };
1587
1598
  const finish = (commit, refocus) => {
1599
+ if (commit && draft !== value) {
1600
+ const problem = problemWith(draft);
1601
+ if (problem) {
1602
+ setError(problem);
1603
+ return;
1604
+ }
1605
+ }
1606
+ setError(null);
1588
1607
  restoreFocus.current = refocus;
1589
1608
  if (commit && draft !== value) {
1590
1609
  if (valueProp === void 0) setInternal(draft);
@@ -1597,66 +1616,84 @@ var InlineEdit = React24.forwardRef(
1597
1616
  const textClasses = cn("text-ui-input-value text-surface-foreground", textClassName);
1598
1617
  const question = variant === "question";
1599
1618
  const fill = multiline || question;
1600
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("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", {
1601
- ref: fieldRef,
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",
1619
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1620
+ "div",
1630
1621
  {
1631
- ref: readRef,
1632
- type: "button",
1633
- disabled,
1634
- "aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
1635
- onClick: start,
1636
- className: cn(
1637
- "group inline-flex min-w-0 max-w-full items-center gap-2 px-3 text-left outline-none",
1638
- fill && "w-full",
1639
- question ? (
1640
- // Hover and focus show a 1px bottom border in the input colour; only a selected question gets the 2px accent
1641
- // one. The extra 1px of bottom padding keeps the height identical so the text never jumps.
1642
- 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"
1643
- ) : "rounded-md border border-transparent py-1 enabled:focus-visible:border-input-accent",
1644
- "enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1645
- textClasses
1646
- ),
1647
- children: [
1648
- /* @__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 }),
1649
- !fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1650
- import_react11.PencilSimple,
1651
- {
1652
- size: 16,
1653
- "aria-hidden": true,
1654
- className: "shrink-0 text-secondary-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
1622
+ 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),
1624
+ ...props,
1625
+ children: editing ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_jsx_runtime25.Fragment, { children: [
1626
+ React24.createElement(multiline ? "textarea" : "input", {
1627
+ ref: fieldRef,
1628
+ value: draft,
1629
+ maxLength,
1630
+ "aria-label": ariaLabel,
1631
+ "aria-invalid": error ? true : void 0,
1632
+ "aria-describedby": error ? errorId : void 0,
1633
+ ...multiline ? { rows: 1 } : { type: "text" },
1634
+ className: cn(
1635
+ "w-full px-3 py-1 outline-none",
1636
+ multiline && "field-sizing-content resize-none",
1637
+ 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")),
1638
+ textClasses
1639
+ ),
1640
+ onChange: (event) => {
1641
+ setDraft(event.target.value);
1642
+ if (error) setError(problemWith(event.target.value));
1643
+ onDraftChange?.(event.target.value);
1644
+ },
1645
+ onKeyDown: (event) => {
1646
+ if (event.key === "Escape") {
1647
+ cancelled.current = true;
1648
+ setError(null);
1649
+ finish(false, true);
1650
+ } else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
1651
+ event.preventDefault();
1652
+ finish(true, true);
1653
+ }
1654
+ },
1655
+ onBlur: () => {
1656
+ if (!cancelled.current) finish(true, false);
1655
1657
  }
1656
- )
1657
- ]
1658
+ }),
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
+ ] })
1663
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
1664
+ "button",
1665
+ {
1666
+ ref: readRef,
1667
+ type: "button",
1668
+ disabled,
1669
+ "aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
1670
+ onClick: start,
1671
+ className: cn(
1672
+ "group inline-flex min-w-0 max-w-full items-center gap-2 px-3 text-left outline-none",
1673
+ fill && "w-full",
1674
+ question ? (
1675
+ // Hover and focus show a 1px bottom border in the input colour; only a selected question gets the 2px accent
1676
+ // one. The extra 1px of bottom padding keeps the height identical so the text never jumps.
1677
+ 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"
1678
+ ) : "rounded-md border border-transparent py-1 enabled:focus-visible:border-input-accent",
1679
+ "enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1680
+ textClasses
1681
+ ),
1682
+ children: [
1683
+ /* @__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 }),
1684
+ !fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1685
+ import_react11.PencilSimple,
1686
+ {
1687
+ size: 16,
1688
+ "aria-hidden": true,
1689
+ className: "shrink-0 text-secondary-muted-foreground opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
1690
+ }
1691
+ )
1692
+ ]
1693
+ }
1694
+ )
1658
1695
  }
1659
- ) });
1696
+ );
1660
1697
  }
1661
1698
  );
1662
1699
  InlineEdit.displayName = "InlineEdit";