docs: update to next 15 + eslint 9 (#9839)
* update next * updated react * update eslint * finish updating eslint * fix content lint errors * fix docs test * fix vale action * fix installation errors
This commit is contained in:
@@ -16,6 +16,7 @@ import { CodeBlockHeaderWrapper } from "../CodeBlock/Header/Wrapper"
|
||||
type CodeTab = BaseTabType & {
|
||||
codeProps: CodeBlockProps
|
||||
codeBlock: React.ReactNode
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
type CodeTabProps = {
|
||||
@@ -33,36 +34,72 @@ export const CodeTabs = ({
|
||||
blockStyle = "loud",
|
||||
}: CodeTabProps) => {
|
||||
const { colorMode } = useColorMode()
|
||||
|
||||
const isCodeBlock = (
|
||||
node: React.ReactNode
|
||||
): node is
|
||||
| React.ReactElement<unknown, string | React.JSXElementConstructor<any>>
|
||||
| React.ReactPortal => {
|
||||
if (!React.isValidElement(node)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (node.type === "pre") {
|
||||
return true
|
||||
}
|
||||
|
||||
const typedProps = node.props as Record<string, unknown>
|
||||
|
||||
return "source" in typedProps
|
||||
}
|
||||
|
||||
const tabs: CodeTab[] = useMemo(() => {
|
||||
const tempTabs: CodeTab[] = []
|
||||
Children.forEach(children, (child) => {
|
||||
if (!React.isValidElement(child)) {
|
||||
return
|
||||
}
|
||||
const typedChildProps = child.props as CodeTab
|
||||
if (
|
||||
!React.isValidElement(child) ||
|
||||
!child.props.label ||
|
||||
!child.props.value ||
|
||||
!React.isValidElement(child.props.children)
|
||||
!typedChildProps.label ||
|
||||
!typedChildProps.value ||
|
||||
!React.isValidElement(typedChildProps.children)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
// extract child code block
|
||||
const codeBlock =
|
||||
child.props.children.type === "pre" &&
|
||||
React.isValidElement(child.props.children.props.children)
|
||||
? child.props.children.props.children
|
||||
: child.props.children
|
||||
const codeBlock: React.ReactNode = isCodeBlock(typedChildProps.children)
|
||||
? typedChildProps.children
|
||||
: undefined
|
||||
|
||||
if (!codeBlock) {
|
||||
return
|
||||
}
|
||||
|
||||
const codeBlockProps = codeBlock.props as CodeBlockProps
|
||||
|
||||
tempTabs.push({
|
||||
label: child.props.label,
|
||||
value: child.props.value,
|
||||
codeProps: codeBlock.props,
|
||||
label: typedChildProps.label,
|
||||
value: typedChildProps.value,
|
||||
codeProps: codeBlockProps,
|
||||
codeBlock: {
|
||||
...codeBlock,
|
||||
props: {
|
||||
...codeBlock.props,
|
||||
badgeLabel: undefined,
|
||||
hasTabs: true,
|
||||
className: clsx("!my-0", codeBlock.props.className),
|
||||
...codeBlockProps,
|
||||
children: {
|
||||
...(typeof codeBlockProps.children === "object"
|
||||
? codeBlockProps.children
|
||||
: {}),
|
||||
props: {
|
||||
...(React.isValidElement(codeBlockProps.children)
|
||||
? (codeBlockProps.children.props as Record<string, unknown>)
|
||||
: {}),
|
||||
badgeLabel: undefined,
|
||||
hasTabs: true,
|
||||
className: clsx("!my-0", codeBlockProps.className),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -188,7 +225,7 @@ export const CodeTabs = ({
|
||||
|
||||
return (
|
||||
<child.type
|
||||
{...child.props}
|
||||
{...(typeof child.props === "object" ? child.props : {})}
|
||||
changeSelectedTab={changeSelectedTab}
|
||||
pushRef={(tabButton: HTMLButtonElement | null) =>
|
||||
tabRefs.push(tabButton)
|
||||
@@ -197,7 +234,7 @@ export const CodeTabs = ({
|
||||
isSelected={
|
||||
!selectedTab
|
||||
? index === 0
|
||||
: selectedTab.value === child.props.value
|
||||
: selectedTab.value === (child.props as CodeTab).value
|
||||
}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user