GithubHelp home page GithubHelp logo

jxdtech / blazorviewport Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 30 KB

Monitors viewport resize and reports breakpoint changes

Home Page: https://github.com/JxdTech/BlazorViewport

License: MIT License

C# 69.61% HTML 4.03% JavaScript 26.36%
blazor blazorserver breakpoint breakpoint-detection breakpoints dotnet-core

blazorviewport's Introduction

BlazorViewport

  • Monitors viewport resize and reports breakpoint changes.


1. Install Package

dotnet add package JxdTech.BlazorViewport 

2. _imports.razor

@using BlazorViewport 

3. App.razor

// Wrap Contents of App.razor with Viewport
<Viewport>
    <Router AppAssembly="@typeof(App).Assembly">
        ...
    </Router>
</Viewport>

4. Index.razor / Any Component

@inherits ViewportComponentBase
  • contains Viewport:IViewport
  • Viewport has 2 properties
    1. bool IsRendered { get; }
      • Changes to true After JSRuntime is available and event listeners are registered
    2. Breakpoint Breakpoint { get; }
      • provides current breakpoint

5. (optional) Customize ViewportOptions in appsettings.json

  • Default ViewportOptions

     "ViewportOptions": {
    
         "EnableLogging": false,
    
         "NotifyOnInitialize": true,
    
         "Breakpoints" : {
             "5" : 1400, // Xxl
             "4" : 1200, // Xl
             "3" : 992, // Lg
             "2" : 768, // Md
             "1" : 576, // Sm
             "0" : 0 // Xs
         }
     }
    


Demo Application

View Demo app for simple example

  1. App.razor
    • Uses Viewport
  2. Pages/Index.razor
    • implements ViewportComponentBase
  3. appsettings.json
    • configures ViewportOptions
  4. appsettings.Development.json
    • configures Development ViewportOptions

blazorviewport's People

Contributors

jxdtech avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.