@discuss-ds/ui 0.28.0 → 0.29.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/dist/index.d.cts CHANGED
@@ -328,8 +328,10 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
328
328
  defaultValue?: string;
329
329
  /** Called when an edit is committed (Enter, blur or the commit key for multiline) with a changed value. */
330
330
  onValueChange?: (value: string) => void;
331
- /** Shown in read mode, muted, while the value is empty. */
331
+ /** Shown in read mode while the value is empty, muted unless `placeholderTone` says otherwise. */
332
332
  placeholder?: string;
333
+ /** `regular` shows the placeholder in the normal text colour instead of the muted one, for hints that read as real content. Default `muted`. */
334
+ placeholderTone?: 'muted' | 'regular';
333
335
  /** Accessible name for the read button and the field. Required: there is no visible label. */
334
336
  'aria-label': string;
335
337
  /** Use a textarea. Enter inserts a line break; Cmd/Ctrl+Enter commits. */
@@ -668,6 +670,10 @@ interface QuestionEditorCardProps extends Omit<React.HTMLAttributes<HTMLDivEleme
668
670
  onTitleChange?: (title: string) => void;
669
671
  /** Shown while the title is empty. Defaults to "Click to write the question text". */
670
672
  titlePlaceholder?: string;
673
+ /** `regular` shows the title placeholder in the normal text colour instead of the muted one. Default `muted`. */
674
+ titlePlaceholderTone?: 'muted' | 'regular';
675
+ /** Shortest title (in characters) that may be saved. Turns on the title guardrail: see `QuestionHeader`'s `titleMinLength`. */
676
+ titleMinLength?: number;
671
677
  /** The question is being edited: accent border, counter and footer are shown. */
672
678
  active?: boolean;
673
679
  /**
@@ -717,6 +723,14 @@ interface QuestionHeaderProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
717
723
  onTitleChange?: (title: string) => void;
718
724
  /** Editor mode: shown while the title is empty. Defaults to "Click to write the question text". */
719
725
  titlePlaceholder?: string;
726
+ /** Editor mode: `regular` shows the title placeholder in the normal text colour instead of the muted one. Default `muted`. */
727
+ titlePlaceholderTone?: 'muted' | 'regular';
728
+ /**
729
+ * Editor mode: shortest title (in characters) that may be saved. When set, the title's limits guardrail turns on: while the title
730
+ * is being edited a line under it shows the allowed range and the live count (using `maxLength`), a title that is too short is not
731
+ * saved (the field stays open and says why), and the always-on counter is replaced by that line.
732
+ */
733
+ titleMinLength?: number;
720
734
  /** Editor mode: action buttons (copy, delete, preview, AI) revealed on hover or focus. */
721
735
  actions?: React.ReactNode;
722
736
  /** Editor mode: content shown right beside the "Question N" tag, e.g. the time allowed for the question. */
@@ -803,6 +817,18 @@ interface QuestionOptionEditorProps {
803
817
  onAdd?: () => void;
804
818
  /** Shown while the option is empty, for example "Option 1". */
805
819
  placeholder?: string;
820
+ /** `regular` shows the placeholder in the normal text colour instead of the muted one. Default `muted`. */
821
+ placeholderTone?: 'muted' | 'regular';
822
+ /**
823
+ * Shortest label (in characters, ignoring surrounding spaces) that may be saved. With `minLength` or `maxLength` the label is
824
+ * guarded like an `InlineEdit`: typing only changes a draft, Enter or leaving the field saves it through `onLabelChange`, a label
825
+ * that is too short is not saved (the field stays open and says why), Escape reverts, and while it is being edited a line under
826
+ * the row shows the allowed range and the live count. An unchanged label is never refused. Without either, `onLabelChange` is
827
+ * called on every keystroke as before.
828
+ */
829
+ minLength?: number;
830
+ /** Longest label (in characters). See `minLength`. */
831
+ maxLength?: number;
806
832
  /** Disables the trash button, for example when the question is already at its minimum number of options. */
807
833
  removeDisabled?: boolean;
808
834
  /** Disables the add (+) button, for example when the question is already at its maximum number of options. */
@@ -838,7 +864,7 @@ interface QuestionOptionEditorProps {
838
864
  */
839
865
  locked?: boolean;
840
866
  }
841
- declare function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }: QuestionOptionEditorProps): React.JSX.Element;
867
+ declare function QuestionOptionEditor({ label, onLabelChange, placeholder, placeholderTone, minLength, maxLength, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }: QuestionOptionEditorProps): React.JSX.Element;
842
868
 
843
869
  interface RankItemData {
844
870
  id: string;
package/dist/index.d.ts CHANGED
@@ -328,8 +328,10 @@ interface InlineEditProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'on
328
328
  defaultValue?: string;
329
329
  /** Called when an edit is committed (Enter, blur or the commit key for multiline) with a changed value. */
330
330
  onValueChange?: (value: string) => void;
331
- /** Shown in read mode, muted, while the value is empty. */
331
+ /** Shown in read mode while the value is empty, muted unless `placeholderTone` says otherwise. */
332
332
  placeholder?: string;
333
+ /** `regular` shows the placeholder in the normal text colour instead of the muted one, for hints that read as real content. Default `muted`. */
334
+ placeholderTone?: 'muted' | 'regular';
333
335
  /** Accessible name for the read button and the field. Required: there is no visible label. */
334
336
  'aria-label': string;
335
337
  /** Use a textarea. Enter inserts a line break; Cmd/Ctrl+Enter commits. */
@@ -668,6 +670,10 @@ interface QuestionEditorCardProps extends Omit<React.HTMLAttributes<HTMLDivEleme
668
670
  onTitleChange?: (title: string) => void;
669
671
  /** Shown while the title is empty. Defaults to "Click to write the question text". */
670
672
  titlePlaceholder?: string;
673
+ /** `regular` shows the title placeholder in the normal text colour instead of the muted one. Default `muted`. */
674
+ titlePlaceholderTone?: 'muted' | 'regular';
675
+ /** Shortest title (in characters) that may be saved. Turns on the title guardrail: see `QuestionHeader`'s `titleMinLength`. */
676
+ titleMinLength?: number;
671
677
  /** The question is being edited: accent border, counter and footer are shown. */
672
678
  active?: boolean;
673
679
  /**
@@ -717,6 +723,14 @@ interface QuestionHeaderProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
717
723
  onTitleChange?: (title: string) => void;
718
724
  /** Editor mode: shown while the title is empty. Defaults to "Click to write the question text". */
719
725
  titlePlaceholder?: string;
726
+ /** Editor mode: `regular` shows the title placeholder in the normal text colour instead of the muted one. Default `muted`. */
727
+ titlePlaceholderTone?: 'muted' | 'regular';
728
+ /**
729
+ * Editor mode: shortest title (in characters) that may be saved. When set, the title's limits guardrail turns on: while the title
730
+ * is being edited a line under it shows the allowed range and the live count (using `maxLength`), a title that is too short is not
731
+ * saved (the field stays open and says why), and the always-on counter is replaced by that line.
732
+ */
733
+ titleMinLength?: number;
720
734
  /** Editor mode: action buttons (copy, delete, preview, AI) revealed on hover or focus. */
721
735
  actions?: React.ReactNode;
722
736
  /** Editor mode: content shown right beside the "Question N" tag, e.g. the time allowed for the question. */
@@ -803,6 +817,18 @@ interface QuestionOptionEditorProps {
803
817
  onAdd?: () => void;
804
818
  /** Shown while the option is empty, for example "Option 1". */
805
819
  placeholder?: string;
820
+ /** `regular` shows the placeholder in the normal text colour instead of the muted one. Default `muted`. */
821
+ placeholderTone?: 'muted' | 'regular';
822
+ /**
823
+ * Shortest label (in characters, ignoring surrounding spaces) that may be saved. With `minLength` or `maxLength` the label is
824
+ * guarded like an `InlineEdit`: typing only changes a draft, Enter or leaving the field saves it through `onLabelChange`, a label
825
+ * that is too short is not saved (the field stays open and says why), Escape reverts, and while it is being edited a line under
826
+ * the row shows the allowed range and the live count. An unchanged label is never refused. Without either, `onLabelChange` is
827
+ * called on every keystroke as before.
828
+ */
829
+ minLength?: number;
830
+ /** Longest label (in characters). See `minLength`. */
831
+ maxLength?: number;
806
832
  /** Disables the trash button, for example when the question is already at its minimum number of options. */
807
833
  removeDisabled?: boolean;
808
834
  /** Disables the add (+) button, for example when the question is already at its maximum number of options. */
@@ -838,7 +864,7 @@ interface QuestionOptionEditorProps {
838
864
  */
839
865
  locked?: boolean;
840
866
  }
841
- declare function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }: QuestionOptionEditorProps): React.JSX.Element;
867
+ declare function QuestionOptionEditor({ label, onLabelChange, placeholder, placeholderTone, minLength, maxLength, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }: QuestionOptionEditorProps): React.JSX.Element;
842
868
 
843
869
  interface RankItemData {
844
870
  id: string;
package/dist/index.js CHANGED
@@ -1444,8 +1444,7 @@ import * as React24 from "react";
1444
1444
  import { PencilSimple, WarningCircle as WarningCircle2 } from "@phosphor-icons/react";
1445
1445
  import { Fragment as Fragment4, jsx as jsx25, jsxs as jsxs17 } from "react/jsx-runtime";
1446
1446
  function limitsText(min, max) {
1447
- if (min !== void 0 && max !== void 0) return `${min}\u2013${max} characters`;
1448
- if (min !== void 0) return `At least ${min} characters`;
1447
+ if (min !== void 0) return `${min} ${min === 1 ? "character" : "characters"} required`;
1449
1448
  if (max !== void 0) return `Up to ${max} characters`;
1450
1449
  return "";
1451
1450
  }
@@ -1457,6 +1456,7 @@ var InlineEdit = React24.forwardRef(
1457
1456
  defaultValue = "",
1458
1457
  onValueChange,
1459
1458
  placeholder = "Click to edit",
1459
+ placeholderTone = "muted",
1460
1460
  multiline,
1461
1461
  maxLength,
1462
1462
  minLength,
@@ -1605,7 +1605,7 @@ var InlineEdit = React24.forwardRef(
1605
1605
  textClasses
1606
1606
  ),
1607
1607
  children: [
1608
- /* @__PURE__ */ jsx25("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && "text-muted-foreground"), children: value || placeholder }),
1608
+ /* @__PURE__ */ jsx25("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && placeholderTone === "muted" && "text-muted-foreground"), children: value || placeholder }),
1609
1609
  !fill && /* @__PURE__ */ jsx25(
1610
1610
  PencilSimple,
1611
1611
  {
@@ -2663,7 +2663,7 @@ import { DotsSixVertical } from "@phosphor-icons/react";
2663
2663
  import { jsx as jsx41, jsxs as jsxs29 } from "react/jsx-runtime";
2664
2664
  var eyebrow = "text-ui-caption uppercase text-secondary-muted-foreground";
2665
2665
  var QuestionHeader = React40.forwardRef(
2666
- ({ className, number, title, required, error, onDismissError, editor, onTitleChange, titlePlaceholder = "Click to write the question text", actions, meta, maxLength = 2e3, active, showCounter = true, dragHandleProps, showDragHandle = true, ...props }, ref) => {
2666
+ ({ className, number, title, required, error, onDismissError, editor, onTitleChange, titlePlaceholder = "Click to write the question text", titlePlaceholderTone, titleMinLength, actions, meta, maxLength = 2e3, active, showCounter = true, dragHandleProps, showDragHandle = true, ...props }, ref) => {
2667
2667
  const [draft, setDraft] = React40.useState(null);
2668
2668
  const label = String(number).padStart(2, "0");
2669
2669
  const showError = error !== void 0 && error !== false;
@@ -2718,6 +2718,9 @@ var QuestionHeader = React40.forwardRef(
2718
2718
  className: "-mx-3 w-auto",
2719
2719
  "aria-label": "Question title",
2720
2720
  placeholder: titlePlaceholder,
2721
+ placeholderTone: titlePlaceholderTone,
2722
+ minLength: titleMinLength,
2723
+ showLimits: titleMinLength !== void 0,
2721
2724
  value: text,
2722
2725
  maxLength,
2723
2726
  onValueChange: onTitleChange,
@@ -2728,7 +2731,7 @@ var QuestionHeader = React40.forwardRef(
2728
2731
  textClassName: "text-heading-h4"
2729
2732
  }
2730
2733
  ),
2731
- showCounter && /* @__PURE__ */ jsxs29("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2734
+ showCounter && titleMinLength === void 0 && /* @__PURE__ */ jsxs29("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2732
2735
  count,
2733
2736
  "/",
2734
2737
  maxLength,
@@ -2761,6 +2764,8 @@ var QuestionEditorCard = React41.forwardRef(
2761
2764
  title,
2762
2765
  onTitleChange,
2763
2766
  titlePlaceholder,
2767
+ titlePlaceholderTone,
2768
+ titleMinLength,
2764
2769
  active,
2765
2770
  hovered,
2766
2771
  maxLength,
@@ -2807,6 +2812,8 @@ var QuestionEditorCard = React41.forwardRef(
2807
2812
  title,
2808
2813
  onTitleChange,
2809
2814
  titlePlaceholder,
2815
+ titlePlaceholderTone,
2816
+ titleMinLength,
2810
2817
  active,
2811
2818
  showCounter: !!active,
2812
2819
  dragHandleProps,
@@ -2969,7 +2976,7 @@ QuestionNavItem.displayName = "QuestionNavItem";
2969
2976
 
2970
2977
  // src/components/Question Types/QuestionOption.tsx
2971
2978
  import * as React44 from "react";
2972
- import { Check as Check4, DotsSixVertical as DotsSixVertical3, Plus as Plus4, Trash as Trash4 } from "@phosphor-icons/react";
2979
+ import { Check as Check4, DotsSixVertical as DotsSixVertical3, Plus as Plus4, Trash as Trash4, WarningCircle as WarningCircle4 } from "@phosphor-icons/react";
2973
2980
  import { Fragment as Fragment9, jsx as jsx45, jsxs as jsxs32 } from "react/jsx-runtime";
2974
2981
  var optionClasses = "flex w-full max-w-150 cursor-pointer items-center gap-2 rounded-md border border-border bg-surface px-4 py-2 text-body-base text-surface-foreground transition-colors hover:bg-accent-soft hover:shadow-md has-[[data-state=checked]]:border-accent-foreground has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50";
2975
2982
  function QuestionOption(props) {
@@ -3024,8 +3031,34 @@ var QuestionOtherOption = React44.forwardRef(
3024
3031
  }
3025
3032
  );
3026
3033
  QuestionOtherOption.displayName = "QuestionOtherOption";
3027
- function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }) {
3034
+ function limitsText2(min, max) {
3035
+ if (min !== void 0) return `${min} ${min === 1 ? "character" : "characters"} required`;
3036
+ if (max !== void 0) return `Up to ${max} characters`;
3037
+ return "";
3038
+ }
3039
+ function QuestionOptionEditor({ label, onLabelChange, placeholder, placeholderTone = "muted", minLength, maxLength, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }) {
3028
3040
  const reveal = kind !== void 0;
3041
+ const guarded = minLength !== void 0 || maxLength !== void 0;
3042
+ const [draft, setDraft] = React44.useState(null);
3043
+ const [error, setError] = React44.useState(null);
3044
+ const helperId = React44.useId();
3045
+ const fieldRef = React44.useRef(null);
3046
+ const skipBlur = React44.useRef(false);
3047
+ const problemWith = (text) => minLength !== void 0 && text.trim().length < minLength ? `Enter at least ${minLength} ${minLength === 1 ? "character" : "characters"}.` : null;
3048
+ const save = () => {
3049
+ if (draft === null) return true;
3050
+ if (draft !== label) {
3051
+ const problem = problemWith(draft);
3052
+ if (problem) {
3053
+ setError(problem);
3054
+ return false;
3055
+ }
3056
+ onLabelChange?.(draft);
3057
+ }
3058
+ setDraft(null);
3059
+ setError(null);
3060
+ return true;
3061
+ };
3029
3062
  const gripProps = dragHandleProps ? {
3030
3063
  "aria-label": rank ? `Reorder option ${rank}` : "Reorder option",
3031
3064
  ...dragHandleProps,
@@ -3033,18 +3066,18 @@ function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onA
3033
3066
  } : { "aria-hidden": true };
3034
3067
  const grip = dragHandleProps ? /* @__PURE__ */ jsx45("span", { ...gripProps, className: cn("shrink-0", gripProps.className), children: /* @__PURE__ */ jsx45(DotsSixVertical3, { size: 20, "aria-hidden": true, className: "text-surface-foreground" }) }) : /* @__PURE__ */ jsx45(DotsSixVertical3, { size: 20, "aria-hidden": true, className: "shrink-0 text-surface-foreground" });
3035
3068
  return /* @__PURE__ */ jsxs32("div", { className: cn("group/option flex w-full items-center gap-2", className), children: [
3036
- /* @__PURE__ */ jsxs32(
3069
+ /* @__PURE__ */ jsx45(
3037
3070
  "div",
3038
3071
  {
3039
3072
  className: cn(
3040
- "flex h-11.5 min-w-0 flex-1 items-center gap-2 rounded-md border bg-surface px-4 py-2 focus-within:border-input-accent",
3073
+ "flex min-h-11.5 min-w-0 flex-1 flex-col justify-center gap-1 rounded-md border bg-surface px-4 py-2 focus-within:border-input-accent",
3041
3074
  reveal ? (
3042
3075
  // The border is always visible and does not change on hover; only the shadow lifts the row. The field being edited keeps the accent.
3043
3076
  cn("border-border group-hover/option:shadow-md group-focus-within/option:shadow-md", lifted && "shadow-md")
3044
3077
  ) : "border-border hover:border-input-muted hover:shadow-md"
3045
3078
  ),
3046
- children: [
3047
- kind === "rank" ? /* @__PURE__ */ jsxs32(Fragment9, { children: [
3079
+ children: /* @__PURE__ */ jsxs32("div", { className: "flex min-w-0 items-start gap-2", children: [
3080
+ (kind !== void 0 || !locked) && /* @__PURE__ */ jsx45("div", { className: "flex h-7 shrink-0 items-center gap-2", children: kind === "rank" ? /* @__PURE__ */ jsxs32(Fragment9, { children: [
3048
3081
  !locked && grip,
3049
3082
  /* @__PURE__ */ jsx45(
3050
3083
  "span",
@@ -3077,18 +3110,76 @@ function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onA
3077
3110
  )
3078
3111
  }
3079
3112
  )
3080
- ] }) : locked ? null : grip,
3081
- /* @__PURE__ */ jsx45(
3082
- "input",
3083
- {
3084
- "aria-label": "Option label",
3085
- placeholder,
3086
- value: label,
3087
- onChange: (event) => onLabelChange?.(event.target.value),
3088
- className: "min-w-0 flex-1 bg-transparent text-body-base text-surface-foreground outline-none"
3089
- }
3090
- )
3091
- ]
3113
+ ] }) : locked ? null : grip }),
3114
+ /* @__PURE__ */ jsxs32("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
3115
+ /* @__PURE__ */ jsx45(
3116
+ "input",
3117
+ {
3118
+ ref: fieldRef,
3119
+ "aria-label": "Option label",
3120
+ "aria-invalid": error ? true : void 0,
3121
+ "aria-describedby": guarded && draft !== null ? helperId : void 0,
3122
+ placeholder,
3123
+ maxLength,
3124
+ value: guarded ? draft ?? label : label,
3125
+ onFocus: () => {
3126
+ if (guarded && draft === null) setDraft(label);
3127
+ },
3128
+ onChange: (event) => {
3129
+ if (!guarded) return onLabelChange?.(event.target.value);
3130
+ setDraft(event.target.value);
3131
+ if (error) setError(problemWith(event.target.value));
3132
+ },
3133
+ onKeyDown: (event) => {
3134
+ if (!guarded) return;
3135
+ if (event.key === "Escape") {
3136
+ skipBlur.current = true;
3137
+ setDraft(null);
3138
+ setError(null);
3139
+ fieldRef.current?.blur();
3140
+ } else if (event.key === "Enter") {
3141
+ event.preventDefault();
3142
+ if (save()) {
3143
+ skipBlur.current = true;
3144
+ fieldRef.current?.blur();
3145
+ }
3146
+ }
3147
+ },
3148
+ onBlur: () => {
3149
+ if (!guarded) return;
3150
+ if (skipBlur.current) {
3151
+ skipBlur.current = false;
3152
+ return;
3153
+ }
3154
+ save();
3155
+ },
3156
+ className: cn(
3157
+ "min-w-0 flex-1 bg-transparent text-body-base text-surface-foreground outline-none",
3158
+ placeholderTone === "regular" ? "placeholder:text-surface-foreground" : "placeholder:text-muted-foreground"
3159
+ )
3160
+ }
3161
+ ),
3162
+ guarded && draft !== null && /* @__PURE__ */ jsxs32(
3163
+ "p",
3164
+ {
3165
+ id: helperId,
3166
+ role: error ? "alert" : void 0,
3167
+ className: cn("flex items-start justify-between gap-2 text-ui-caption", error ? "text-destructive" : "text-secondary-muted-foreground"),
3168
+ children: [
3169
+ /* @__PURE__ */ jsxs32("span", { className: "flex items-start gap-2", children: [
3170
+ error && /* @__PURE__ */ jsx45(WarningCircle4, { size: 16, "aria-hidden": true, className: "shrink-0" }),
3171
+ limitsText2(minLength, maxLength),
3172
+ error && /* @__PURE__ */ jsx45("span", { className: "sr-only", children: error })
3173
+ ] }),
3174
+ /* @__PURE__ */ jsxs32("span", { "aria-hidden": true, className: "shrink-0 tabular-nums", children: [
3175
+ draft.length,
3176
+ maxLength !== void 0 && `/${maxLength}`
3177
+ ] })
3178
+ ]
3179
+ }
3180
+ )
3181
+ ] })
3182
+ ] })
3092
3183
  }
3093
3184
  ),
3094
3185
  !locked && /* @__PURE__ */ jsxs32(