diff --git a/site/src/components/shortcodes/Code.astro b/site/src/components/shortcodes/Code.astro index ba2c61165f..e737b19409 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 aria-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) {