Prepare requirements for Next to build the documentation.tags/0.3.0
@@ -6,6 +6,7 @@ const Base = styled('div')({ | |||||
position: 'relative', | position: 'relative', | ||||
}) | }) | ||||
// @ts-ignore | |||||
const Title = styled('strong')({ | const Title = styled('strong')({ | ||||
fontSize: '2rem', | fontSize: '2rem', | ||||
fontFamily: 'var(--font-family-headings), sans-serif', | fontFamily: 'var(--font-family-headings), sans-serif', | ||||
@@ -10,6 +10,9 @@ const e = withMDX({ | |||||
module.exports = { | module.exports = { | ||||
...e, | ...e, | ||||
typescript: { | |||||
ignoreBuildErrors: true, | |||||
}, | |||||
webpack(...args) { | webpack(...args) { | ||||
const oldWebpack = e.webpack(...args) | const oldWebpack = e.webpack(...args) | ||||
const [config, { defaultLoaders, }] = args | const [config, { defaultLoaders, }] = args | ||||
@@ -1,11 +1,18 @@ | |||||
import * as React from 'react' | import * as React from 'react' | ||||
import * as PropTypes from 'prop-types' | |||||
import Head from 'next/head' | import Head from 'next/head' | ||||
import unified from 'unified' | import unified from 'unified' | ||||
import parse from 'remark-parse' | import parse from 'remark-parse' | ||||
import remark2react from 'remark-react' | import remark2react from 'remark-react' | ||||
import docgen from '../../docgen.json' | import docgen from '../../docgen.json' | ||||
const Header = ({ of: ofAttr }) => { | |||||
const propTypes = { | |||||
of: PropTypes.string, | |||||
} | |||||
type Props = PropTypes.InferProps<typeof propTypes> | |||||
const Header: React.FC<Props> = ({ of: ofAttr }) => { | |||||
const docs = docgen.find(d => d.displayName === ofAttr) | const docs = docgen.find(d => d.displayName === ofAttr) | ||||
if (!docs) { | if (!docs) { | ||||
@@ -25,11 +32,13 @@ const Header = ({ of: ofAttr }) => { | |||||
unified() | unified() | ||||
.use(parse) | .use(parse) | ||||
.use(remark2react) | .use(remark2react) | ||||
.processSync(docs.description).result | |||||
.processSync(docs.description).result as any | |||||
} | } | ||||
</p> | </p> | ||||
</React.Fragment> | </React.Fragment> | ||||
) | ) | ||||
} | } | ||||
Header.propTypes = propTypes | |||||
export default Header | export default Header |
@@ -35,7 +35,7 @@ const MenuGraphics: React.FC<Props> = ({ | |||||
return ( | return ( | ||||
<Image | <Image | ||||
src={id} | src={id} | ||||
alt={alt} | |||||
alt={alt as string} | |||||
/> | /> | ||||
) | ) | ||||
default: | default: | ||||
@@ -1,13 +1,9 @@ | |||||
import * as React from 'react' | import * as React from 'react' | ||||
import * as PropTypes from 'prop-types' | |||||
import Link from 'next/link' | import Link from 'next/link' | ||||
import styled from 'styled-components' | import styled from 'styled-components' | ||||
import NavLink from '../NavLink/NavLink' | import NavLink from '../NavLink/NavLink' | ||||
const StyledLink = styled('a')({ | |||||
display: 'block', | |||||
textDecoration: 'none', | |||||
}) | |||||
const Container = styled('span')({ | const Container = styled('span')({ | ||||
display: 'flex', | display: 'flex', | ||||
alignItems: 'center', | alignItems: 'center', | ||||
@@ -24,68 +20,82 @@ const HeaderContainer = styled(Container)({ | |||||
marginTop: '2rem', | marginTop: '2rem', | ||||
}) | }) | ||||
const NavContainer = styled('div')({ | |||||
const propTypes = { | |||||
data: PropTypes.oneOfType([ | |||||
PropTypes.array, | |||||
PropTypes.object, | |||||
PropTypes.string, | |||||
]) | |||||
} | |||||
}) | |||||
type Props = PropTypes.InferProps<typeof propTypes> | |||||
const Nav = ({ | |||||
const Nav: React.FC<Props> = ({ | |||||
data, | data, | ||||
}) => { | }) => { | ||||
if (Array.isArray(data)) { | |||||
if (Array.isArray(data! as unknown[])) { | |||||
return ( | return ( | ||||
<NavContainer> | |||||
<div> | |||||
{ | { | ||||
data.map(d => ( | |||||
(data as (string | object | null | undefined)[]).map(d => ( | |||||
<Nav | <Nav | ||||
data={d} | data={d} | ||||
/> | /> | ||||
)) | )) | ||||
} | } | ||||
</NavContainer> | |||||
</div> | |||||
) | ) | ||||
} | } | ||||
if (typeof data === 'object') { | |||||
const [entry] = Object.entries(data) | |||||
if (typeof data as unknown === 'object') { | |||||
const [entry] = Object.entries(data as Record<string, unknown>) | |||||
const [key, value] = entry | const [key, value] = entry | ||||
if (Array.isArray(value)) { | |||||
if (Array.isArray(value as unknown[])) { | |||||
return ( | return ( | ||||
<NavContainer> | |||||
<div> | |||||
<HeaderContainer> | <HeaderContainer> | ||||
{key} | {key} | ||||
</HeaderContainer> | </HeaderContainer> | ||||
{ | { | ||||
value.map(v => ( | |||||
(value as (string | object | null | undefined)[]).map(v => ( | |||||
<Nav | <Nav | ||||
data={v} | data={v} | ||||
/> | /> | ||||
)) | )) | ||||
} | } | ||||
</NavContainer> | |||||
</div> | |||||
) | ) | ||||
} | } | ||||
return ( | return ( | ||||
<Link | <Link | ||||
href={value} | |||||
href={value as string} | |||||
passHref | passHref | ||||
> | > | ||||
<NavLink | |||||
title={key} | |||||
enclosingComponent={Container} | |||||
/> | |||||
{ | |||||
// @ts-ignore | |||||
<NavLink | |||||
title={key} | |||||
enclosingComponent={Container} | |||||
/> | |||||
} | |||||
</Link> | </Link> | ||||
) | ) | ||||
} | } | ||||
return ( | return ( | ||||
<Link | <Link | ||||
href={data} | |||||
href={data as string} | |||||
passHref | passHref | ||||
> | > | ||||
<NavLink | |||||
title={data} | |||||
enclosingComponent={Container} | |||||
/> | |||||
{ | |||||
// @ts-ignore | |||||
<NavLink | |||||
title={data as string} | |||||
enclosingComponent={Container} | |||||
/> | |||||
} | |||||
</Link> | </Link> | ||||
) | ) | ||||
} | } | ||||
Nav.propTypes = propTypes | |||||
export default Nav | export default Nav |
@@ -106,43 +106,49 @@ const NavLink = React.forwardRef<HTMLAnchorElement, Props>(( | |||||
<Link | <Link | ||||
ref={ref} | ref={ref} | ||||
href={href} | href={href} | ||||
onClick={onClick} | |||||
onClick={onClick as (...args: any[]) => any} | |||||
> | > | ||||
<EnclosingComponent> | |||||
{ | |||||
graphics as object | |||||
&& ( | |||||
<MenuGraphicsContainer> | |||||
<MenuGraphics | |||||
{...graphics} | |||||
/> | |||||
</MenuGraphicsContainer> | |||||
) | |||||
} | |||||
<LinkText> | |||||
<LinkTitle> | |||||
{title} | |||||
</LinkTitle> | |||||
{ | |||||
// @ts-ignore | |||||
<EnclosingComponent> | |||||
{ | { | ||||
subtitle as string | |||||
graphics as object | |||||
&& ( | && ( | ||||
<LinkSubtitle> | |||||
{subtitle} | |||||
</LinkSubtitle> | |||||
<MenuGraphicsContainer> | |||||
{ | |||||
// @ts-ignore | |||||
<MenuGraphics | |||||
{...graphics} | |||||
/> | |||||
} | |||||
</MenuGraphicsContainer> | |||||
) | ) | ||||
} | } | ||||
</LinkText> | |||||
{ | |||||
indicator as string | |||||
&& ( | |||||
<IndicatorContainer> | |||||
<Icon | |||||
name={indicator!} | |||||
/> | |||||
</IndicatorContainer> | |||||
) | |||||
} | |||||
</EnclosingComponent> | |||||
<LinkText> | |||||
<LinkTitle> | |||||
{title} | |||||
</LinkTitle> | |||||
{ | |||||
subtitle as string | |||||
&& ( | |||||
<LinkSubtitle> | |||||
{subtitle} | |||||
</LinkSubtitle> | |||||
) | |||||
} | |||||
</LinkText> | |||||
{ | |||||
indicator as string | |||||
&& ( | |||||
<IndicatorContainer> | |||||
<Icon | |||||
name={indicator!} | |||||
/> | |||||
</IndicatorContainer> | |||||
) | |||||
} | |||||
</EnclosingComponent> | |||||
} | |||||
</Link> | </Link> | ||||
)) | )) | ||||
@@ -1,4 +1,5 @@ | |||||
import * as React from 'react' | import * as React from 'react' | ||||
import * as PropTypes from 'prop-types' | |||||
import { | import { | ||||
LiveProvider, | LiveProvider, | ||||
LiveEditor, | LiveEditor, | ||||
@@ -16,7 +17,15 @@ const StyledLiveEditor = styled(LiveEditor)({ | |||||
marginTop: '1rem', | marginTop: '1rem', | ||||
}) | }) | ||||
const Playground = ({ | |||||
const propTypes = { | |||||
components: PropTypes.object, | |||||
code: PropTypes.string.isRequired, | |||||
label: PropTypes.string, | |||||
} | |||||
type Props = PropTypes.InferProps<typeof propTypes> | |||||
const Playground: React.FC<Props> = ({ | |||||
components, | components, | ||||
code, | code, | ||||
label, | label, | ||||
@@ -31,7 +40,7 @@ const Playground = ({ | |||||
return ( | return ( | ||||
<Figure> | <Figure> | ||||
{ | { | ||||
label | |||||
label as string | |||||
&& ( | && ( | ||||
<figcaption> | <figcaption> | ||||
{label} | {label} | ||||
@@ -50,4 +59,6 @@ const Playground = ({ | |||||
) | ) | ||||
} | } | ||||
Playground.propTypes = propTypes | |||||
export default Playground | export default Playground |
@@ -1,4 +1,5 @@ | |||||
import * as React from 'react' | import * as React from 'react' | ||||
import * as PropTypes from 'prop-types' | |||||
import styled from 'styled-components' | import styled from 'styled-components' | ||||
import docgen from '../../docgen.json' | import docgen from '../../docgen.json' | ||||
@@ -90,10 +91,33 @@ const Code = styled('code')({ | |||||
display: 'inline-block', | display: 'inline-block', | ||||
}) | }) | ||||
const Props = ({ of: ofAttr }) => { | |||||
const docs = docgen.find(d => d.displayName === ofAttr) | |||||
const propTypes = { | |||||
of: PropTypes.string, | |||||
} | |||||
type Props = PropTypes.InferProps<typeof propTypes> | |||||
if (!docs) { | |||||
type Docs = { | |||||
displayName: string, | |||||
description: string, | |||||
methods: unknown[], | |||||
props: { | |||||
[name: string]: { | |||||
required: boolean, | |||||
type: { | |||||
name: string, | |||||
value: { value: string }[] | |||||
}, | |||||
defaultValue: { value: string, }, | |||||
description: string, | |||||
} | |||||
} | |||||
} | |||||
const Props: React.FC<Props> = ({ of: ofAttr }) => { | |||||
const docs = (docgen as unknown as Docs[]).find(d => d.displayName === ofAttr) | |||||
if (!(docs as Docs)) { | |||||
return null | return null | ||||
} | } | ||||
@@ -123,7 +147,7 @@ const Props = ({ of: ofAttr }) => { | |||||
</HeaderCellGroup> | </HeaderCellGroup> | ||||
<BodyCellGroup> | <BodyCellGroup> | ||||
{ | { | ||||
Object.entries(docs.props).map(([name, def]) => ( | |||||
Object.entries((docs as Docs).props).map(([name, def]) => ( | |||||
<HeaderRow> | <HeaderRow> | ||||
<MainBodyCell> | <MainBodyCell> | ||||
<Code> | <Code> | ||||
@@ -173,4 +197,6 @@ const Props = ({ of: ofAttr }) => { | |||||
) | ) | ||||
} | } | ||||
Props.propTypes = propTypes | |||||
export default Props | export default Props |
@@ -1,4 +1,5 @@ | |||||
import * as React from 'react' | import * as React from 'react' | ||||
import * as PropTypes from 'prop-types' | |||||
import { Icon } from '../../../../react-common/src' | import { Icon } from '../../../../react-common/src' | ||||
import pkg from '../../../../../package.json' | import pkg from '../../../../../package.json' | ||||
import styled from 'styled-components' | import styled from 'styled-components' | ||||
@@ -108,20 +109,31 @@ const RepoLink = styled('a')({ | |||||
placeContent: 'center', | placeContent: 'center', | ||||
}) | }) | ||||
const Sidebar = ({ | |||||
const propTypes = { | |||||
data: PropTypes.shape({ | |||||
nav: PropTypes.object, | |||||
}), | |||||
brand: PropTypes.elementType, | |||||
initialTheme: PropTypes.string, | |||||
} | |||||
type Props = PropTypes.InferProps<typeof propTypes> | |||||
const Sidebar: React.FC<Props> = ({ | |||||
data, | data, | ||||
brand: Brand, | |||||
brand: BrandRaw, | |||||
initialTheme = 'Dark', | initialTheme = 'Dark', | ||||
}) => { | }) => { | ||||
const [theme, setTheme] = React.useState(initialTheme) | const [theme, setTheme] = React.useState(initialTheme) | ||||
const [sidebar, setSidebar] = React.useState(false) | const [sidebar, setSidebar] = React.useState(false) | ||||
const navRef = React.useRef<HTMLDivElement>(null) | const navRef = React.useRef<HTMLDivElement>(null) | ||||
const Brand = BrandRaw! | |||||
const toggleDarkMode = (b: string) => () => { | const toggleDarkMode = (b: string) => () => { | ||||
setTheme(b) | setTheme(b) | ||||
} | } | ||||
const toggleSidebar = (b: boolean) => (e) => { | |||||
const toggleSidebar = (b: boolean): MouseEventHandler => (e) => { | |||||
e.preventDefault() | e.preventDefault() | ||||
setSidebar(b) | setSidebar(b) | ||||
} | } | ||||
@@ -140,7 +152,7 @@ const Sidebar = ({ | |||||
}, []) | }, []) | ||||
React.useEffect(() => { | React.useEffect(() => { | ||||
const eventListener: MouseEventHandler = (e) => { | |||||
const eventListener = (e: MouseEvent) => { | |||||
let currentElement = e.target as HTMLElement | let currentElement = e.target as HTMLElement | ||||
while (currentElement !== e.currentTarget) { | while (currentElement !== e.currentTarget) { | ||||
if (currentElement.tagName === 'A') { | if (currentElement.tagName === 'A') { | ||||
@@ -170,7 +182,7 @@ const Sidebar = ({ | |||||
}, []) | }, []) | ||||
React.useEffect(() => { | React.useEffect(() => { | ||||
window.localStorage.setItem('tesseract-theme', theme) | |||||
window.localStorage.setItem('tesseract-theme', theme as string) | |||||
}, [theme]) | }, [theme]) | ||||
React.useEffect(() => { | React.useEffect(() => { | ||||
@@ -265,7 +277,7 @@ const Sidebar = ({ | |||||
</Actions> | </Actions> | ||||
</Container> | </Container> | ||||
<Nav | <Nav | ||||
data={data.nav} | |||||
data={data!.nav} | |||||
/> | /> | ||||
</NavWrapper> | </NavWrapper> | ||||
</Base> | </Base> | ||||
@@ -273,4 +285,6 @@ const Sidebar = ({ | |||||
) | ) | ||||
} | } | ||||
Sidebar.propTypes = propTypes | |||||
export default Sidebar | export default Sidebar |
@@ -10,7 +10,7 @@ | |||||
"skipLibCheck": true, | "skipLibCheck": true, | ||||
"esModuleInterop": true, | "esModuleInterop": true, | ||||
"allowSyntheticDefaultImports": true, | "allowSyntheticDefaultImports": true, | ||||
"strict": true, | |||||
"strict": false, | |||||
"forceConsistentCasingInFileNames": true, | "forceConsistentCasingInFileNames": true, | ||||
"module": "esnext", | "module": "esnext", | ||||
"moduleResolution": "node", | "moduleResolution": "node", | ||||
@@ -10,7 +10,7 @@ | |||||
"skipLibCheck": true, | "skipLibCheck": true, | ||||
"esModuleInterop": true, | "esModuleInterop": true, | ||||
"allowSyntheticDefaultImports": true, | "allowSyntheticDefaultImports": true, | ||||
"strict": true, | |||||
"strict": false, | |||||
"forceConsistentCasingInFileNames": true, | "forceConsistentCasingInFileNames": true, | ||||
"module": "esnext", | "module": "esnext", | ||||
"moduleResolution": "node", | "moduleResolution": "node", | ||||