feat(shared): Modal for all MDX and Strapi content
This commit is contained in:
parent
39dd5ebaa2
commit
0b40f6f347
9 changed files with 84 additions and 42 deletions
|
@ -16,6 +16,7 @@ const PageWrapper= ({
|
|||
noSearch=false,
|
||||
app=false,
|
||||
layout=Docs,
|
||||
crumbs=false,
|
||||
children=[]
|
||||
}) => {
|
||||
|
||||
|
@ -41,6 +42,7 @@ const PageWrapper= ({
|
|||
const childProps = {
|
||||
app: app,
|
||||
title: title,
|
||||
crumbs: crumbs,
|
||||
search, setSearch, toggleSearch: () => setSearch(!search),
|
||||
noSearch: noSearch,
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ function useApp(full = true) {
|
|||
/*
|
||||
* Helper method to construct breadcrumb from navigation structure
|
||||
*/
|
||||
const getBreadcrumb = slug => ({ title: get(navigation, slug).__title, slug })
|
||||
const getBreadcrumb = slug => ([ get(navigation, slug).__title, `/${slug}` ])
|
||||
|
||||
return {
|
||||
// Static vars
|
||||
|
|
|
@ -5,6 +5,7 @@ import MdxWrapper from 'shared/components/wrappers/mdx'
|
|||
import mdxCompiler from 'shared/mdx/compiler'
|
||||
import Markdown from 'react-markdown'
|
||||
import Head from 'next/head'
|
||||
import Modal from 'shared/components/modal.js'
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||
import { strapiHost } from 'shared/config/freesewing.mjs'
|
||||
import { strapiImage } from 'shared/utils.js'
|
||||
|
@ -81,6 +82,7 @@ const PostPage = ({ post, author }) => {
|
|||
</span>
|
||||
</div>
|
||||
<figure>
|
||||
<Modal>
|
||||
<img
|
||||
src={`${strapiHost}${post.image.url}`}
|
||||
alt={post.caption}
|
||||
|
@ -90,6 +92,7 @@ const PostPage = ({ post, author }) => {
|
|||
className="text-center mb-8 prose m-auto"
|
||||
dangerouslySetInnerHTML={{__html: post.caption}}
|
||||
/>
|
||||
</Modal>
|
||||
</figure>
|
||||
<div className="strapi prose lg:prose-lg mb-12 m-auto">
|
||||
<MdxWrapper mdx={post.mdx} app={app} />
|
||||
|
|
|
@ -55,7 +55,7 @@ const BlogIndexPage = (props) => {
|
|||
|
||||
return (
|
||||
<Page app={app} title={t('blog')} slug='blog'>
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 px-8">
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2 px-8 max-w-7xl">
|
||||
{props.posts.map(post => <Preview app={app} post={post} key={post.slug}/>)
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@ import mdxCompiler from 'shared/mdx/compiler'
|
|||
import Markdown from 'react-markdown'
|
||||
import Head from 'next/head'
|
||||
import PageLink from 'shared/components/page-link.js'
|
||||
import Modal from 'shared/components/modal.js'
|
||||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||
import { strapiHost } from 'shared/config/freesewing.mjs'
|
||||
import { strapiImage } from 'shared/utils.js'
|
||||
|
@ -59,12 +60,9 @@ const PostPage = ({ post, maker }) => {
|
|||
const app = useApp()
|
||||
const crumbs = [
|
||||
app.getBreadcrumb('showcase'),
|
||||
{
|
||||
title: post.title,
|
||||
slug: `showcase/${post.slug}`
|
||||
}
|
||||
[ post.title ]
|
||||
]
|
||||
|
||||
console.log(crumbs)
|
||||
return (
|
||||
<Page app={app} title={post.title} crumbs={crumbs} >
|
||||
<article className="mb-12 px-8 max-w-7xl">
|
||||
|
@ -84,15 +82,17 @@ const PostPage = ({ post, maker }) => {
|
|||
</div>
|
||||
</div>
|
||||
<figure>
|
||||
<Modal>
|
||||
<img
|
||||
src={`${strapiHost}${post.image.url}`}
|
||||
alt={post.caption}
|
||||
className="shadow m-auto"
|
||||
className="shadow m-auto max-h-full"
|
||||
/>
|
||||
<figcaption
|
||||
className="text-center mb-8 prose m-auto"
|
||||
dangerouslySetInnerHTML={{__html: post.caption}}
|
||||
/>
|
||||
</Modal>
|
||||
</figure>
|
||||
<div className="strapi prose lg:prose-lg mb-12 m-auto">
|
||||
<MdxWrapper mdx={post.mdx} app={app} />
|
||||
|
|
|
@ -45,8 +45,14 @@ const DesignIndexPage = (props) => {
|
|||
}
|
||||
}
|
||||
|
||||
const crumbs = [
|
||||
app.getBreadcrumb('showcase'),
|
||||
[ t('designs'), '/showcase/designs' ],
|
||||
[ t(`patterns:${props.design}.t`) ]
|
||||
]
|
||||
|
||||
return (
|
||||
<Page app={app} title={t('showcase')+': '+t(`patterns:${props.design}.t`)} slug='showcase'>
|
||||
<Page app={app} title={t('showcase')+': '+t(`patterns:${props.design}.t`)} crumbs={crumbs}>
|
||||
<div className={`
|
||||
px-8 2xl:pl-16 overflow-visible overscroll-x-hidden
|
||||
max-w-sm
|
||||
|
|
|
@ -15,7 +15,7 @@ const Breadcrumbs = ({ crumbs=[], title }) => (
|
|||
<React.Fragment key={crumb[1]}>
|
||||
<li className="text-base-content px-2">»</li>
|
||||
<li>
|
||||
{crumb[2]
|
||||
{crumb[1]
|
||||
? (
|
||||
<Link href={crumb[1]}>
|
||||
<a title={crumb[0]} className="text-secondary hover:text-secondary-focus">
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import Popout from 'shared/components/popout'
|
||||
import Modal from 'shared/components/modal'
|
||||
|
||||
const Figure = props => {
|
||||
|
||||
const title = props?.title
|
||||
? props.title
|
||||
: props?.alt
|
||||
|
@ -9,11 +11,12 @@ const Figure = props => {
|
|||
|
||||
return (
|
||||
<figure className="block my-4">
|
||||
<Modal>
|
||||
<img
|
||||
src={props?.src}
|
||||
alt={props?.alt || ''}
|
||||
title={title || ''}
|
||||
className="m-auto"
|
||||
className="m-auto max-h-full max-w-full"
|
||||
/>
|
||||
{title
|
||||
? <figcaption className="text-center italic text-base-content mt-1">{title}</figcaption>
|
||||
|
@ -24,6 +27,7 @@ const Figure = props => {
|
|||
</Popout>
|
||||
)
|
||||
}
|
||||
</Modal>
|
||||
</figure>
|
||||
)
|
||||
}
|
||||
|
|
27
packages/freesewing.shared/components/modal.js
Normal file
27
packages/freesewing.shared/components/modal.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { useState } from 'react'
|
||||
|
||||
const Modal = ({ cancel, children }) => {
|
||||
|
||||
const [ modal, setModal ] = useState(false)
|
||||
|
||||
if (modal) return (
|
||||
<div className={`
|
||||
fixed top-0 left-0 right-0 w-screen h-screen
|
||||
bg-base-100 bg-opacity-90 z-30
|
||||
hover:cursor-zoom-out flex flex-col justify-center
|
||||
`} onClick={() => setModal(false)}>
|
||||
<div className="p-8 max-h-full max-w-full">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => setModal(!modal)}
|
||||
className="hover:cursor-zoom-in"
|
||||
>{children}</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
Loading…
Add table
Add a link
Reference in a new issue