-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pattern Library: Add Readymade Templates section (#92023)
Introduces a new Pattern Library section to highlight Readymade Templates.
- Loading branch information
Showing
12 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
client/my-sites/patterns/components/readymade-templates/client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
PatternRenderer, | ||
BlockRendererProvider, | ||
PatternsRendererContext, | ||
} from '@automattic/block-renderer'; | ||
import { ReadymadeTemplatesSection } from 'calypso/my-sites/patterns/components/readymade-templates/section'; | ||
import { RENDERER_SITE_ID } from 'calypso/my-sites/patterns/constants'; | ||
import { useRenderReadymadeTemplate } from 'calypso/my-sites/patterns/hooks/use-render-readymade-template'; | ||
import { ReadymadeTemplate, ReadymadeTemplatesFC } from 'calypso/my-sites/patterns/types'; | ||
|
||
const ReadymadeTemplatePreview = ( readymadeTemplate: ReadymadeTemplate ) => { | ||
const { data: renderedPatterns = {} } = useRenderReadymadeTemplate( readymadeTemplate ); | ||
|
||
return ( | ||
<PatternsRendererContext.Provider value={ { renderedPatterns, shouldShufflePosts: false } }> | ||
{ Object.keys( renderedPatterns ).map( ( pattern ) => ( | ||
<PatternRenderer patternId={ pattern } viewportWidth={ 1200 } key={ pattern } /> | ||
) ) } | ||
</PatternsRendererContext.Provider> | ||
); | ||
}; | ||
|
||
export const ReadymadeTemplatesClient: ReadymadeTemplatesFC = ( { readymadeTemplates } ) => ( | ||
<BlockRendererProvider siteId={ RENDERER_SITE_ID }> | ||
<ReadymadeTemplatesSection | ||
readymadeTemplates={ readymadeTemplates } | ||
renderPreview={ ReadymadeTemplatePreview } | ||
/> | ||
</BlockRendererProvider> | ||
); |
42 changes: 42 additions & 0 deletions
42
client/my-sites/patterns/components/readymade-templates/section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { ReactNode } from 'react'; | ||
import { PatternsSection } from 'calypso/my-sites/patterns/components/section'; | ||
import { ReadymadeTemplate, ReadymadeTemplatesProps } from 'calypso/my-sites/patterns/types'; | ||
import './style.scss'; | ||
|
||
type ReadymadeTemplatesSectionProps = ReadymadeTemplatesProps & { | ||
renderPreview?: ( readymadeTemplate: ReadymadeTemplate ) => ReactNode; | ||
}; | ||
|
||
export const ReadymadeTemplatesSection = ( { | ||
readymadeTemplates, | ||
renderPreview, | ||
}: ReadymadeTemplatesSectionProps ) => { | ||
const translate = useTranslate(); | ||
|
||
if ( ! readymadeTemplates.length ) { | ||
return; | ||
} | ||
|
||
return ( | ||
<PatternsSection | ||
bodyFullWidth | ||
description={ translate( | ||
'Explore a collection of beautiful site layouts made with our patterns.' | ||
) } | ||
theme="dark" | ||
title={ translate( 'Ready-to-use site layouts' ) } | ||
> | ||
<div className="readymade-templates"> | ||
{ readymadeTemplates.map( ( readymadeTemplate ) => ( | ||
<div className="readymade-template" key={ readymadeTemplate.template_id }> | ||
<div className="readymade-template__content"> | ||
{ renderPreview?.( readymadeTemplate ) } | ||
</div> | ||
<div className="readymade-template__title">{ readymadeTemplate.title }</div> | ||
</div> | ||
) ) } | ||
</div> | ||
</PatternsSection> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
client/my-sites/patterns/components/readymade-templates/server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ReadymadeTemplatesSection } from 'calypso/my-sites/patterns/components/readymade-templates/section'; | ||
import { ReadymadeTemplatesFC } from 'calypso/my-sites/patterns/types'; | ||
|
||
export const ReadymadeTemplatesServer: ReadymadeTemplatesFC = ( { readymadeTemplates } ) => ( | ||
<ReadymadeTemplatesSection readymadeTemplates={ readymadeTemplates } /> | ||
); |
51 changes: 51 additions & 0 deletions
51
client/my-sites/patterns/components/readymade-templates/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@import "@wordpress/base-styles/breakpoints"; | ||
|
||
.readymade-templates { | ||
display: flex; | ||
gap: 24px; | ||
padding: 16px 110px 24px; | ||
overflow: auto; | ||
mask-image: linear-gradient(to right, transparent, #fff 110px, #fff calc(100% - 110px), transparent); | ||
|
||
@media (max-width: $break-wide) { | ||
padding-left: 24px; | ||
padding-right: 24px; | ||
mask-image: none; | ||
} | ||
|
||
@media (max-width: $break-medium) { | ||
padding-top: 0; | ||
padding-bottom: 0; | ||
} | ||
} | ||
|
||
.readymade-template__content { | ||
--readymade-template-width: 390px; | ||
width: var(--readymade-template-width); | ||
height: calc(var(--readymade-template-width) * 1.4); | ||
background-color: #fff; | ||
margin-bottom: 24px; | ||
overflow: hidden; | ||
border-radius: 2px; | ||
|
||
@media (max-width: $break-huge) { | ||
--readymade-template-width: calc(100vw / 3 - 90px); | ||
} | ||
|
||
@media (max-width: $break-wide) { | ||
--readymade-template-width: calc(100vw / 3 - 50px); | ||
} | ||
|
||
@media (max-width: $break-medium) { | ||
--readymade-template-width: calc(100vw / 2 - 72px); | ||
} | ||
|
||
@media (max-width: $break-small) { | ||
--readymade-template-width: calc(100vw - 170px); | ||
} | ||
} | ||
|
||
.readymade-template__title { | ||
font-size: 1.125rem; /* stylelint-disable-line scales/font-sizes */ | ||
line-height: 26px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import type { ReadymadeTemplate } from 'calypso/my-sites/patterns/types'; | ||
|
||
export const useReadymadeTemplates = () => | ||
useQuery< ReadymadeTemplate[] >( { | ||
queryKey: [ 'pattern-library', 'readymade-templates' ], | ||
queryFn() { | ||
return wpcom.req.get( { | ||
path: '/themes/readymade-templates', | ||
apiNamespace: 'wpcom/v2', | ||
} ); | ||
}, | ||
staleTime: 5 * 60 * 1000, | ||
} ); |
23 changes: 23 additions & 0 deletions
23
client/my-sites/patterns/hooks/use-render-readymade-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { RenderedPattern } from '@automattic/block-renderer'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import { RENDERER_SITE_ID } from 'calypso/my-sites/patterns/constants'; | ||
import type { ReadymadeTemplate } from 'calypso/my-sites/patterns/types'; | ||
|
||
export const useRenderReadymadeTemplate = ( readymadeTemplate: ReadymadeTemplate ) => | ||
useQuery< { [ key: string ]: RenderedPattern } >( { | ||
queryKey: [ 'pattern-library', 'readymade-template', readymadeTemplate.template_id, 'render' ], | ||
queryFn() { | ||
return wpcom.req.get( | ||
{ | ||
path: `/sites/${ RENDERER_SITE_ID }/block-renderer/patterns/render`, | ||
apiNamespace: 'wpcom/v2', | ||
}, | ||
{ | ||
pattern_ids: readymadeTemplate.patterns.map( ( { id } ) => id ).join( ',' ), | ||
site_title: readymadeTemplate.title, | ||
} | ||
); | ||
}, | ||
staleTime: 5 * 60 * 1000, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as BlockRendererContainer } from './block-renderer-container'; | ||
export { default as BlockRendererProvider } from './block-renderer-provider'; | ||
export { default as PatternRenderer } from './pattern-renderer'; | ||
export { default as PatternsRendererContext } from './patterns-renderer-context'; | ||
export { default as PatternsRendererProvider } from './patterns-renderer-provider'; |