Skip to content

Commit

Permalink
Merge pull request #54 from majorimi/release/v1.1.0
Browse files Browse the repository at this point in the history
Updated demo App.
  • Loading branch information
majorimi authored Dec 18, 2020
2 parents 4abf7ed + efab827 commit 8a097d0
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 31 deletions.
22 changes: 12 additions & 10 deletions demo/Blazor.Components.DemoApp/Blazor.Components.DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Majorsoft.Blazor.Components.Common.JsInterop" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.CssEvents" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Debounce" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Loading" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Modal" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.PermaLink" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Timer" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Typeahead" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Server.Logging.Console" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.WebAssembly.Logging.Console" Version="1.0.1" />
<PackageReference Include="Majorsoft.Blazor.Components.Common.JsInterop" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.CssEvents" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Debounce" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Loading" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Modal" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.PermaLink" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Tabs" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Timer" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Toggle" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Components.Typeahead" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.Server.Logging.Console" Version="1.1.0" />
<PackageReference Include="Majorsoft.Blazor.WebAssembly.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
Expand Down
14 changes: 12 additions & 2 deletions demo/Blazor.Components.DemoApp/Components/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<li><NavLink href="jsinterop#focus-js">Focus Js</NavLink></li>
<li><NavLink href="jsinterop#info-js">Element info Js</NavLink></li>
<li><NavLink href="jsinterop#scroll-js">Scroll Js</NavLink></li>
<li><NavLink href="jsinterop#resize-js">Resize Js</NavLink></li>
<li><NavLink href="jsinterop#clipboard-js">Clipboard Js</NavLink></li>
</ul>
</li>
Expand All @@ -50,7 +51,16 @@
<li><NavLink href="permalink#PermaLink-Element-wrapper">Customizable PermaLinkElement</NavLink></li>
</ul>
</li>
<li>
<NavLink href="toggle">Toggle</NavLink>
<ul>
<li><NavLink href="toggle#switch">Toggle switch</NavLink></li>
<li><NavLink href="toggle#toggle-button">Toggle button</NavLink></li>
<li><NavLink href="toggle#toggle-buttongroup">Toggle button group</NavLink></li>
</ul>
</li>
<li><NavLink href="tabs">Tabs</NavLink></li>
@* <li><NavLink href="draganddrop">Drag and Drop</NavLink></li>
<li><NavLink href="colorpicker">Color Picker</NavLink></li>*@
</ul>
<li><NavLink href="colorpicker">Color Picker</NavLink></li>
*@ </ul>
</p>
80 changes: 72 additions & 8 deletions demo/Blazor.Components.DemoApp/Components/JSInterop.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<li><NavLink href="jsinterop#focus-js">Focus Js</NavLink></li>
<li><NavLink href="jsinterop#info-js">Element info Js</NavLink></li>
<li><NavLink href="jsinterop#scroll-js">Scroll Js</NavLink></li>
<li><NavLink href="jsinterop#resize-js">Resize Js</NavLink></li>
<li><NavLink href="jsinterop#clipboard-js">Clipboard Js</NavLink></li>
</ul>
</div>
Expand Down Expand Up @@ -182,12 +183,39 @@
<hr />
</div>

<div class="container-fluid p-3 mb-3 border rounded">
<PermaLinkElement PermaLinkName="resize-js" IconMarginTop="8" IconSize="18">
<Content><h3>Resize JS</h3></Content>
</PermaLinkElement>
<p>
<strong>Resize JS</strong> is an <strong>injectable <code>IResizeHandler</code> service</strong> for Window (global) and HTML Elements resize event callback handlers.
</p>

<div class="row pb-2">
<div class="col-12">
<p><code>RegisterPageResizeAsync()</code> will add event listener to HTML document/window <code>resize events.</code></p>
<p><code>RegisterResizeAsync()</code> will add event listener to the given HTML Element <code>resize events.</code></p>

<label>Resizabel Textarea with event listener:</label>
<br />
<textarea @ref="_resizeElement" style="resize:both;" readonly>Grab right bottom corner to resize element...</textarea>

<br />
<button class="btn btn-primary" @onclick="ResizeEventHandler">@(_resizeSubscribed ? "Unsubscribe from resize" : "Subscribe to resize")</button>
<br />
<label><strong>Resize Events log</strong>:</label>
<textarea @ref="_log4" @bind="_logMessage4" class="form-control w-100 logText" readonly></textarea>
</div>
</div>

</div>

<div class="container-fluid p-3 mb-3 border rounded">
<PermaLinkElement PermaLinkName="clipboard-js" IconMarginTop="8" IconSize="18">
<Content><h3>Clipboard JS</h3></Content>
</PermaLinkElement>
<p>
<strong>Clipboard JS</strong> is an <strong>injectable <code>IClipboardHandler</code> service</strong> for accessing computer Clipboard from Blazor Application.
<strong>Resize JS</strong> is an <strong>injectable <code>IClipboardHandler</code> service</strong> for accessing computer Clipboard from Blazor Application.
</p>

<div class="row pb-2">
Expand All @@ -213,6 +241,7 @@

@inject IScrollHandler _scrollHandler
@inject IFocusHandler _focusHandler
@inject IResizeHandler _resizeHandler
@inject IClickBoundariesHandler _clichHandler;
@inject IClipboardHandler _clipboardHandler;
@inject IGlobalMouseEventHandler _globalMouseEventHandler;
Expand All @@ -224,6 +253,7 @@
await ScrollEventHandler();
await ClickEventHandler();
await GlobalClickEventHandler();
await ResizeEventHandler();
}

//Click examples
Expand All @@ -248,7 +278,7 @@
}
private async Task PageClick(MouseEventArgs args, string message)
{
_logMessage += $"Page clicked {message} X pos: {args.ClientX}, Y pos: {args.ClientY}{Environment.NewLine}";
_logMessage += $"{DateTime.Now.TimeOfDay}: Page clicked {message} X pos: {args.ClientX}, Y pos: {args.ClientY}{Environment.NewLine}";
StateHasChanged();

await _log.ScrollToEndAsync();
Expand All @@ -269,16 +299,16 @@
}
else
{
_mouseDown = await _globalMouseEventHandler.RegisterPageMouseDownAsync(async (args) => await PageMouseEvents(args, "Document Mouse DOWN"));
_mouseUp = await _globalMouseEventHandler.RegisterPageMouseUpAsync(async (args) => await PageMouseEvents(args, "Document Mouse UP"));
_mouseMove = await _globalMouseEventHandler.RegisterPageMouseMoveAsync(async (args) => await PageMouseEvents(args, "Document Mouse MOVE"));
_mouseDown = await _globalMouseEventHandler.RegisterPageMouseDownAsync(async (args) => await PageMouseEvents(args, "Mouse DOWN"));
_mouseUp = await _globalMouseEventHandler.RegisterPageMouseUpAsync(async (args) => await PageMouseEvents(args, "Mouse UP"));
_mouseMove = await _globalMouseEventHandler.RegisterPageMouseMoveAsync(async (args) => await PageMouseEvents(args, "Mouse MOVE"));
}

_clickSubscribed2 = !_clickSubscribed2;
}
private async Task PageMouseEvents(MouseEventArgs args, string message)
{
_logMessage3 += $"Page clicked {message} X pos: {args.ClientX}, Y pos: {args.ClientY}, Buttons: {args.Buttons}{Environment.NewLine}";
_logMessage3 += $"{DateTime.Now.TimeOfDay}: Global Mouse event: {message} X pos: {args.ClientX}, Y pos: {args.ClientY}, Buttons: {args.Buttons}{Environment.NewLine}";
StateHasChanged();

await _log3.ScrollToEndAsync();
Expand All @@ -290,7 +320,7 @@
{
await _focusHandler.StoreFocusedElementAsync();
_focusMsg = "Focused element stored, click somewhere else and do not hover on RED area.";
}
}
private async Task RestoreFocus()
{
await _focusHandler.RestoreStoredElementFocusAsync();
Expand Down Expand Up @@ -335,7 +365,7 @@
private string _logMessage2;
private async Task PageScrolled(ScrollEventArgs args)
{
_logMessage2 += $"Page scrolled: X pos: {args.X}, Y pos: {args.Y}{Environment.NewLine}";
_logMessage2 += $"{DateTime.Now.TimeOfDay}: Page scrolled: X pos: {args.X}, Y pos: {args.Y}{Environment.NewLine}";
StateHasChanged();

await _log2.ScrollToEndAsync();
Expand All @@ -356,6 +386,35 @@
_scrollSubscribed = !_scrollSubscribed;
}

//Resize JS
private bool _resizeSubscribed;
private async Task ResizeEventHandler()
{
if (_resizeSubscribed)
{
await _resizeHandler.RemovePageResizeAsync(_scrollEventId);
await _resizeHandler.RemoveResizeAsync(_resizeElement);
}
else
{
_scrollEventId = await _resizeHandler.RegisterPageResizeAsync(arg => Resized(arg, "Window resized"));
await _resizeHandler.RegisterResizeAsync(_resizeElement, arg => Resized(arg, "Textarea resized"));
}

_resizeSubscribed = !_resizeSubscribed;
}

private ElementReference _resizeElement;
private ElementReference _log4;
private string _logMessage4;
private async Task Resized(ResizeEventArgs args, string message)
{
_logMessage4 += $"{DateTime.Now.TimeOfDay}: {message} - Width: {args.Width}, Height: {args.Height}{Environment.NewLine}";
StateHasChanged();

await _log4.ScrollToEndAsync();
}

//Clipboard JS
private ElementReference _copyInput;
private string _codedString = "Copy string value form C# code...";
Expand Down Expand Up @@ -391,5 +450,10 @@
{
await _clipboardHandler.DisposeAsync();
}

if (_resizeHandler is not null)
{
await _resizeHandler.DisposeAsync();
}
}
}
167 changes: 167 additions & 0 deletions demo/Blazor.Components.DemoApp/Components/Tabs.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<h1>Tabs Components</h1>
<p>
Blazor component that renders customizable Tabs element panel with many tabs and custom content. For usege see soruce code and docs on
<a href="https://github.com/majorimi/blazor-components/blob/master/.github/docs/Tabs.md" target="_blank">Github</a>.
<br /><strong>Majorsoft.Blazor.Components.Tabs</strong> package is available on <a href="https://www.nuget.org/packages/Majorsoft.Blazor.Components.Tabs" target="_blank">Nuget</a>
</p>

<div class="container-fluid p-3 mb-3 border rounded">
<h3>TabsPanel with TabItems</h3>
<p>Renders <strong><code>TabsPanel</code> container </strong> for <strong><code>TabItem</code> components</strong> with custumizable header and content.</p>

<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Active tab color (Name, RGB, Hex, HSL): <input class="form-control w-100" @bind="_activeColor" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Inactive tabs color (Name, RGB, Hex, HSL): <input class="form-control w-100" @bind="_inactiveColor" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Tabs Hover color (Name, RGB, Hex, HSL): <input class="form-control w-100" @bind="_hoverColor" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Tab items Width (0 is auto): @(_width)px
<input type="range" class="w-100" min="0" max="300" @bind="_width" @oninput="(e => _width = int.Parse(e.Value?.ToString()))" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Tab items Height (0 is auto): @(_height)px
<input type="range" class="w-100" min="0" max="70" @bind="_height" @oninput="(e => _height = int.Parse(e.Value?.ToString()))" />
</div>
</div>

<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Number of tabs: <strong>@_tabsCount</strong>
<br />
TabsPanel Disabled: <input class="mr-3" type="checkbox" @bind="_allTabsDisabled" />
Disable Tab: <input class="mr-3" type="checkbox" @bind="_isTabDisabled" />
<br />
Animate Tab changes: <input class="mr-3" type="checkbox" @bind="_isAnimated" />
</div>
</div>

<div class="row pb-4">
<div class="col-12 col-lg-8 col-xl-5">
Tabs horizontal positon: <select class="form-control selectpicker w-100" @bind="_tabPositon">
@foreach (var item in Enum.GetValues(typeof(TabPositons)))
{
<option value="@item">@item</option>
}
</select>
</div>
</div>

<div class="row mb-3 border rounded m-1">
<div class="col-12">
<TabsPanel @ref="_tabs"
ActiveColor="@_activeColor"
InactiveColor="@_inactiveColor"
HoverColor="@_hoverColor"
ActiveTab="@_activeTab"
TabItemsHeight="@_height"
TabItemsWidth="@_width"
Disabled="@_allTabsDisabled"
TabPositon="@_tabPositon"
Animate="@_isAnimated"
OnTabChanged="OnTabChanged">
<TabItems>
<TabItem id="tab1" @ref="_tab1">
<Header><strong>Tab 1</strong></Header>
<Content>
<h1>The first tab</h1>
</Content>
</TabItem>
<TabItem @ref="_tab2">
<Header><i>Tab 2</i></Header>
<Content>
<h1>The second tab</h1>
</Content>
</TabItem>
<TabItem id="tab3" @ref="_tab3" Disabled="@_isTabDisabled">
<Header><u>Can disable</u></Header>
<Content>
<h1>This tab can be disabled</h1>
<p>And also any <code>TabItem</code> can be disabled by using <code>Disabled</code> property.</p>
</Content>
</TabItem>
<TabItem id="tab4" @ref="_tab4">
<Header>Header icon <i class="fa fa-home"></i></Header>
<Content>
<h1>Tab with icon in header</h1>
</Content>
</TabItem>
</TabItems>
</TabsPanel>
</div>
</div>

<div class="row pb-2">
<div class="col-12">
<label><strong>Tabs Event log</strong>:</label>
<textarea @ref="_log" @bind="_tabsLog" style="height:200px;" class="form-control w-100" readonly></textarea>
</div>
</div>

</div>

@using System.Linq;

@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await _tabs.InnerElementReference.FocusAsync();

//Group
_activeTab = _tab2;
_tabsCount = _tabs.TabCount;
StateHasChanged();
}
}

private string _activeColor = "DodgerBlue";
private string _inactiveColor = "White";
private string _hoverColor = "WhiteSmoke";
private int _width = 135;
private int _height = 40;
private TabPositons _tabPositon = TabPositons.Left;
private bool _isAnimated = true;
private bool _allTabsDisabled = false;
private bool _isTabDisabled = false;

private int _tabsCount;

private TabsPanel _tabs;
private TabItem _activeTab;
private TabItem _tab1;
private TabItem _tab2;
private TabItem _tab3;
private TabItem _tab4;

private ElementReference _log;
private string _tabsLog;

private async Task OnTabChanged(TabItem tab)
{
_activeTab = tab;
var index = _tabs.Tabs.ToList().IndexOf(tab);
_tabsLog = await WriteLog(_tabsLog, $"Tab item activated event Active tab index: {index}");
}

private async Task<string> WriteLog(string log, string message)
{
log += $"{DateTime.Now.TimeOfDay}: {message}. \r\n";
await _log.ScrollToEndAsync();

return log;
}
}
Loading

0 comments on commit 8a097d0

Please sign in to comment.