docs: fix copy in code blocks with tabs (#10123)
* docs: fix copy in code blocks with tabs * fix lint error
This commit is contained in:
1 parent
1fb2998620
commit
b0c6efa98b
2 files changed
+42
-9
No files matched your search
@@ -53,6 +53,36 @@ export const CodeTabs = ({
|
|||||||
return "source" in typedProps
|
return "source" in typedProps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getCodeBlockProps = (
|
||||||
|
codeBlock: React.ReactElement<
|
||||||
|
unknown,
|
||||||
|
string | React.JSXElementConstructor<any>
|
||||||
|
>
|
||||||
|
): CodeBlockProps | undefined => {
|
||||||
|
if (typeof codeBlock.props !== "object" || !codeBlock.props) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("source" in codeBlock.props) {
|
||||||
|
return codeBlock.props as CodeBlockProps
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
"children" in codeBlock.props &&
|
||||||
|
typeof codeBlock.props.children === "object" &&
|
||||||
|
codeBlock.props.children
|
||||||
|
) {
|
||||||
|
return getCodeBlockProps(
|
||||||
|
codeBlock.props.children as React.ReactElement<
|
||||||
|
unknown,
|
||||||
|
string | React.JSXElementConstructor<any>
|
||||||
|
>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
const tabs: CodeTab[] = useMemo(() => {
|
const tabs: CodeTab[] = useMemo(() => {
|
||||||
const tempTabs: CodeTab[] = []
|
const tempTabs: CodeTab[] = []
|
||||||
Children.forEach(children, (child) => {
|
Children.forEach(children, (child) => {
|
||||||
@@ -79,10 +109,19 @@ export const CodeTabs = ({
|
|||||||
|
|
||||||
const codeBlockProps = codeBlock.props as CodeBlockProps
|
const codeBlockProps = codeBlock.props as CodeBlockProps
|
||||||
|
|
||||||
|
const modifiedProps: CodeBlockProps = {
|
||||||
|
...(getCodeBlockProps(codeBlock) || {
|
||||||
|
source: "",
|
||||||
|
}),
|
||||||
|
badgeLabel: undefined,
|
||||||
|
hasTabs: true,
|
||||||
|
className: clsx("!my-0", codeBlockProps.className),
|
||||||
|
}
|
||||||
|
|
||||||
tempTabs.push({
|
tempTabs.push({
|
||||||
label: typedChildProps.label,
|
label: typedChildProps.label,
|
||||||
value: typedChildProps.value,
|
value: typedChildProps.value,
|
||||||
codeProps: codeBlockProps,
|
codeProps: modifiedProps,
|
||||||
codeBlock: {
|
codeBlock: {
|
||||||
...codeBlock,
|
...codeBlock,
|
||||||
props: {
|
props: {
|
||||||
@@ -91,14 +130,7 @@ export const CodeTabs = ({
|
|||||||
...(typeof codeBlockProps.children === "object"
|
...(typeof codeBlockProps.children === "object"
|
||||||
? codeBlockProps.children
|
? codeBlockProps.children
|
||||||
: {}),
|
: {}),
|
||||||
props: {
|
props: modifiedProps,
|
||||||
...(React.isValidElement(codeBlockProps.children)
|
|
||||||
? (codeBlockProps.children.props as Record<string, unknown>)
|
|
||||||
: {}),
|
|
||||||
badgeLabel: undefined,
|
|
||||||
hasTabs: true,
|
|
||||||
className: clsx("!my-0", codeBlockProps.className),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const Npm2YarnCode = ({ npmCode, ...rest }: Npm2YarnCodeProps) => {
|
|||||||
const lang = "bash"
|
const lang = "bash"
|
||||||
|
|
||||||
const { title = "", ...codeOptions } = rest
|
const { title = "", ...codeOptions } = rest
|
||||||
|
codeOptions.hasTabs = true
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user