From 51a8f52c1c2b4808ba0b05c93bb4c61d98e50844 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 16 Nov 2025 22:50:02 +0000
Subject: [PATCH 1/3] Initial plan
From 4378424dcb89fd15556f4a1014e017eb6e28dc58 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 16 Nov 2025 22:52:39 +0000
Subject: [PATCH 2/3] Initial plan for minimal variant feature
Co-authored-by: dwjohnston <2467377+dwjohnston@users.noreply.github.com>
---
package-lock.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index b102eea..86badbe 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "react-github-permalink",
- "version": "1.11.0",
+ "version": "1.11.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "react-github-permalink",
- "version": "1.11.0",
+ "version": "1.11.1",
"license": "MIT",
"dependencies": {
"react-responsive": "^10.0.0",
From 895c2147713823649874f5b3e6b039cc60a2f41c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 16 Nov 2025 22:56:04 +0000
Subject: [PATCH 3/3] Add expand/collapse functionality with
isInitiallyExpanded prop
Co-authored-by: dwjohnston <2467377+dwjohnston@users.noreply.github.com>
---
.../GithubPermalink.stories.tsx | 30 +++++++++++++
.../GithubPermalink/GithubPermalink.tsx | 7 ++-
.../GithubPermalink/GithubPermalinkBase.tsx | 34 ++++++++++-----
.../GithubPermalink/GithubPermalinkRsc.tsx | 6 ++-
.../GithubPermalink/github-permalink.css | 43 +++++++++++++++++++
src/library/config/BaseConfiguration.ts | 7 +++
src/library/config/GithubPermalinkContext.tsx | 2 +
.../config/GithubPermalinkRscConfig.ts | 4 ++
src/library/images/ChevronSvg.tsx | 19 ++++++++
9 files changed, 139 insertions(+), 13 deletions(-)
create mode 100644 src/library/images/ChevronSvg.tsx
diff --git a/src/library/GithubPermalink/GithubPermalink.stories.tsx b/src/library/GithubPermalink/GithubPermalink.stories.tsx
index 3696dc2..9f52206 100644
--- a/src/library/GithubPermalink/GithubPermalink.stories.tsx
+++ b/src/library/GithubPermalink/GithubPermalink.stories.tsx
@@ -117,3 +117,33 @@ export const SingleLine: Story = {
),
};
+
+export const InitiallyCollapsed: Story = {
+ render: () => (
+
+
This permalink starts collapsed (minimal variant):
+
+
This permalink starts expanded (default):
+
+
+ ),
+};
+
+export const GlobalConfigCollapsed: Story = {
+ render: () => (
+
+
Using global configuration to set default to collapsed:
+
+
+ Second permalink also collapsed by default:
+
+
+
+ ),
+};
diff --git a/src/library/GithubPermalink/GithubPermalink.tsx b/src/library/GithubPermalink/GithubPermalink.tsx
index 351d46b..64f0bb2 100644
--- a/src/library/GithubPermalink/GithubPermalink.tsx
+++ b/src/library/GithubPermalink/GithubPermalink.tsx
@@ -9,7 +9,7 @@ export function GithubPermalink(props: GithubPermalinkProps) {
const { permalink } = props;
const [data, setData] = useState(null as null | GithubPermalinkDataResponse)
- const { getDataFn, githubToken, onError } = useContext(GithubPermalinkContext);
+ const { getDataFn, githubToken, onError, initiallyExpandGithubPermalinks } = useContext(GithubPermalinkContext);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
@@ -27,7 +27,10 @@ export function GithubPermalink(props: GithubPermalinkProps) {
}
- return
+ return
}
diff --git a/src/library/GithubPermalink/GithubPermalinkBase.tsx b/src/library/GithubPermalink/GithubPermalinkBase.tsx
index 7036ebc..051519a 100644
--- a/src/library/GithubPermalink/GithubPermalinkBase.tsx
+++ b/src/library/GithubPermalink/GithubPermalinkBase.tsx
@@ -1,12 +1,13 @@
import { GithubPermalinkDataResponse, } from "../config/GithubPermalinkContext";
import { ErrorMessages } from "../ErrorMessages/ErrorMessages";
import { GithubSvg } from "../GithubSvg/GithubSvg";
-import { PropsWithChildren } from "react";
+import { PropsWithChildren, useState } from "react";
import { SyntaxHighlight } from "../SyntaxHighlight/SyntaxHighlight";
import { formatForLineExclusions } from "./formatLineExclusions";
import { CopyButton } from "../common/CopyButton/CopyButton";
import { getLanguageFromPath } from "../utils/getLanguageFromPath";
import { AvailableLanguagesPrism } from "../SyntaxHighlight/availableLanguagesPrism";
+import { ChevronDownSvg, ChevronRightSvg } from "../images/ChevronSvg";
export type GithubPermalinkBaseProps = {
className?: string;
@@ -15,6 +16,12 @@ export type GithubPermalinkBaseProps = {
excludeText?: string;
data: GithubPermalinkDataResponse;
language?: AvailableLanguagesPrism;
+ /**
+ * Whether the permalink should be initially expanded to show the full header.
+ * When false, only the code block is shown with a subtle GitHub icon link.
+ * Default is controlled by the global configuration `initiallyExpandGithubPermalinks`.
+ */
+ isInitiallyExpanded?: boolean;
}
@@ -67,20 +74,27 @@ function GithubPermalinkInner(props: PropsWithChildren<{
clipboard?: string;
} & GithubPermalinkBaseProps>) {
- const { clipboard } = props;
+ const { clipboard, isInitiallyExpanded = true } = props;
+ const [isExpanded, setIsExpanded] = useState(isInitiallyExpanded);
-
- return
+ return
-
-
-
+
+
-
}
- {clipboard &&
+ {clipboard && isExpanded &&
}
diff --git a/src/library/GithubPermalink/GithubPermalinkRsc.tsx b/src/library/GithubPermalink/GithubPermalinkRsc.tsx
index 96e4165..e0e1289 100644
--- a/src/library/GithubPermalink/GithubPermalinkRsc.tsx
+++ b/src/library/GithubPermalink/GithubPermalinkRsc.tsx
@@ -12,7 +12,11 @@ export async function GithubPermalinkRsc(props: GithubPermalinkRscProps) {
const dataFn = githubPermalinkRscConfig.getPermalinkFn();
const token = githubPermalinkRscConfig.getGithubToken();
const onError = githubPermalinkRscConfig.getOnError();
+ const initiallyExpandGithubPermalinks = githubPermalinkRscConfig.getInitiallyExpandGithubPermalinks();
const data = await dataFn(permalink, token, onError);
- return
+ return
}
diff --git a/src/library/GithubPermalink/github-permalink.css b/src/library/GithubPermalink/github-permalink.css
index 41e6f25..0a55f27 100644
--- a/src/library/GithubPermalink/github-permalink.css
+++ b/src/library/GithubPermalink/github-permalink.css
@@ -224,6 +224,49 @@ svg.github-logo {
align-items: center;
}
+.react-github-permalink .expand-button {
+ all: unset;
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ padding: 0;
+ margin: 0;
+ border: none;
+ background: none;
+ color: var(--rgp-color-text-frame);
+ transition: color 0.2s ease;
+}
+
+.react-github-permalink .expand-button:hover {
+ color: var(--rgp-color-file-link);
+}
+
+.react-github-permalink .expand-button svg {
+ fill: currentColor;
+}
+
+.react-github-permalink.collapsed .header {
+ background-color: transparent;
+ border: none;
+ padding: 0;
+}
+
+.react-github-permalink.collapsed {
+ border: none;
+ margin: 0;
+}
+
+.react-github-permalink .github-icon-link a {
+ display: flex;
+ align-items: center;
+ opacity: 0.6;
+ transition: opacity 0.2s ease;
+}
+
+.react-github-permalink .github-icon-link a:hover {
+ opacity: 1;
+}
+
.copy-button-container {
.tooltip-container {
diff --git a/src/library/config/BaseConfiguration.ts b/src/library/config/BaseConfiguration.ts
index f75651f..b8d9d3a 100644
--- a/src/library/config/BaseConfiguration.ts
+++ b/src/library/config/BaseConfiguration.ts
@@ -24,6 +24,13 @@ export type BaseConfiguration = {
* @returns
*/
onError?: (e: unknown) => void;
+
+ /**
+ * Default value for whether GitHub permalinks should be initially expanded.
+ * When false, permalinks will be collapsed by default showing only the code block.
+ * Default: true
+ */
+ initiallyExpandGithubPermalinks?: boolean;
};
diff --git a/src/library/config/GithubPermalinkContext.tsx b/src/library/config/GithubPermalinkContext.tsx
index c9b7f57..041a8dd 100644
--- a/src/library/config/GithubPermalinkContext.tsx
+++ b/src/library/config/GithubPermalinkContext.tsx
@@ -63,6 +63,7 @@ export type GithubIssueLinkDataResponse = {
export const GithubPermalinkContext = createContext
({
getDataFn: defaultGetPermalinkFn,
getIssueFn: defaultGetIssueFn,
+ initiallyExpandGithubPermalinks: true,
});
export function GithubPermalinkProvider(props: PropsWithChildren>) {
@@ -71,6 +72,7 @@ export function GithubPermalinkProvider(props: PropsWithChildren
{props.children}
diff --git a/src/library/config/GithubPermalinkRscConfig.ts b/src/library/config/GithubPermalinkRscConfig.ts
index 0e66ded..c4cdd20 100644
--- a/src/library/config/GithubPermalinkRscConfig.ts
+++ b/src/library/config/GithubPermalinkRscConfig.ts
@@ -30,6 +30,10 @@ class GithubPermalinkRscConfig {
public getOnError() {
return this.baseConfiguration.onError;
}
+
+ public getInitiallyExpandGithubPermalinks() {
+ return this.baseConfiguration.initiallyExpandGithubPermalinks ?? true;
+ }
}
export const githubPermalinkRscConfig = new GithubPermalinkRscConfig();
diff --git a/src/library/images/ChevronSvg.tsx b/src/library/images/ChevronSvg.tsx
new file mode 100644
index 0000000..007a7e6
--- /dev/null
+++ b/src/library/images/ChevronSvg.tsx
@@ -0,0 +1,19 @@
+export function ChevronDownSvg(props: {
+ size?: number
+}) {
+ const size = props.size ?? 16;
+
+ return
+}
+
+export function ChevronRightSvg(props: {
+ size?: number
+}) {
+ const size = props.size ?? 16;
+
+ return
+}