From 20a996ec2c97dc6a3c3af3af4a5af64ca62e814e Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Sat, 31 Aug 2024 04:01:35 +0800 Subject: [PATCH 1/3] feat(theme-classic): code block button place improve --- .../src/theme/CodeBlock/Content/String.tsx | 40 ++++++++++++++----- .../theme/CodeBlock/Content/styles.module.css | 3 ++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx index b7ee289e2dca..820228eb4713 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx @@ -71,7 +71,23 @@ export default function CodeBlockString({ !blockClassName.includes(`language-${language}`) && `language-${language}`, )}> - {title &&
{title}
} + {title && ( +
+ {title} + {title && ( +
+ {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( + wordWrap.toggle()} + isEnabled={wordWrap.isEnabled} + /> + )} + +
+ )} +
+ )}
)} -
- {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( - wordWrap.toggle()} - isEnabled={wordWrap.isEnabled} - /> - )} - -
+ {!title && ( +
+ {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( + wordWrap.toggle()} + isEnabled={wordWrap.isEnabled} + /> + )} + +
+ )}
); diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/styles.module.css b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/styles.module.css index 3760c530c4c4..508aa048a38e 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/styles.module.css +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/styles.module.css @@ -19,6 +19,9 @@ padding: 0.75rem var(--ifm-pre-padding); border-top-left-radius: inherit; border-top-right-radius: inherit; + position: relative; + /* rtl:ignore */ + direction: ltr; } .codeBlock { From 198965e983240bd9015e3199d17758db9a4d713f Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Sat, 31 Aug 2024 04:21:01 +0800 Subject: [PATCH 2/3] clean code --- .../src/theme/CodeBlock/Content/String.tsx | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx index 820228eb4713..4f2e70b3a9a2 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx @@ -62,6 +62,19 @@ export default function CodeBlockString({ const showLineNumbers = showLineNumbersProp ?? containsLineNumbers(metastring); + function ButtonGroup() { + return
+ {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( + wordWrap.toggle()} + isEnabled={wordWrap.isEnabled} + /> + )} + +
+} + return ( {title} - {title && ( -
- {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( - wordWrap.toggle()} - isEnabled={wordWrap.isEnabled} - /> - )} - -
- )} + )}
@@ -119,18 +121,7 @@ export default function CodeBlockString({ )} - {!title && ( -
- {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( - wordWrap.toggle()} - isEnabled={wordWrap.isEnabled} - /> - )} - -
- )} + {!title && }
); From d7c9188fdd23b41053920c1b32f9960a472d8a2b Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Sat, 31 Aug 2024 04:22:30 +0800 Subject: [PATCH 3/3] fix indentation --- .../src/theme/CodeBlock/Content/String.tsx | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx index 4f2e70b3a9a2..28bdaea826e7 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx @@ -63,17 +63,19 @@ export default function CodeBlockString({ showLineNumbersProp ?? containsLineNumbers(metastring); function ButtonGroup() { - return
- {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( - wordWrap.toggle()} - isEnabled={wordWrap.isEnabled} - /> - )} - -
-} + return ( +
+ {(wordWrap.isEnabled || wordWrap.isCodeScrollable) && ( + wordWrap.toggle()} + isEnabled={wordWrap.isEnabled} + /> + )} + +
+ ); + } return (