From 0e141cdb46e9b79cb732743e4fe36aeb094f198f Mon Sep 17 00:00:00 2001 From: Hannah Issermann Date: Mon, 13 Oct 2025 11:31:12 +0200 Subject: [PATCH 1/3] Add the possibility to pass an aria-label for Copy to clipboard and Edit on Stackblitz buttons in code examples --- site/src/components/shortcodes/Code.astro | 29 +++++++++++-------- site/src/components/shortcodes/Example.astro | 16 +++++++--- site/src/components/shortcodes/JsDocs.astro | 12 ++++++-- site/src/components/shortcodes/ScssDocs.astro | 12 ++++++-- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/site/src/components/shortcodes/Code.astro b/site/src/components/shortcodes/Code.astro index ba2c61165f..3b4f5d6c0f 100644 --- a/site/src/components/shortcodes/Code.astro +++ b/site/src/components/shortcodes/Code.astro @@ -38,9 +38,16 @@ interface Props { * @default false */ nestedInExample?: boolean + /** + * Defines label to complete 'Edit code on Stackblitz' and/or 'Copy code to clipboard' buttons labels. + */ + buttonLabel?: string } -const { class: className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false } = Astro.props +const { class: className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false, buttonLabel } = Astro.props + +const clipboardLabel = buttonLabel ? `Copy ${buttonLabel} code to clipboard` : filePath ? + `Copy ${filePath} code to clipboard` : 'Copy code to clipboard' let codeToDisplay = filePath ? fs.readFileSync(path.join(process.cwd(), filePath), 'utf8') @@ -62,17 +69,15 @@ if (filePath && fileMatch && codeToDisplay) {