@discuss-ds/ui 0.2.0 → 0.3.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,13 @@
1
1
  # @discuss-ds/ui
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#9](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/9) [`db43142`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/db4314275efe9be5428b446ea3f170b1ab5d3829) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `InlineEdit` gets a second style for question text and clearer rules for long text. A short single-line label keeps the pencil and hugs its text; `multiline` (longer text) now hides the pencil and fills the full width. New `variant="question"`: full width, no pencil, square corners, and a bottom border on hover and focus. New `selected` keeps that bottom border while the owning question is selected. In the question variant Enter saves and Shift+Enter adds a line break. New `onDraftChange` reports the text on every keystroke.
8
+
9
+ `QuestionHeader` (and so `QuestionEditorCard`) editor mode now edits the title with the question-variant `InlineEdit`: click the title to edit, Enter or blur saves, and the underline stays while the card is `active`. `onTitleChange` now fires when an edit is saved instead of on every keystroke; the character counter still updates live.
10
+
3
11
  ## 0.2.0
4
12
 
5
13
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1531,6 +1531,9 @@ var InlineEdit = React24.forwardRef(
1531
1531
  maxLength,
1532
1532
  disabled,
1533
1533
  onEditingChange,
1534
+ onDraftChange,
1535
+ variant = "default",
1536
+ selected,
1534
1537
  "aria-label": ariaLabel,
1535
1538
  ...props
1536
1539
  }, ref) => {
@@ -1566,26 +1569,32 @@ var InlineEdit = React24.forwardRef(
1566
1569
  }
1567
1570
  setEditing(false);
1568
1571
  onEditingChange?.(false);
1572
+ onDraftChange?.(commit ? draft : value);
1569
1573
  };
1570
1574
  const textClasses = cn("text-ui-input-value text-surface-foreground", textClassName);
1571
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { ref, className: cn("inline-flex min-w-0 max-w-full", className), ...props, children: editing ? React24.createElement(multiline ? "textarea" : "input", {
1575
+ const question = variant === "question";
1576
+ const fill = multiline || question;
1577
+ 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", {
1572
1578
  ref: fieldRef,
1573
1579
  value: draft,
1574
1580
  maxLength,
1575
1581
  "aria-label": ariaLabel,
1576
1582
  ...multiline ? { rows: 1 } : { type: "text" },
1577
1583
  className: cn(
1578
- "w-full rounded-md px-3 py-1 outline-none focus-visible:border-input-accent",
1584
+ "w-full px-3 py-1 outline-none",
1579
1585
  multiline && "field-sizing-content resize-none",
1580
- fieldSurfaceClasses("default"),
1586
+ question ? "rounded-none border-0 border-b-2 border-input-accent bg-transparent" : cn("rounded-md focus-visible:border-input-accent", fieldSurfaceClasses("default")),
1581
1587
  textClasses
1582
1588
  ),
1583
- onChange: (event) => setDraft(event.target.value),
1589
+ onChange: (event) => {
1590
+ setDraft(event.target.value);
1591
+ onDraftChange?.(event.target.value);
1592
+ },
1584
1593
  onKeyDown: (event) => {
1585
1594
  if (event.key === "Escape") {
1586
1595
  cancelled.current = true;
1587
1596
  finish(false, true);
1588
- } else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey)) {
1597
+ } else if (event.key === "Enter" && (!multiline || event.metaKey || event.ctrlKey || question && !event.shiftKey)) {
1589
1598
  event.preventDefault();
1590
1599
  finish(true, true);
1591
1600
  }
@@ -1602,13 +1611,16 @@ var InlineEdit = React24.forwardRef(
1602
1611
  "aria-label": `${ariaLabel}: ${value || placeholder}. Edit`,
1603
1612
  onClick: start,
1604
1613
  className: cn(
1605
- "group inline-flex min-w-0 max-w-full items-center gap-2 rounded-md border border-transparent px-3 py-1 text-left outline-none",
1614
+ "group inline-flex min-w-0 max-w-full items-center gap-2 px-3 py-1 text-left outline-none",
1615
+ fill && "w-full",
1616
+ question ? cn("rounded-none border-b-2", selected ? "border-input-accent" : "border-transparent") : "rounded-md border border-transparent",
1606
1617
  "enabled:hover:bg-secondary enabled:focus-visible:border-input-accent disabled:cursor-not-allowed disabled:opacity-50",
1618
+ question && "enabled:hover:border-input-accent",
1607
1619
  textClasses
1608
1620
  ),
1609
1621
  children: [
1610
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: cn("min-w-0 truncate", multiline && "whitespace-pre-wrap", !value && "text-muted-foreground"), children: value || placeholder }),
1611
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1622
+ /* @__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 }),
1623
+ !fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1612
1624
  import_react11.PencilSimple,
1613
1625
  {
1614
1626
  size: 16,
@@ -2635,10 +2647,12 @@ var import_jsx_runtime41 = require("react/jsx-runtime");
2635
2647
  var eyebrow = "text-ui-caption uppercase text-secondary-muted-foreground";
2636
2648
  var QuestionHeader = React40.forwardRef(
2637
2649
  ({ className, number, title, required, error, onDismissError, editor, onTitleChange, actions, maxLength = 2e3, active, showCounter = true, ...props }, ref) => {
2650
+ const [draft, setDraft] = React40.useState(null);
2638
2651
  const label = String(number).padStart(2, "0");
2639
2652
  const showError = error !== void 0 && error !== false;
2640
2653
  if (editor) {
2641
2654
  const text = typeof title === "string" ? title : "";
2655
+ const count = (draft ?? text).length;
2642
2656
  return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { ref, className: cn("group/header flex w-full flex-col gap-2", className), ...props, children: [
2643
2657
  /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex items-center justify-between", children: [
2644
2658
  /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
@@ -2658,18 +2672,26 @@ var QuestionHeader = React40.forwardRef(
2658
2672
  actions && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "flex items-center gap-2 opacity-0 transition-opacity group-focus-within/header:opacity-100 group-hover/header:opacity-100", children: actions })
2659
2673
  ] }),
2660
2674
  /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
2661
- "textarea",
2675
+ InlineEdit,
2662
2676
  {
2663
- rows: 1,
2677
+ variant: "question",
2678
+ multiline: true,
2679
+ selected: active,
2680
+ className: "-mx-3 w-auto",
2664
2681
  "aria-label": "Question title",
2682
+ placeholder: "Click to write the question text",
2665
2683
  value: text,
2666
2684
  maxLength,
2667
- onChange: (event) => onTitleChange?.(event.target.value),
2668
- className: "field-sizing-content w-full resize-none bg-transparent text-heading-h4 text-surface-foreground outline-none"
2685
+ onValueChange: onTitleChange,
2686
+ onDraftChange: setDraft,
2687
+ onEditingChange: (editing) => {
2688
+ if (!editing) setDraft(null);
2689
+ },
2690
+ textClassName: "text-heading-h4"
2669
2691
  }
2670
2692
  ),
2671
2693
  showCounter && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2672
- text.length,
2694
+ count,
2673
2695
  "/",
2674
2696
  maxLength,
2675
2697
  " characters"