Skip to content

Commit 3c9a6b9

Browse files
authored
[docs] use mostly new components to render MDX files, unify links appearance (expo#20429)
1 parent fbc6896 commit 3c9a6b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1808
-1963
lines changed

docs/common/create-permalinked-component.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ type Options = {
88
sidebarType?: HeadingType;
99
};
1010

11-
type PermalinkedComponentProps = React.PropsWithChildren<{ level?: number } & AdditionalProps>;
11+
type PermalinkedComponentProps = React.PropsWithChildren<
12+
{ level?: number; id?: string } & AdditionalProps
13+
>;
1214

1315
const isDev = process.env.NODE_ENV === 'development';
1416

@@ -17,7 +19,7 @@ export const createPermalinkedComponent = (
1719
options?: Options
1820
) => {
1921
const { baseNestingLevel, sidebarType = HeadingType.Text } = options || {};
20-
return ({ children, level, ...props }: PermalinkedComponentProps) => {
22+
return ({ children, level, id, ...props }: PermalinkedComponentProps) => {
2123
const cleanChildren = React.Children.map(children, child => {
2224
if (React.isValidElement(child) && child?.props?.href) {
2325
isDev &&
@@ -31,7 +33,7 @@ export const createPermalinkedComponent = (
3133
});
3234
const nestingLevel = baseNestingLevel != null ? (level ?? 0) + baseNestingLevel : undefined;
3335
return (
34-
<Permalink nestingLevel={nestingLevel} additionalProps={{ ...props, sidebarType }}>
36+
<Permalink nestingLevel={nestingLevel} additionalProps={{ ...props, sidebarType }} id={id}>
3537
<BaseComponent>{cleanChildren}</BaseComponent>
3638
</Permalink>
3739
);

docs/common/headingManager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type AdditionalProps = {
4141
sidebarDepth?: number;
4242
sidebarType?: HeadingType;
4343
tags?: string[];
44+
style?: React.CSSProperties;
4445
};
4546

4647
type Metadata = Partial<PageMetadata> & { headings: (RemarkHeading & { _processed?: boolean })[] };

docs/common/translate-markdown.tsx

-34
This file was deleted.

docs/components/Permalink.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LinkBase } from '~/ui/components/Text';
1111
type BaseProps = React.PropsWithChildren<{
1212
component: any;
1313
className?: string;
14+
style?: React.CSSProperties;
1415
}>;
1516

1617
type EnhancedProps = React.PropsWithChildren<{
@@ -89,7 +90,10 @@ const Permalink: React.FC<EnhancedProps> = withHeadingManager(
8990
const permalinkKey = props.id ?? heading?.slug;
9091

9192
return (
92-
<PermalinkBase component={component} data-components-heading>
93+
<PermalinkBase
94+
component={component}
95+
data-components-heading
96+
style={props.additionalProps?.style}>
9397
<LinkBase css={STYLES_PERMALINK_LINK} href={'#' + permalinkKey} ref={heading?.ref}>
9498
<span css={STYLES_PERMALINK_TARGET} id={permalinkKey} />
9599
<span css={STYLED_PERMALINK_CONTENT}>{children}</span>

docs/components/base/code.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ export class Code extends React.Component<React.PropsWithChildren<Props>> {
203203
render() {
204204
// note(simek): MDX dropped `inlineCode` pseudo-tag, and we need to relay on `pre` and `code` now,
205205
// which results in this nesting mess, we should fix it in the future
206-
const child = this.props.className
207-
? this
208-
: (React.Children.toArray(this.props.children)[0] as JSX.Element);
206+
const child =
207+
this.props.className && this.props.className.startsWith('language')
208+
? this
209+
: (React.Children.toArray(this.props.children)[0] as JSX.Element);
209210

210211
const value = this.parseValue(child?.props?.children?.toString() || '');
211212
let html = value.value;

docs/components/base/link.tsx

-48
This file was deleted.

docs/components/base/paragraph.tsx

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/react';
2-
import { typography, spacing, breakpoints } from '@expo/styleguide';
2+
import { typography, spacing } from '@expo/styleguide';
33
import { PropsWithChildren } from 'react';
44

55
import { paragraph } from './typography';
@@ -28,36 +28,3 @@ const STYLES_BOLD_PARAGRAPH = css`
2828
export const B = ({ children }: PropsWithChildren<object>) => (
2929
<strong css={STYLES_BOLD_PARAGRAPH}>{children}</strong>
3030
);
31-
32-
const STYLES_PARAGRAPH_DIV = css`
33-
${STYLES_PARAGRAPH}
34-
display: block;
35-
36-
&.is-wider {
37-
max-width: 1200px;
38-
}
39-
40-
@media screen and (max-width: ${breakpoints.medium + 124}px) {
41-
&.is-wider {
42-
max-width: 100%;
43-
width: 100%;
44-
}
45-
}
46-
`;
47-
48-
export const PDIV = ({ children }: PropsWithChildren<object>) => {
49-
const isWider = (children as JSX.Element)?.props?.snackId;
50-
return (
51-
<div {...getAttributes()} css={STYLES_PARAGRAPH_DIV} className={isWider ? 'is-wider' : ''}>
52-
{children}
53-
</div>
54-
);
55-
};
56-
57-
export const PDIVHEADER = ({ children }: PropsWithChildren<object>) => {
58-
return (
59-
<div {...getAttributes(true)} css={STYLES_PARAGRAPH_DIV}>
60-
{children}
61-
</div>
62-
);
63-
};

docs/components/plugins/APISection.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import React from 'react';
2-
31
import { P } from '~/components/base/paragraph';
42
import { ClassDefinitionData, GeneratedData } from '~/components/plugins/api/APIDataTypes';
53
import APISectionClasses from '~/components/plugins/api/APISectionClasses';

docs/components/plugins/AppConfigSchemaPropertiesTable.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { css } from '@emotion/react';
22
import { borderRadius, breakpoints, spacing, theme, typography } from '@expo/styleguide';
33
import ReactMarkdown from 'react-markdown';
44

5-
import { InlineCode } from '../base/code';
6-
75
import { createPermalinkedComponent } from '~/common/create-permalinked-component';
86
import { HeadingType } from '~/common/headingManager';
9-
import { PDIVHEADER } from '~/components/base/paragraph';
107
import { APIBox } from '~/components/plugins/APIBox';
118
import { mdComponents, mdInlineComponents } from '~/components/plugins/api/APISectionUtils';
129
import { Collapsible } from '~/ui/components/Collapsible';
13-
import { CALLOUT } from '~/ui/components/Text';
10+
import { P, CALLOUT, CODE } from '~/ui/components/Text';
1411

1512
type PropertyMeta = {
1613
regexHuman?: string;
@@ -53,17 +50,19 @@ type AppConfigSchemaProps = {
5350
schema: Record<string, Property>;
5451
};
5552

56-
const Anchor = createPermalinkedComponent(PDIVHEADER, {
53+
const Anchor = createPermalinkedComponent(P, {
5754
baseNestingLevel: 3,
5855
sidebarType: HeadingType.InlineCode,
5956
});
6057

6158
const PropertyName = ({ name, nestingLevel }: { name: string; nestingLevel: number }) => (
62-
<Anchor level={nestingLevel} data-testid={name} data-heading="true">
63-
<InlineCode css={typography.fontSizes[16]}>{name}</InlineCode>
59+
<Anchor level={nestingLevel} data-testid={name} data-heading="true" css={propertyNameStyle}>
60+
<CODE css={typography.fontSizes[16]}>{name}</CODE>
6461
</Anchor>
6562
);
6663

64+
const propertyNameStyle = css({ marginBottom: spacing[4] });
65+
6766
export function formatSchema(rawSchema: [string, Property][]) {
6867
const formattedSchema: FormattedProperty[] = [];
6968

@@ -140,15 +139,15 @@ const AppConfigSchemaPropertiesTable = ({ schema }: AppConfigSchemaProps) => {
140139
const formattedSchema = formatSchema(rawSchema);
141140

142141
return (
143-
<div>
142+
<>
144143
{formattedSchema.map((formattedProperty, index) => (
145144
<AppConfigProperty
146145
{...formattedProperty}
147146
key={`${formattedProperty.name}-${index}`}
148147
nestingLevel={0}
149148
/>
150149
))}
151-
</div>
150+
</>
152151
);
153152
};
154153

@@ -166,7 +165,7 @@ const AppConfigProperty = ({
166165
<APIBox css={boxStyle}>
167166
<PropertyName name={name} nestingLevel={nestingLevel} />
168167
<CALLOUT theme="secondary" data-text="true">
169-
Type: <InlineCode>{type || 'undefined'}</InlineCode>
168+
Type: <CODE>{type || 'undefined'}</CODE>
170169
{nestingLevel > 0 && (
171170
<>
172171
&emsp;&bull;&emsp;Path:{' '}

docs/components/plugins/ConfigSection/ConfigClassic.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import React, { PropsWithChildren, useEffect } from 'react';
1+
import { PropsWithChildren, useEffect } from 'react';
22

3-
import { InlineCode } from '~/components/base/code';
43
import { Collapsible } from '~/ui/components/Collapsible';
4+
import { CODE } from '~/ui/components/Text';
55

66
type Props = PropsWithChildren<object>;
77

88
export const ConfigClassic = ({ children }: Props) => {
99
useEffect(() => {
1010
if (typeof children === 'string') {
1111
throw new Error(
12-
`Content inside 'ConfigClassic' needs to be surrounded by new lines to be parsed as markdown.\n\nMake sure there is a blank new line before and after this content: '${children}'`
12+
`Content inside 'ConfigClassic' needs to be surrounded by new lines to be parsed as markdown.\n\n` +
13+
`Make sure there is a blank new line before and after this content: '${children}'`
1314
);
1415
}
1516
}, [children]);
@@ -18,8 +19,7 @@ export const ConfigClassic = ({ children }: Props) => {
1819
<Collapsible
1920
summary={
2021
<span>
21-
Are you using the classic build system? (<InlineCode>expo build:[android|ios]</InlineCode>
22-
)
22+
Are you using the classic build system? (<CODE>expo build:[android|ios]</CODE>)
2323
</span>
2424
}>
2525
{children}

docs/components/plugins/ConfigSection/ConfigPluginProperties.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, { PropsWithChildren } from 'react';
22

3-
import { InlineCode } from '~/components/base/code';
4-
import { P } from '~/components/base/paragraph';
53
import { H3 } from '~/components/plugins/Headings';
64
import { APISectionPlatformTags } from '~/components/plugins/api/APISectionPlatformTags';
75
import { Cell, HeaderCell, Row, Table, TableHead } from '~/ui/components/Table';
6+
import { P, CODE } from '~/ui/components/Text';
87

98
type Props = PropsWithChildren<{
109
properties: PluginProperty[];
@@ -26,9 +25,9 @@ export const ConfigPluginProperties = ({ children, properties }: Props) => (
2625
{properties.map(property => (
2726
<Row key={property.name}>
2827
<Cell fitContent>
29-
<InlineCode>{property.name}</InlineCode>
28+
<CODE>{property.name}</CODE>
3029
</Cell>
31-
<Cell>{!property.default ? '-' : <InlineCode>{property.default}</InlineCode>}</Cell>
30+
<Cell>{!property.default ? '-' : <CODE>{property.default}</CODE>}</Cell>
3231
<Cell>
3332
{!!property.platform && (
3433
<APISectionPlatformTags

0 commit comments

Comments
 (0)