@discuss-ds/ui 0.2.0 → 0.3.1

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,19 @@
1
1
  # @discuss-ds/ui
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#11](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/11) [`515842c`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/515842c8cb05412776f3fe76bc60623230aaec22) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `InlineEdit` question variant: on hover or focus the bottom border now uses the input border colour. Only a `selected` question (and the field while editing) takes the accent foreground colour.
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#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.
14
+
15
+ `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.
16
+
3
17
  ## 0.2.0
4
18
 
5
19
  ### 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-accent-foreground 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,18 @@ 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",
1606
- "enabled:hover:bg-secondary enabled:focus-visible:border-input-accent disabled:cursor-not-allowed disabled:opacity-50",
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 ? (
1617
+ // Hover and focus use the input border colour; only a selected question takes the accent.
1618
+ cn("rounded-none border-b-2", selected ? "border-accent-foreground" : "border-transparent enabled:hover:border-input enabled:focus-visible:border-input")
1619
+ ) : "rounded-md border border-transparent enabled:focus-visible:border-input-accent",
1620
+ "enabled:hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1607
1621
  textClasses
1608
1622
  ),
1609
1623
  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)(
1624
+ /* @__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 }),
1625
+ !fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1612
1626
  import_react11.PencilSimple,
1613
1627
  {
1614
1628
  size: 16,
@@ -2635,10 +2649,12 @@ var import_jsx_runtime41 = require("react/jsx-runtime");
2635
2649
  var eyebrow = "text-ui-caption uppercase text-secondary-muted-foreground";
2636
2650
  var QuestionHeader = React40.forwardRef(
2637
2651
  ({ className, number, title, required, error, onDismissError, editor, onTitleChange, actions, maxLength = 2e3, active, showCounter = true, ...props }, ref) => {
2652
+ const [draft, setDraft] = React40.useState(null);
2638
2653
  const label = String(number).padStart(2, "0");
2639
2654
  const showError = error !== void 0 && error !== false;
2640
2655
  if (editor) {
2641
2656
  const text = typeof title === "string" ? title : "";
2657
+ const count = (draft ?? text).length;
2642
2658
  return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { ref, className: cn("group/header flex w-full flex-col gap-2", className), ...props, children: [
2643
2659
  /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex items-center justify-between", children: [
2644
2660
  /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
@@ -2658,18 +2674,26 @@ var QuestionHeader = React40.forwardRef(
2658
2674
  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
2675
  ] }),
2660
2676
  /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
2661
- "textarea",
2677
+ InlineEdit,
2662
2678
  {
2663
- rows: 1,
2679
+ variant: "question",
2680
+ multiline: true,
2681
+ selected: active,
2682
+ className: "-mx-3 w-auto",
2664
2683
  "aria-label": "Question title",
2684
+ placeholder: "Click to write the question text",
2665
2685
  value: text,
2666
2686
  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"
2687
+ onValueChange: onTitleChange,
2688
+ onDraftChange: setDraft,
2689
+ onEditingChange: (editing) => {
2690
+ if (!editing) setDraft(null);
2691
+ },
2692
+ textClassName: "text-heading-h4"
2669
2693
  }
2670
2694
  ),
2671
2695
  showCounter && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2672
- text.length,
2696
+ count,
2673
2697
  "/",
2674
2698
  maxLength,
2675
2699
  " characters"