Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Overview

Laravel Window Size and Breakpoints

Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT css.

An example to show the purpose of this package:

<?php

if(windowXs()) {
 //execute a tiny Eloquent query and return a minimalistic view
}
if(window2xl()) {
 //execute a huge Eloquent query and return a gigantic view
}

Software License Travis Total Downloads

Requirements

  • php 8
  • Laravel 8
  • IE11 not supported, (but you can update the blade component yourself :).

Do you use Livewire?

There is a Livewire version of this package. Link >>>

Description

The main purpose of this package is not to avoid duplicated html, but to avoid unnecessary server side code execution, just to render content that will never be seen.

  • Vanilla JS syncs the browsers inner width and height, in realtime (debounced 750ms), when the browser window is resized.
  • The corresponding Laravel controller will store the values to the Laravel Session.
  • The package has a config/breakpoints file where you set your breakpoints
  • The package provides multiple @blade directives and Laravel helpers()
  • You have access to the browser window width/height via session('windowW') and session('windowH')
  • You can change the config dynamically with Laravel Config::set(...)
  • The route is throttling the request 15:1. (The route is: /update-laravel-window-size)

Important note

It's important to understand the difference between the server side rendered breakpoints, that this package provides, and css media queries.

When using css, the content of the page will update in realtime as the user resizes the window, whereas this package debounces a network request and updates the page on the next page request.

It's important that you place the <x-window-size::save-to-session /> at first point of contact with the user, for your application to look its best. I have it in my app.blade.php and on the login/register pages.

Installation

composer require tanthammar/laravel-window-size

Publish config

php artisan vendor:publish --tag=laravel-window-size

The default settings are based on TailwindCSS breakpoints

'window-width' => [
    // 0 = undefined|false
    // @windowXs (>= 1px && < Sm)
    'Sm' => 640, // => @windowSm (>= 640px && < Md)
    'Md' => 768, // => @windowMd (>= 768px && < Lg)
    'Lg' => 1024, // => @windowLg (>= 1024px && < Xl)
    'Xl' => 1280, // => @windowXl (>= 1280px && < 2xl)
    '2xl' => 1536, // => @window2xl (>= 1536px)
],

Add the component to your layout

  • Add this to all layouts where you want to keep track of the browser window size.
  • You will have access to the browser window width/height via session('windowW') and session('windowH')

Example: app.blade.php

<x-window-size::save-to-session />

Blade directives

@elsif..., @else..., @end..., @unless... and @endif works with all the directives. Explanation in Laravel docs.

//Browser width, with example values
@windowWidthLessThan(400)
@windowWidthGreaterThan(399)
@windowWidthBetween(400, 1500)

//Browser height, with example values
@windowHeightLessThan(500)
@windowHeightGreaterThan(499)
@windowHeightBetween(400, 900)

//Breakpoints based on config values
@windowXs()
@windowSm()
@windowMd()
@windowLg()
@windowXl()
@window2xl()

Example

@windowXs()
<div>This window is extra small</div>
@endif

@window2xl()
<div>This window is very large</div>
@endif

Helpers

Same name as Blade directives

//Browser width, with example values
windowWidthLessThan(400)
windowWidthGreaterThan(399)
windowWidthBetween(400, 1500)

//Browser height, with example values
windowHeightLessThan(500)
windowHeightGreaterThan(499)
windowHeightBetween(400, 900)

//Breakpoints based on config values
windowXs()
windowSm()
windowMd()
windowLg()
windowXl()
window2xl()

Example php

if(windowXs()) {
 //execute a tiny Eloquent query and return a minimalistic view
}
if(window2xl()) {
 //execute a huge Eloquent query and return a gigantic view
}

Blade directives test component

Add this to any blade view to test the blade directives

<x-window-size::test-windowsize />

πŸ’¬ Let's connect

Credits

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Scripts, helpers and configs to make hacking on Synack less painful

SynackMoPleasure Scripts, helpers and configs to make hacking on Synack less painful TuPOC HTTP OOB PHP Logger This PHP script was created to test/exp

Automatically load your helpers in your laravel application.

Laravel AutoHelpers Automatically load your helpers in your laravel application. Installation You can install the package via composer: composer requi

Laravel translation helpers
Laravel translation helpers

Laravel Translator Installation and setup Installation You can install the package via composer: composer require isaeken/laravel-translator Setup You

Laravel Helpers Automatic Loading System

About Laravel Helpers Automatic Load Laravel Helpers Automatic Loading System Doc: Copy the Helpers folder and paste it on app folder Then Go To app/P

Laravel magical helpers such as Controllers / Requests / Models

Laravel Magic provides Abstract Controller, Model, generic Request, Traits, Exceptions and various middlewares in order to generate very easily and quickly API resources from scratch.

Because I can never remember exactly how to autoload my helpers.php file.

Laravel Helpers File (helpers.php) I add a app/helpers.php file to every project for any custom helpers I might want to create. Everytime I go to add

A Laravel Code Generator based on your Models using Blade Template Engine
A Laravel Code Generator based on your Models using Blade Template Engine

Laravel Code Generator is a PHP Laravel Package that uses Blade template engine to generate code for you. The difference between other code generators

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

How to get cookies from users' browser and send the information to your email address and telegram bot

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Comments
  • `route:cache` and `config:cache` throw error

    `route:cache` and `config:cache` throw error

    After installing the package (in a brand new project) I get the following error when running php artisan route:cache or php artisan config:cache.

    seb@MBP% php artisan route:cache                         
    Route cache cleared!
    
       Symfony\Component\ErrorHandler\Error\FatalError 
    
      Cannot redeclare Tanthammar\LivewireWindowSize\windowWidthLessThan() (previously declared in /Users/seb/dev/twist-gui/vendor/tanthammar/livewire-window-size/src/LivewireWindowSizeServiceProvider.php:89)
    
      at vendor/tanthammar/livewire-window-size/src/LivewireWindowSizeServiceProvider.php:89
         85β–• 
         86β–•     protected function registerHelpers()
         87β–•     {
         88β–•         if (!function_exists('windowWidthLessThan')) {
      ➜  89β–•             function windowWidthLessThan(int $value): bool
         90β–•             {
         91β–•                 return session('windowW') < $value;
         92β–•             }
         93β–•         }
    
    
       Symfony\Component\ErrorHandler\Error\FatalError 
    

    Same goes for livewire-window-size.

    opened by SebastianSchoeps 3
  • Remove base controller dependency

    Remove base controller dependency

    Currently the LaravelWindowsSizeController extends the Laravel base controller. This does not work in projects where the base controller is not at App\Http\Controllers\Controller. The good news is that the base controller's function are not utilized at all, so we can just remove it.

    Has been tested and works!

    opened by joschua-nanuc 0
Releases(1.2.0)
Owner
Tina Hammar
Laravel packages
Tina Hammar
Source code behind the Laracasts Larabit: Creating and Using Custom Blade Directives

This is the source code behind the Laracasts Larabit: Creating and Using Custom Blade Directives, and features all of the files and code available in that video.

Andrew Schmelyun 1 Nov 12, 2021
Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

Blade UI Kit 1.2k Jan 5, 2023
Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline.

Blade Snip Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline: <div class="products"> @snip('pr

Jack Sleight 18 Dec 4, 2022
Use Blade templates without the full Laravel framework

blade Use Laravel Blade templates as a standalone component without the full Laravel framework Full documentation is available at http://duncan3dc.git

Craig Duncan 138 Dec 7, 2022
CSS Exfil helper script to generate injected CSS and corresponding HTML (inspired by mike gualtieri)

The PoC-CSS Exfill Basic Keylogger First of all i was developing bot stuff and i seen attribute=value] [target=_blank] in source code of website. This

Ahsen 6 Apr 2, 2022
Collection of agnostic PHP Functions and helpers with zero dependencies to use as foundation in packages and other project

Collection of agnostic PHP Functions and helpers This package provides a lot of very usefull agnostic helpers to use as foundation in packages and oth

padosoft 54 Sep 21, 2022
This package provides a console command to convert dynamic JS/CSS to static JS/CSS assets.

Laravel Nova Search This package provides a console command to convert dynamic JS/CSS to static JS/CSS assets. Requirements laravel-mix v6.0+ php 7.3+

Akki Khare 3 Jul 19, 2022
πŸ”Œ Convert Bootstrap CSS code to Tailwind CSS code

Tailwindo This tool can convert Your CSS framework (currently Bootstrap) classes in HTML/PHP (any of your choice) files to equivalent Tailwind CSS cla

Awssat 938 Dec 24, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).

SEO Helper By ARCANEDEVΒ© SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization). Feel free to check out the rele

ARCANEDEV 301 Nov 25, 2022