1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-22 13:13:03 +02:00

Docs: fix missing "Copy to clipboard" tooltips when <Example> was used, not just <Code> (#41582)

Co-authored-by: Julien Déramond <juderamond@gmail.com>
This commit is contained in:
Louis-Maxime Piton
2025-08-10 19:38:15 +02:00
committed by GitHub
parent 2acf59d89b
commit 6d3345b24c
2 changed files with 26 additions and 19 deletions

View File

@@ -33,15 +33,20 @@ interface Props {
* This takes precedence over the `code` prop. * This takes precedence over the `code` prop.
*/ */
filePath?: string filePath?: string
/**
* Defines if the `<Code>` component is nested inside an `<Example>` component or not.
* @default false
*/
nestedInExample?: boolean
} }
const { class: className, code, containerClass, fileMatch, filePath, lang } = Astro.props const { class: className, code, containerClass, fileMatch, filePath, lang, nestedInExample = false } = Astro.props
let codeToDisplay = filePath let codeToDisplay = filePath
? fs.readFileSync(path.join(process.cwd(), filePath), 'utf8') ? fs.readFileSync(path.join(process.cwd(), filePath), 'utf8')
: Array.isArray(code) : Array.isArray(code)
? code.join('\n') ? code.join('\n')
: code : code
if (filePath && fileMatch && codeToDisplay) { if (filePath && fileMatch && codeToDisplay) {
const match = codeToDisplay.match(new RegExp(fileMatch)) const match = codeToDisplay.match(new RegExp(fileMatch))
@@ -130,19 +135,23 @@ if (filePath && fileMatch && codeToDisplay) {
}) })
</script> </script>
<div class:list={['bd-code-snippet', containerClass]}> <div class:list={[{ 'bd-code-snippet': !nestedInExample }, containerClass]}>
{ {
Astro.slots.has('pre') ? ( nestedInExample
<slot name="pre" /> ? (<></>)
) : ( : Astro.slots.has('pre')
<div class="bd-clipboard"> ? (
<button type="button" class="btn-clipboard"> <slot name="pre" />
<svg class="bi" role="img" aria-label="Copy"> )
<use xlink:href="#clipboard" /> : (
</svg> <div class="bd-clipboard">
</button> <button type="button" class="btn-clipboard">
</div> <svg class="bi" role="img" aria-label="Copy">
) <use xlink:href="#clipboard" />
</svg>
</button>
</div>
)
} }
<div class="highlight"> <div class="highlight">
{ {

View File

@@ -1,6 +1,6 @@
--- ---
import { replacePlaceholdersInHtml } from '@libs/placeholder' import { replacePlaceholdersInHtml } from '@libs/placeholder'
import { Prism } from '@astrojs/prism' import Code from '@components/shortcodes/Code.astro'
interface Props { interface Props {
/** /**
@@ -96,9 +96,7 @@ const simplifiedMarkup = markup
</div> </div>
</div> </div>
)} )}
<div class="highlight"> <Code code={simplifiedMarkup} lang={lang} nestedInExample={true} />
<Prism code={simplifiedMarkup} lang={lang} />
</div>
</> </>
) )
} }