Skip to content

Commit fd35d53

Browse files
committed
revise dropdown implementation to use swizzling
1 parent 07bb728 commit fd35d53

File tree

7 files changed

+86
-156
lines changed

7 files changed

+86
-156
lines changed

docs/intro-replicated.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
pagination_prev: null
3+
hide_table_of_contents: true
34
---
45

56
import ApiAbout from "/docs/partials/vendor-api/_api-about.mdx"

src/components/CopyMarkdown.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import React, { useState, useEffect, useCallback, useRef } from 'react';
1111
import styles from './CopyMarkdown.module.css';
12+
import clsx from 'clsx';
1213

1314
function CopyMarkdown() {
1415
const [isOpen, setIsOpen] = useState(false);
@@ -18,6 +19,8 @@ function CopyMarkdown() {
1819
const buttonRef = useRef(null);
1920
const dropdownRef = useRef(null);
2021

22+
console.log('CopyMarkdown component mounted');
23+
2124
// Toggle dropdown
2225
const toggleDropdown = useCallback(() => {
2326
setIsOpen(prev => !prev);
@@ -137,8 +140,30 @@ function CopyMarkdown() {
137140

138141
// Initialize on client side
139142
useEffect(() => {
140-
// Check if we have markdown content
141-
const hasMarkdownContent = !!document.querySelector('.theme-doc-markdown.markdown h1');
143+
// More detailed debugging
144+
const h1Elements = document.querySelectorAll('h1');
145+
console.log('Found h1 elements:', h1Elements);
146+
h1Elements.forEach(el => {
147+
console.log('H1 element:', el);
148+
console.log('H1 text content:', el.textContent);
149+
console.log('H1 parent element:', el.parentElement);
150+
console.log('Full element tree:', el.closest('article'));
151+
});
152+
153+
// Check for content in multiple ways
154+
const hasH1 = document.querySelector('h1');
155+
const hasArticle = document.querySelector('article');
156+
const hasMainContent = document.querySelector('main');
157+
158+
console.log('Detection results:', {
159+
hasH1: !!hasH1,
160+
hasArticle: !!hasArticle,
161+
hasMainContent: !!hasMainContent
162+
});
163+
164+
// Set content flag if we have both an h1 and either an article or main element
165+
const hasMarkdownContent = !!hasH1 && (!!hasArticle || !!hasMainContent);
166+
console.log('Setting hasContent to:', hasMarkdownContent);
142167
setHasContent(hasMarkdownContent);
143168

144169
// Set up click outside handler
@@ -177,7 +202,7 @@ function CopyMarkdown() {
177202
<div className={styles.container}>
178203
<button
179204
ref={buttonRef}
180-
className={`${styles.button} ${isCopied ? styles.copied : ''}`}
205+
className={clsx(styles.button, isCopied && styles.copied)}
181206
onClick={!isCopied ? toggleDropdown : undefined}
182207
aria-expanded={isOpen}
183208
aria-haspopup="true"
@@ -212,7 +237,7 @@ function CopyMarkdown() {
212237
aria-orientation="vertical"
213238
>
214239
<ul className={styles.list}>
215-
<li className={styles.item}>
240+
<li className={styles.item}>
216241
<button
217242
className={styles.actionButton}
218243
onClick={openInChatGpt}

src/components/CopyMarkdown.module.css

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.container {
22
position: relative;
3-
display: inline-block;
4-
margin-left: auto;
3+
display: flex;
4+
align-items: center;
5+
margin-left: 1rem;
56
z-index: 10;
67
}
78

@@ -70,7 +71,6 @@
7071
}
7172

7273
.dropdown {
73-
display: block;
7474
position: absolute;
7575
top: 100%;
7676
left: 0;
@@ -220,5 +220,7 @@ html[data-theme='dark'] .actionDescription {
220220
.container {
221221
margin-top: 1rem;
222222
margin-left: 0;
223+
flex-direction: column;
224+
align-items: flex-start;
223225
}
224226
}

src/theme/DocItem/Layout/index.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/theme/DocItem/Layout/styles.module.css

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/theme/DocItem/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import DocItem from '@theme-original/DocItem';
3+
import CopyMarkdown from '../../components/CopyMarkdown';
4+
import styles from './styles.module.css';
5+
6+
export default function DocItemWrapper(props) {
7+
return (
8+
<div className={styles.container}>
9+
<div className={styles.headerContainer}>
10+
<h1>{props.content.metadata.title}</h1>
11+
<CopyMarkdown />
12+
</div>
13+
<div className={styles.contentContainer}>
14+
<DocItem {...props} />
15+
</div>
16+
</div>
17+
);
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.container {
2+
display: flex;
3+
flex-direction: column;
4+
width: 100%;
5+
}
6+
7+
.headerContainer {
8+
display: flex;
9+
align-items: center;
10+
justify-content: space-between;
11+
margin-bottom: 1rem;
12+
gap: 1rem;
13+
/* Ensure the header stays within article width */
14+
max-width: 800px;
15+
width: 100%;
16+
}
17+
18+
.contentContainer {
19+
width: 100%;
20+
}
21+
22+
/* Hide the original h1 from DocItem */
23+
.contentContainer :global(h1:first-child) {
24+
display: none;
25+
}
26+
27+
/* Responsive styles */
28+
@media (max-width: 768px) {
29+
.headerContainer {
30+
flex-direction: column;
31+
align-items: flex-start;
32+
}
33+
}

0 commit comments

Comments
 (0)