Git Product home page Git Product logo

blazorsvg's Introduction

BlazorSvg

SVGs source generated into Blazor Component

Usage

  1. Add the project to your solution
  2. Add the attributes OutputItemType="Analyzer" ReferenceOutputAssembly="false" to the <ProjectReference> tag.
  3. Add the *.svg files to use to into the project directory somewhere.
  4. Include the *.svg files with one or more <AdditionalFiles Include=".../*.svg" /> tags.
  5. Create a file Icon.cs somewhere in the project, and add the following content:
public enum IconType // The enum type to use is specified by the `Type` property in the targeted class.
{
    Home, // => home.svg
    LayoutList, // => layout-list.svg
    Plus, // => plus.svg
    //NonExistant // Warning if matching <AdditionalFile> not found
}

[GenerateSvg(nameof(Type), nameof(AdditionalAttributes))] // Warning if properties not found
public partial class Icon : ComponentBase
{
    [Parameter] public IconType Type { get; set; } // Warning if not an enum type
    [Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, object>? AdditionalAttributes { get; set; }
}
  1. Use the component like so:
<div>
  <Icon Type="IconType.Home" title="This is my home" style="color: red;"/>
  Home
</div>

and it will be rendered as an inline <svg> based on the home.svg image:

<div>
  <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color: red;">
    <title>This is my home</tile>
    <path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
    <polyline points="9 22 9 12 15 12 15 22" />
  </svg>
  Home
</div>

blazorsvg's People

Contributors

mizardx avatar

Stargazers

 avatar  avatar  avatar

Watchers

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