Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 12dab35

Browse files
feat: add to link api call names in description - generalise
1 parent f3d1a96 commit 12dab35

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
@use 'src/styles/utility' as *;
22

33
.schemaRole {
4-
background-color: rgba(255, 255, 255, 0.16);
5-
border: none;
6-
font-size: rem(1.4);
7-
font-weight: 400;
8-
line-height: rem(2.4);
9-
color: var(--ifm-color-white);
10-
height: fit-content;
11-
padding: rem(0.5) rem(0.5);
12-
margin: 0 rem(0.5);
4+
background-color: rgba(255, 255, 255, 0.16);
5+
border: none;
6+
font-size: rem(1.4);
7+
font-weight: 400;
8+
line-height: rem(2.4);
9+
color: var(--ifm-color-white);
10+
height: fit-content;
11+
padding: rem(0.5) rem(0.5);
12+
margin: 0 rem(0.5);
1313
}
14-
14+
1515
.schemaCode {
16-
color: var(--ifm-color-white);
17-
font-size: rem(1.4);
16+
color: var(--ifm-color-white);
17+
font-size: rem(1.4);
18+
}
19+
20+
.schemaLink {
21+
cursor: pointer;
22+
text-decoration: underline;
1823
}

src/features/Apiexplorer/Schema/HighlightCode/index.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
import React from 'react';
22
import clsx from 'clsx';
33
import styles from './HighlightCode.module.scss';
4+
import { playground_requests } from '@site/src/utils/playground_requests';
45
import { SchemaDescriptionTypes } from '../RecursiveContent/SchemaDescription';
6+
import { useHistory, useLocation } from '@docusaurus/router';
57

68
export const HighlightCode = ({ description }: SchemaDescriptionTypes) => {
9+
const { pathname } = useLocation();
10+
const history = useHistory();
11+
712
if (!description) return null;
813

914
const [first, code, ...rest] = description.split('`');
15+
16+
const api_call_object = playground_requests.find((el) => el.name === code);
17+
const link_api_call = (obj) => {
18+
window.scrollTo(0, 0);
19+
history.push(`${pathname}#${obj?.name}`);
20+
};
21+
1022
return (
1123
<React.Fragment>
1224
{first}
13-
{code && <span className={clsx(styles.schemaRole, styles.schemaCode)}>{code}</span>}
25+
{code && (
26+
<span className={clsx(styles.schemaRole, styles.schemaCode)}>
27+
{api_call_object ? (
28+
<button onClick={() => link_api_call(api_call_object)} className={styles.schemaLink}>
29+
{code}
30+
</button>
31+
) : (
32+
code
33+
)}
34+
</span>
35+
)}
1436
{rest.length > 0 && <HighlightCode description={rest.join('`')} />}
1537
</React.Fragment>
1638
);

0 commit comments

Comments
 (0)