diff --git a/packages/react-common-docs/brand.tsx b/packages/react-common-docs/brand.tsx index 527d3d8..b45a0a1 100644 --- a/packages/react-common-docs/brand.tsx +++ b/packages/react-common-docs/brand.tsx @@ -6,6 +6,7 @@ const Base = styled('div')({ position: 'relative', }) +// @ts-ignore const Title = styled('strong')({ fontSize: '2rem', fontFamily: 'var(--font-family-headings), sans-serif', diff --git a/packages/react-common-docs/next.config.js b/packages/react-common-docs/next.config.js index d24602c..30ab0d3 100644 --- a/packages/react-common-docs/next.config.js +++ b/packages/react-common-docs/next.config.js @@ -10,6 +10,9 @@ const e = withMDX({ module.exports = { ...e, + typescript: { + ignoreBuildErrors: true, + }, webpack(...args) { const oldWebpack = e.webpack(...args) const [config, { defaultLoaders, }] = args diff --git a/packages/react-common-docs/src/components/Header/Header.tsx b/packages/react-common-docs/src/components/Header/Header.tsx index a0672f4..a690f89 100644 --- a/packages/react-common-docs/src/components/Header/Header.tsx +++ b/packages/react-common-docs/src/components/Header/Header.tsx @@ -1,11 +1,18 @@ import * as React from 'react' +import * as PropTypes from 'prop-types' import Head from 'next/head' import unified from 'unified' import parse from 'remark-parse' import remark2react from 'remark-react' import docgen from '../../docgen.json' -const Header = ({ of: ofAttr }) => { +const propTypes = { + of: PropTypes.string, +} + +type Props = PropTypes.InferProps + +const Header: React.FC = ({ of: ofAttr }) => { const docs = docgen.find(d => d.displayName === ofAttr) if (!docs) { @@ -25,11 +32,13 @@ const Header = ({ of: ofAttr }) => { unified() .use(parse) .use(remark2react) - .processSync(docs.description).result + .processSync(docs.description).result as any }

) } +Header.propTypes = propTypes + export default Header diff --git a/packages/react-common-docs/src/components/MenuGraphics/MenuGraphics.tsx b/packages/react-common-docs/src/components/MenuGraphics/MenuGraphics.tsx index c7ea6f7..e6fb8a8 100644 --- a/packages/react-common-docs/src/components/MenuGraphics/MenuGraphics.tsx +++ b/packages/react-common-docs/src/components/MenuGraphics/MenuGraphics.tsx @@ -35,7 +35,7 @@ const MenuGraphics: React.FC = ({ return ( {alt} ) default: diff --git a/packages/react-common-docs/src/components/Nav/Nav.tsx b/packages/react-common-docs/src/components/Nav/Nav.tsx index 1415a35..8fd4ffe 100644 --- a/packages/react-common-docs/src/components/Nav/Nav.tsx +++ b/packages/react-common-docs/src/components/Nav/Nav.tsx @@ -1,13 +1,9 @@ import * as React from 'react' +import * as PropTypes from 'prop-types' import Link from 'next/link' import styled from 'styled-components' import NavLink from '../NavLink/NavLink' -const StyledLink = styled('a')({ - display: 'block', - textDecoration: 'none', -}) - const Container = styled('span')({ display: 'flex', alignItems: 'center', @@ -24,68 +20,82 @@ const HeaderContainer = styled(Container)({ marginTop: '2rem', }) -const NavContainer = styled('div')({ +const propTypes = { + data: PropTypes.oneOfType([ + PropTypes.array, + PropTypes.object, + PropTypes.string, + ]) +} -}) +type Props = PropTypes.InferProps -const Nav = ({ +const Nav: React.FC = ({ data, }) => { - if (Array.isArray(data)) { + if (Array.isArray(data! as unknown[])) { return ( - +
{ - data.map(d => ( + (data as (string | object | null | undefined)[]).map(d => (
) } - if (typeof data === 'object') { - const [entry] = Object.entries(data) + if (typeof data as unknown === 'object') { + const [entry] = Object.entries(data as Record) const [key, value] = entry - if (Array.isArray(value)) { + if (Array.isArray(value as unknown[])) { return ( - +
{key} { - value.map(v => ( + (value as (string | object | null | undefined)[]).map(v => (
) } return ( - + { + // @ts-ignore + + } ) } return ( - + { + // @ts-ignore + + } ) } +Nav.propTypes = propTypes + export default Nav diff --git a/packages/react-common-docs/src/components/NavLink/NavLink.tsx b/packages/react-common-docs/src/components/NavLink/NavLink.tsx index 3c20273..e70bbd5 100644 --- a/packages/react-common-docs/src/components/NavLink/NavLink.tsx +++ b/packages/react-common-docs/src/components/NavLink/NavLink.tsx @@ -106,43 +106,49 @@ const NavLink = React.forwardRef(( any} > - - { - graphics as object - && ( - - - - ) - } - - - {title} - + { + // @ts-ignore + { - subtitle as string + graphics as object && ( - - {subtitle} - + + { + // @ts-ignore + + } + ) } - - { - indicator as string - && ( - - - - ) - } - + + + {title} + + { + subtitle as string + && ( + + {subtitle} + + ) + } + + { + indicator as string + && ( + + + + ) + } + + } )) diff --git a/packages/react-common-docs/src/components/Playground/Playground.tsx b/packages/react-common-docs/src/components/Playground/Playground.tsx index 29071c6..68ca3a9 100644 --- a/packages/react-common-docs/src/components/Playground/Playground.tsx +++ b/packages/react-common-docs/src/components/Playground/Playground.tsx @@ -1,4 +1,5 @@ import * as React from 'react' +import * as PropTypes from 'prop-types' import { LiveProvider, LiveEditor, @@ -16,7 +17,15 @@ const StyledLiveEditor = styled(LiveEditor)({ marginTop: '1rem', }) -const Playground = ({ +const propTypes = { + components: PropTypes.object, + code: PropTypes.string.isRequired, + label: PropTypes.string, +} + +type Props = PropTypes.InferProps + +const Playground: React.FC = ({ components, code, label, @@ -31,7 +40,7 @@ const Playground = ({ return (
{ - label + label as string && (
{label} @@ -50,4 +59,6 @@ const Playground = ({ ) } +Playground.propTypes = propTypes + export default Playground diff --git a/packages/react-common-docs/src/components/Props/Props.tsx b/packages/react-common-docs/src/components/Props/Props.tsx index f932ee4..784d711 100644 --- a/packages/react-common-docs/src/components/Props/Props.tsx +++ b/packages/react-common-docs/src/components/Props/Props.tsx @@ -1,4 +1,5 @@ import * as React from 'react' +import * as PropTypes from 'prop-types' import styled from 'styled-components' import docgen from '../../docgen.json' @@ -90,10 +91,33 @@ const Code = styled('code')({ display: 'inline-block', }) -const Props = ({ of: ofAttr }) => { - const docs = docgen.find(d => d.displayName === ofAttr) +const propTypes = { + of: PropTypes.string, +} + +type Props = PropTypes.InferProps - 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 = ({ of: ofAttr }) => { + const docs = (docgen as unknown as Docs[]).find(d => d.displayName === ofAttr) + + if (!(docs as Docs)) { return null } @@ -123,7 +147,7 @@ const Props = ({ of: ofAttr }) => { { - Object.entries(docs.props).map(([name, def]) => ( + Object.entries((docs as Docs).props).map(([name, def]) => ( @@ -173,4 +197,6 @@ const Props = ({ of: ofAttr }) => { ) } +Props.propTypes = propTypes + export default Props diff --git a/packages/react-common-docs/src/components/Sidebar/Sidebar.tsx b/packages/react-common-docs/src/components/Sidebar/Sidebar.tsx index ac93157..daf9e6c 100644 --- a/packages/react-common-docs/src/components/Sidebar/Sidebar.tsx +++ b/packages/react-common-docs/src/components/Sidebar/Sidebar.tsx @@ -1,4 +1,5 @@ import * as React from 'react' +import * as PropTypes from 'prop-types' import { Icon } from '../../../../react-common/src' import pkg from '../../../../../package.json' import styled from 'styled-components' @@ -108,20 +109,31 @@ const RepoLink = styled('a')({ placeContent: 'center', }) -const Sidebar = ({ +const propTypes = { + data: PropTypes.shape({ + nav: PropTypes.object, + }), + brand: PropTypes.elementType, + initialTheme: PropTypes.string, +} + +type Props = PropTypes.InferProps + +const Sidebar: React.FC = ({ data, - brand: Brand, + brand: BrandRaw, initialTheme = 'Dark', }) => { const [theme, setTheme] = React.useState(initialTheme) const [sidebar, setSidebar] = React.useState(false) const navRef = React.useRef(null) + const Brand = BrandRaw! const toggleDarkMode = (b: string) => () => { setTheme(b) } - const toggleSidebar = (b: boolean) => (e) => { + const toggleSidebar = (b: boolean): MouseEventHandler => (e) => { e.preventDefault() setSidebar(b) } @@ -140,7 +152,7 @@ const Sidebar = ({ }, []) React.useEffect(() => { - const eventListener: MouseEventHandler = (e) => { + const eventListener = (e: MouseEvent) => { let currentElement = e.target as HTMLElement while (currentElement !== e.currentTarget) { if (currentElement.tagName === 'A') { @@ -170,7 +182,7 @@ const Sidebar = ({ }, []) React.useEffect(() => { - window.localStorage.setItem('tesseract-theme', theme) + window.localStorage.setItem('tesseract-theme', theme as string) }, [theme]) React.useEffect(() => { @@ -265,7 +277,7 @@ const Sidebar = ({