@farming-labs/theme 0.2.15 → 0.2.16

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.
@@ -8,6 +8,7 @@ interface DocsFeedbackProps {
8
8
  locale?: string;
9
9
  question?: string;
10
10
  placeholder?: string;
11
+ requireComment?: boolean;
11
12
  positiveLabel?: string;
12
13
  negativeLabel?: string;
13
14
  submitLabel?: string;
@@ -20,6 +21,7 @@ declare function DocsFeedback({
20
21
  locale,
21
22
  question,
22
23
  placeholder,
24
+ requireComment,
23
25
  positiveLabel,
24
26
  negativeLabel,
25
27
  submitLabel,
@@ -116,12 +116,13 @@ function CheckIcon() {
116
116
  })
117
117
  });
118
118
  }
119
- function DocsFeedback({ pathname, entry, locale, question = "How is this guide?", placeholder = "Leave your feedback...", positiveLabel = "Good", negativeLabel = "Bad", submitLabel = "Submit", onFeedback, analytics = false }) {
119
+ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?", placeholder = "Leave your feedback...", requireComment = false, positiveLabel = "Good", negativeLabel = "Bad", submitLabel = "Submit", onFeedback, analytics = false }) {
120
120
  const [selected, setSelected] = useState(null);
121
121
  const [comment, setComment] = useState("");
122
122
  const [status, setStatus] = useState("idle");
123
123
  const normalizedPathname = useMemo(() => normalizePathname(pathname), [pathname]);
124
124
  const showForm = selected !== null;
125
+ const commentRequired = requireComment && comment.trim().length === 0;
125
126
  const submitButtonLabel = status === "submitted" ? "Submitted" : submitLabel;
126
127
  useEffect(() => {
127
128
  setSelected(null);
@@ -151,7 +152,7 @@ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?"
151
152
  }
152
153
  }
153
154
  async function handleSubmit() {
154
- if (!selected || status === "submitting") return;
155
+ if (!selected || status === "submitting" || commentRequired) return;
155
156
  setStatus("submitting");
156
157
  const payload = buildFeedbackPayload(selected, normalizedPathname, entry, comment, locale);
157
158
  try {
@@ -221,6 +222,8 @@ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?"
221
222
  className: "fd-feedback-input",
222
223
  "aria-label": "Additional feedback",
223
224
  placeholder,
225
+ required: requireComment,
226
+ "aria-required": requireComment,
224
227
  value: comment,
225
228
  disabled: status === "submitting",
226
229
  onChange: (event) => {
@@ -233,7 +236,7 @@ function DocsFeedback({ pathname, entry, locale, question = "How is this guide?"
233
236
  children: [/* @__PURE__ */ jsxs("button", {
234
237
  type: "button",
235
238
  className: "fd-page-action-btn fd-feedback-submit",
236
- disabled: status === "submitting" || status === "submitted",
239
+ disabled: status === "submitting" || status === "submitted" || commentRequired,
237
240
  onClick: () => void handleSubmit(),
238
241
  children: [
239
242
  status === "submitting" && /* @__PURE__ */ jsx("span", {
@@ -652,6 +652,7 @@ function createDocsLayout(config, options) {
652
652
  const layoutDimensions = config.theme?.ui?.layout;
653
653
  const pageActions = config.pageActions;
654
654
  const copyMarkdownEnabled = resolveBool(pageActions?.copyMarkdown);
655
+ const copyMarkdownConfig = pageActions?.copyMarkdown && typeof pageActions.copyMarkdown === "object" ? pageActions.copyMarkdown : void 0;
655
656
  const openDocsEnabled = resolveBool(pageActions?.openDocs);
656
657
  const pageActionsPosition = pageActions?.position ?? "below-title";
657
658
  const pageActionsAlignment = pageActions?.alignment ?? "left";
@@ -790,6 +791,8 @@ function createDocsLayout(config, options) {
790
791
  publicPath: localeContext.publicPath,
791
792
  locale: activeLocale,
792
793
  copyMarkdown: copyMarkdownEnabled,
794
+ copyMarkdownLabel: copyMarkdownConfig?.label,
795
+ copyMarkdownCopiedLabel: copyMarkdownConfig?.copiedLabel,
793
796
  openDocs: openDocsEnabled,
794
797
  openDocsProviders,
795
798
  openDocsTarget: openDocsConfig?.target,
@@ -812,6 +815,7 @@ function createDocsLayout(config, options) {
812
815
  feedbackEnabled: feedbackConfig.enabled,
813
816
  feedbackQuestion: feedbackConfig.question,
814
817
  feedbackPlaceholder: feedbackConfig.placeholder,
818
+ feedbackRequireComment: feedbackConfig.requireComment,
815
819
  feedbackPositiveLabel: feedbackConfig.positiveLabel,
816
820
  feedbackNegativeLabel: feedbackConfig.negativeLabel,
817
821
  feedbackSubmitLabel: feedbackConfig.submitLabel,
@@ -839,6 +843,7 @@ function resolveFeedbackConfig(feedback) {
839
843
  enabled: false,
840
844
  question: "How is this guide?",
841
845
  placeholder: "Leave your feedback...",
846
+ requireComment: false,
842
847
  positiveLabel: "Good",
843
848
  negativeLabel: "Bad",
844
849
  submitLabel: "Submit"
@@ -848,11 +853,12 @@ function resolveFeedbackConfig(feedback) {
848
853
  ...defaults,
849
854
  enabled: true
850
855
  };
851
- const hasHumanFeedbackConfig = feedback.enabled !== void 0 || feedback.question !== void 0 || feedback.placeholder !== void 0 || feedback.positiveLabel !== void 0 || feedback.negativeLabel !== void 0 || feedback.submitLabel !== void 0 || feedback.onFeedback !== void 0;
856
+ const hasHumanFeedbackConfig = feedback.enabled !== void 0 || feedback.question !== void 0 || feedback.placeholder !== void 0 || feedback.requireComment !== void 0 || feedback.positiveLabel !== void 0 || feedback.negativeLabel !== void 0 || feedback.submitLabel !== void 0 || feedback.onFeedback !== void 0;
852
857
  return {
853
858
  enabled: feedback.enabled === true || feedback.enabled !== false && hasHumanFeedbackConfig,
854
859
  question: feedback.question ?? defaults.question,
855
860
  placeholder: feedback.placeholder ?? defaults.placeholder,
861
+ requireComment: feedback.requireComment ?? defaults.requireComment,
856
862
  positiveLabel: feedback.positiveLabel ?? defaults.positiveLabel,
857
863
  negativeLabel: feedback.negativeLabel ?? defaults.negativeLabel,
858
864
  submitLabel: feedback.submitLabel ?? defaults.submitLabel
@@ -23,6 +23,8 @@ interface DocsPageClientProps {
23
23
  /** Active locale (used for llms.txt links) */
24
24
  locale?: string;
25
25
  copyMarkdown?: boolean;
26
+ copyMarkdownLabel?: string;
27
+ copyMarkdownCopiedLabel?: string;
26
28
  openDocs?: boolean;
27
29
  openDocsProviders?: SerializedProvider[];
28
30
  openDocsTarget?: "markdown" | "page" | "source" | "github";
@@ -74,6 +76,7 @@ interface DocsPageClientProps {
74
76
  feedbackEnabled?: boolean;
75
77
  feedbackQuestion?: string;
76
78
  feedbackPlaceholder?: string;
79
+ feedbackRequireComment?: boolean;
77
80
  feedbackPositiveLabel?: string;
78
81
  feedbackNegativeLabel?: string;
79
82
  feedbackSubmitLabel?: string;
@@ -90,6 +93,8 @@ declare function DocsPageClient({
90
93
  publicPath,
91
94
  locale,
92
95
  copyMarkdown,
96
+ copyMarkdownLabel,
97
+ copyMarkdownCopiedLabel,
93
98
  openDocs,
94
99
  openDocsProviders,
95
100
  openDocsTarget,
@@ -117,6 +122,7 @@ declare function DocsPageClient({
117
122
  feedbackEnabled,
118
123
  feedbackQuestion,
119
124
  feedbackPlaceholder,
125
+ feedbackRequireComment,
120
126
  feedbackPositiveLabel,
121
127
  feedbackNegativeLabel,
122
128
  feedbackSubmitLabel,
@@ -255,7 +255,7 @@ function findThreadlineTocActionsContainer() {
255
255
  }
256
256
  return toc.parentElement ?? toc;
257
257
  }
258
- function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", structuredDataMap, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedPosition = "footer", llmsTxtEnabled = false, descriptionMap, description, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackOnFeedback, analytics = false, children }) {
258
+ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, copyMarkdownLabel, copyMarkdownCopiedLabel, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", structuredDataMap, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedPosition = "footer", llmsTxtEnabled = false, descriptionMap, description, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackRequireComment, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackOnFeedback, analytics = false, children }) {
259
259
  const fdTocStyle = tocStyle === "directional" ? "clerk" : void 0;
260
260
  const [toc, setToc] = useState([]);
261
261
  const [titlePortalHost, setTitlePortalHost] = useState(null);
@@ -465,6 +465,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
465
465
  "data-actions-alignment": pageActionsAlignment,
466
466
  children: /* @__PURE__ */ jsx(PageActions, {
467
467
  copyMarkdown,
468
+ copyMarkdownLabel,
469
+ copyMarkdownCopiedLabel,
468
470
  openDocs,
469
471
  providers: openDocsProviders,
470
472
  openDocsTarget,
@@ -508,6 +510,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
508
510
  className: "fd-actions-toc-portal not-prose",
509
511
  children: /* @__PURE__ */ jsx(PageActions, {
510
512
  copyMarkdown,
513
+ copyMarkdownLabel,
514
+ copyMarkdownCopiedLabel,
511
515
  openDocs,
512
516
  providers: openDocsProviders,
513
517
  openDocsTarget,
@@ -560,6 +564,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
560
564
  "data-actions-alignment": pageActionsAlignment,
561
565
  children: /* @__PURE__ */ jsx(PageActions, {
562
566
  copyMarkdown,
567
+ copyMarkdownLabel,
568
+ copyMarkdownCopiedLabel,
563
569
  openDocs,
564
570
  providers: openDocsProviders,
565
571
  openDocsTarget,
@@ -589,6 +595,7 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
589
595
  locale: activeLocale,
590
596
  question: feedbackQuestion,
591
597
  placeholder: feedbackPlaceholder,
598
+ requireComment: feedbackRequireComment,
592
599
  positiveLabel: feedbackPositiveLabel,
593
600
  negativeLabel: feedbackNegativeLabel,
594
601
  submitLabel: feedbackSubmitLabel,
@@ -11,6 +11,8 @@ interface SerializedProvider {
11
11
  }
12
12
  interface PageActionsProps {
13
13
  copyMarkdown?: boolean;
14
+ copyMarkdownLabel?: string;
15
+ copyMarkdownCopiedLabel?: string;
14
16
  openDocs?: boolean;
15
17
  providers?: SerializedProvider[];
16
18
  openDocsTarget?: "markdown" | "page" | "source" | "github";
@@ -23,6 +25,8 @@ interface PageActionsProps {
23
25
  }
24
26
  declare function PageActions({
25
27
  copyMarkdown,
28
+ copyMarkdownLabel,
29
+ copyMarkdownCopiedLabel,
26
30
  openDocs,
27
31
  providers,
28
32
  openDocsTarget,
@@ -132,7 +132,7 @@ function pageUrlToMarkdownUrl(pageUrl) {
132
132
  function fillPromptTemplate(template, values) {
133
133
  return template.replace(/\{pageUrl\}/g, values.pageUrl).replace(/\{markdownUrl\}/g, values.markdownUrl).replace(/\{sourceUrl\}/g, values.sourceUrl).replace(/\{mdxUrl\}/g, values.sourceUrl).replace(/\{githubUrl\}/g, values.githubUrl).replace(/\{url\}/g, values.url);
134
134
  }
135
- function PageActions({ copyMarkdown, openDocs, providers, openDocsTarget = DEFAULT_OPEN_DOCS_TARGET, openDocsPrompt = DEFAULT_OPEN_DOCS_PROMPT, alignment = "left", variant = "default", githubFileUrl, analytics = false }) {
135
+ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdownCopiedLabel = "Copied!", openDocs, providers, openDocsTarget = DEFAULT_OPEN_DOCS_TARGET, openDocsPrompt = DEFAULT_OPEN_DOCS_PROMPT, alignment = "left", variant = "default", githubFileUrl, analytics = false }) {
136
136
  const [copied, setCopied] = useState(false);
137
137
  const [dropdownOpen, setDropdownOpen] = useState(false);
138
138
  const dropdownRef = useRef(null);
@@ -238,7 +238,7 @@ function PageActions({ copyMarkdown, openDocs, providers, openDocsTarget = DEFAU
238
238
  onClick: handleCopyMarkdown,
239
239
  className: "fd-page-action-btn",
240
240
  "data-copied": copied,
241
- children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? "Copied!" : "Copy page" })]
241
+ children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
242
242
  }),
243
243
  openDocs && /* @__PURE__ */ jsxs("a", {
244
244
  className: "fd-page-action-btn",
@@ -271,7 +271,7 @@ function PageActions({ copyMarkdown, openDocs, providers, openDocsTarget = DEFAU
271
271
  onClick: handleCopyMarkdown,
272
272
  className: "fd-page-action-btn",
273
273
  "data-copied": copied,
274
- children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? "Copied!" : "Copy page" })]
274
+ children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
275
275
  }), openDocs && resolvedProviders.length > 0 && /* @__PURE__ */ jsxs("div", {
276
276
  ref: dropdownRef,
277
277
  className: "fd-page-action-dropdown",
@@ -193,6 +193,7 @@ function resolveFeedbackConfig(feedback) {
193
193
  enabled: false,
194
194
  question: "How is this guide?",
195
195
  placeholder: "Leave your feedback...",
196
+ requireComment: false,
196
197
  positiveLabel: "Good",
197
198
  negativeLabel: "Bad",
198
199
  submitLabel: "Submit"
@@ -202,11 +203,12 @@ function resolveFeedbackConfig(feedback) {
202
203
  ...defaults,
203
204
  enabled: true
204
205
  };
205
- const hasHumanFeedbackConfig = feedback.enabled !== void 0 || feedback.question !== void 0 || feedback.placeholder !== void 0 || feedback.positiveLabel !== void 0 || feedback.negativeLabel !== void 0 || feedback.submitLabel !== void 0 || feedback.onFeedback !== void 0;
206
+ const hasHumanFeedbackConfig = feedback.enabled !== void 0 || feedback.question !== void 0 || feedback.placeholder !== void 0 || feedback.requireComment !== void 0 || feedback.positiveLabel !== void 0 || feedback.negativeLabel !== void 0 || feedback.submitLabel !== void 0 || feedback.onFeedback !== void 0;
206
207
  return {
207
208
  enabled: feedback.enabled === true || feedback.enabled !== false && hasHumanFeedbackConfig,
208
209
  question: feedback.question ?? defaults.question,
209
210
  placeholder: feedback.placeholder ?? defaults.placeholder,
211
+ requireComment: feedback.requireComment ?? defaults.requireComment,
210
212
  positiveLabel: feedback.positiveLabel ?? defaults.positiveLabel,
211
213
  negativeLabel: feedback.negativeLabel ?? defaults.negativeLabel,
212
214
  submitLabel: feedback.submitLabel ?? defaults.submitLabel
@@ -238,6 +240,7 @@ function TanstackDocsLayout({ config, tree, locale, description, readingTime, la
238
240
  const layoutDimensions = config.theme?.ui?.layout;
239
241
  const pageActions = config.pageActions;
240
242
  const copyMarkdownEnabled = resolveBool(pageActions?.copyMarkdown);
243
+ const copyMarkdownConfig = pageActions?.copyMarkdown && typeof pageActions.copyMarkdown === "object" ? pageActions.copyMarkdown : void 0;
241
244
  const openDocsEnabled = resolveBool(pageActions?.openDocs);
242
245
  const pageActionsPosition = pageActions?.position ?? "below-title";
243
246
  const pageActionsAlignment = pageActions?.alignment ?? "left";
@@ -354,6 +357,8 @@ function TanstackDocsLayout({ config, tree, locale, description, readingTime, la
354
357
  entry: config.entry ?? "docs",
355
358
  locale,
356
359
  copyMarkdown: copyMarkdownEnabled,
360
+ copyMarkdownLabel: copyMarkdownConfig?.label,
361
+ copyMarkdownCopiedLabel: copyMarkdownConfig?.copiedLabel,
357
362
  openDocs: openDocsEnabled,
358
363
  openDocsProviders,
359
364
  openDocsTarget: openDocsConfig?.target,
@@ -372,6 +377,7 @@ function TanstackDocsLayout({ config, tree, locale, description, readingTime, la
372
377
  feedbackEnabled: feedbackConfig.enabled,
373
378
  feedbackQuestion: feedbackConfig.question,
374
379
  feedbackPlaceholder: feedbackConfig.placeholder,
380
+ feedbackRequireComment: feedbackConfig.requireComment,
375
381
  feedbackPositiveLabel: feedbackConfig.positiveLabel,
376
382
  feedbackNegativeLabel: feedbackConfig.negativeLabel,
377
383
  feedbackSubmitLabel: feedbackConfig.submitLabel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -145,7 +145,7 @@
145
145
  "tsdown": "^0.20.3",
146
146
  "typescript": "^5.9.3",
147
147
  "vitest": "^4.1.8",
148
- "@farming-labs/docs": "0.2.15"
148
+ "@farming-labs/docs": "0.2.16"
149
149
  },
150
150
  "peerDependencies": {
151
151
  "@farming-labs/docs": ">=0.0.1",