npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@j0nz/nifty-layouts

v1.0.0

Published

Dynamic Vue Layouts for your SPA

Downloads

69

Readme

NiftyLayouts

Make Page Layouts for your Vue Single Page Apps easy.

Install & Setup

yarn add @j0nz/nifty-layouts
# Or
npm install @j0nz/nifty-layouts
import Vue from 'vue'
import App from './App.vue'
import router from './router' // vue-router configuration
import NiftyLayouts from '@j0nz/nifty-layouts'

const layout = new NiftyLayouts({
    /**
     * currentLayout is the 'finder' to determine which
     * layout should be used
     */
    currentLayout() {
        // 'this' is the root vue instance.
        // this.$store (if you have vuex installed)
        // this.$route
        // etc

        // Write whatever logic you need to find
        // the right page layout. Here I'm using a little
        // lookup table to match the routeName to the layout component.
        // Just make sure to return a string with the name of
        // layout you wish to be using
        return {
            "HomePage": "MainLayout",
            "AboutPage": "MainLayout",
            "SingleArticle": "ArticleLayout"
        }[this.$route.name] ?? 'MainLayout' // optional fallback, 'default route'
    },

    layouts: {
        // import your layout view files.
        // these are just regular vue components.
        // put a <slot /> wherever you want the main page
        // to be inserted.
        // e.g.
        // BasicLayout: { template: `<div> <slot /> </div>` }
        MainLayout: () => import('./layouts/MainLayout'),
        ArticleLayout: () => import('./layouts/ArticleLayout')
    }
})

/**
 * Now setup your base vue instance with vue-router
 * passing the 'layout' we built above.
 */
new Vue({
    el: '#app',
    router,
    layout, // <-- Add this
    render: (h) => h(App),
});
<template>
    <!-- App.vue -->
    <NiftyLayout />
</template>

And Viola! now you have super easy dynamic layouts in your SPA!

Transitions

If you want page transitions these are broken down into two levels. You can set 'route' level transitions for when you are transitioning between two pages that are using the same layout (only the parts that are actually changing will get animated, your e.g. persistent navbar will remain intact), and 'layout' level transitions. These occur when the full layout is swapped out. An example with these options could look something like this

<template functional>
    <NiftyLayout
        layout-transition-name="layout-transition"
        layout-transition-mode="out-in"
        route-transition-name="route-transition"
        route-transition-mode="out-in" />
</template>

<style>
/* Layout Transitions */
.layout-transition-leave-active,
.layout-transition-enter-active {
  transition: .3s;
}

.layout-transition-enter,
.layout-transition-leave-to {
    filter: blur(25px);
    opacity: 0;
}

.route-transition-enter-active,
.route-transition-leave-active {
  transition: .15s;
}
.route-transition-enter,
.route-transition-leave-to {
  opacity: 0;
}
</style>