Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
17f271f
copy in codegroup components and lint
lawreka Jan 22, 2026
49ac992
clean up props and ts error
lawreka Jan 22, 2026
4fa7c64
address bugbot comments
lawreka Jan 22, 2026
386fa93
address bugbot comments and fix dropdown background colors
lawreka Jan 22, 2026
37e2900
bounds check initial index and fix tailwind selectors
lawreka Jan 23, 2026
30eedf9
Merge branch 'main' of https://github.com/mintlify/components into ka…
lawreka Jan 23, 2026
8529777
migrate radix usage to base-ui
lawreka Jan 23, 2026
051b2bf
clean comments
lawreka Jan 23, 2026
7e95ec6
fix fallback and potential memory leak issues
lawreka Jan 23, 2026
2cea3b6
fix bad tailwind selector and duplicate data-test-id
lawreka Jan 23, 2026
06848e9
Merge branch 'main' of https://github.com/mintlify/components into ka…
lawreka Jan 23, 2026
aa894cc
Update packages/components/src/components/code-group/code-group-selec…
lawreka Jan 23, 2026
4228f5f
Update packages/components/src/components/code-group/code-group.tsx
lawreka Jan 23, 2026
e2c2139
Update packages/components/src/components/code-group/code-select-drop…
lawreka Jan 23, 2026
3d5a179
Update packages/components/src/components/code-group/code-snippet.tsx
lawreka Jan 23, 2026
6bc0157
lint and fix interface to type typo
lawreka Jan 23, 2026
92bdece
add TabItemProps
lawreka Jan 23, 2026
a328b3a
LanguageIconProps
lawreka Jan 23, 2026
6798042
centralize codeBlockTheme prop in validaiton
lawreka Jan 23, 2026
f566c72
remove unused select component, clean up passing of copy button props…
lawreka Jan 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agents/Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if empty - nothing to change
- ~~Callouts~~
- ~~update to `variant="note"` instead of 7 different components. add `variant="custom"`, set it by default~~
- ~~Cards~~
- Code groups
- ~~Code groups~~
- ~~Color~~
- nits https://mintlify.slack.com/archives/C09QQDHD7PG/p1764635576242229?thread_ts=1763963569.715779&cid=C09QQDHD7PG
- ~~Columns~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CodeFooter } from "./code-footer";
interface BaseCodeBlockProps extends CodeBlockProps {
isParentCodeGroup?: boolean;
shouldHighlight?: boolean;
// pass isLivePreview to forceExtract to force code string theme changes
forceExtract?: boolean;
}

Expand Down
29 changes: 18 additions & 11 deletions packages/components/src/components/code-block/code-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type { ReactNode, RefObject } from "react";

import { Classes } from "@/lib/local/selectors";
import { cn } from "@/utils/cn";
import type { CopyToClipboardResult } from "@/utils/copy-to-clipboard";
import { getNodeText } from "@/utils/get-node-text";
import type { CodeStyling } from "@/validation";
import type { CodeBlockTheme, CodeStyling } from "@/validation";

import { BaseCodeBlock } from "./base-code-block";
import { CodeHeader } from "./code-header";
import { CopyToClipboardButton } from "./copy-button";
import {
CopyToClipboardButton,
type CopyToClipboardButtonProps,
} from "./copy-button";

type CodeBlockProps = {
language?: string;
Expand Down Expand Up @@ -62,7 +64,7 @@ type CodeBlockProps = {
/**
* Prop to set the code block theme (code block UI theme)
*/
codeBlockTheme?: "dark" | "system";
codeBlockTheme?: CodeBlockTheme;
/**
* Prop to set the code block theme object (syntax highlighting theme)
*/
Expand All @@ -75,17 +77,13 @@ type CodeBlockProps = {
* Pass in CodeSnippetFeedbackButton component
*/
feedbackButton?: ReactNode;
/**
* The callback function when a user clicks on the copied to clipboard button
*/
onCopied?: (result: CopyToClipboardResult, textToCopy?: string) => void;
children?: ReactNode;
copyButtonProps?: CopyToClipboardButtonProps;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyButtonProps type requires textToCopy, overrides computed value

Medium Severity

The copyButtonProps prop has type CopyToClipboardButtonProps which requires textToCopy: string. Since the component computes textToCopy internally and spreads copyButtonProps after the explicit prop, users face two problems: TypeScript errors when passing just onCopied without textToCopy, and unintentional override of the computed text when they do provide textToCopy. The type should likely be Omit<CopyToClipboardButtonProps, 'textToCopy'> to allow passing callbacks without forcing a textToCopy value.

Additional Locations (1)

Fix in Cursor Fix in Web

};

const CodeBlock = function CodeBlock(params: CodeBlockProps) {
const {
filename,
onCopied,
children,
className,
icon,
Expand All @@ -97,6 +95,7 @@ const CodeBlock = function CodeBlock(params: CodeBlockProps) {
codeBlockThemeObject,
askAiButton,
feedbackButton,
copyButtonProps,
} = params;

const codeString = getNodeText(children);
Expand Down Expand Up @@ -126,7 +125,11 @@ const CodeBlock = function CodeBlock(params: CodeBlockProps) {
icon={icon}
>
{feedbackButton && feedbackButton}
<CopyToClipboardButton onCopied={onCopied} textToCopy={codeString} />
<CopyToClipboardButton
codeBlockTheme={codeBlockTheme}
textToCopy={codeString}
{...copyButtonProps}
/>
{askAiButton && askAiButton}
</CodeHeader>
) : (
Expand All @@ -135,7 +138,11 @@ const CodeBlock = function CodeBlock(params: CodeBlockProps) {
data-floating-buttons
>
{feedbackButton && feedbackButton}
<CopyToClipboardButton onCopied={onCopied} textToCopy={codeString} />
<CopyToClipboardButton
codeBlockTheme={codeBlockTheme}
textToCopy={codeString}
{...copyButtonProps}
/>
{askAiButton && askAiButton}
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { ReactNode } from "react";
import { Icon as ComponentIcon } from "@/components/icon";
import { Classes } from "@/lib/local/selectors";
import { cn } from "@/utils/cn";
import type { CodeBlockTheme } from "@/validation";

type CodeHeaderProps = {
filename?: string;
icon?: string;
codeBlockTheme?: "dark" | "system";
codeBlockTheme?: CodeBlockTheme;
children?: ReactNode;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type CopyToClipboardResult,
copyToClipboard,
} from "@/utils/copy-to-clipboard";
import type { CodeBlockTheme } from "@/validation";

const DEFAULT_COPY_BUTTON_ARIA_LABEL = "Copy the contents from the code block";
const DEFAULT_TOOLTIP_COPY_TEXT = "Copy";
Expand All @@ -15,7 +16,7 @@ type CopyToClipboardButtonProps = {
onCopied?: (result: CopyToClipboardResult, textToCopy?: string) => void;
className?: string;
showTooltip?: boolean;
codeBlockTheme?: "system" | "dark";
codeBlockTheme?: CodeBlockTheme;
copyButtonAriaLabel?: string;
tooltipCopyText?: string;
tooltipCopiedText?: string;
Expand Down
36 changes: 36 additions & 0 deletions packages/components/src/components/code-block/story-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ function MyComponent() {
);
}`;

const getString = (tabIndex = 1, language?: string) => {
const lineInfo = tabIndex ? `Here are ${tabIndex} line(s)` : "";
if (language === "python") {
return new Array(tabIndex)
.fill(`print("Hello, World!${lineInfo ? ` ${lineInfo}` : ""}")`)
.join("\n");
}

if (language === "java") {
return new Array(tabIndex)
.fill(
`System.out.println("Hello, World!${lineInfo ? ` ${lineInfo}` : ""}");`
)
.join("\n");
}

return new Array(tabIndex)
.fill(`console.log('Hello, World!${lineInfo ? ` ${lineInfo}` : ""}');`)
.join("\n");
};

const shortMultiLineCode = `function greet(name) {
console.log("Hello, " + name + "!");
return true;
}`;

const shortMultiLineCodeTS =
// biome-ignore lint/suspicious/noTemplateCurlyInString: just example code for stories
"function greet(name: string): boolean {\n console.log(`Hello, ${name}!`);\n return true;\n}";

const shortCode = `def greet(name):\n print(f"Hello, {name}!")\n return True`;

export {
mediumCode,
longExpandableCode,
Expand All @@ -140,4 +172,8 @@ export {
diffCodeWithRemove,
simpleDiffCode,
complexDiffCode,
getString,
shortMultiLineCode,
shortCode,
shortMultiLineCodeTS,
};
Loading