Skip to content

Commit

Permalink
fix: tab content cls
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Mar 18, 2024
1 parent 8587b97 commit cb40ff6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
18 changes: 13 additions & 5 deletions src/components/modules/shared/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ReactNode } from 'react'
import { HighLighterPrismCdn } from '~/components/ui/code-highlighter'
import { isSupportedShikiLang } from '~/components/ui/code-highlighter/shiki/utils'
import { ExcalidrawLoading } from '~/components/ui/excalidraw/ExcalidrawLoading'
import { isClientSide } from '~/lib/env'

import { BlockLoading } from './BlockLoading'

Expand All @@ -29,6 +30,8 @@ const ExcalidrawLazy = ({ data }: any) => {
</Suspense>
)
}

let shikiImport: ComponentType<any>
export const CodeBlockRender = (props: {
lang: string | undefined
content: string
Expand Down Expand Up @@ -56,11 +59,16 @@ export const CodeBlockRender = (props: {
default: {
const lang = props.lang
if (lang && isSupportedShikiLang(lang)) {
const ShikiHighLighter = dynamic(() =>
import('~/components/ui/code-highlighter/shiki/Shiki').then(
(mod) => mod.ShikiHighLighter,
),
)
const ShikiHighLighter =
shikiImport ??
dynamic(() =>
import('~/components/ui/code-highlighter/shiki/Shiki').then(
(mod) => mod.ShikiHighLighter,
),
)
if (isClientSide) {
shikiImport = ShikiHighLighter
}
return <ShikiHighLighter {...props} />
}

Expand Down
12 changes: 0 additions & 12 deletions src/components/ui/code-highlighter/shiki/Shiki.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
counter-increment: step 0;
}

code .line::before {
content: counter(step);
counter-increment: step;
width: 1.5rem;
margin: 0 6px;
display: inline-block;
text-align: right;
opacity: 0.3;
padding-right: 6px;
/* border-right: 1px solid currentColor; */
}

.shiki,
code {
@apply !bg-transparent;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/code-highlighter/shiki/Shiki.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ export const ShikiHighLighter: FC<Props> = (props) => {
}
>
{renderedHtml ? undefined : (
<pre className="bg-transparent">
<code className="px-4">{value}</code>
<pre className="bg-transparent px-4">
<code className="!px-4">{value}</code>
</pre>
)}
</div>
Expand Down
26 changes: 15 additions & 11 deletions src/components/ui/markdown/renderers/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useId,
useState,
} from 'react'
import { useIsomorphicLayoutEffect } from 'foxact/use-isomorphic-layout-effect'
import { m } from 'framer-motion'
import type { FC, PropsWithChildren } from 'react'

Expand All @@ -19,20 +20,23 @@ export const Tabs: FC<PropsWithChildren> = ({ children }) => {
const [tabs, setTabs] = useState<string[]>([])
const [activeTab, setActiveTab] = useState<string | null>(null)
const id = useId()

useEffect(() => {
if (!tabs.length) return
if (!activeTab) {
setActiveTab(tabs[0])
}
}, [tabs.length])
return (
<TabActionContext.Provider
value={{
addTab: useCallback(
(label) => {
setTabs((tabs) => [...tabs, label])
addTab: useCallback((label) => {
setTabs((tabs) => [...tabs, label])

if (!activeTab) setActiveTab(label)
return () => {
setTabs((tabs) => tabs.filter((tab) => tab !== label))
}
},
[activeTab],
),
return () => {
setTabs((tabs) => tabs.filter((tab) => tab !== label))
}
}, []),
}}
>
<RadixTabs.Root value={activeTab || ''} onValueChange={setActiveTab}>
Expand Down Expand Up @@ -72,7 +76,7 @@ export const Tab: FC<{
children: React.ReactNode
}> = ({ label, children }) => {
const { addTab } = useContext(TabActionContext)
useEffect(() => {
useIsomorphicLayoutEffect(() => {
return addTab(label)
}, [])

Expand Down

0 comments on commit cb40ff6

Please sign in to comment.