Skip to content

Commit

Permalink
feat: Remove Wire Elements modal dependencies and import modal into t…
Browse files Browse the repository at this point in the history
…he project
  • Loading branch information
mckenziearts committed Aug 14, 2024
1 parent d4fca09 commit 75c0d2f
Show file tree
Hide file tree
Showing 25 changed files with 745 additions and 60 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ We send an email about 3-4 emails per year. Sometimes less.
- [Arthur Monney](https://github.com/mckenziearts)
- [Jean-Vincent QUILICHINI](https://github.com/sense)
- [FilamentPHP](https://filamentphp.com)
- [Wire Elements](https://wire-elements.dev)
- [All Contributors](../../contributors)

And a special thanks to [Caneco](https://twitter.com/caneco) for the logo ✨
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"spatie/laravel-livewire-wizard": "^2.2",
"stevebauman/location": "^7.2",
"spatie/laravel-package-tools": "^1.15",
"symplify/monorepo-builder": "^10.0",
"wire-elements/modal": "^2.0"
"symplify/monorepo-builder": "^10.0"
},
"autoload": {
"files": [
Expand Down
3 changes: 1 addition & 2 deletions packages/admin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"shopper/sidebar": "self.version",
"spatie/laravel-livewire-wizard": "^2.2",
"spatie/laravel-package-tools": "^1.15",
"stevebauman/location": "^7.2",
"wire-elements/modal": "^2.0"
"stevebauman/location": "^7.2"
},
"autoload": {
"files": [
Expand Down
1 change: 1 addition & 0 deletions packages/admin/config/components/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'components' => [
// 'search' => Components\Search::class,
'side-panel' => Components\SlideOverPanel::class,
'modal' => Components\Modal::class,
],

];
61 changes: 61 additions & 0 deletions packages/admin/public/shopper.css
Original file line number Diff line number Diff line change
Expand Up @@ -4657,11 +4657,21 @@ html {
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.translate-y-0 {
--tw-translate-y: 0px;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.translate-y-12 {
--tw-translate-y: 3rem;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.translate-y-4 {
--tw-translate-y: 1rem;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.-rotate-180 {
--tw-rotate: -180deg;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
Expand Down Expand Up @@ -5552,6 +5562,11 @@ html {
background-color: rgba(var(--gray-50), var(--tw-bg-opacity));
}

.bg-gray-500 {
--tw-bg-opacity: 1;
background-color: rgba(var(--gray-500), var(--tw-bg-opacity));
}

.bg-gray-700 {
--tw-bg-opacity: 1;
background-color: rgba(var(--gray-700), var(--tw-bg-opacity));
Expand Down Expand Up @@ -5806,6 +5821,10 @@ html {
padding: 2rem;
}

.p-10 {
padding: 2.5rem;
}

.px-0\.5 {
padding-left: 0.125rem;
padding-right: 0.125rem;
Expand Down Expand Up @@ -10538,6 +10557,11 @@ html.dark .shiki span {
margin-right: 0px;
}

.sm\:my-8 {
margin-top: 2rem;
margin-bottom: 2rem;
}

.sm\:ml-3 {
margin-left: 0.75rem;
}
Expand All @@ -10562,6 +10586,10 @@ html.dark .shiki span {
display: block;
}

.sm\:inline-block {
display: inline-block;
}

.sm\:flex {
display: flex;
}
Expand All @@ -10586,6 +10614,10 @@ html.dark .shiki span {
height: 2.5rem;
}

.sm\:h-screen {
height: 100vh;
}

.sm\:w-10 {
width: 2.5rem;
}
Expand All @@ -10598,6 +10630,10 @@ html.dark .shiki span {
width: auto;
}

.sm\:w-full {
width: 100%;
}

.sm\:w-screen {
width: 100vw;
}
Expand Down Expand Up @@ -10646,6 +10682,23 @@ html.dark .shiki span {
max-width: 20rem;
}

.sm\:translate-y-0 {
--tw-translate-y: 0px;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.sm\:scale-100 {
--tw-scale-x: 1;
--tw-scale-y: 1;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.sm\:scale-95 {
--tw-scale-x: .95;
--tw-scale-y: .95;
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.sm\:columns-\[--cols-sm\] {
-moz-columns: var(--cols-sm);
columns: var(--cols-sm);
Expand Down Expand Up @@ -10782,6 +10835,10 @@ html.dark .shiki span {
border-color: rgba(var(--gray-200), var(--tw-border-opacity));
}

.sm\:p-0 {
padding: 0px;
}

.sm\:p-10 {
padding: 2.5rem;
}
Expand Down Expand Up @@ -10866,6 +10923,10 @@ html.dark .shiki span {
text-align: left;
}

.sm\:align-middle {
vertical-align: middle;
}

.sm\:text-3xl {
font-size: 1.875rem;
line-height: 2.25rem;
Expand Down
148 changes: 147 additions & 1 deletion packages/admin/public/shopper.js

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions packages/admin/resources/js/components/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
const Modal = () => {
return {
show: false,
showActiveComponent: true,
activeComponent: false,
componentHistory: [],
modalWidth: null ,
listeners: [],
getActiveComponentModalAttribute(key) {
if (this.$wire.get('components')[this.activeComponent] !== undefined) {
return this.$wire.get('components')[this.activeComponent]['modalAttributes'][key];
}
},
closeModalOnEscape(trigger) {
if (this.getActiveComponentModalAttribute('closeOnEscape') === false) {
return;
}

let force = this.getActiveComponentModalAttribute('closeOnEscapeIsForceful') === true;
this.closeModal(force);
},
closeModalOnClickAway(trigger) {
if (this.getActiveComponentModalAttribute('closeOnClickAway') === false) {
return;
}

this.closeModal(true);
},
closeModal(force = false, skipPreviousModals = 0, destroySkipped = false) {
if(this.show === false) {
return;
}

if (this.getActiveComponentModalAttribute('dispatchCloseEvent') === true) {
const componentName = this.$wire.get('components')[this.activeComponent].name;
Livewire.dispatch('modalClosed', {name: componentName});
}

if (this.getActiveComponentModalAttribute('destroyOnClose') === true) {
Livewire.dispatch('destroyComponent', {id: this.activeComponent});
}

if (skipPreviousModals > 0) {
for (var i = 0; i < skipPreviousModals; i++) {
if (destroySkipped) {
const id = this.componentHistory[this.componentHistory.length - 1];
Livewire.dispatch('destroyComponent', {id: id});
}
this.componentHistory.pop();
}
}

const id = this.componentHistory.pop();

if (id && !force) {
if (id) {
this.setActiveModalComponent(id, true);
} else {
this.setShowPropertyTo(false);
}
} else {
this.setShowPropertyTo(false);
}
},
setActiveModalComponent(id, skip = false) {
this.setShowPropertyTo(true);

if (this.activeComponent === id) {
return;
}

if (this.activeComponent !== false && skip === false) {
this.componentHistory.push(this.activeComponent);
}

let focusableTimeout = 50;

if (this.activeComponent === false) {
this.activeComponent = id
this.showActiveComponent = true;
this.modalWidth = this.getActiveComponentModalAttribute('maxWidthClass');
} else {
this.showActiveComponent = false;

focusableTimeout = 400;

setTimeout(() => {
this.activeComponent = id;
this.showActiveComponent = true;
this.modalWidth = this.getActiveComponentModalAttribute('maxWidthClass');
}, 300);
}

this.$nextTick(() => {
let focusable = this.$refs[id]?.querySelector('[autofocus]');
if (focusable) {
setTimeout(() => {
focusable.focus();
}, focusableTimeout);
}
});
},
focusables() {
let selector = 'a, button, input:not([type=\'hidden\'], textarea, select, details, [tabindex]:not([tabindex=\'-1\']))'

return [...this.$el.querySelectorAll(selector)]
.filter(el => !el.hasAttribute('disabled'))
},
firstFocusable() {
return this.focusables()[0]
},
lastFocusable() {
return this.focusables().slice(-1)[0]
},
nextFocusable() {
return this.focusables()[this.nextFocusableIndex()] || this.firstFocusable()
},
prevFocusable() {
return this.focusables()[this.prevFocusableIndex()] || this.lastFocusable()
},
nextFocusableIndex() {
return (this.focusables().indexOf(document.activeElement) + 1) % (this.focusables().length + 1)
},
prevFocusableIndex() {
return Math.max(0, this.focusables().indexOf(document.activeElement)) - 1
},
setShowPropertyTo(show) {
this.show = show;

if (show) {
document.body.classList.add('overflow-y-hidden');
} else {
document.body.classList.remove('overflow-y-hidden');

setTimeout(() => {
this.activeComponent = false;
this.$wire.resetState();
}, 300);
}
},
init() {
this.modalWidth = this.getActiveComponentModalAttribute('maxWidthClass');

this.listeners.push(
Livewire.on('closeModal', (data) => {
this.closeModal(data?.force ?? false, data?.skipPreviousModals ?? 0, data?.destroySkipped ?? false);
})
);

this.listeners.push(
Livewire.on('activeModalComponentChanged', ({id}) => {
this.setActiveModalComponent(id);
})
);
},
destroy() {
this.listeners.forEach((listener) => {
listener();
});
}
};
}

export default Modal
2 changes: 2 additions & 0 deletions packages/admin/resources/js/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import SlideOverPanel from './components/panel'
import Modal from './components/modal'
import SelectTree from './components/select-tree'
import CodePreview from './components/code-preview'
import './components/sortable'

window.SlideOverPanel = SlideOverPanel
window.selectTree = SelectTree
window.codePreview = CodePreview
window.modal = Modal

document.addEventListener('alpine:init', () => {
const theme = localStorage.getItem('theme') ?? 'system'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class="flex cursor-pointer items-center px-2 py-3 hover:bg-gray-50 focus:bg-gray
value="{{ $product->id }}"
/>
</span>
<span class="flex flex-1 items-center justify-between">
<span class="block text-sm font-medium text-gray-700 dark:text-gray-300">
<span class="flex flex-1 items-center justify-between truncate">
<span class="block text-sm font-medium text-gray-700 truncate dark:text-gray-300">
{{ $product->name }}
</span>
<span class="flex items-center space-x-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@

@livewire(\Filament\Notifications\Livewire\Notifications::class)
@livewire(\Shopper\Livewire\Components\SlideOverPanel::class)
@livewire(\Shopper\Livewire\Components\Modal::class)

<div class="ui-modal">
@livewire(\LivewireUI\Modal\Modal::class)
</div>
@isset($filamentModal)
<div class="ui-modal">
{{ $filamentModal }}
</div>
@endisset

@filamentScripts

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/resources/views/components/modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'footerClasses' => 'p-4 sm:flex sm:p-6',
])

<div {{ $attributes->twMerge(['class' => 'h-full bg-white dark:bg-gray-800']) }}>
<div {{ $attributes->twMerge(['class' => 'h-full']) }}>
@if ($formAction)
{{-- format-ignore-start --}}<form wire:submit="{{ $formAction }}">{{-- format-ignore-end --}}
@endif
Expand Down
Loading

0 comments on commit 75c0d2f

Please sign in to comment.