-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Theme Previews: show education modal when previewing theme
- Loading branch information
Showing
19 changed files
with
342 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
module.exports = { | ||
extends: [ require.resolve( 'jetpack-js-tools/eslintrc/react' ) ], | ||
parserOptions: { | ||
requireConfigFile: false, | ||
babelOptions: { | ||
configFile: require.resolve( './babel.config.js' ), | ||
}, | ||
}, | ||
rules: { | ||
'jsdoc/require-returns': 0, | ||
'@wordpress/i18n-text-domain': [ | ||
'error', | ||
{ | ||
allowedTextDomain: 'jetpack-mu-wpcom', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = { | ||
presets: [ [ '@automattic/jetpack-webpack-config/babel/preset' ] ], | ||
}; |
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/block-theme-previews-modal
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Block theme previews: show an education modal when previewing a theme. |
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
10 changes: 10 additions & 0 deletions
10
projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/index.js
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,10 @@ | ||
import domReady from '@wordpress/dom-ready'; | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import BlockThemePreviewsModal from './modal'; | ||
import './store'; | ||
|
||
domReady( () => { | ||
registerPlugin( 'wpcom-block-theme-previews', { | ||
render: BlockThemePreviewsModal, | ||
} ); | ||
} ); |
82 changes: 82 additions & 0 deletions
82
projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/modal.jsx
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,82 @@ | ||
import { Button, Modal } from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import React from 'react'; | ||
import { getPreviewedThemeStylesheet } from './utils'; | ||
|
||
import './modal.scss'; | ||
|
||
/** | ||
* The modal that shows in the Site Editor the first time a user previews a block theme. | ||
*/ | ||
export default function BlockThemePreviewsModal() { | ||
const stylesheet = getPreviewedThemeStylesheet(); | ||
const theme = useSelect( select => select( 'core' ).getTheme( stylesheet ), [ stylesheet ] ); | ||
|
||
const isInSiteEditor = useSelect( select => !! select( 'core/edit-site' ), [] ); | ||
const isModalVisible = useSelect( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
select => select( 'automattic/wpcom-block-theme-previews' ).isModalVisible(), | ||
[] | ||
); | ||
const { dismissModal } = useDispatch( 'automattic/wpcom-block-theme-previews' ); | ||
const { suppressLivePreviewModal } = useDispatch( 'automattic/wpcom-welcome-guide' ); | ||
|
||
useEffect( () => { | ||
if ( isInSiteEditor ) { | ||
// Hide the legacy modal from the WordPress Editing Toolkit plugin. | ||
suppressLivePreviewModal?.(); | ||
} | ||
}, [ isInSiteEditor, suppressLivePreviewModal ] ); | ||
|
||
if ( ! isInSiteEditor || ! isModalVisible ) { | ||
return null; | ||
} | ||
return ( | ||
<Modal | ||
className="wpcom-block-theme-previews-modal" | ||
onRequestClose={ dismissModal } | ||
shouldCloseOnClickOutside={ false } | ||
> | ||
<div className="wpcom-block-theme-previews-modal__content"> | ||
<div className="wpcom-block-theme-previews-modal__text"> | ||
<h1 className="wpcom-block-theme-previews-modal__heading"> | ||
{ sprintf( | ||
// translators: %s: theme name | ||
__( 'You’re previewing %s', 'jetpack-mu-wpcom' ), | ||
theme?.name?.rendered || stylesheet | ||
) } | ||
</h1> | ||
<div className="wpcom-block-theme-previews-modal__description"> | ||
<p> | ||
{ __( | ||
'Changes you make in the editor won’t be applied to your site until you activate the theme.', | ||
'jetpack-mu-wpcom' | ||
) } | ||
</p> | ||
<p> | ||
{ __( | ||
'Try customizing your theme styles to get your site looking just right.', | ||
'jetpack-mu-wpcom' | ||
) } | ||
</p> | ||
</div> | ||
<div className="wpcom-block-theme-previews-modal__actions"> | ||
<Button variant="primary" onClick={ dismissModal }> | ||
{ __( 'Start customizing', 'jetpack-mu-wpcom' ) } | ||
</Button> | ||
</div> | ||
</div> | ||
<div className="wpcom-block-theme-previews-modal__video"> | ||
<video autoPlay loop muted> | ||
<source | ||
src="https://videos.files.wordpress.com/gTXUlIAB/wpcom-block-theme-previews-modal.mp4" | ||
type="video/mp4" | ||
/> | ||
</video> | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
} |
90 changes: 90 additions & 0 deletions
90
projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/modal.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,90 @@ | ||
@import "@automattic/typography/styles/fonts"; | ||
@import "@wordpress/base-styles/breakpoints"; | ||
@import "@wordpress/base-styles/mixins"; | ||
|
||
.wpcom-block-theme-previews-modal { | ||
&.components-modal__frame { | ||
margin: auto; | ||
} | ||
|
||
.components-modal__content { | ||
padding: 0; | ||
margin-top: 0; | ||
} | ||
|
||
.components-modal__header { | ||
height: auto; | ||
position: absolute; | ||
border-bottom-width: 0; | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__content { | ||
display: flex; | ||
flex-direction: column-reverse; | ||
justify-content: flex-end; | ||
|
||
@include break-small { | ||
@media (min-width: #{ ($break-small) }) { | ||
flex-direction: row; | ||
align-items: stretch; | ||
} | ||
} | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__text { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 48px; | ||
|
||
@include break-small { | ||
@media (min-width: #{ ($break-small) }) { | ||
max-width: 400px; | ||
} | ||
} | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__heading { | ||
margin-top: 0; | ||
font-family: $brand-serif; | ||
font-weight: 400; | ||
font-size: 32px; | ||
line-height: 40px; | ||
margin-bottom: 16px; | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__description { | ||
margin-top: 0; | ||
margin-bottom: 16px; | ||
|
||
p { | ||
font-size: 16px; | ||
line-height: 24px; | ||
text-wrap: pretty; | ||
} | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__actions { | ||
width: unset; | ||
} | ||
|
||
.wpcom-block-theme-previews-modal__video { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
background-color: rgba(56, 88, 233, 0.40); | ||
padding-left: 48px; | ||
overflow: hidden; | ||
|
||
@include break-small { | ||
@media (min-width: #{ ($break-small) }) { | ||
max-width: 500px; | ||
} | ||
} | ||
|
||
video { | ||
max-width: unset; | ||
width: 526px; | ||
border-radius: 6px 0px 0px 0px; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/store.js
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,27 @@ | ||
import { registerStore } from '@wordpress/data'; | ||
|
||
const DEFAULT_STATE = { | ||
isModalVisible: true, | ||
}; | ||
|
||
registerStore( 'automattic/wpcom-block-theme-previews', { | ||
reducer: ( state = DEFAULT_STATE, action ) => { | ||
switch ( action.type ) { | ||
case 'DISMISS_MODAL': | ||
return { | ||
...state, | ||
isModalVisible: false, | ||
}; | ||
} | ||
return state; | ||
}, | ||
actions: { | ||
dismissModal: () => ( { | ||
type: 'DISMISS_MODAL', | ||
} ), | ||
}, | ||
selectors: { | ||
isModalVisible: state => state.isModalVisible, | ||
}, | ||
persist: true, | ||
} ); |
Oops, something went wrong.