@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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @discuss-ds/ui
2
2
 
3
+ ## 0.29.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#104](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/104) [`1918d72`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/1918d72cab1c11e67c889abd7158e3b07aabe365) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `QuestionOptionEditor`: the helper line shown while a guarded option is edited lines up with the option text instead of the drag grip.
8
+
9
+ - [#106](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/106) [`3b04f34`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/3b04f34cedb63b5ae41edefedb0ed13de28fc3b8) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `QuestionOptionEditor`: the grip, indicator or number stays vertically centred with the option text in the default state.
10
+
11
+ ## 0.29.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#102](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/102) [`036f9fc`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/036f9fc0c1ed044ee9a1706f5869fb27bd2e3705) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - Guardrails for question and option text. `QuestionEditorCard` and `QuestionHeader` take `titleMinLength` (with `maxLength`): while the title is edited a line shows "N characters required" with the live count out of the maximum, a title that is too short is not saved, and the always-on counter gives way to that line. `QuestionOptionEditor` takes `minLength` and `maxLength` with the same behaviour (draft, helper line inside the option's box while editing, refusal, Escape to revert). The same line now reads "N characters required" in `InlineEdit`'s `showLimits` (it used to read "MIN–MAX characters"). `InlineEdit`, `QuestionHeader` (`titlePlaceholderTone`), `QuestionEditorCard` and `QuestionOptionEditor` (`placeholderTone`) can show their placeholder in the regular text colour. Apart from that wording, everything is opt-in: without the new props nothing changes.
16
+
3
17
  ## 0.28.0
4
18
 
5
19
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1598,8 +1598,7 @@ var React24 = __toESM(require("react"), 1);
1598
1598
  var import_react11 = require("@phosphor-icons/react");
1599
1599
  var import_jsx_runtime25 = require("react/jsx-runtime");
1600
1600
  function limitsText(min, max) {
1601
- if (min !== void 0 && max !== void 0) return `${min}\u2013${max} characters`;
1602
- if (min !== void 0) return `At least ${min} characters`;
1601
+ if (min !== void 0) return `${min} ${min === 1 ? "character" : "characters"} required`;
1603
1602
  if (max !== void 0) return `Up to ${max} characters`;
1604
1603
  return "";
1605
1604
  }
@@ -1611,6 +1610,7 @@ var InlineEdit = React24.forwardRef(
1611
1610
  defaultValue = "",
1612
1611
  onValueChange,
1613
1612
  placeholder = "Click to edit",
1613
+ placeholderTone = "muted",
1614
1614
  multiline,
1615
1615
  maxLength,
1616
1616
  minLength,
@@ -1759,7 +1759,7 @@ var InlineEdit = React24.forwardRef(
1759
1759
  textClasses
1760
1760
  ),
1761
1761
  children: [
1762
- /* @__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 }),
1762
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: cn("min-w-0", multiline ? "whitespace-pre-wrap" : "truncate", fill && "flex-1", !value && placeholderTone === "muted" && "text-muted-foreground"), children: value || placeholder }),
1763
1763
  !fill && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1764
1764
  import_react11.PencilSimple,
1765
1765
  {
@@ -2809,7 +2809,7 @@ var import_react19 = require("@phosphor-icons/react");
2809
2809
  var import_jsx_runtime41 = require("react/jsx-runtime");
2810
2810
  var eyebrow = "text-ui-caption uppercase text-secondary-muted-foreground";
2811
2811
  var QuestionHeader = React40.forwardRef(
2812
- ({ 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) => {
2812
+ ({ 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) => {
2813
2813
  const [draft, setDraft] = React40.useState(null);
2814
2814
  const label = String(number).padStart(2, "0");
2815
2815
  const showError = error !== void 0 && error !== false;
@@ -2864,6 +2864,9 @@ var QuestionHeader = React40.forwardRef(
2864
2864
  className: "-mx-3 w-auto",
2865
2865
  "aria-label": "Question title",
2866
2866
  placeholder: titlePlaceholder,
2867
+ placeholderTone: titlePlaceholderTone,
2868
+ minLength: titleMinLength,
2869
+ showLimits: titleMinLength !== void 0,
2867
2870
  value: text,
2868
2871
  maxLength,
2869
2872
  onValueChange: onTitleChange,
@@ -2874,7 +2877,7 @@ var QuestionHeader = React40.forwardRef(
2874
2877
  textClassName: "text-heading-h4"
2875
2878
  }
2876
2879
  ),
2877
- showCounter && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2880
+ showCounter && titleMinLength === void 0 && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("p", { className: "text-ui-caption text-secondary-muted-foreground", children: [
2878
2881
  count,
2879
2882
  "/",
2880
2883
  maxLength,
@@ -2907,6 +2910,8 @@ var QuestionEditorCard = React41.forwardRef(
2907
2910
  title,
2908
2911
  onTitleChange,
2909
2912
  titlePlaceholder,
2913
+ titlePlaceholderTone,
2914
+ titleMinLength,
2910
2915
  active,
2911
2916
  hovered,
2912
2917
  maxLength,
@@ -2953,6 +2958,8 @@ var QuestionEditorCard = React41.forwardRef(
2953
2958
  title,
2954
2959
  onTitleChange,
2955
2960
  titlePlaceholder,
2961
+ titlePlaceholderTone,
2962
+ titleMinLength,
2956
2963
  active,
2957
2964
  showCounter: !!active,
2958
2965
  dragHandleProps,
@@ -3170,8 +3177,34 @@ var QuestionOtherOption = React44.forwardRef(
3170
3177
  }
3171
3178
  );
3172
3179
  QuestionOtherOption.displayName = "QuestionOtherOption";
3173
- function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }) {
3180
+ function limitsText2(min, max) {
3181
+ if (min !== void 0) return `${min} ${min === 1 ? "character" : "characters"} required`;
3182
+ if (max !== void 0) return `Up to ${max} characters`;
3183
+ return "";
3184
+ }
3185
+ function QuestionOptionEditor({ label, onLabelChange, placeholder, placeholderTone = "muted", minLength, maxLength, onRemove, onAdd, removeDisabled, addDisabled, className, kind, rank, dragHandleProps, lifted, locked }) {
3174
3186
  const reveal = kind !== void 0;
3187
+ const guarded = minLength !== void 0 || maxLength !== void 0;
3188
+ const [draft, setDraft] = React44.useState(null);
3189
+ const [error, setError] = React44.useState(null);
3190
+ const helperId = React44.useId();
3191
+ const fieldRef = React44.useRef(null);
3192
+ const skipBlur = React44.useRef(false);
3193
+ const problemWith = (text) => minLength !== void 0 && text.trim().length < minLength ? `Enter at least ${minLength} ${minLength === 1 ? "character" : "characters"}.` : null;
3194
+ const save = () => {
3195
+ if (draft === null) return true;
3196
+ if (draft !== label) {
3197
+ const problem = problemWith(draft);
3198
+ if (problem) {
3199
+ setError(problem);
3200
+ return false;
3201
+ }
3202
+ onLabelChange?.(draft);
3203
+ }
3204
+ setDraft(null);
3205
+ setError(null);
3206
+ return true;
3207
+ };
3175
3208
  const gripProps = dragHandleProps ? {
3176
3209
  "aria-label": rank ? `Reorder option ${rank}` : "Reorder option",
3177
3210
  ...dragHandleProps,
@@ -3179,18 +3212,18 @@ function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onA
3179
3212
  } : { "aria-hidden": true };
3180
3213
  const grip = dragHandleProps ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { ...gripProps, className: cn("shrink-0", gripProps.className), children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_react23.DotsSixVertical, { size: 20, "aria-hidden": true, className: "text-surface-foreground" }) }) : /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_react23.DotsSixVertical, { size: 20, "aria-hidden": true, className: "shrink-0 text-surface-foreground" });
3181
3214
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: cn("group/option flex w-full items-center gap-2", className), children: [
3182
- /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
3215
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3183
3216
  "div",
3184
3217
  {
3185
3218
  className: cn(
3186
- "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",
3219
+ "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",
3187
3220
  reveal ? (
3188
3221
  // The border is always visible and does not change on hover; only the shadow lifts the row. The field being edited keeps the accent.
3189
3222
  cn("border-border group-hover/option:shadow-md group-focus-within/option:shadow-md", lifted && "shadow-md")
3190
3223
  ) : "border-border hover:border-input-muted hover:shadow-md"
3191
3224
  ),
3192
- children: [
3193
- kind === "rank" ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(import_jsx_runtime45.Fragment, { children: [
3225
+ children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex min-w-0 items-start gap-2", children: [
3226
+ (kind !== void 0 || !locked) && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "flex h-7 shrink-0 items-center gap-2", children: kind === "rank" ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(import_jsx_runtime45.Fragment, { children: [
3194
3227
  !locked && grip,
3195
3228
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3196
3229
  "span",
@@ -3223,18 +3256,76 @@ function QuestionOptionEditor({ label, onLabelChange, placeholder, onRemove, onA
3223
3256
  )
3224
3257
  }
3225
3258
  )
3226
- ] }) : locked ? null : grip,
3227
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3228
- "input",
3229
- {
3230
- "aria-label": "Option label",
3231
- placeholder,
3232
- value: label,
3233
- onChange: (event) => onLabelChange?.(event.target.value),
3234
- className: "min-w-0 flex-1 bg-transparent text-body-base text-surface-foreground outline-none"
3235
- }
3236
- )
3237
- ]
3259
+ ] }) : locked ? null : grip }),
3260
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
3261
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3262
+ "input",
3263
+ {
3264
+ ref: fieldRef,
3265
+ "aria-label": "Option label",
3266
+ "aria-invalid": error ? true : void 0,
3267
+ "aria-describedby": guarded && draft !== null ? helperId : void 0,
3268
+ placeholder,
3269
+ maxLength,
3270
+ value: guarded ? draft ?? label : label,
3271
+ onFocus: () => {
3272
+ if (guarded && draft === null) setDraft(label);
3273
+ },
3274
+ onChange: (event) => {
3275
+ if (!guarded) return onLabelChange?.(event.target.value);
3276
+ setDraft(event.target.value);
3277
+ if (error) setError(problemWith(event.target.value));
3278
+ },
3279
+ onKeyDown: (event) => {
3280
+ if (!guarded) return;
3281
+ if (event.key === "Escape") {
3282
+ skipBlur.current = true;
3283
+ setDraft(null);
3284
+ setError(null);
3285
+ fieldRef.current?.blur();
3286
+ } else if (event.key === "Enter") {
3287
+ event.preventDefault();
3288
+ if (save()) {
3289
+ skipBlur.current = true;
3290
+ fieldRef.current?.blur();
3291
+ }
3292
+ }
3293
+ },
3294
+ onBlur: () => {
3295
+ if (!guarded) return;
3296
+ if (skipBlur.current) {
3297
+ skipBlur.current = false;
3298
+ return;
3299
+ }
3300
+ save();
3301
+ },
3302
+ className: cn(
3303
+ "min-w-0 flex-1 bg-transparent text-body-base text-surface-foreground outline-none",
3304
+ placeholderTone === "regular" ? "placeholder:text-surface-foreground" : "placeholder:text-muted-foreground"
3305
+ )
3306
+ }
3307
+ ),
3308
+ guarded && draft !== null && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
3309
+ "p",
3310
+ {
3311
+ id: helperId,
3312
+ role: error ? "alert" : void 0,
3313
+ className: cn("flex items-start justify-between gap-2 text-ui-caption", error ? "text-destructive" : "text-secondary-muted-foreground"),
3314
+ children: [
3315
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { className: "flex items-start gap-2", children: [
3316
+ error && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_react23.WarningCircle, { size: 16, "aria-hidden": true, className: "shrink-0" }),
3317
+ limitsText2(minLength, maxLength),
3318
+ error && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "sr-only", children: error })
3319
+ ] }),
3320
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { "aria-hidden": true, className: "shrink-0 tabular-nums", children: [
3321
+ draft.length,
3322
+ maxLength !== void 0 && `/${maxLength}`
3323
+ ] })
3324
+ ]
3325
+ }
3326
+ )
3327
+ ] })
3328
+ ] })
3238
3329
  }
3239
3330
  ),
3240
3331
  !locked && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(