No description
- CSS 50%
- HTML 33.9%
- JavaScript 9.4%
- C# 6.7%
| BlazorDemo.Frontend.InteractiveServer | ||
| BlazorDemo.Frontend.Shared.Ui | ||
| .editorconfig | ||
| .gitignore | ||
| BlazorDemo.sln | ||
| README.md | ||
Step 1 - Solution Structure + Frontend
CLI - Put the Project Structure in Place
Git
git init && dotnet new gitignore
Add Solution
dotnet new sln --format sln -n BlazorDemo
Add Blazor Server
dotnet new blazor -int Server -n BlazorDemo.Frontend.InteractiveServer
Add Shared UI Components
dotnet new razorclasslib -n BlazorDemo.Frontend.Shared.Ui
add reference to UI for InteractiveServer
dotnet reference add BlazorDemo.Frontend.Shared.Ui/BlazorDemo.Frontend.Shared.Ui.csproj --project BlazorDemo.Frontend.InteractiveServer/BlazorDemo.Frontend.InteractiveServer.csproj
Update sln
dotnet sln add **/*.csproj
Code - Use the Shared UI
BlazorDemo.Frontend.Shared.Ui/CustomLayout.razor
@inherits LayoutComponentBase
<div class="page">
<main>
<div class="top-row">
<h3 class="top-row">
Custom Layout
</h3>
<a class="px-2"
href="/">
Home
</a>
<a class="px-2"
href="weather">
Weather
</a>
</div>
<article class="customcontent px-2">
<div class="content-center">
@Body
</div>
</article>
</main>
</div>
<div id="blazor-error-ui"
data-nosnippet>
An unhandled error has occurred.
<a href="."
class="reload">
Reload
</a>
<span class="dismiss">🗙</span>
</div>
BlazorDemo.Frontend.Shared.Ui/CustomLayout.razor.css
.page {
position: relative;
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
flex: 1;
display: flex;
flex-direction: column;
}
.customcontent {
flex: 1;
display: flex;
justify-content: center; /* horizontal center */
align-items: flex-start; /* top instead of vertical center */
padding-top: 2rem; /* optional */
}
.content-center {
text-align: center;
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-start;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row :deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
blazor-error-ui {
color-scheme: light only;
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
box-sizing: border-box;
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
BlazorDemo.Frontend.InteractiveServer/Components/Routes.razor
...
<RouteView RouteData="routeData" DefaultLayout="typeof(CustomLayout)" />
...
BlazorDemo.Frontend.InteractiveServer/Components/_Imports.razor
...
@using BlazorDemo.Frontend.Shared.Ui
Bonus: Formatting
.editorconfig
[*]
# charset = utf-8-bom
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 100
tab_width = 4
end_of_line = lf
[*.razor]
resharper_html_attribute_style = first_attribute_on_single_line
resharper_html_attribute_indent = align
resharper_html_space_before_self_closing = true
[*.cs]
# attributes
resharper_place_attribute_on_same_line = never
# fluent call formatting
resharper_csharp_wrap_after_dot = true
resharper_csharp_wrap_chained_method_calls = chop_always
resharper_csharp_wrap_before_first_method_call = true
install resharper cli
dotnet tool install -g JetBrains.ReSharper.GlobalTools
use resharper cli
jb cleanupcode BlazorDemo.sln --profile="Built-in: Reformat Code"