Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

docs(self-hosting): add copy button for env vars (#7779)

Adrian Kahali02dc4dbb7443
diff --git a/docs/field-name-copy.js b/docs/field-name-copy.js
new file mode 100644
index 0000000000..f5a39debd8
--- /dev/null
+++ b/docs/field-name-copy.js
@@ -0,0 +1,42 @@
+(() => {
+ const fieldSelector = '[data-component-part="field-name"]';
+ const resetTimers = new WeakMap();
+
+ document.addEventListener(
+ "click",
+ async (event) => {
+ if (!(event.target instanceof Element)) return;
+
+ const field = event.target.closest(fieldSelector);
+ if (!(field instanceof HTMLElement)) return;
+
+ const fieldName = field.textContent?.trim();
+ if (!fieldName) return;
+
+ // The separate chain icon keeps the permalink action.
+ event.preventDefault();
+ event.stopPropagation();
+
+ try {
+ await navigator.clipboard.writeText(fieldName);
+ field.dataset.copyState = "copied";
+
+ const existingTimer = resetTimers.get(field);
+ if (existingTimer) {
+ window.clearTimeout(existingTimer);
+ }
+
+ resetTimers.set(
+ field,
+ window.setTimeout(() => {
+ delete field.dataset.copyState;
+ resetTimers.delete(field);
+ }, 1500)
+ );
+ } catch (error) {
+ console.error("Unable to copy field name.", error);
+ }
+ },
+ true
+ );
+})();
diff --git a/docs/style.css b/docs/style.css
index d90032c349..f7e0c4e1d9 100644
--- a/docs/style.css
+++ b/docs/style.css
@@ -571,6 +571,7 @@ a.ifx-steps__label:hover {
.ifx-card {
--ifx-ink: #6f6f6f;
--ifx-accent: #dbf530;
+ position: relative;
display: flex;
flex-direction: column;
padding: 1.5rem;
@@ -669,6 +670,17 @@ a.ifx-card__title {
text-decoration: none;
}
+div.ifx-card a.ifx-card__title::after {
+ position: absolute;
+ inset: 0;
+ content: "";
+}
+
+div.ifx-card a:not(.ifx-card__title) {
+ position: relative;
+ z-index: 1;
+}
+
.ifx-card__chevron {
flex: none;
opacity: 0;
@@ -943,3 +955,34 @@ a.ifx-card__title:hover .ifx-card__chevron {
align-self: stretch;
}
}
+
+[data-component-part="field-name"] {
+ position: relative;
+}
+
+[data-component-part="field-name"]::after {
+ content: "Click to copy";
+ position: absolute;
+ bottom: calc(100% + 0.5rem);
+ left: 50%;
+ z-index: 50;
+ transform: translateX(-50%);
+ visibility: hidden;
+ padding: 0.375rem 0.5rem;
+ border-radius: 0.375rem;
+ background: #18181b;
+ color: #ffffff;
+ font: 500 0.75rem/1 system-ui, sans-serif;
+ white-space: nowrap;
+ pointer-events: none;
+}
+
+[data-component-part="field-name"]:hover::after,
+[data-component-part="field-name"]:focus-visible::after {
+ visibility: visible;
+}
+
+[data-component-part="field-name"][data-copy-state="copied"]::after {
+ content: "Copied";
+ visibility: visible;
+}