Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mobile slideout styling within live preview #13739

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- When slideouts are opened within Live Preview, they now slide up over the editor pane, rather than covering the preview pane. ([#13739](https://github.com/craftcms/cms/pull/13739))
- Fixed a bug where it wasn’t always possible to create new entries from custom sources which were limited to one section.
- Fixed a bug where relational fields weren’t factoring in cross-site elements when enforcing their “Min Relations”, “Max Relations”, and “Validate related entries” settings. ([#13699](https://github.com/craftcms/cms/issues/13699))
- Fixed a bug where pagination wasn’t working for admin tables, if the `onQueryParams` callback method wasn’t set. ([#13677](https://github.com/craftcms/cms/issues/13677))
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4007,7 +4007,7 @@ ul.tree,
display: flex;
flex-direction: row;
align-items: center;
margin: calc(var(--s) * -1) calc(var(--xl) * -1);
margin: calc(var(--s) * -1) calc(var(--padding) * -1);

&:first-child {
border-radius: var(--large-border-radius) var(--large-border-radius) 0 0;
Expand Down Expand Up @@ -4060,7 +4060,7 @@ ul.tree,
flex-direction: row;
align-items: center;
position: relative;
padding: 0 24px;
padding: 0 var(--padding);
white-space: nowrap;
color: var(--tab-label-color);
height: 50px;
Expand Down Expand Up @@ -4565,6 +4565,14 @@ $min2ColWidth: 400px;
height: -webkit-fill-available; // h/t https://twitter.com/AllThingsSmitty/status/1254151507412496384
pointer-events: none;

&.so-lp {
position: absolute;
top: var(--m);
left: var(--m);
width: calc(100% - var(--m) * 2);
height: calc(100vh - var(--m) * 2);
}

body.has-debug-toolbar & {
height: calc(100vh - 42px);
}
Expand All @@ -4580,22 +4588,30 @@ $min2ColWidth: 400px;
overflow: hidden;
padding: 24px var(--padding);
pointer-events: all;
container-type: inline-size;

&.so-mobile {
--padding: 14px;
--neg-padding: -14px;
width: 100%;
height: 100%;
&.so-mobile,
&.so-lp {
width: 100% !important;
height: 100% !important;
left: 0;
transition: top linear 250ms;
will-change: top;
}

&.so-mobile {
--padding: 14px;
--neg-padding: -14px;
}

&:not(.so-mobile) {
border-radius: var(--large-border-radius);
}

&:not(.so-mobile):not(.so-lp) {
top: 8px;
width: calc(50% - 8px);
height: calc(100% - 16px);
border-radius: var(--large-border-radius);

@media screen and (prefers-reduced-motion: no-preference) {
body.ltr & {
Expand All @@ -4611,6 +4627,8 @@ $min2ColWidth: 400px;
}

& > .pane-header {
padding-left: var(--padding);
padding-right: var(--padding);
z-index: 2;

& > .so-toolbar {
Expand All @@ -4628,11 +4646,6 @@ $min2ColWidth: 400px;
}
}

&.so-mobile > .pane-header {
padding-left: 10px;
padding-right: 10px;
}

& > .so-body {
flex: 1;
margin: -24px var(--neg-padding) 0;
Expand Down Expand Up @@ -4730,7 +4743,7 @@ $min2ColWidth: 400px;
}
}

@media (min-width: 1536px) {
@container (width > 700px) {
.slideout {
&.has-sidebar {
.pane-header:not(.so-visible) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/assets/cp/src/css/_preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
background-color: var(--white);
z-index: 100;

header {
& > header {
padding: 8px 24px;
background-color: var(--gray-100);
box-shadow: 0 1px 0 transparentize($grey700, 0.8);
Expand Down Expand Up @@ -68,7 +68,7 @@

.lp-draghandle {
position: absolute;
z-index: 6;
z-index: 101;
top: 0;
@include right(-2px);
width: 4px;
Expand Down
8 changes: 8 additions & 0 deletions src/web/assets/cp/src/js/LivePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@ Craft.LivePreview = Garnish.Base.extend(
previewAction: null,
previewParams: {},
},

getActive: function () {
for (let preview of Craft.LivePreview.instances) {
if (preview.inPreviewMode) {
return preview;
}
}
},
}
);

Expand Down
12 changes: 10 additions & 2 deletions src/web/assets/cp/src/js/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,20 @@ Craft.Preview = Garnish.Base.extend(
instances: [],

refresh: function () {
for (preview of Craft.Preview.instances) {
for (let preview of Craft.Preview.instances) {
preview.updateIframe();
}
for (preview of Craft.LivePreview.instances) {
for (let preview of Craft.LivePreview.instances) {
preview.forceUpdateIframe();
}
},

getActive: function () {
for (let preview of Craft.Preview.instances) {
if (preview.isActive) {
return preview;
}
}
},
}
);
77 changes: 51 additions & 26 deletions src/web/assets/cp/src/js/Slideout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,11 @@
$container: null,
$shade: null,
isOpen: false,
useMobileStyles: null,

init: function (contents, settings) {
this.setSettings(settings, Craft.Slideout.defaults);

if (!Craft.useMobileStyles()) {
this.$shade = $('<div class="slideout-shade"/>').appendTo(
Garnish.$bod
);

if (this.settings.closeOnShadeClick) {
this.addListener(this.$shade, 'click', (ev) => {
ev.stopPropagation();
this.close();
});
}
}

this.$outerContainer = $('<div/>', {
class: 'slideout-container hidden',
});
Expand All @@ -42,10 +30,6 @@

Garnish.addModalAttributes(this.$outerContainer);

if (Craft.useMobileStyles()) {
this.$container.addClass('so-mobile');
}

Craft.trapFocusWithin(this.$container);

if (this.settings.autoOpen) {
Expand All @@ -62,17 +46,58 @@

this._cancelTransitionListeners();

// Move the shade + container to the end of <body> so they get the highest sub-z-indexes
if (this.$shade) {
this.$shade.appendTo(Garnish.$bod).show();
const activePreview =
Craft.Preview.getActive() || Craft.LivePreview.getActive();
this.useMobileStyles = activePreview || Craft.useMobileStyles();

this.$outerContainer.removeClass('so-mobile so-lp');
this.$container.removeClass('so-mobile so-lp');

if (activePreview) {
this.$outerContainer.addClass('so-lp');
this.$container.addClass('so-lp');
} else if (this.useMobileStyles) {
this.$container.addClass('so-mobile');
}

if (activePreview || !this.useMobileStyles) {
if (!this.$shade) {
this.$shade = $('<div class="slideout-shade"/>');

if (this.settings.closeOnShadeClick) {
this.addListener(this.$shade, 'click', (ev) => {
ev.stopPropagation();
this.close();
});
}
}

// Keep the shade + container to the end of <body> so they get the highest sub-z-indexes
if (activePreview) {
this.$shade.appendTo(activePreview.$editorContainer);
} else {
this.$shade.appendTo(Garnish.$bod);
}

this.$shade.show();
}

if (activePreview) {
this.$outerContainer.appendTo(activePreview.$editorContainer);
} else {
this.$outerContainer.appendTo(Garnish.$bod);
}

this.$outerContainer.appendTo(Garnish.$bod).removeClass('hidden');
this.$outerContainer.removeClass('hidden');

if (Craft.useMobileStyles()) {
this.$container.css('top', '100vh');
if (this.useMobileStyles) {
this.$container
.css('top', '100vh')
.css(Garnish.ltr ? 'left' : 'right', '');
} else {
this.$container.css(Garnish.ltr ? 'left' : 'right', '100vw');
this.$container
.css('top', '')
.css(Garnish.ltr ? 'left' : 'right', '100vw');
}

this.$container.one('transitionend.slideout', () => {
Expand Down Expand Up @@ -173,7 +198,7 @@
openPanels: [],
addPanel: function (panel) {
Craft.Slideout.openPanels.unshift(panel);
if (Craft.useMobileStyles()) {
if (panel.useMobileStyles) {
panel.$container.css('top', 0);
} else {
Craft.Slideout.updateStyles();
Expand All @@ -183,7 +208,7 @@
Craft.Slideout.openPanels = Craft.Slideout.openPanels.filter(
(m) => m !== panel
);
if (Craft.useMobileStyles()) {
if (panel.useMobileStyles) {
panel.$container.css('top', '100vh');
} else {
panel.$container.css(Garnish.ltr ? 'left' : 'right', '100vw');
Expand Down