Skip to content

Commit 300f42b

Browse files
Added icon maker demo.
1 parent 527c1e8 commit 300f42b

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/IconMaker"
2+
@inject IJSRuntime JSRuntime
3+
4+
<button class="btn btn-primary" @onclick=Copy>Copy SVG to clipboard</button>
5+
<div style="display:flex;flex-direction:row;width:100%;">
6+
<textarea @bind="Input" @bind:event="oninput" style="width:100%;" />
7+
<div style="height:80vh;aspect-ratio:1">
8+
<SVGEditor @ref=sVGEditor
9+
Input=@Input
10+
InputUpdated="(string s) => { Input = s; StateHasChanged(); }"
11+
InputRendered="InputHasBeenRendered"
12+
DisableZoom=true
13+
DisablePanning=true
14+
SnapToInteger=true
15+
/>
16+
</div>
17+
</div>
18+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.JSInterop;
2+
3+
namespace KristofferStrube.Blazor.SVGEditor.WasmExample.Pages;
4+
public partial class IconMaker
5+
{
6+
protected SVGEditor sVGEditor = default!;
7+
8+
protected string Input = "";
9+
10+
protected void InputHasBeenRendered()
11+
{
12+
double newScale = 1 / (16 / sVGEditor.BBox.Height);
13+
if (sVGEditor.Scale != newScale)
14+
{
15+
sVGEditor.Scale = newScale;
16+
StateHasChanged();
17+
}
18+
}
19+
20+
public async Task Copy()
21+
{
22+
string SVG = $"""
23+
<svg class="bi" width="30" height="30" viewBox="0 0 16 16">
24+
{Input}
25+
</svg>
26+
""";
27+
28+
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", SVG);
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
::deep .anchor-inner-thin {
2+
stroke-width: 2;
3+
r: 12
4+
}
5+
6+
::deep .anchor-inner-thick {
7+
stroke-width: 4;
8+
r: 12
9+
}
10+
11+
::deep .anchor-outer-thin {
12+
stroke-width: 4;
13+
r: 14
14+
}
15+
16+
::deep .anchor-outer-thick {
17+
stroke-width: 6;
18+
r: 16
19+
}
20+
21+
::deep .svg-editor {
22+
background-color: #f5f5f5;
23+
}

samples/KristofferStrube.Blazor.SVGEditor.WasmExample/Shared/NavMenu.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
<span class="oi oi-play-circle" aria-hidden="true"></span> Animation
3838
</NavLink>
3939
</li>
40+
<li class="nav-item px-3">
41+
<NavLink class="nav-link" href="IconMaker">
42+
<svg class="bi" width="30" height="30" viewBox="0 0 16 16">
43+
<polygon stroke="#FFFFFF" stroke-width="2" fill="none" points="2,6 6,6 8,2 10,6 14,6 11,9 12,14 8,11 4,14 5,9" stroke-linejoin="round"></polygon>
44+
</svg>
45+
Icon Maker
46+
</NavLink>
47+
</li>
4048
</ul>
4149
</div>
4250

samples/KristofferStrube.Blazor.SVGEditor.WasmExample/Shared/NavMenu.razor.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
top: -2px;
1919
}
2020

21+
.bi {
22+
display: inline-block;
23+
position: relative;
24+
width: 1.25rem;
25+
height: 1.25rem;
26+
margin-right: 0.75rem;
27+
top: -1px;
28+
background-size: cover;
29+
}
30+
2131
.nav-item {
2232
font-size: 0.9rem;
2333
padding-bottom: 0.5rem;

0 commit comments

Comments
 (0)