Browse Source

Improve links

Use Next.js router links instead of the ordinary `<a>` tags.
tags/0.3.0
TheoryOfNekomata 3 years ago
parent
commit
8310ded3d7
4 changed files with 44 additions and 4 deletions
  1. +4
    -0
      packages/react-common-docs/src/components/Nav/Nav.tsx
  2. +12
    -2
      packages/react-common-docs/src/components/Props/Props.tsx
  3. +2
    -2
      packages/react-common-docs/src/components/Sidebar/Sidebar.tsx
  4. +26
    -0
      packages/react-common-docs/src/pages/_app.tsx

+ 4
- 0
packages/react-common-docs/src/components/Nav/Nav.tsx View File

@@ -42,6 +42,7 @@ const Nav: React.FC<Props> = ({
{ {
(data as (string | object | null | undefined)[]).map(d => ( (data as (string | object | null | undefined)[]).map(d => (
<Nav <Nav
key={JSON.stringify(d)}
data={d} data={d}
/> />
)) ))
@@ -61,6 +62,7 @@ const Nav: React.FC<Props> = ({
{ {
(value as (string | object | null | undefined)[]).map(v => ( (value as (string | object | null | undefined)[]).map(v => (
<Nav <Nav
key={JSON.stringify(v)}
data={v} data={v}
/> />
)) ))
@@ -76,6 +78,7 @@ const Nav: React.FC<Props> = ({
{ {
// @ts-ignore // @ts-ignore
<NavLink <NavLink
href={value as string}
title={key} title={key}
enclosingComponent={Container} enclosingComponent={Container}
/> />
@@ -91,6 +94,7 @@ const Nav: React.FC<Props> = ({
{ {
// @ts-ignore // @ts-ignore
<NavLink <NavLink
href={data as string}
title={data as string} title={data as string}
enclosingComponent={Container} enclosingComponent={Container}
/> />


+ 12
- 2
packages/react-common-docs/src/components/Props/Props.tsx View File

@@ -195,7 +195,9 @@ const getPropTypeHtml = propType => {
let currentToken let currentToken
if (t.trim().startsWith('"') && t.trim().endsWith('"')) { if (t.trim().startsWith('"') && t.trim().endsWith('"')) {
currentToken = ( currentToken = (
<React.Fragment>
<React.Fragment
key={t}
>
<span <span
style={punctuation.style} style={punctuation.style}
> >
@@ -216,6 +218,7 @@ const getPropTypeHtml = propType => {
} else if ('any string boolean number symbol unknown object bigint'.split(' ').includes(t)) { } else if ('any string boolean number symbol unknown object bigint'.split(' ').includes(t)) {
currentToken = ( currentToken = (
<span <span
key={t}
style={keyword.style} style={keyword.style}
> >
{t} {t}
@@ -224,6 +227,7 @@ const getPropTypeHtml = propType => {
} else if ('null'.split(' ').includes(t)) { } else if ('null'.split(' ').includes(t)) {
currentToken = ( currentToken = (
<span <span
key={t}
style={keyword.style} style={keyword.style}
> >
{t} {t}
@@ -232,6 +236,7 @@ const getPropTypeHtml = propType => {
} else if ('true false'.split(' ').includes(t)) { } else if ('true false'.split(' ').includes(t)) {
currentToken = ( currentToken = (
<span <span
key={t}
style={boolean.style} style={boolean.style}
> >
{t} {t}
@@ -240,6 +245,7 @@ const getPropTypeHtml = propType => {
} else if (!isNaN(Number(t))) { } else if (!isNaN(Number(t))) {
currentToken = ( currentToken = (
<span <span
key={t}
style={number.style} style={number.style}
> >
{t} {t}
@@ -248,6 +254,7 @@ const getPropTypeHtml = propType => {
} else { } else {
currentToken = ( currentToken = (
<span <span
key={t}
style={type.style} style={type.style}
> >
{t} {t}
@@ -257,6 +264,7 @@ const getPropTypeHtml = propType => {
return [ return [
...tt, ...tt,
i > 0 && <span i > 0 && <span
key={`**separator:${t}**`}
style={operator.style} style={operator.style}
> >
| |
@@ -314,7 +322,9 @@ const Props: React.FC<Props> = ({ of: ofAttr }) => {
) )
: undefined : undefined
return ( return (
<HeaderRow>
<HeaderRow
key={name}
>
<MainBodyCell> <MainBodyCell>
<Code> <Code>
{getPropNameHtml(propName, propType)} {getPropNameHtml(propName, propType)}


+ 2
- 2
packages/react-common-docs/src/components/Sidebar/Sidebar.tsx View File

@@ -98,7 +98,7 @@ const RepoLink = styled('a')({


const propTypes = { const propTypes = {
data: PropTypes.shape({ data: PropTypes.shape({
nav: PropTypes.object,
nav: PropTypes.array,
}), }),
brand: PropTypes.elementType, brand: PropTypes.elementType,
initialTheme: PropTypes.string, initialTheme: PropTypes.string,
@@ -187,7 +187,7 @@ const Sidebar: React.FC<Props> = ({
<RepoLink <RepoLink
href={pkg.repository} href={pkg.repository}
target="_blank" target="_blank"
rel="noopener noreferer"
rel="noopener noreferrer"
> >
<Icon <Icon
name="code" name="code"


+ 26
- 0
packages/react-common-docs/src/pages/_app.tsx View File

@@ -1,4 +1,5 @@
import * as React from 'react' import * as React from 'react'
import Link from 'next/link'
import { MDXProvider } from '@mdx-js/react' import { MDXProvider } from '@mdx-js/react'
import Head from 'next/head' import Head from 'next/head'
import styled from 'styled-components' import styled from 'styled-components'
@@ -42,6 +43,31 @@ const App: React.FC<AppProps> = ({
<Container> <Container>
<MDXProvider <MDXProvider
components={{ components={{
a: ({ href, children, ...etcProps }) => {
if (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//')) {
return (
<a
{...etcProps}
href={href}
target="_blank"
rel="noreferrer noopener"
>
{children}
</a>
)
}
return (
<Link
href={href}
passHref
{...etcProps}
>
<a>
{children}
</a>
</Link>
)
},
pre: CodeBlock, pre: CodeBlock,
}} }}
> >


Loading…
Cancel
Save