commit 2d033da6366888edbddb496eae32ad49bde3df07 Author: honzapatCZ Date: Wed Mar 8 17:00:38 2023 +0100 Create NejBlazor diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e81b9ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,253 @@ +#gitignore for .NET shared projects +# Visual Studio code coverage results +*.coverage +*.coveragexml + +#Object +obj/ + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/DataTable/DataTable.razor b/DataTable/DataTable.razor new file mode 100644 index 0000000..9dadc31 --- /dev/null +++ b/DataTable/DataTable.razor @@ -0,0 +1,58 @@ +@namespace Nejcraft.Shared +@using Nejcraft.Shared.Parts.ButtonParts +@using Nejcraft.Shared.Parts.InputParts +@using Nejcraft.Shared.Parts + +@typeparam TItem + +@inherits NejComponentBase + +
+ + + + + + @ChildContent + + + + + @foreach (TItem it in Data ?? Array.Empty()) + { + + + @foreach (DataTableCol tab in Columns ?? new List>()) + { + + @tab.ChildContent(it) + + } + + } + + + +
+ + + +@code { + + [Parameter] + public IEnumerable? Data { get; set; } + + private List> Columns { get; set; } = new List>(); + + [Parameter] + public RenderFragment? ChildContent { get; set; } + + [Parameter] + public Func? Key { get; set; } + + public void AddColumn(DataTableCol item) + { + Columns.Add(item); + InvokeAsync(StateHasChanged); + } +} \ No newline at end of file diff --git a/DataTable/DataTableCol.razor b/DataTable/DataTableCol.razor new file mode 100644 index 0000000..b8a73b5 --- /dev/null +++ b/DataTable/DataTableCol.razor @@ -0,0 +1,23 @@ +@namespace Nejcraft.Shared +@typeparam TItem +@inherits Nejcraft.Shared.Parts.NejComponentBase + + + @Title + + +@code { + [Parameter] + public string Title { get; set; } = default!; + + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [CascadingParameter] + public DataTable Table { get; set; } = default!; + + protected override void OnInitialized(){ + base.OnInitialized(); + Table.AddColumn(this); + } +} \ No newline at end of file diff --git a/NejBlazor.csproj b/NejBlazor.csproj new file mode 100644 index 0000000..3c48a8b --- /dev/null +++ b/NejBlazor.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/Parts/ButtonParts/Button.cs b/Parts/ButtonParts/Button.cs new file mode 100644 index 0000000..ee00834 --- /dev/null +++ b/Parts/ButtonParts/Button.cs @@ -0,0 +1,35 @@ + +namespace Nejcraft.Shared.Parts.ButtonParts +{ + public class Button : ButtonBase + { + public override string GetCssClass() + { + return "px-4 py-2 rounded-lg " + base.GetCssClass(); + } + } + + public class ButtonSmall : ButtonBase + { + public override string GetCssClass() + { + return "px-3 py-1 rounded-lg " + base.GetCssClass(); + } + } + + public class ButtonBig : ButtonBase + { + public override string GetCssClass() + { + return "px-6 py-4 rounded-lg " + base.GetCssClass(); + } + } + + public class ButtonRound : ButtonBase + { + public override string GetCssClass() + { + return "p-2 rounded-full " + base.GetCssClass(); + } + } +} diff --git a/Parts/ButtonParts/ButtonBase.razor b/Parts/ButtonParts/ButtonBase.razor new file mode 100644 index 0000000..ae63080 --- /dev/null +++ b/Parts/ButtonParts/ButtonBase.razor @@ -0,0 +1,65 @@ +@using Microsoft.AspNetCore.Components.Web; +@using Nejcraft.Shared.Parts +@inherits NejComponentBase + + + +@code { + + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + public enum ButtonType { + Normal, + Submit, + Danger + } + + public static Dictionary ColorMap = new Dictionary(){ + { ButtonType.Submit, Colors.ColorType.Accent }, + { ButtonType.Danger, Colors.ColorType.Error } + }; + + string Color { + get { + if (!ColorMap.TryGetValue(Type, out Colors.ColorType col)) + return "bg-secondary"; + return Colors.BgColors[col]; + } + } + + string HoverColor + { + get + { + if (!ColorMap.TryGetValue(Type, out Colors.ColorType col)) + return "hover:bg-trinary"; + return Colors.BgColorsHover[col]; + } + } + + string DisabledColor + { + get + { + if (!ColorMap.TryGetValue(Type, out Colors.ColorType col)) + return "disabled:bg-trinary"; + return Colors.BgColorsDisabled[col]; + } + } + + + [Parameter] + public ButtonType Type { get; set; } + + [Parameter] + public string? HtmlButtonType { get; set; } = "button"; + + [Parameter] + public EventCallback OnClick { get; set; } +} diff --git a/Parts/CardParts/Card.razor b/Parts/CardParts/Card.razor new file mode 100644 index 0000000..a95d975 --- /dev/null +++ b/Parts/CardParts/Card.razor @@ -0,0 +1,12 @@ +@using Nejcraft.Shared.Parts +@inherits NejComponentBase + +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/CardParts/CardHeader.razor b/Parts/CardParts/CardHeader.razor new file mode 100644 index 0000000..86318e4 --- /dev/null +++ b/Parts/CardParts/CardHeader.razor @@ -0,0 +1,19 @@ +
+
+
+ @if (!string.IsNullOrEmpty(Desc)) + { +

@Desc

+ } +
+ @ChildContent +
+
+ +@code { + [Parameter] + public string? Desc { get; set; } + + [Parameter] + public RenderFragment? ChildContent { get; set; } +} diff --git a/Parts/Colors.cs b/Parts/Colors.cs new file mode 100644 index 0000000..0d25b2f --- /dev/null +++ b/Parts/Colors.cs @@ -0,0 +1,64 @@ +namespace Nejcraft.Shared.Parts +{ + public class Colors + { + public enum ColorType + { + Error, + Accent, + Accent2, + Accent3, + Accent4, + Accent5, + } + + public static Dictionary BgColors = new Dictionary() + { + {ColorType.Error, "bg-red-600"}, + {ColorType.Accent, "bg-accent"}, + {ColorType.Accent2, "bg-accent2"}, + {ColorType.Accent3, "bg-accent3"}, + {ColorType.Accent4, "bg-accent4"}, + {ColorType.Accent5, "bg-accent5"}, + }; + + public static Dictionary BgColorsHover = new Dictionary() + { + {ColorType.Error, "hover:bg-red-700"}, + {ColorType.Accent, "hover:bg-accent-dark"}, + {ColorType.Accent2, "hover:bg-accent2-dark"}, + {ColorType.Accent3, "hover:bg-accent3-dark"}, + {ColorType.Accent4, "hover:bg-accent4-dark"}, + {ColorType.Accent5, "hover:bg-accent5-dark"}, + }; + + public static Dictionary BgColorsDisabled = new Dictionary() + { + {ColorType.Error, "disabled:bg-red-700"}, + {ColorType.Accent, "disabled:bg-accent-dark"}, + {ColorType.Accent2, "disabled:bg-accent2-dark"}, + {ColorType.Accent3, "disabled:bg-accent3-dark"}, + {ColorType.Accent4, "disabled:bg-accent4-dark"}, + {ColorType.Accent5, "disabled:bg-accent5-dark"}, + }; + + public static Dictionary TextColors = new Dictionary() + { + {ColorType.Error, "text-red-600"}, + {ColorType.Accent, "text-accent"}, + {ColorType.Accent2, "text-accent2"}, + {ColorType.Accent3, "text-accent3"}, + {ColorType.Accent4, "text-accent4"}, + {ColorType.Accent5, "text-accent5"}, + }; + public static Dictionary TextColorsHover = new Dictionary() + { + {ColorType.Error, "hover:text-red-700"}, + {ColorType.Accent, "hover:text-accent-dark"}, + {ColorType.Accent2, "hover:text-accent2-dark"}, + {ColorType.Accent3, "hover:text-accent3-dark"}, + {ColorType.Accent4, "hover:text-accent4-dark"}, + {ColorType.Accent5, "hover:text-accent5-dark"}, + }; + } +} diff --git a/Parts/InputParts/CheckBox.razor b/Parts/InputParts/CheckBox.razor new file mode 100644 index 0000000..308fc95 --- /dev/null +++ b/Parts/InputParts/CheckBox.razor @@ -0,0 +1,23 @@ +
+ + @if (!string.IsNullOrEmpty(Title)) + { + + } + @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Title { get; set; } + + [Parameter] + public string? Id { get; set; } + + [Parameter] + public string? Name { get; set; } + +} diff --git a/Parts/InputParts/Input.razor b/Parts/InputParts/Input.razor new file mode 100644 index 0000000..affbb25 --- /dev/null +++ b/Parts/InputParts/Input.razor @@ -0,0 +1,34 @@ +
+ @if (!string.IsNullOrEmpty(Title)) + { + + } + + @ChildContent +
+ +@code { + [Parameter] + public string? Value { get; set; } + + [Parameter] + public EventCallback ValueChanged { get; set; } + + private void onChange(Microsoft.AspNetCore.Components.ChangeEventArgs args) + { + ValueChanged.InvokeAsync(args.Value as string ?? ""); + } + + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Title { get; set; } + + [Parameter] + public string? Id { get; set; } + + [Parameter] + public string? Name { get; set; } + +} diff --git a/Parts/InputParts/TextArea.razor b/Parts/InputParts/TextArea.razor new file mode 100644 index 0000000..2543266 --- /dev/null +++ b/Parts/InputParts/TextArea.razor @@ -0,0 +1,24 @@ +
+ @if (!string.IsNullOrEmpty(Title)) + { + + } + +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Title { get; set; } + + [Parameter] + public string? Id { get; set; } + + [Parameter] + public string? Name { get; set; } + +} diff --git a/Parts/LayoutParts/Full.razor b/Parts/LayoutParts/Full.razor new file mode 100644 index 0000000..f95a182 --- /dev/null +++ b/Parts/LayoutParts/Full.razor @@ -0,0 +1,9 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/LayoutParts/Half.razor b/Parts/LayoutParts/Half.razor new file mode 100644 index 0000000..9321d82 --- /dev/null +++ b/Parts/LayoutParts/Half.razor @@ -0,0 +1,9 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/LayoutParts/Quarter.razor b/Parts/LayoutParts/Quarter.razor new file mode 100644 index 0000000..960ebff --- /dev/null +++ b/Parts/LayoutParts/Quarter.razor @@ -0,0 +1,10 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} + \ No newline at end of file diff --git a/Parts/LayoutParts/Sixth.razor b/Parts/LayoutParts/Sixth.razor new file mode 100644 index 0000000..82aaa0e --- /dev/null +++ b/Parts/LayoutParts/Sixth.razor @@ -0,0 +1,9 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/LayoutParts/Third.razor b/Parts/LayoutParts/Third.razor new file mode 100644 index 0000000..578086e --- /dev/null +++ b/Parts/LayoutParts/Third.razor @@ -0,0 +1,9 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/LayoutParts/TwoThird.razor b/Parts/LayoutParts/TwoThird.razor new file mode 100644 index 0000000..ea2d0cf --- /dev/null +++ b/Parts/LayoutParts/TwoThird.razor @@ -0,0 +1,9 @@ +
+ @ChildContent +
+ +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/MiscParts/QrCode.razor b/Parts/MiscParts/QrCode.razor new file mode 100644 index 0000000..5bcaed1 --- /dev/null +++ b/Parts/MiscParts/QrCode.razor @@ -0,0 +1,21 @@ +@using QRCoder; +@inherits NejComponentBase + + + +@code { + private string QrBase64Image; + + protected override void OnParametersSet() + { + base.OnParametersSet(); + + QRCodeGenerator qrGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrGenerator.CreateQrCode(QrCodeData, QRCodeGenerator.ECCLevel.Q); + PngByteQRCode qrCode = new PngByteQRCode(qrCodeData); + QrBase64Image = Convert.ToBase64String(qrCode.GetGraphic(20, false)); + } + + [Parameter] + public string QrCodeData { get; set; } +} diff --git a/Parts/Modal.razor b/Parts/Modal.razor new file mode 100644 index 0000000..f63451a --- /dev/null +++ b/Parts/Modal.razor @@ -0,0 +1,18 @@ +@using LayoutParts + +@if (IsOpen) { +
+ + @ChildContent + +
+} + +@code { + [Parameter] + public Boolean IsOpen { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/NejComponentBase.cs b/Parts/NejComponentBase.cs new file mode 100644 index 0000000..294d8d3 --- /dev/null +++ b/Parts/NejComponentBase.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Components; + +namespace Nejcraft.Shared.Parts +{ + public class NejComponentBase : ComponentBase + { + + [Parameter] + public string Class { get; set; } = ""; + + public virtual string GetCssClass() + { + return Class; + } + } +} diff --git a/Parts/SidebarParts/GroupNavItem.razor b/Parts/SidebarParts/GroupNavItem.razor new file mode 100644 index 0000000..1e6ecb1 --- /dev/null +++ b/Parts/SidebarParts/GroupNavItem.razor @@ -0,0 +1,19 @@ +
  • +
    + +
    + @Title +
    +
      + @ChildContent +
    +
    +
  • + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Title { get; set; } +} diff --git a/Parts/SidebarParts/NavBar.razor b/Parts/SidebarParts/NavBar.razor new file mode 100644 index 0000000..482893e --- /dev/null +++ b/Parts/SidebarParts/NavBar.razor @@ -0,0 +1,12 @@ +
    +
      + @ChildContent +
    +
    + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + +} diff --git a/Parts/SidebarParts/NavItem.razor b/Parts/SidebarParts/NavItem.razor new file mode 100644 index 0000000..fdab36c --- /dev/null +++ b/Parts/SidebarParts/NavItem.razor @@ -0,0 +1,20 @@ +
  • + + @ChildContent + +
  • + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Href { get; set; } + /* + [Parameter] + public NavLinkMatch NavLinkMatch { get; set; } = NavLinkMatch.All; + */ + +} diff --git a/Parts/TableParts/Table.razor b/Parts/TableParts/Table.razor new file mode 100644 index 0000000..e440624 --- /dev/null +++ b/Parts/TableParts/Table.razor @@ -0,0 +1,13 @@ +@using Nejcraft.Shared.Parts +@inherits NejComponentBase + +
    + + @ChildContent +
    +
    + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; +} diff --git a/Parts/TableParts/TableHeader.razor b/Parts/TableParts/TableHeader.razor new file mode 100644 index 0000000..d900dda --- /dev/null +++ b/Parts/TableParts/TableHeader.razor @@ -0,0 +1,10 @@ +@inherits NejComponentBase + + + @ChildContent + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; +} diff --git a/Parts/TableParts/TableNote.razor b/Parts/TableParts/TableNote.razor new file mode 100644 index 0000000..62635a9 --- /dev/null +++ b/Parts/TableParts/TableNote.razor @@ -0,0 +1,8 @@ +

    + @ChildContent +

    + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; +} diff --git a/Parts/TableParts/TablePart.razor b/Parts/TableParts/TablePart.razor new file mode 100644 index 0000000..e79476d --- /dev/null +++ b/Parts/TableParts/TablePart.razor @@ -0,0 +1,11 @@ + + @ChildContent + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; + + [Parameter] + public string? Class { get; set; } +} diff --git a/Parts/TableParts/TableSidePart.razor b/Parts/TableParts/TableSidePart.razor new file mode 100644 index 0000000..8c1ab7d --- /dev/null +++ b/Parts/TableParts/TableSidePart.razor @@ -0,0 +1,8 @@ + + @ChildContent + + +@code { + [Parameter] + public RenderFragment ChildContent { get; set; } = default!; +} diff --git a/Parts/TextParts/Divider.razor b/Parts/TextParts/Divider.razor new file mode 100644 index 0000000..569ac14 --- /dev/null +++ b/Parts/TextParts/Divider.razor @@ -0,0 +1,3 @@ +@inherits NejComponentBase + +
    \ No newline at end of file diff --git a/Parts/_Imports.razor b/Parts/_Imports.razor new file mode 100644 index 0000000..50e7e69 --- /dev/null +++ b/Parts/_Imports.razor @@ -0,0 +1 @@ +@namespace Nejcraft.Shared.Parts \ No newline at end of file diff --git a/_Imports.razor b/_Imports.razor new file mode 100644 index 0000000..7728512 --- /dev/null +++ b/_Imports.razor @@ -0,0 +1 @@ +@using Microsoft.AspNetCore.Components.Web