-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create discord-api-types documentation component (#9555)
feat: add discord-api-types link component Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0c175c0
commit 7b617bd
Showing
5 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { FiExternalLink } from '@react-icons/all-files/fi/FiExternalLink'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { | ||
BASE_URL_DISCORD_API_TYPES, | ||
DISCORD_API_TYPES_VERSION, | ||
DISCORD_API_TYPES_VOICE_VERSION, | ||
} from '~/util/constants'; | ||
|
||
interface DiscordAPITypesLinkOptions { | ||
/** | ||
* The initial documentation enum, interface, function etc. | ||
* | ||
* @example `'RESTJSONErrorCodes'` | ||
*/ | ||
parent?: string; | ||
/** | ||
* The scope of where this link lives. | ||
* | ||
* @remarks API does not have a scope. | ||
*/ | ||
scope?: 'gateway' | 'globals' | 'payloads' | 'rest' | 'rpc' | 'utils' | 'voice'; | ||
/** | ||
* The symbol belonging to the parent. | ||
* | ||
* @example '`MaximumNumberOfGuildsReached'` | ||
*/ | ||
symbol?: string; | ||
/** | ||
* The type of the {@link DiscordAPITypesLinkOptions.parent}. | ||
* | ||
* @example `'enum'` | ||
* @example `'interface'` | ||
*/ | ||
type?: string; | ||
} | ||
|
||
export function DiscordAPITypesLink({ | ||
parent, | ||
scope, | ||
symbol, | ||
type, | ||
children, | ||
}: PropsWithChildren<DiscordAPITypesLinkOptions>) { | ||
let url = BASE_URL_DISCORD_API_TYPES; | ||
let text = 'discord-api-types'; | ||
|
||
if (type || parent) { | ||
url += `/api/discord-api-types`; | ||
|
||
switch (scope) { | ||
case 'globals': | ||
url += `-${scope}`; | ||
break; | ||
case 'gateway': | ||
case 'payloads': | ||
case 'rest': | ||
url += `-${scope}/common`; | ||
break; | ||
case 'rpc': | ||
case 'utils': | ||
url += `-${scope}/${DISCORD_API_TYPES_VERSION}`; | ||
break; | ||
case 'voice': | ||
url += `-${scope}/${DISCORD_API_TYPES_VOICE_VERSION}`; | ||
break; | ||
default: | ||
url += `-${DISCORD_API_TYPES_VERSION}`; | ||
} | ||
|
||
if (type) { | ||
url += `/${type}/${parent}`; | ||
if (symbol) url += `#${symbol}`; | ||
} else { | ||
url += `#${parent}`; | ||
} | ||
|
||
text = `${parent}${symbol ? `#${symbol}` : ''}${type?.toUpperCase() === 'FUNCTION' ? '()' : ''}`; | ||
} | ||
|
||
return ( | ||
<a | ||
className="inline-flex flex-row place-items-center gap-1" | ||
href={url} | ||
rel="external noopener noreferrer" | ||
target="_blank" | ||
> | ||
{children ?? text} | ||
<FiExternalLink size={18} /> | ||
</a> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7b617bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
discord-js-guide – ./apps/guide
discord-js-guide-git-main-discordjs.vercel.app
discord-js-guide.vercel.app
guide.discordjs.dev
next.discordjs.guide
discord-js-guide-discordjs.vercel.app