Skip to content

Commit

Permalink
Global slideover (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Dec 11, 2024
1 parent 8330810 commit adb82f3
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
19 changes: 19 additions & 0 deletions resources/js/components/GlobalSlideover.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
export default {
props: {
title: String,
position: String,
content: String,
},
render() {
return this.$scopedSlots.default(this)
},
methods: {
open() {
this.$root.$emit('global-slideover-open', { content: this.content, title: this.title, position: this.position })
},
},
}
</script>
25 changes: 25 additions & 0 deletions resources/js/components/GlobalSlideoverInstance.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
export default {
render() {
return this.$scopedSlots.default(this)
},
data() {
return {
content: '',
title: '',
position: 'left',
}
},
mounted() {
this.$root.$on('global-slideover-open', (data) => {
this.content = data.content || ''
this.title = data.title || ''
this.position = data.position || 'left'
this.$el.querySelector('#slideover-global').checked = true
})
},
}
</script>
4 changes: 4 additions & 0 deletions resources/js/vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Vue.component('graphql-mutation', graphqlMutation)

import notifications from './components/Notifications/Notifications.vue'
Vue.component('notifications', notifications)
import globalSlideover from './components/GlobalSlideover.vue'
Vue.component('global-slideover', globalSlideover)
import globalSlideoverInstance from './components/GlobalSlideoverInstance.vue'
Vue.component('global-slideover-instance', globalSlideoverInstance)

import images from './components/Product/Images.vue'
Vue.component('images', images)
Expand Down
25 changes: 25 additions & 0 deletions resources/views/components/slideover/global.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{--
This is a wrapper for the global slideover. Use this as much as possible to reduce the amount of html elements in the DOM.
Standard usage may look like this:
```
<x-rapidez::slideover.global :title="__('My slideover')">
<x-slot:label class="rounded p-3 border">
Click me
</x-slot:label>
<div class="font-semibold">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</x-rapidez::slideover.global>
```
--}}

@props(['title', 'position' => 'left'])
@slots(['label'])

<global-slideover title="{{ $title }}" position="{{ $position }}" content="{{ $slot->toHtml() }}" v-slot="slideover">
<label {{ $label->attributes->class('global-slideover-label cursor-pointer') }} v-on:click="slideover.open">
{{ $label }}
</label>
</global-slideover>
2 changes: 2 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
</main>
@includeWhen(!request()->is('checkout'), 'rapidez::layouts.partials.footer')
@includeWhen(request()->is('checkout'), 'rapidez::layouts.checkout.footer')

@include('rapidez::layouts.partials.global-slideover')
@stack('page_end')
</div>

Expand Down
14 changes: 14 additions & 0 deletions resources/views/layouts/partials/global-slideover.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<global-slideover-instance>
<template v-slot="{ content, title, position }" v-cloak>
<x-rapidez::slideover
id="slideover-global"
v-bind:class="{ '-right-full peer-checked:right-0 !left-auto': (position ?? 'left') === 'right' }"
>
<x-slot:title>
<div v-html="title"></div>
</x-slot:title>

<div v-html="content"></div>
</x-rapidez::slideover>
</template>
</global-slideover-instance>

0 comments on commit adb82f3

Please sign in to comment.