-
Notifications
You must be signed in to change notification settings - Fork 591
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
Pro 6518 mobile preview #4720
Open
haroun
wants to merge
36
commits into
main
Choose a base branch
from
pro-6518-mobile-preview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pro 6518 mobile preview #4720
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
38e5020
experiment with mobile preview
haroun be578e8
fix lint issue
haroun 60de087
add media to container query loader
haroun 4c20516
clean up media to container queries loader
haroun 62fd03a
use apostrophe options to toggle mobile preview
haroun c9579c8
add breakpoints support
haroun 895fb42
experiment with screen options
haroun 7db9493
refactor as device preview mode to avoid name conflicts with preview …
haroun 8991290
set todos
haroun 6806ded
rename devicePreview into devicePreviewMode and validate screens
haroun 174c897
set active style
haroun 4573f98
set active style and keyboard shortcuts
haroun e52a478
restore previous filename logic
haroun bf528e8
revert plugins
haroun ca2bb37
note about deep merge
haroun c296953
Merge branch 'main' into pro-6518-mobile-preview
haroun e6e4cd1
update changelog
haroun 52c8cb3
remove test styles
haroun 129cc3a
fix mixed declaration warnings
haroun 0ac0e49
translate device
haroun f7eaa02
translate additional keys in keyboard shortcut label
haroun 070fc88
add transform function
haroun 1329f7e
explain available transform options
haroun 64e6c27
up to 9 shortcuts
haroun 5b8b7a3
Merge branch 'main' into pro-6518-mobile-preview
haroun b2c051a
use flexbox
haroun ec60630
rename devicePreviewMode options
haroun bffb915
add label
haroun c93db00
fix lint issue
haroun 180a12d
support preview mode background
haroun 3b887ff
style tweaks
stuartromanek 05f0f75
lint
stuartromanek 0d072dd
save device preview state, transition only for non-resizable containers
haroun d08b8fd
save device preview mode state inside own component
haroun f86f60a
update background on body
haroun 7da9500
keep state
haroun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
154 changes: 154 additions & 0 deletions
154
modules/@apostrophecms/admin-bar/ui/apos/components/TheAposContextDevicePreviewMode.vue
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,154 @@ | ||
<template> | ||
<div | ||
data-apos-test="devicePreviewMode" | ||
class="apos-admin-bar__device-preview-mode" | ||
> | ||
<component | ||
:is="'AposButton'" | ||
v-for="(screen, name) in screens" | ||
:key="name" | ||
:data-apos-test="`devicePreviewMode:${name}`" | ||
:modifiers="['small', 'no-motion']" | ||
:label="screen.label" | ||
:title="$t(screen.label)" | ||
:icon="screen.icon" | ||
:icon-only="true" | ||
type="subtle" | ||
class="apos-admin-bar__device-preview-mode-button" | ||
:class="{ 'apos-is-active': mode === name }" | ||
@click="toggleDevicePreviewMode({ mode: name, label: screen.label, width: screen.width, height: screen.height })" | ||
/> | ||
</div> | ||
</template> | ||
<script> | ||
|
||
export default { | ||
name: 'TheAposContextDevicePreview', | ||
props: { | ||
// { screenName: { label: string, width: string, height: string, icon: string } } | ||
screens: { | ||
type: Object, | ||
validator(value, props) { | ||
return Object.values(value).every(screen => | ||
typeof screen.label === 'string' && | ||
typeof screen.width === 'string' && | ||
typeof screen.height === 'string' && | ||
typeof screen.icon === 'string' | ||
); | ||
}, | ||
default: () => { | ||
return {}; | ||
} | ||
}, | ||
resizable: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
emits: [ 'switch-device-preview-mode', 'reset-device-preview-mode' ], | ||
data() { | ||
return { | ||
mode: null | ||
}; | ||
}, | ||
mounted() { | ||
apos.bus.$on('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode); | ||
|
||
const state = this.loadState(); | ||
if (state.mode) { | ||
this.toggleDevicePreviewMode(state); | ||
} | ||
}, | ||
unmounted() { | ||
apos.bus.$off('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode); | ||
}, | ||
methods: { | ||
switchDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) { | ||
document.querySelector('body').setAttribute('data-device-preview-mode', mode); | ||
document.querySelector('[data-apos-refreshable]').setAttribute('data-resizable', this.resizable); | ||
document.querySelector('[data-apos-refreshable]').setAttribute('data-label', this.$t(label)); | ||
document.querySelector('[data-apos-refreshable]').style.width = width; | ||
document.querySelector('[data-apos-refreshable]').style.height = height; | ||
this.mode = mode; | ||
this.$emit('switch-device-preview-mode', { | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
this.saveState({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
}, | ||
toggleDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) { | ||
if (this.mode === mode || mode === null) { | ||
document.querySelector('body').removeAttribute('data-device-preview-mode'); | ||
document.querySelector('[data-apos-refreshable]').removeAttribute('data-resizable'); | ||
document.querySelector('[data-apos-refreshable]').removeAttribute('data-label'); | ||
document.querySelector('[data-apos-refreshable]').style.removeProperty('width'); | ||
document.querySelector('[data-apos-refreshable]').style.removeProperty('height'); | ||
this.mode = null; | ||
this.$emit('reset-device-preview-mode'); | ||
|
||
return; | ||
} | ||
|
||
this.switchDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
}, | ||
loadState() { | ||
return JSON.parse(sessionStorage.getItem('aposDevicePreviewMode') || '{}'); | ||
}, | ||
saveState({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) { | ||
sessionStorage.setItem( | ||
'aposDevicePreviewMode', | ||
JSON.stringify({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) | ||
); | ||
} | ||
} | ||
}; | ||
</script> | ||
<style lang="scss" scoped> | ||
.apos-admin-bar__device-preview-mode { | ||
display: flex; | ||
gap: $spacing-half; | ||
margin-left: $spacing-double; | ||
} | ||
|
||
.apos-admin-bar__device-preview-mode-button { | ||
&.apos-is-active { | ||
color: var(--a-text-primary); | ||
text-decoration: none; | ||
background-color: var(--a-base-10); | ||
border-radius: var(--a-border-radius); | ||
outline: 1px solid var(--a-base-7); | ||
} | ||
} | ||
</style> |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems more UX-friendly to me