Giter Site home page Giter Site logo

anu-prakash-dev / blazorscopedcss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexandrereyes/blazorscopedcss

0.0 0.0 0.0 6.86 MB

Blazor Scoped Css is a library to fill the css gap in current Blazor version

License: GNU General Public License v3.0

JavaScript 0.25% C# 92.85% CSS 2.11% HTML 4.78%

blazorscopedcss's Introduction

Blazor Scoped Css

BlazorScopedCss is a library to fill the css gap in current Blazor version. This is how it works: Hot it works

How does it work in razor files?

image

Getting started

  1. Dependency Injection time: go to Startup.cs ConfigureServices and add the line bellow: services.AddBlazorScopedCss(Assembly.GetExecutingAssembly());

  2. Go to the main cshtml or html file and add the <style id="scopedCss"></style tag inside html->head, this is the place where BlazorScopedCss will render the styles

  3. In the same file, add the BlazorScopedCss js: <script src="/_content/BlazorScopedCss/jsInterop.js"></script>

  4. Time to add the css! In the folder where your component or page is located, add the css file, FetchData.razor.css for example (Visual Studio will nest the file inside .razor, awesome!)

  5. Inside de CSS, add some classes:

.myFirstScopedComponent-scopeId {
    background-color: red;
}

.mySecondScopedComponent-scopeId {
    background-color: blue;
}

This library will replace -scopeId by the componentId, so...if you don't put this keyword it will not work!

  1. Select the css in solution explorer and press f4 (properties), change the Build Action to Embedded resource

  2. Ok, now go to your .razor page or component, and add BazorScopedCss:

<BlazorScopedCss.ScopedStyle EmbeddedStylePath="FetchData.razor.css"
                             Parent="this"
                             AfterInit="StateHasChanged"
                             @ref="scopedStyle" />

@if (scopedStyle?.IsComplete ?? false)
{
    <h1 class="@scopedStyle.CssScopedClasses(scopedCssClasses: "myFirstScopedComponent")">Weather forecast</h1>

    <p class="@scopedStyle.CssClassesMixed(nonScopedCssClasses: "display-1", scopedCssClasses: "mySecondScopedComponent")">This component demonstrates fetching data from a service.</p>
}

That's it! Watch HTML <style id="scopedCss"> tag to see the magic :)

Install

https://www.nuget.org/packages/BlazorScopedCss

blazorscopedcss's People

Contributors

alexandrereyes 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.