Skip to content

Commit

Permalink
Block Theme Previews: show modal when previewing theme
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Jan 10, 2024
1 parent b05d166 commit 63875a2
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 3 deletions.
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions projects/packages/jetpack-mu-wpcom/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
rules: {
'@wordpress/i18n-text-domain': [
'error',
{
allowedTextDomain: 'jetpack-mu-wpcom',
},
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Block theme previews: show modal when previewing a theme.
11 changes: 10 additions & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@
},
"devDependencies": {
"@automattic/jetpack-webpack-config": "workspace:*",
"sass": "1.64.1",
"sass-loader": "12.4.0",
"typescript": "^5.0.4",
"webpack": "5.76.0",
"webpack-cli": "4.9.1"
},
"dependencies": {
"@automattic/typography": "1.0.0",
"@sentry/browser": "7.80.1",
"@wordpress/api-fetch": "6.45.0",
"@wordpress/hooks": "3.48.0"
"@wordpress/base-styles": "4.39.0",
"@wordpress/components": "25.14.0",
"@wordpress/dom-ready": "^3.48.0",
"@wordpress/data": "9.18.0",
"@wordpress/hooks": "3.48.0",
"@wordpress/i18n": "4.48.0",
"@wordpress/plugins": "6.16.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Jetpack_Mu_Wpcom;

Check warning on line 8 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/block-theme-previews.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Found precision alignment of 1 spaces. (Universal.WhiteSpace.PrecisionAlignment.Found)

/**
* Always show the correct homepage when previewing a theme in the Site Editor
*
Expand All @@ -17,3 +19,24 @@ function () {
return 'posts';
}
);

function wpcom_enqueue_block_theme_previews_assets() {

Check failure on line 23 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/block-theme-previews.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Missing doc comment for function wpcom_enqueue_block_theme_previews_assets() (Squiz.Commenting.FunctionComment.Missing)
$asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/block-theme-previews/block-theme-previews.asset.php';
$dependencies = isset( $asset_file['dependencies'] ) ? $asset_file['dependencies'] : array();

Check warning on line 25 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/block-theme-previews.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Unused variable $dependencies. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)
$version = isset( $asset_file['version'] ) ? $asset_file['version'] : filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/block-theme-previews/block-theme-previews.js' );

Check warning on line 26 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/block-theme-previews.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer (non-excluded files only)

Unused variable $version. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)

wp_enqueue_script(
'wpcom-block-theme-previews',
plugins_url( 'build/block-theme-previews/block-theme-previews.js', Jetpack_Mu_Wpcom::BASE_FILE ),
$asset_file['dependencies'] ?? array(),
$asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/block-theme-previews/block-theme-previews.js' ),
true
);
wp_enqueue_style(
'wpcom-block-theme-previews',
plugins_url( 'build/block-theme-previews/block-theme-previews.css', Jetpack_Mu_Wpcom::BASE_FILE ),
array(),
filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/block-theme-previews/block-theme-previews.css' )
);
}
add_action( 'enqueue_block_editor_assets', 'wpcom_enqueue_block_theme_previews_assets' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import domReady from '@wordpress/dom-ready';
import { registerPlugin } from '@wordpress/plugins';
import BlockThemePreviewsModal from './modal';

domReady( () => {
registerPlugin( 'block-theme-previews', {
render: () => <BlockThemePreviewsModal />,
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@import "@automattic/typography/styles/fonts";
@import "@wordpress/base-styles/breakpoints";
@import "@wordpress/base-styles/mixins";

.wpcom-block-theme-previews-modal {
.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;
align-items: flex-start;

@include break-small {
flex-direction: row;
justify-content: flex-start;

@media (min-height: #{ ($break-small) }) {
align-items: stretch;
}
}
}

.wpcom-block-theme-previews-modal__text,
.wpcom-block-theme-previews-modal__image {
width: 100%;

@include break-small {
width: auto;
max-width: 380px;
}
}

.wpcom-block-theme-previews-modal__text {
padding: 32px;
display: flex;
flex-direction: column;

@include break-small {
@media (min-height: #{ ($break-small) }) {
padding: 64px 48px;
}
}
}

.wpcom-block-theme-previews-modal__heading {
margin-top: 0;
font-family: $brand-serif;
font-weight: 400;
font-size: 1.75rem;
line-height: 32px;
margin-bottom: 16px;

@include break-small {
@media (min-height: #{ ($break-small) }) {
font-size: 2rem;
line-height: 40px;
}
}
}

.wpcom-block-theme-previews-modal__description {
font-size: 1rem;
line-height: 24px;
margin-top: 0;
margin-bottom: 32px;
text-wrap: pretty;
}

.wpcom-block-theme-previews-modal__actions {
display: flex;
justify-content: center;
gap: 16px;
margin-top: auto;

.components-button {
flex-grow: 1;
justify-content: center;
}
}

.wpcom-block-theme-previews-modal__image {
background-color: #d0cce3;
padding: 32px 0 32px 32px;
display: flex;
justify-content: flex-end;
max-height: 50vh;

@include break-small {
max-height: 70vh;

@media (min-height: #{ ($break-small) }) {
max-height: none;
padding: 64px 0 64px 64px;
}
}

img {
width: 100%;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Button, Modal } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import React from 'react';

import './modal.scss';

/**

Check warning on line 8 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/modal.tsx

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

Missing JSDoc block description

Check warning on line 8 in projects/packages/jetpack-mu-wpcom/src/features/block-theme-previews/modal.tsx

View workflow job for this annotation

GitHub Actions / ESLint (non-excluded files only)

Missing JSDoc @returns declaration
*
*/
export default function BlockThemePreviewsModal() {
const isInSiteEditor = useSelect( select => !! select( 'core/edit-site' ), [] );

if ( ! isInSiteEditor ) {
return null;
}
return (
<Modal className="wpcom-block-theme-previews-modal" 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">
{ __( "You're previewing theme", 'jetpack-mu-wpcom' ) }
</h1>
<p className="wpcom-block-theme-previews-modal__description">xxx</p>
<div className="wpcom-block-theme-previews-modal__actions">
<Button variant="primary">{ __( 'Start customizing', 'jetpack-mu-wpcom' ) }</Button>
</div>
</div>
<div className="wpcom-block-theme-previews-modal__image"></div>
</div>
</Modal>
);
}
10 changes: 8 additions & 2 deletions projects/packages/jetpack-mu-wpcom/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const jetpackConfig = require( '@automattic/jetpack-webpack-config/webpack' );
module.exports = {
entry: {
'error-reporting': './src/features/error-reporting/index.js',
'block-theme-previews': './src/features/block-theme-previews/index.tsx',
},
mode: jetpackConfig.mode,
devtool: jetpackConfig.devtool,
Expand All @@ -19,7 +20,9 @@ module.exports = {
...jetpackConfig.resolve,
},
node: false,
plugins: [ ...jetpackConfig.StandardPlugins() ],
plugins: [
...jetpackConfig.StandardPlugins( { MiniCssExtractPlugin: { filename: '[name]/[name].css' } } ),
],
module: {
strictExportPresence: true,
rules: [
Expand All @@ -34,7 +37,10 @@ module.exports = {
} ),

// Handle CSS.
jetpackConfig.CssRule(),
jetpackConfig.CssRule( {
extensions: [ 'css', 'scss' ],
extraLoaders: [ 'sass-loader' ],
} ),

// Handle images.
jetpackConfig.FileRule(),
Expand Down

0 comments on commit 63875a2

Please sign in to comment.