Skip to content

Commit 2c6d345

Browse files
committed
ref to be more extensible
1 parent 89646e8 commit 2c6d345

File tree

4 files changed

+149
-130
lines changed

4 files changed

+149
-130
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {PlatformCategory} from 'sentry-docs/types';
2+
3+
import styles from './style.module.scss';
4+
5+
import {PlatformCategorySection} from '../platformCategorySection';
6+
7+
type Props = {
8+
name: string;
9+
categorySupported?: PlatformCategory[];
10+
children?: React.ReactNode;
11+
};
12+
13+
export function SdkDefinition({name, children, categorySupported = []}: Props) {
14+
return (
15+
<PlatformCategorySection supported={categorySupported}>
16+
<div>
17+
<h3 id={name} aria-label={name} data-sdk-option>
18+
<a href={`#${name}`}>
19+
<svg
20+
className="anchorlink before"
21+
viewBox="0 0 24 24"
22+
xmlns="http://www.w3.org/2000/svg"
23+
width="16"
24+
height="16"
25+
>
26+
<path
27+
d="M9.199 13.599a5.99 5.99 0 0 0 3.949 2.345 5.987 5.987 0 0 0 5.105-1.702l2.995-2.994a5.992 5.992 0 0 0 1.695-4.285 5.976 5.976 0 0 0-1.831-4.211 5.99 5.99 0 0 0-6.431-1.242 6.003 6.003 0 0 0-1.905 1.24l-1.731 1.721a.999.999 0 1 0 1.41 1.418l1.709-1.699a3.985 3.985 0 0 1 2.761-1.123 3.975 3.975 0 0 1 2.799 1.122 3.997 3.997 0 0 1 .111 5.644l-3.005 3.006a3.982 3.982 0 0 1-3.395 1.126 3.987 3.987 0 0 1-2.632-1.563A1 1 0 0 0 9.201 13.6zm5.602-3.198a5.99 5.99 0 0 0-3.949-2.345 5.987 5.987 0 0 0-5.105 1.702l-2.995 2.994a5.992 5.992 0 0 0-1.695 4.285 5.976 5.976 0 0 0 1.831 4.211 5.99 5.99 0 0 0 6.431 1.242 6.003 6.003 0 0 0 1.905-1.24l1.723-1.723a.999.999 0 1 0-1.414-1.414L9.836 19.81a3.985 3.985 0 0 1-2.761 1.123 3.975 3.975 0 0 1-2.799-1.122 3.997 3.997 0 0 1-.111-5.644l3.005-3.006a3.982 3.982 0 0 1 3.395-1.126 3.987 3.987 0 0 1 2.632 1.563 1 1 0 0 0 1.602-1.198z"
28+
fill="currentColor"
29+
/>
30+
</svg>
31+
{name}
32+
</a>
33+
</h3>
34+
35+
{children}
36+
</div>
37+
</PlatformCategorySection>
38+
);
39+
}
40+
41+
export function SdkDefinitionTable({children}: {children?: React.ReactNode}) {
42+
return (
43+
<table className={styles['sdk-option-table']}>
44+
<tbody>{children}</tbody>
45+
</table>
46+
);
47+
}
48+
49+
export function SdkDefinitionTableRow({
50+
label,
51+
children,
52+
}: {
53+
label: string;
54+
children?: React.ReactNode;
55+
}) {
56+
return (
57+
<tr>
58+
<th>{label}</th>
59+
<td>
60+
<code>{children}</code>
61+
</td>
62+
</tr>
63+
);
64+
}

src/components/sdkOption.tsx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree';
2+
import {serverContext} from 'sentry-docs/serverContext';
3+
import {PlatformCategory} from 'sentry-docs/types';
4+
5+
import {PlatformCategorySection} from './platformCategorySection';
6+
import {PlatformSection} from './platformSection';
7+
import {SdkDefinition, SdkDefinitionTable, SdkDefinitionTableRow} from './sdkDefinition';
8+
9+
type Props = {
10+
name: string;
11+
type: string;
12+
categorySupported?: PlatformCategory[];
13+
children?: React.ReactNode;
14+
defaultValue?: string;
15+
envVar?: string;
16+
group?: string;
17+
};
18+
19+
export function SdkOption({
20+
name,
21+
children,
22+
type,
23+
defaultValue,
24+
envVar,
25+
categorySupported = [],
26+
}: Props) {
27+
const {showBrowserOnly, showServerLikeOnly} = getPlatformHints(categorySupported);
28+
29+
return (
30+
<SdkDefinition name={name} categorySupported={categorySupported}>
31+
<SdkDefinitionTable>
32+
{type && <SdkDefinitionTableRow label="Type">{type}</SdkDefinitionTableRow>}
33+
{defaultValue && (
34+
<SdkDefinitionTableRow label="Default">{defaultValue}</SdkDefinitionTableRow>
35+
)}
36+
37+
<PlatformCategorySection supported={['server', 'serverless']}>
38+
<PlatformSection notSupported={['javascript.nextjs']}>
39+
{envVar && (
40+
<SdkDefinitionTableRow label="ENV Variable">{envVar}</SdkDefinitionTableRow>
41+
)}
42+
</PlatformSection>
43+
</PlatformCategorySection>
44+
45+
{showBrowserOnly && (
46+
<SdkDefinitionTableRow label="Only available on">Client</SdkDefinitionTableRow>
47+
)}
48+
49+
{showServerLikeOnly && (
50+
<SdkDefinitionTableRow label="Only available on">Server</SdkDefinitionTableRow>
51+
)}
52+
</SdkDefinitionTable>
53+
54+
{children}
55+
</SdkDefinition>
56+
);
57+
}
58+
59+
function getPlatformHints(categorySupported: PlatformCategory[]) {
60+
const {rootNode, path} = serverContext();
61+
const currentPlatformOrGuide = getCurrentPlatformOrGuide(rootNode, path);
62+
const currentCategories = currentPlatformOrGuide?.categories || [];
63+
64+
// We only handle browser, server & serverless here for now
65+
const currentIsBrowser = currentCategories.includes('browser');
66+
const currentIsServer = currentCategories.includes('server');
67+
const currentIsServerless = currentCategories.includes('serverless');
68+
const currentIsServerLike = currentIsServer || currentIsServerless;
69+
70+
const hasCategorySupported = categorySupported.length > 0;
71+
const supportedBrowserOnly =
72+
categorySupported.includes('browser') &&
73+
!categorySupported.includes('server') &&
74+
!categorySupported.includes('serverless');
75+
const supportedServerLikeOnly =
76+
!categorySupported.includes('browser') &&
77+
(categorySupported.includes('server') || categorySupported.includes('serverless'));
78+
79+
const showBrowserOnly =
80+
hasCategorySupported && supportedBrowserOnly && currentIsServerLike;
81+
const showServerLikeOnly =
82+
hasCategorySupported && supportedServerLikeOnly && currentIsBrowser;
83+
84+
return {showBrowserOnly, showServerLikeOnly};
85+
}

src/components/sdkOption/index.tsx

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)