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

[2.x] Upgrade VueJS to version 3 #666

Merged
merged 14 commits into from
Feb 15, 2021
Prev Previous commit
use the new Composition API for Dropdown and Modal components
  • Loading branch information
octoper committed Feb 13, 2021
commit e06cf8e4b409ca509471814c69db039c242cd184
28 changes: 10 additions & 18 deletions stubs/inertia/resources/js/Jetstream/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</template>

<script>
import {onMounted, onUnmounted, ref} from "vue";

export default {
props: {
align: {
Expand All @@ -42,30 +44,21 @@
}
},

data() {
return {
open: false
}
},
setup() {
let open = ref(false)

created() {
const closeOnEscape = (e) => {
if (this.open && e.keyCode === 27) {
this.open = false
if (open.value && e.keyCode === 27) {
open.value = false
}
}

document.addEventListener('keydown', closeOnEscape)
},
onMounted(() => document.addEventListener('keydown', closeOnEscape))
onUnmounted(() => document.removeEventListener('keydown', closeOnEscape))

unmounted() {
const closeOnEscape = (e) => {
if (this.open && e.keyCode === 27) {
this.open = false
}
return {
open,
}

document.removeEventListener('keydown', closeOnEscape)
},

computed: {
Expand All @@ -74,7 +67,6 @@
'48': 'w-48',
}[this.width.toString()]
},

alignmentClasses() {
if (this.align === 'left') {
return 'origin-top-left left-0'
Expand Down
31 changes: 18 additions & 13 deletions stubs/inertia/resources/js/Jetstream/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
</template>

<script>
export default {
import {onMounted, onUnmounted} from "vue";

export default {
emits: ['close'],

props: {
Expand All @@ -44,14 +46,6 @@
},
},

methods: {
close() {
if (this.closeable) {
this.$emit('close')
}
}
},

watch: {
show: {
immediate: true,
Expand All @@ -65,14 +59,25 @@
}
},

created() {
setup(props, {emit}) {
const close = () => {
if (props.closeable) {
emit('close')
}
}

const closeOnEscape = (e) => {
if (e.key === 'Escape' && this.show) {
this.close()
if (e.key === 'Escape' && props.show) {
close()
}
}

document.addEventListener('keydown', closeOnEscape)
onMounted(() => document.addEventListener('keydown', closeOnEscape))
onUnmounted(() => document.removeEventListener('keydown', closeOnEscape))

return {
close,
}
},

computed: {
Expand Down