diff --git a/components/action-block.js b/components/action-block.js index c72b1f4..964a36b 100644 --- a/components/action-block.js +++ b/components/action-block.js @@ -7,7 +7,7 @@ import Link from "./link"; const ActionBlock = ({ heading, content, action, url }) => { return ( -

{heading}

+

{heading}

{Array.isArray(content) ? content.map((line) => ( diff --git a/components/block-text-serializer.tsx b/components/block-text-serializer.tsx index 5d6010f..3ed7150 100644 --- a/components/block-text-serializer.tsx +++ b/components/block-text-serializer.tsx @@ -10,15 +10,20 @@ import { StyledPlayer } from "./newfrontdoor/audio-player"; import Link from "next/link"; import { submitForm } from "../lib/sanity-fns"; -const AudioSerializer = ({ node }) => { +type AudioSerializer = { + node: PropTypes.object.isRequired +}; + +const AudioSerializer = ({ node }: AudioSerializer) => { return ; }; -AudioSerializer.propTypes = { + +type VideoSerializer = { node: PropTypes.object.isRequired }; -const VideoSerializer = ({ node }) => { +const VideoSerializer = ({ node }: VideoSerializer) => { const { url } = node; if (url) { const video = getVideoId(url || null); @@ -33,46 +38,47 @@ const VideoSerializer = ({ node }) => { } }; -VideoSerializer.propTypes = { - node: PropTypes.object.isRequired -}; +type CustomStyleSerializer = { + children: string; +} -const CustomStyleSerializer = ({ children }) => { - return

{children}

; +const CustomStyleSerializer = ({ children }: CustomStyleSerializer) => { + return

{children}

; }; -CustomStyleSerializer.propTypes = { - children: PropTypes.string.isRequired -}; +type AnchorSerializer = { + children: PropTypes.array.isRequired, + mark: PropTypes.object.isRequired +} -const AnchorSerializer = ({ children, mark }) => { +const AnchorSerializer = ({ children, mark }: AnchorSerializer) => { return {children}; }; -AnchorSerializer.propTypes = { - children: PropTypes.array.isRequired, - mark: PropTypes.object.isRequired +type ImageSerializer = { + node: PropTypes.node.isRequired }; -const ImageSerializer = ({ node }) => { +const ImageSerializer = ({ node }: ImageSerializer) => { return ; }; -ImageSerializer.propTypes = { - node: PropTypes.node.isRequired -}; const Success = (node) => (
-

+

{node.onSuccess || "Thank you for your submission. We will get back to you as soon as we can."}

); -const FormSerializer = ({ node }) => { +type FormSerializer = { + node: PropTypes.object.isRequired +}; + +const FormSerializer = ({ node }: FormSerializer) => { return (
{ ); }; -FormSerializer.propTypes = { - node: PropTypes.object.isRequired -}; const InternalLinkSerializer = ({ mark, children }) => { return ( - + {children} ); @@ -104,7 +107,7 @@ InternalLinkSerializer.propTypes = { }; const ExternalLinkSerializer = ({ mark, children }) => ( - + {children} ); @@ -118,7 +121,7 @@ ExternalLinkSerializer.propTypes = { const FileLinkSerializer = ({ mark, children }) => { return ( - + {children} ); @@ -131,16 +134,21 @@ FileLinkSerializer.propTypes = { }).isRequired }; -const BlockRenderer = (props) => { +type BlockRenderer = { + children: PropTypes.any, + node: PropTypes.object.isRequired +}; + +const BlockRenderer = (props: BlockRenderer) => { const style = props.node.style || "normal"; const elements = { - h1:

{props.children}

, - h2:

{props.children}

, - h3:

{props.children}

, - h4:

{props.children}

, - h5:
{props.children}
, - h6:
{props.children}
+ h1:

{props.children}

, + h2:

{props.children}

, + h3:

{props.children}

, + h4:

{props.children}

, + h5:
{props.children}
, + h6:
{props.children}
}; if (/^h\d/.test(style)) { @@ -155,12 +163,11 @@ const BlockRenderer = (props) => { return BlockContent.defaultSerializers.types.block(props); }; -BlockRenderer.propTypes = { - children: PropTypes.any, - node: PropTypes.object.isRequired +type BlockText = { + blocks: PropTypes.array.isRequired }; -const BlockText = ({ blocks }) => { +const BlockText = ({ blocks }: BlockText) => { return ( { ); }; -BlockText.propTypes = { - blocks: PropTypes.array.isRequired -}; export default BlockText; diff --git a/components/link.js b/components/link.js deleted file mode 100644 index e95dc90..0000000 --- a/components/link.js +++ /dev/null @@ -1,64 +0,0 @@ -import PropTypes from "prop-types"; -import React from "react"; -import NextLink from "next/link"; -import { Link as ThemeUiLink } from "theme-ui"; - -//TODO: replace all instances of this component with next/link and remove it - -const pageLookup = (link) => { - // This depends on the fact that no sub-subdirectory of pages contains an index file - if (link.includes("/")) { - const urlArray = link.split("/"); - urlArray.pop(); - const root = urlArray.reduce((url, element) => { - return url.concat("/", element); - }); - return `/${root}/${link}`; - } - - switch (link) { - case "": - case "blog": - return `/blog/${link}`; - default: - return `/${link}`; - } -}; - -const regex = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|api|\/api).*/; - -const Link = ({ link = "", children, isBlank, hasNoAnchor, passedSx, ...rest }) => { - if (isBlank) { - rest.target = "_blank"; - rest.rel = "noreferrer noopener"; - } - - return regex.test(link) ? ( - hasNoAnchor ? ( - - {children} - - ) : ( - - - {children} - - - ) - ) : ( - - {children} - - ); -}; - -Link.propTypes = { - children: PropTypes.any, - variant: PropTypes.string, - link: PropTypes.string.isRequired, - isBlank: PropTypes.bool, - hasNoAnchor: PropTypes.bool, - passedSx: PropTypes.object -}; - -export default Link; diff --git a/components/link.tsx b/components/link.tsx new file mode 100644 index 0000000..2fb56f3 --- /dev/null +++ b/components/link.tsx @@ -0,0 +1,16 @@ +import NextLink from "next/link"; +type Link = { + children: any, + variant: String, + href: Required, + isBlank: Boolean, + hasNoAnchor: Boolean, +}; + +const Link = ({ href, children, ...rest }: Link) => { + + {children} + +}; + +export default Link; diff --git a/components/newfrontdoor/audio-player/audio-player.tsx b/components/newfrontdoor/audio-player/audio-player.tsx index f9d1bd6..b766d0d 100644 --- a/components/newfrontdoor/audio-player/audio-player.tsx +++ b/components/newfrontdoor/audio-player/audio-player.tsx @@ -11,7 +11,7 @@ type AudioPlayerProps = { isPlayOnLoad?: boolean; } & StyledPlayerProps; -const AudioPlayer: FC = ({src, isPlayOnLoad, ...props}) => { +const AudioPlayer: FC = ({src, isPlayOnLoad = false, ...props}) => { return ( @@ -19,10 +19,6 @@ const AudioPlayer: FC = ({src, isPlayOnLoad, ...props}) => { ); }; -AudioPlayer.defaultProps = { - isPlayOnLoad: false -}; - AudioPlayer.propTypes = { src: PropTypes.string, isPlayOnLoad: PropTypes.bool diff --git a/components/newfrontdoor/audio-player/index.ts b/components/newfrontdoor/audio-player/index.ts index 96328c7..facc9f9 100644 --- a/components/newfrontdoor/audio-player/index.ts +++ b/components/newfrontdoor/audio-player/index.ts @@ -1,3 +1,3 @@ -import { StyledPlayer } from "./styled-player"; +import StyledPlayer from "./styled-player"; export { StyledPlayer }; \ No newline at end of file diff --git a/components/newfrontdoor/audio-player/progress-bar.tsx b/components/newfrontdoor/audio-player/progress-bar.tsx index 1c9fe85..ecca31b 100644 --- a/components/newfrontdoor/audio-player/progress-bar.tsx +++ b/components/newfrontdoor/audio-player/progress-bar.tsx @@ -14,7 +14,7 @@ type ProgressBarProps = { }; const ProgressBar = forwardRef( - ({value, max, onChange, step, isInteracting, color, isInvert}, rangeRef) => { + ({value, max, onChange, step = 1, isInteracting, color, isInvert = false}, rangeRef) => { return ( ( export default ProgressBar; -ProgressBar.defaultProps = { - step: 1, - isInvert: false -}; - ProgressBar.propTypes = { value: PropTypes.number.isRequired, max: PropTypes.number.isRequired, diff --git a/components/newfrontdoor/audio-player/styled-player.tsx b/components/newfrontdoor/audio-player/styled-player.tsx index 19aefef..b4ff9ff 100644 --- a/components/newfrontdoor/audio-player/styled-player.tsx +++ b/components/newfrontdoor/audio-player/styled-player.tsx @@ -60,13 +60,13 @@ export type StyledPlayerProps = { }; const StyledPlayer: FC = ({ - highlight, - base, - hasBorder, - background, - isInvert, - hasPlaybackspeed, - width + highlight = '#548BF4', + base = '#ddd', + hasBorder = true, + background = 'unset', + isInvert = "false", + hasPlaybackspeed = true, + width = "280px" }) => { const volumeBar = useRef(null); const {playerState, playerProps, dispatch} = useAudioPlayer(); @@ -240,16 +240,6 @@ const StyledPlayer: FC = ({ ); }; -StyledPlayer.defaultProps = { - highlight: '#548BF4', - base: '#ddd', - hasBorder: true, - background: 'unset', - isInvert: false, - hasPlaybackspeed: true, - width: '280px' -}; - StyledPlayer.propTypes = { highlight: PropTypes.string, base: PropTypes.string, diff --git a/components/newfrontdoor/blog/post-page.js b/components/newfrontdoor/blog/post-page.js index c08ec4f..1b99e71 100644 --- a/components/newfrontdoor/blog/post-page.js +++ b/components/newfrontdoor/blog/post-page.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import {Flex, jsx} from 'theme-ui'; import format from 'date-fns/format'; -const PostPage = ({post, dateFormat, link, blockText}) => { +const PostPage = ({post, dateFormat = 'dddd, MMMM do yyyy', link, blockText}) => { const {title, author, _createdAt, categories, date, body} = post; return ( { - const {body, blockText, bodyTransform, Sidebar} = props; +const Post = ({ + body, + blockText, + bodyTransform = (props) => props, + Sidebar = DefaultSidebar, + ...rest +}) => { const readingLength = readingTime(bodyTransform(body)); return body ? ( @@ -14,23 +19,27 @@ const Post = (props) => { margin: 'auto', width: '100vw', maxWidth: '920px', - paddingTop: '40px', + paddingBottom: '40px', minHeight: [null, '600px'] }} > - + +
{blockText(body)}
- ) : null; + ) :
empty
; }; Post.propTypes = { @@ -40,9 +49,4 @@ Post.propTypes = { bodyTransform: PropTypes.func }; -Post.defaultProps = { - bodyTransform: (props) => props, - Sidebar: DefaultSidebar -}; - export default Post; diff --git a/components/newfrontdoor/blog/sidebar.js b/components/newfrontdoor/blog/sidebar.js index 50b3fe2..81b3d37 100644 --- a/components/newfrontdoor/blog/sidebar.js +++ b/components/newfrontdoor/blog/sidebar.js @@ -6,11 +6,11 @@ const Sidebar = ({ title, author, _createdAt, - dateFormat, + overrides = {}, + dateFormat = 'EEEE, MMMM do yyyy', readingLength, categories, Link, - overrides }) => { return (