]> _ Git - pmi.git/commitdiff
WIP #2738 @8
authorStephen Cameron <s@hybridvision.net>
Wed, 5 Jun 2019 20:16:00 +0000 (22:16 +0200)
committerStephen Cameron <s@hybridvision.net>
Wed, 5 Jun 2019 20:16:00 +0000 (22:16 +0200)
package.json
resources/js/app.js
resources/js/components/Search.vue
resources/views/partials/header.blade.php
yarn.lock

index 7d4bd8a29811dbbee9e5a33397211714d902a9fa..6bfb5aa102e84042a56a2eed3c708b7637426344 100644 (file)
@@ -21,6 +21,7 @@
         "lodash": "^4.17.5",
         "lost": "^8.3.1",
         "popper.js": "^1.12",
+        "portal-vue": "^2.1.5",
         "resolve-url-loader": "^2.3.1",
         "rupture": "^0.7.1",
         "stylus": "acidjazz/stylus#dev",
index 048f8d465c636337e377744d082c82957fe2039a..1f9f6c53f488c1b7aec26ca42d32043977a3df83 100644 (file)
@@ -9,6 +9,9 @@ require('./bootstrap');
 
 window.Vue = require('vue');
 
+import PortalVue from 'portal-vue';
+Vue.use(PortalVue);
+
 /**
  * The following block of code may be used to automatically register your
  * Vue components. It will recursively scan this directory for the Vue
index 34ce91cdf750647ae0686aeafeda48eb980b4db7..9fc256d4318029793ca03361194a5688b9c0e8c3 100644 (file)
@@ -1,22 +1,25 @@
 <template>
-    <div class="bg-white" v-show="visible">
-        <div class="header-search-box container py-3">
+    <div class="bg-white">
+
+        <!-- Trigger Link that will appear inside the nav portal -->
+        <portal to="nav-search-toggle">
+            <a href="#" class="text-white hover:text-blue" @click.prevent="toggleVisibility">
+                <slot name="link"></slot>
+            </a>
+        </portal>
+
+
+        <div class="header-search-box container py-3" v-show="visible">
             <form action="/search/" method="get" class="flex justify-between items-center">
                 <input class="pl-2 -ml-2 py-2 font-display text-2xl flex-grow appearance-none focus:outline-none focus:bg-grey-100"
                        type="text"
                        name="search"
                        autocomplete="off"
-                       placeholder="Search...">
+                       tabindex="-1"
+                       ref="searchInput"
+                       :placeholder="placeholder">
                 <button class="ml-4 p-3 -mr-3 appearance-none focus:outline-none focus:bg-grey-100">
-
-                    <!-- Todo: work out the best way to inline SVG files in vue components (via props, slots etc?) -->
-                    <!--
-                        See: https://gist.github.com/calebporzio/623c536f7fff77861b8a37ec11a1d3da
-                        and https://stackoverflow.com/questions/44695560/how-can-i-import-a-svg-file-to-a-vue-component
-                    -->
-
-                    <!-- @svg('search', 'fill-current text-navy w-6 h-6') -->
-
+                    <slot name="button"></slot>
                 </button>
             </form>
         </div>
     export default {
 
         data() {
-            return {}
+            return {
+                visible: false
+            }
         },
 
-        mounted() {
-            console.log('Search component mounted.')
+        props: {
+            placeholder: {
+                type: String,
+                default: 'Search...'
+            }
         },
-
-        props: ['visible'],
         methods: {
-
+            toggleVisibility() {
+                this.visible = !this.visible;
+
+                // When visible, auto focus cursor into search field
+                if (this.visible) {
+                    this.$nextTick(() => this.$refs.searchInput.focus())
+                }
+            }
         }
     }
 </script>
index 60f5fe32ce9b9c5286197c392bc1cf84f1208f34..1050d4a7021f54ee9ee473db3d87a211b6bc27d6 100644 (file)
 
         <div class="nav mx-auto flex items-center">
             @include('partials.nav')
-            <a class="text-white hover:text-blue" href="#" @click.prevent="showSearchBar = !showSearchBar">
-                @svg('search', 'nav-search-icon')
-            </a>
+            <portal-target name="nav-search-toggle" slim></portal-target>
         </div>
 
+        {{-- TODO: Make a Vue component for the cart + popout using portals and slots (see Search.vue) --}}
+
         <div class="cart-header text-right flex items-center cursor-pointer hover:text-blue" @click="openCart">
             @include('partials.cart')
         </div>
 
 </header>
 
-<search :visible="showSearchBar"></search>
+<search placeholder="{{ __('Search...') }}">
+    <template v-slot:link>
+        @svg('search')
+    </template>
+    <template v-slot:button>
+        @svg('search', 'fill-current text-navy w-6 h-6')
+    </template>
+</search>
\ No newline at end of file
index 1797b3abcc664a46c47697bf2cfddc82d5f17e8a..1be293468abb70f186266cc0f89be0f26afa92f3 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -3047,6 +3047,7 @@ html-entities@^1.2.0:
 html-loader@^0.5.5:
   version "0.5.5"
   resolved "https://registry.yarnpkg.com/html-loader/-/html-loader-0.5.5.tgz#6356dbeb0c49756d8ebd5ca327f16ff06ab5faea"
+  integrity sha512-7hIW7YinOYUpo//kSYcPB6dCKoceKLmOwjEMmhIobHuWGDVl0Nwe4l68mdG/Ru0wcUxQjVMEoZpkalZ/SE7zog==
   dependencies:
     es6-templates "^0.2.3"
     fastparse "^1.1.1"
@@ -4655,6 +4656,11 @@ popper.js@^1.12:
   version "1.14.7"
   resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.7.tgz#e31ec06cfac6a97a53280c3e55e4e0c860e7738e"
 
+portal-vue@^2.1.5:
+  version "2.1.5"
+  resolved "https://registry.yarnpkg.com/portal-vue/-/portal-vue-2.1.5.tgz#ecd0997cb32958205151cb72f40fd4f38d175e5c"
+  integrity sha512-vZmdMn0mOo7puvxoMQ5zju6S29aFD+9yygJxyWQtPaMXS9xunAeoYdnx6yzfL9J8HD8pMZYgSieEIbioAKhrSQ==
+
 portfinder@^1.0.9:
   version "1.0.20"
   resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.20.tgz#bea68632e54b2e13ab7b0c4775e9b41bf270e44a"