]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
fix(docs): Add a tooltip on buttons whenever `<Example>` is called and not only ... main-lmp-tooltip-example-fix 41582/head
authorLouis-Maxime Piton <louismaxime.piton@orange.com>
Tue, 1 Jul 2025 10:09:48 +0000 (12:09 +0200)
committerLouis-Maxime Piton <louismaxime.piton@orange.com>
Tue, 1 Jul 2025 10:09:48 +0000 (12:09 +0200)
site/src/components/shortcodes/Code.astro
site/src/components/shortcodes/Example.astro

index 231002a50b622fed5c884f6983b596de7b07e2e4..53d170859bd3fa9a1eb068366622c9849d406ded 100644 (file)
@@ -33,15 +33,20 @@ interface Props {
    * This takes precedence over the `code` prop.
    */
   filePath?: string
+  /**
+   * If the component is nested inside an example or not.
+   * @default false
+   */
+  nested?: boolean
 }
 
-const { class: className, code, containerClass, fileMatch, filePath, lang } = Astro.props
+const { class: className, code, containerClass, fileMatch, filePath, lang, nested = false } = Astro.props
 
 let codeToDisplay = filePath
   ? fs.readFileSync(path.join(process.cwd(), filePath), 'utf8')
   : Array.isArray(code)
-  ? code.join('\n')
-  : code
+    ? code.join('\n')
+    : code
 
 if (filePath && fileMatch && codeToDisplay) {
   const match = codeToDisplay.match(new RegExp(fileMatch))
@@ -130,19 +135,23 @@ if (filePath && fileMatch && codeToDisplay) {
   })
 </script>
 
-<div class:list={['bd-code-snippet', containerClass]}>
+<div class:list={[{ 'bd-code-snippet': !nested }, containerClass]}>
   {
-    Astro.slots.has('pre') ? (
-      <slot name="pre" />
-    ) : (
-      <div class="bd-clipboard">
-        <button type="button" class="btn-clipboard">
-          <svg class="bi" role="img" aria-label="Copy">
-            <use xlink:href="#clipboard" />
-          </svg>
-        </button>
-      </div>
-    )
+    nested
+      ? (<></>)
+      : Astro.slots.has('pre')
+        ? (
+          <slot name="pre" />
+        )
+        : (
+          <div class="bd-clipboard">
+            <button type="button" class="btn-clipboard">
+              <svg class="bi" role="img" aria-label="Copy">
+                <use xlink:href="#clipboard" />
+              </svg>
+            </button>
+          </div>
+        )
   }
   <div class="highlight">
     {
index a09fffeb31fbb2649bab6fdeec03760d58e5e73c..767f4cf4976c21bca68d1184d92dd902f5443b5e 100644 (file)
@@ -1,6 +1,6 @@
 ---
 import { replacePlaceholdersInHtml } from '@libs/placeholder'
-import { Prism } from '@astrojs/prism'
+import Code from '@components/shortcodes/Code.astro'
 
 interface Props {
   /**
@@ -96,9 +96,7 @@ const simplifiedMarkup = markup
             </div>
           </div>
         )}
-        <div class="highlight">
-          <Prism code={simplifiedMarkup} lang={lang} />
-        </div>
+        <Code code={simplifiedMarkup} lang={lang} nested={true} />
       </>
     )
   }