@discuss-ds/ui 0.27.0 → 0.29.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.29.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
9
+ ## 0.28.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#100](https://github.com/TamyresLucas/Discuss-UI-Storybook/pull/100) [`0fc18de`](https://github.com/TamyresLucas/Discuss-UI-Storybook/commit/0fc18ded23abc77fedb0af83fe7a23fe55816e22) Thanks [@TamyresLucas](https://github.com/TamyresLucas)! - `QuestionEditorCard` and `QuestionHeader` take an optional `titlePlaceholder` (default unchanged: "Click to write the question text"), and `QuestionOptionEditor` takes an optional `placeholder` for its empty option text.
14
+
3
15
  ## 0.27.0
4
16
 
5
17
  ### 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, 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;
@@ -2863,7 +2863,10 @@ var QuestionHeader = React40.forwardRef(
2863
2863
  selected: active,
2864
2864
  className: "-mx-3 w-auto",
2865
2865
  "aria-label": "Question title",
2866
- placeholder: "Click to write the question text",
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,
@@ -2906,6 +2909,9 @@ var QuestionEditorCard = React41.forwardRef(
2906
2909
  number,
2907
2910
  title,
2908
2911
  onTitleChange,
2912
+ titlePlaceholder,
2913
+ titlePlaceholderTone,
2914
+ titleMinLength,
2909
2915
  active,
2910
2916
  hovered,
2911
2917
  maxLength,
@@ -2951,6 +2957,9 @@ var QuestionEditorCard = React41.forwardRef(
2951
2957
  number,
2952
2958
  title,
2953
2959
  onTitleChange,
2960
+ titlePlaceholder,
2961
+ titlePlaceholderTone,
2962
+ titleMinLength,
2954
2963
  active,
2955
2964
  showCounter: !!active,
2956
2965
  dragHandleProps,
@@ -3168,8 +3177,34 @@ var QuestionOtherOption = React44.forwardRef(
3168
3177
  }
3169
3178
  );
3170
3179
  QuestionOtherOption.displayName = "QuestionOtherOption";
3171
- function QuestionOptionEditor({ label, onLabelChange, 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 }) {
3172
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
+ };
3173
3208
  const gripProps = dragHandleProps ? {
3174
3209
  "aria-label": rank ? `Reorder option ${rank}` : "Reorder option",
3175
3210
  ...dragHandleProps,
@@ -3181,54 +3216,113 @@ function QuestionOptionEditor({ label, onLabelChange, onRemove, onAdd, removeDis
3181
3216
  "div",
3182
3217
  {
3183
3218
  className: cn(
3184
- "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",
3185
3220
  reveal ? (
3186
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.
3187
3222
  cn("border-border group-hover/option:shadow-md group-focus-within/option:shadow-md", lifted && "shadow-md")
3188
3223
  ) : "border-border hover:border-input-muted hover:shadow-md"
3189
3224
  ),
3190
3225
  children: [
3191
- kind === "rank" ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(import_jsx_runtime45.Fragment, { children: [
3192
- !locked && grip,
3193
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3194
- "span",
3195
- {
3196
- "aria-hidden": "true",
3197
- className: "flex size-6 shrink-0 items-center justify-center rounded-full border border-border bg-background bg-linear-to-r from-overlay-dark-5 to-overlay-dark-5 text-ui-caption text-surface-foreground",
3198
- children: rank
3199
- }
3200
- )
3201
- ] }) : reveal && locked ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { "aria-hidden": "true", className: "relative flex size-5 shrink-0 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: cn("inline-flex size-4 border-2 border-input bg-surface", kind === "radio" ? "rounded-full" : "rounded-xxs") }) }) : reveal ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { ...gripProps, className: cn("relative flex size-5 shrink-0 items-center justify-center", gripProps.className), children: [
3202
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3203
- "span",
3204
- {
3205
- "aria-hidden": "true",
3206
- className: cn(
3207
- "inline-flex size-4 border-2 border-input bg-surface group-hover/option:hidden group-focus-within/option:hidden",
3208
- lifted && "hidden",
3209
- kind === "radio" ? "rounded-full" : "rounded-xxs"
3210
- )
3211
- }
3212
- ),
3226
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex min-w-0 items-center gap-2", children: [
3227
+ kind === "rank" ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(import_jsx_runtime45.Fragment, { children: [
3228
+ !locked && grip,
3229
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3230
+ "span",
3231
+ {
3232
+ "aria-hidden": "true",
3233
+ className: "flex size-6 shrink-0 items-center justify-center rounded-full border border-border bg-background bg-linear-to-r from-overlay-dark-5 to-overlay-dark-5 text-ui-caption text-surface-foreground",
3234
+ children: rank
3235
+ }
3236
+ )
3237
+ ] }) : reveal && locked ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { "aria-hidden": "true", className: "relative flex size-5 shrink-0 items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: cn("inline-flex size-4 border-2 border-input bg-surface", kind === "radio" ? "rounded-full" : "rounded-xxs") }) }) : reveal ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { ...gripProps, className: cn("relative flex size-5 shrink-0 items-center justify-center", gripProps.className), children: [
3238
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3239
+ "span",
3240
+ {
3241
+ "aria-hidden": "true",
3242
+ className: cn(
3243
+ "inline-flex size-4 border-2 border-input bg-surface group-hover/option:hidden group-focus-within/option:hidden",
3244
+ lifted && "hidden",
3245
+ kind === "radio" ? "rounded-full" : "rounded-xxs"
3246
+ )
3247
+ }
3248
+ ),
3249
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3250
+ import_react23.DotsSixVertical,
3251
+ {
3252
+ size: 20,
3253
+ "aria-hidden": true,
3254
+ className: cn(
3255
+ "hidden shrink-0 text-surface-foreground group-hover/option:block group-focus-within/option:block",
3256
+ lifted && "block"
3257
+ )
3258
+ }
3259
+ )
3260
+ ] }) : locked ? null : grip,
3213
3261
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3214
- import_react23.DotsSixVertical,
3262
+ "input",
3215
3263
  {
3216
- size: 20,
3217
- "aria-hidden": true,
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
+ },
3218
3302
  className: cn(
3219
- "hidden shrink-0 text-surface-foreground group-hover/option:block group-focus-within/option:block",
3220
- lifted && "block"
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"
3221
3305
  )
3222
3306
  }
3223
3307
  )
3224
- ] }) : locked ? null : grip,
3225
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
3226
- "input",
3308
+ ] }),
3309
+ guarded && draft !== null && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
3310
+ "p",
3227
3311
  {
3228
- "aria-label": "Option label",
3229
- value: label,
3230
- onChange: (event) => onLabelChange?.(event.target.value),
3231
- className: "min-w-0 flex-1 bg-transparent text-body-base text-surface-foreground outline-none"
3312
+ id: helperId,
3313
+ role: error ? "alert" : void 0,
3314
+ className: cn("flex items-start justify-between gap-2 text-ui-caption", error ? "text-destructive" : "text-secondary-muted-foreground"),
3315
+ children: [
3316
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { className: "flex items-start gap-2", children: [
3317
+ error && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_react23.WarningCircle, { size: 16, "aria-hidden": true, className: "shrink-0" }),
3318
+ limitsText2(minLength, maxLength),
3319
+ error && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "sr-only", children: error })
3320
+ ] }),
3321
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("span", { "aria-hidden": true, className: "shrink-0 tabular-nums", children: [
3322
+ draft.length,
3323
+ maxLength !== void 0 && `/${maxLength}`
3324
+ ] })
3325
+ ]
3232
3326
  }
3233
3327
  )
3234
3328
  ]