Skip to content

Commit f811e71

Browse files
fix: tabs update (#624)
* fix: clean up codeblock styles and improve tab layout * fix: enhance tab styles for improved visibility and layout * fix: improve heading collection logic within tab components * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 40400dd commit f811e71

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

src/components/CodeBlock.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ export function CodeBlock({
167167

168168
setCodeElement(
169169
<div
170-
// className={`m-0 text-sm rounded-md w-full border border-gray-500/20 dark:border-gray-500/30`}
171170
className={twMerge(
172171
isEmbedded ? 'h-full [&>pre]:h-full [&>pre]:rounded-none' : '',
173172
)}
@@ -181,7 +180,7 @@ export function CodeBlock({
181180
return (
182181
<div
183182
className={twMerge(
184-
'codeblock w-full max-w-full relative not-prose border border-gray-500/20 rounded-md [&_pre]:rounded-md [*[data-tab]_&]:only:border-0',
183+
'codeblock w-full max-w-full relative not-prose border border-gray-500/20 rounded-md [&_pre]:rounded-md',
185184
props.className,
186185
)}
187186
style={props.style}

src/components/Tabs.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function Tabs({ tabs, id, children }: TabsProps) {
2424

2525
return (
2626
<div className="not-prose my-4">
27-
<div className="flex items-center justify-start gap-2 rounded-t-md border-b border-gray-200 dark:border-gray-700 overflow-x-auto scrollbar-hide bg-white dark:bg-[#1a1b26]">
27+
<div className="flex items-center justify-start gap-2 rounded-t-md border-1 border-b-none border-gray-200 dark:border-gray-800 overflow-x-auto overflow-y-hidden bg-white dark:bg-gray-950">
2828
{tabs.map((tab) => {
2929
return (
3030
<Tab
@@ -37,7 +37,7 @@ export function Tabs({ tabs, id, children }: TabsProps) {
3737
)
3838
})}
3939
</div>
40-
<div className="border border-gray-500/20 rounded-b-md p-4 bg-white dark:bg-[#1a1b26]">
40+
<div className="border border-gray-500/20 rounded-b-md p-4 bg-gray-100 dark:bg-gray-900">
4141
{children.map((child, index) => {
4242
const tab = tabs[index]
4343
if (!tab) return null
@@ -76,14 +76,14 @@ const Tab = ({
7676
title={tab.name}
7777
type="button"
7878
onClick={() => setActiveSlug(tab.slug)}
79-
className={`inline-flex items-center justify-center gap-2 px-3 py-1.5 -mb-[1px] border-b-2 text-sm font-bold transition-colors ${
79+
className={`inline-flex items-center justify-center gap-2 px-3 py-1.5 -mb-[1px] border-b-2 text-sm font-bold transition-colors hover:bg-gray-100 dark:hover:bg-gray-800 rounded-t-md overflow-y-none ${
8080
activeSlug === tab.slug
81-
? 'border-current text-current'
81+
? 'border-current text-current bg-gray-100 dark:bg-gray-900'
8282
: 'border-transparent text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200'
8383
}`}
8484
>
8585
{options[0] ? (
86-
<img src={options[0].logo} alt="" className="w-4 h-4" />
86+
<img src={options[0].logo} alt="" className="w-4 h-4 -ml-1" />
8787
) : null}
8888
<span>{tab.name}</span>
8989
</button>

src/styles/app.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,6 @@ html.dark .shiki.vitesse-dark span[style*='color: #51597D'] {
772772
@apply bg-gray-100 dark:bg-gray-900;
773773
}
774774

775-
[data-tab] > .codeblock:not(:only-child) pre {
776-
@apply dark:bg-white/5! bg-black/5!;
777-
}
778-
779775
[data-tab] > .markdown-alert [aria-label] svg {
780776
@apply stroke-current fill-current;
781777
}

src/utils/markdown/plugins/collectHeadings.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { visit } from 'unist-util-visit'
22
import { toString } from 'hast-util-to-string'
3+
import type { Element, Root } from 'hast'
4+
import type { VFile } from 'vfile'
35

46
import { isHeading } from './helpers'
57

@@ -9,19 +11,44 @@ export type MarkdownHeading = {
911
level: number
1012
}
1113

14+
const isTabsAncestor = (ancestor: Element) => {
15+
if (ancestor.type !== 'element') {
16+
console.log('skip')
17+
return false
18+
}
19+
20+
if (ancestor.tagName !== 'md-comment-component') {
21+
console.log('skip')
22+
return false
23+
}
24+
25+
const component = ancestor.properties?.['data-component']
26+
console.log('dont skip', component)
27+
return typeof component === 'string' && component.toLowerCase() === 'tabs'
28+
}
29+
1230
export function rehypeCollectHeadings(
13-
tree,
14-
file,
31+
_tree: Root,
32+
_file: VFile,
1533
initialHeadings?: MarkdownHeading[],
1634
) {
1735
const headings = initialHeadings ?? []
1836

19-
return function collectHeadings(tree, file: any) {
20-
visit(tree, 'element', (node) => {
37+
return function collectHeadings(tree: Root, file?: VFile) {
38+
visit(tree, 'element', (node: Element, _index, ancestors) => {
2139
if (!isHeading(node)) {
2240
return
2341
}
2442

43+
if (Array.isArray(ancestors)) {
44+
const insideTabs = ancestors.some((ancestor) =>
45+
isTabsAncestor(ancestor as Element),
46+
)
47+
if (insideTabs) {
48+
return
49+
}
50+
}
51+
2552
const id =
2653
typeof node.properties?.id === 'string' ? node.properties.id : ''
2754
if (!id) {

src/utils/markdown/plugins/parseCommentComponents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { unified } from 'unified'
22
import rehypeParse from 'rehype-parse'
3-
import { visit } from 'unist-util-visit'
3+
import { SKIP, visit } from 'unist-util-visit'
44

55
const COMPONENT_PREFIX = '::'
66
const START_PREFIX = '::start:'

0 commit comments

Comments
 (0)