mirror of https://github.com/zulip/zulip.git
copy: Use redesigned copy button in codeblocks of /help docs.
Fixes #28700.
This commit is contained in:
parent
4afdb33906
commit
9c5978e85b
|
@ -1,10 +1,12 @@
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
import SimpleBar from "simplebar";
|
import SimpleBar from "simplebar";
|
||||||
import * as tippy from "tippy.js";
|
import * as tippy from "tippy.js";
|
||||||
|
|
||||||
import copy_to_clipboard_svg from "../../templates/copy_to_clipboard_svg.hbs";
|
import zulip_copy_icon from "../../templates/zulip_copy_icon.hbs";
|
||||||
import * as common from "../common";
|
import * as common from "../common";
|
||||||
|
import {show_copied_confirmation} from "../copied_tooltip";
|
||||||
import * as util from "../util";
|
import * as util from "../util";
|
||||||
|
|
||||||
import {activate_correct_tab} from "./tabbed-instructions";
|
import {activate_correct_tab} from "./tabbed-instructions";
|
||||||
|
@ -33,8 +35,8 @@ function register_tabbed_section($tabbed_section: JQuery): void {
|
||||||
// Display the copy-to-clipboard button inside the .codehilite element
|
// Display the copy-to-clipboard button inside the .codehilite element
|
||||||
// within the API and Help Center docs using clipboard.js
|
// within the API and Help Center docs using clipboard.js
|
||||||
function add_copy_to_clipboard_element($codehilite: JQuery): void {
|
function add_copy_to_clipboard_element($codehilite: JQuery): void {
|
||||||
const $copy_button = $("<button>").addClass("copy-codeblock");
|
const $copy_button = $("<span>").addClass("copy-btn copy-codeblock");
|
||||||
$copy_button.html(copy_to_clipboard_svg());
|
$copy_button.html(zulip_copy_icon());
|
||||||
|
|
||||||
$($codehilite).append($copy_button);
|
$($codehilite).append($copy_button);
|
||||||
|
|
||||||
|
@ -47,28 +49,18 @@ function add_copy_to_clipboard_element($codehilite: JQuery): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show a tippy tooltip when the button is hovered
|
// Show a tippy tooltip when the button is hovered
|
||||||
const tooltip_copy = tippy.default(util.the($copy_button), {
|
tippy.default(util.the($copy_button), {
|
||||||
content: "Copy code",
|
content: "Copy code",
|
||||||
trigger: "mouseenter",
|
trigger: "mouseenter",
|
||||||
placement: "top",
|
placement: "top",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show a tippy tooltip when the code is copied
|
|
||||||
const tooltip_copied = tippy.default(util.the($copy_button), {
|
|
||||||
content: "Copied!",
|
|
||||||
trigger: "manual",
|
|
||||||
placement: "top",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Show "Copied!" tooltip when code is successfully copied
|
// Show "Copied!" tooltip when code is successfully copied
|
||||||
clipboard.on("success", () => {
|
clipboard.on("success", (e) => {
|
||||||
tooltip_copy.hide();
|
assert(e.trigger instanceof HTMLElement);
|
||||||
tooltip_copied.show();
|
show_copied_confirmation(e.trigger, {
|
||||||
|
show_check_icon: true,
|
||||||
// Hide the "Copied!" tooltip after 1 second
|
});
|
||||||
setTimeout(() => {
|
|
||||||
tooltip_copied.hide();
|
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
.markdown {
|
.markdown {
|
||||||
|
/* Copied from app_variables.css to be used in portico pages. */
|
||||||
|
--color-copy-btn: color-mix(in oklch, hsl(229deg 9% 36%) 70%, transparent);
|
||||||
|
--color-copy-btn-hover: hsl(229deg 9% 36%);
|
||||||
|
--color-copy-btn-active: color-mix(
|
||||||
|
in oklch,
|
||||||
|
hsla(229deg 9% 36%) 70%,
|
||||||
|
transparent
|
||||||
|
);
|
||||||
|
--color-copy-btn-success: hsl(146deg 90% 27%);
|
||||||
|
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
@ -412,9 +422,27 @@
|
||||||
outline-offset: -1px;
|
outline-offset: -1px;
|
||||||
outline-color: hsl(176deg 46% 41%);
|
outline-color: hsl(176deg 46% 41%);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:hover svg path {
|
.copy-btn {
|
||||||
fill: hsl(200deg 100% 40%);
|
display: flex;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: var(--color-copy-btn);
|
||||||
|
/* 2px at 16px/1em */
|
||||||
|
padding: 0.125em;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus-visible {
|
||||||
|
color: var(--color-copy-btn-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
color: var(--color-copy-btn-active);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.copy-btn-success {
|
||||||
|
color: var(--color-copy-btn-success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
<svg height="20" width="16" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" id="clipboard_image">
|
|
||||||
<path fill="#777" d="M128 768h256v64H128v-64z m320-384H128v64h320v-64z m128 192V448L384 640l192 192V704h320V576H576z m-288-64H128v64h160v-64zM128 704h160v-64H128v64z m576 64h64v128c-1 18-7 33-19 45s-27 18-45 19H64c-35 0-64-29-64-64V192c0-35 29-64 64-64h192C256 57 313 0 384 0s128 57 128 128h192c35 0 64 29 64 64v320h-64V320H64v576h640V768zM128 256h512c0-35-29-64-64-64h-64c-35 0-64-29-64-64s-29-64-64-64-64 29-64 64-29 64-64 64h-64c-35 0-64 29-64 64z" />
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 575 B |
|
@ -0,0 +1 @@
|
||||||
|
<i class="zulip-icon zulip-icon-copy" aria-hidden="true"></i>
|
Loading…
Reference in New Issue