8 |
9 | @functions {
10 |
11 | [Parameter] public string Header { get; set; }
12 |
13 | [Parameter] public string Introduction { get; set; }
14 |
15 | [Parameter] public RenderFragment ChildContent { get; set; }
16 |
17 | }
--------------------------------------------------------------------------------
/BlazorBinding/Components/DocumentationSupport/ChangeLogItems.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace BlazorBinding.Components.DocumentationSupport
7 | {
8 | public class ChangeLog
9 | {
10 | public DateTime dated { get; set; }
11 | public string content { get; set; }
12 | public Child[] child { get; set; }
13 | }
14 |
15 | public class Child
16 | {
17 | public string text { get; set; }
18 | }
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/BlazorBinding/Components/DocumentationSupport/DisplayCode.md:
--------------------------------------------------------------------------------
1 | # DisplayCode enhancement
2 |
3 | *Update: 5th Dec 2018*
4 | *Much of this has now been replaced by the new DisplayCode component which does not use JSInterop*
5 |
6 | When I saw SQL Mister Magoo's excellent BlazorBinding project I thought it would be an
7 | interesting experiment to try to add Code Syntax Highlighting to his `` component.
8 |
9 | This turned out to be a bit tricker than I realised, since we had to permit Blazor to render the
10 | `ChildContent` render fragment first, and then grab the HTML via JS interop, and re-render
11 | using a .NET library.
12 |
13 | ### ColorCode
14 |
15 | I looked on [Nuget](https://nuget.org) for Syntax Highlighting packages that would work on
16 | .NET Standard (required since this is client-side Blazor), and found
17 | [ColorCode](https://github.com/WilliamABradley/ColorCode-Universal), which works very well and
18 | supports multiple languages.
19 |
20 | ### DisplayCode
21 | So I amended the `` component to add a unique ID to each code `
` so we
22 | could pull the `innerText` from the element, apply the syntax highlighting, and then re-render
23 | the text back.
24 |
25 | I added the file `wwwroot/js/displayCode.js` library to host the Javascript methods I needed, and
26 | added these to the `index.html` page. The helper methods `GetInnerText` and `SetInnerHTML` call the
27 | Javascript code.
28 |
29 | I also added an override for `OnAfterRenderAsync` which then grabs the raw inner text
30 | from the `div` and applies the syntax highlighting.
31 |
32 | I also added a new `[Parameter] string Languages {get;set;} = "html";` which
33 | defaults to HTML (since most examples use this), but allows the component to do
34 | highlighting for any of the
35 | [supported languages](https://github.com/WilliamABradley/ColorCode-Universal/blob/master/ColorCode.Core/Common/LanguageId.cs)
36 |
37 | Example:
38 | ```
39 |
40 | @("")
41 |
42 | ```
43 | ### Issues
44 |
45 | The `
` tag added a number of blank lines and I added the `CleanCode` method to trim these off, otherwise the code sample
46 | has a lot of blank space above/below. There might be a better fix for this, as it would also remove intentionally blank lines within
47 | the code as well as at the start/end.
48 |
49 |
50 |
--------------------------------------------------------------------------------
/BlazorBinding/Components/DocumentationSupport/DisplayCode.razor:
--------------------------------------------------------------------------------
1 | @using BlazorBinding.Services
2 | @inject ICodeHighlighter CodeHighlighter
3 |
4 | @if (Code != null)
5 | {
6 |
8 | This is a working example of various binding techniques for Blazor.
9 |
10 |
11 | Please use the menu to work through the different options - if you work down the list, I think you will see how we have to accomodate the fact there are some issues in data-binding in Blazor.
12 |
39 | }
40 | }
41 |
42 | @functions
43 | {
44 | //
45 | [Inject] HttpClient httpClient { get; set; }
46 | ChangeLog[] ChangeLogItems;
47 |
48 | protected async override Task OnInitializedAsync()
49 | {
50 | await base.OnInitializedAsync();
51 | try
52 | {
53 | var changeLogString = await httpClient.GetStringAsync("data/changelog.json");
54 | var changeLogItems = JsonSerializer.Deserialize(changeLogString);
55 | ChangeLogItems = changeLogItems;
56 | Console.WriteLine($"Got {ChangeLogItems.Length} ChangeLogItems");
57 | }
58 | catch (Exception e)
59 | {
60 | Console.WriteLine($"ERROR: {e.GetBaseException().Message}");
61 | }
62 | }
63 |
64 | //
65 | }
--------------------------------------------------------------------------------
/BlazorBinding/Pages/Readme.razor:
--------------------------------------------------------------------------------
1 | @page "/readme"
2 |
3 | @Contents
4 |
5 |
6 | @code
7 | {
8 | //
9 | [Inject] HttpClient httpClient { get; set; }
10 | MarkupString Contents;
11 |
12 | protected async override Task OnInitializedAsync()
13 | {
14 | await base.OnInitializedAsync();
15 | try
16 | {
17 | var stream = await httpClient.GetStringAsync("https://raw.githubusercontent.com/SQL-MisterMagoo/BlazorBinding/master/README.md");
18 | Contents = (MarkupString)Markdig.Markdown.ToHtml(stream);
19 | }
20 | catch (Exception ex)
21 | {
22 | Console.WriteLine("Failed to load README.md");
23 | Console.WriteLine(ex.GetBaseException().Message);
24 | Contents = (MarkupString)Markdig.Markdown.ToHtml("# BlazorBinding\n" +
25 | "Sample Blazor App demonstrating various data binding scenarios\n" +
26 | "\n" +
27 | "## Simple Cascade\n" +
28 | "Demonstrates how CascadingValue is a one-way data transfer, which updates the subscriber but not the publisher.\n" +
29 | "\n" +
30 | "## Cascade With Callback\n" +
31 | "Demonstrates how you can add a Callback Action to update the CascadingValue from subscriber to publisher.\n" +
32 | "\n" +
33 | "## Simple Binding\n" +
34 | "Demonstrates the use of parameter binding, which is a one-way binding like the CascadingValue, but specific to the bound Component.\n" +
35 | "\n" +
36 | "## Simple Binding With Callback\n" +
37 | "Demonstrates how you can add a Callback Action to update the parent values from the child.\n" +
38 | "\n" +
39 | "## Value Binding\n" +
40 | "Demonstrates how the bind-Value syntax works in a one-way mode, like simple binding.\n" +
41 | "*This is considered to be a bug by many*\n" +
42 | "\n" +
43 | "## Value Binding With Callback\n" +
44 | "Demonstrates how you can update the parent from a child component by invoking the _required_ ValueChanged Action.\n" +
45 | "\n" +
46 | "## Value Binding With Callback + Refresh\n" +
47 | "Demonstrates how you can ensure the parent knows a child component has updated data, and trigger a refresh.\n" +
48 | "\n" +
49 | "## Value Binding Class Object" +
50 | "Demonstrates how to two-way bind a list of objects with multiple properties." +
51 | "\n" +
52 | "## The Problem With Clicks - \"Propagation\"\n" +
53 | "Demonstrates how events on standard html elements propagate in Blazor. This is very bad.\n" +
54 | "\n" +
55 | "## Using CascadingValue To Share A Global Component - Dialog\n" +
56 | "Demonstrates how to use CascadingValue to share a component from MainLayout so that it is globally accessible.\n" +
57 | "\n" +
58 | "## Autocomplete text input" +
59 | "Demonstrates how to perform autocomplete on a text input." +
60 | "\n" +
61 | "## ViewModel Binding" +
62 | "Demonstrates a simple method to enable a page to bind a ViewModel that automatically hooks into StateHasChanged." +
63 | "\n" +
64 | "### Summary\n" +
65 | "\n" +
66 | "In all cases, some kind of callback action is required to notify the parent component of a change in the data.\n" +
67 | "This is, in my opinion OK - as it gives me control of the data and UI - however, some people consider the manual intervention required to be a bug.\n" +
68 | "\n" +
69 | "I have not included any examples of using \"State\" to achieve two way binding, although that is also possible, it would also require some kind of callback notification.\n" +
70 | "");
71 | }
72 | }
73 |
74 | //
75 | }
--------------------------------------------------------------------------------
/BlazorBinding/Pages/SimpleBinding.razor:
--------------------------------------------------------------------------------
1 | @page "/sb"
2 |
3 |
Simple Binding Value - "One Way Binding"
4 |
5 |
This is the parent control
6 |
7 |
The second checkbox will also change because of the Value parameter.
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | "})"/>
16 |
17 |
18 |
19 |
This is the Child control
20 |
21 |
Try clicking the checkbox - it will not update the parent Value.
22 |
23 |
24 |
25 |
26 |
27 | ",
29 | })"/>
30 |
31 | The CheckBox3 implementation :
32 | ",
34 | })"/>
35 |
40 |
41 |
42 |
43 |
Invoking StateHasChanged
44 |
45 |
46 |
47 |
48 | Last refresh @DateTime.Now
49 |
50 |
51 |
52 | Refresh
53 |
54 |
55 |
56 | Now click the button to refresh this page - nothing will change except the Last Refresh time, because the Value parameter is a one-way binding.
57 |
Try clicking the checkbox - the second checkbox will also change because of the Value parameter.
7 |
8 |
9 |
10 |
11 |
12 |
13 | "})"/>
14 |
15 |
16 |
17 |
18 |
This is the Child control
19 |
20 |
This is the child control, try clicking the checkbox - it will update the parent Value.
21 |
22 |
23 |
24 |
25 |
26 | "})"/>
27 |
The CheckBox4 implementation :
28 |
Here we bind to a local proxy value so we can fire the Callback when the local value changes.
29 | ",
30 | "@functions {",
31 | "[Parameter] public bool Value { get; set; }",
32 | "[Parameter] public Action Callback { get; set; }",
33 | "bool LocalValue { get { return Value; } set { Callback?.Invoke(value); } }",
34 | "}"
35 | })"/>
36 |
37 |
38 |
39 |
Invoking StateHasChanged
40 |
41 |
42 |
43 |
44 | Last refresh @DateTime.Now
45 |
46 |
47 |
48 | Refresh
49 |
50 |
51 |
52 | Page implementation:
53 |
54 |
55 | Now click the button to refresh this page - nothing will change except the Last Refresh time, because we are propogating the value back from Child to Parent and refreshing the Parent.
56 |
Try clicking the checkbox - the second checkbox will also change because of the CascadingValue.
9 |
10 |
11 |
12 |
13 |
14 |
15 | "
17 | })"/>
18 |
19 |
20 |
21 |
22 |
This is the Child control
23 |
24 |
Try clicking the checkbox - it will not update the parent Value.
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | ",
34 | " ",
35 | "",
36 | })"/>
37 |
The CheckBox implementation :
38 | "
40 | })"/>
41 |
47 |
48 |
49 |
50 |
Invoking StateHasChanged
51 |
52 |
53 |
54 |
55 | Last refresh @DateTime.Now
56 |
57 |
58 |
59 | Refresh
60 |
61 |
62 |
63 | Now click the button to refresh this page - nothing will change except the Last Refresh time, because the CascadingValue is a one-way binding
64 |
63 | Now click the button to refresh this page - the child checkbox will revert back to match the parent value
64 | because we are doing nothing to propogate the value change from child to parent
65 | and Blazor does not do it for us, despite requiring the ValueChanged Action.
66 |
63 | Now click the button to refresh this page - the Parent checkbox will revert back to match the Child's value
64 | because we are propogating the value change from child to parent but there is no automatic Refresh
65 | The value has propogated back from Child to Parent, but the parent has not refreshed.
66 |
83 |
84 | @functions {
85 | bool collapseNavMenu = true;
86 |
87 | void ToggleNavMenu()
88 | {
89 | collapseNavMenu = !collapseNavMenu;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/BlazorBinding/Startup.cs:
--------------------------------------------------------------------------------
1 | using BlazorBinding.Services;
2 | using Microsoft.AspNetCore.Components.Builder;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace BlazorBinding
6 | {
7 | public class Startup
8 | {
9 | public void ConfigureServices(IServiceCollection services)
10 | {
11 | services.AddSingleton((sp) => new CodeHighlighter());
12 | }
13 |
14 | public void Configure(IComponentsApplicationBuilder app)
15 | {
16 | app.AddComponent("app");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/BlazorBinding/_Imports.razor:
--------------------------------------------------------------------------------
1 | @using System.Net.Http
2 | @using Microsoft.AspNetCore.Components.Forms
3 | @using Microsoft.AspNetCore.Components.Routing
4 | @using Microsoft.AspNetCore.Components.Web
5 | @using Microsoft.JSInterop
6 | @using BlazorBinding
7 | @using BlazorBinding.Shared
8 | @using BlazorBinding.Components
9 | @using BlazorBinding.Components.DocumentationSupport
--------------------------------------------------------------------------------
/BlazorBinding/wwwroot/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 | #ffffff
--------------------------------------------------------------------------------
/BlazorBinding/wwwroot/css/open-iconic/FONT-LICENSE:
--------------------------------------------------------------------------------
1 | SIL OPEN FONT LICENSE Version 1.1
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | PREAMBLE
6 | The goals of the Open Font License (OFL) are to stimulate worldwide
7 | development of collaborative font projects, to support the font creation
8 | efforts of academic and linguistic communities, and to provide a free and
9 | open framework in which fonts may be shared and improved in partnership
10 | with others.
11 |
12 | The OFL allows the licensed fonts to be used, studied, modified and
13 | redistributed freely as long as they are not sold by themselves. The
14 | fonts, including any derivative works, can be bundled, embedded,
15 | redistributed and/or sold with any software provided that any reserved
16 | names are not used by derivative works. The fonts and derivatives,
17 | however, cannot be released under any other type of license. The
18 | requirement for fonts to remain under this license does not apply
19 | to any document created using the fonts or their derivatives.
20 |
21 | DEFINITIONS
22 | "Font Software" refers to the set of files released by the Copyright
23 | Holder(s) under this license and clearly marked as such. This may
24 | include source files, build scripts and documentation.
25 |
26 | "Reserved Font Name" refers to any names specified as such after the
27 | copyright statement(s).
28 |
29 | "Original Version" refers to the collection of Font Software components as
30 | distributed by the Copyright Holder(s).
31 |
32 | "Modified Version" refers to any derivative made by adding to, deleting,
33 | or substituting -- in part or in whole -- any of the components of the
34 | Original Version, by changing formats or by porting the Font Software to a
35 | new environment.
36 |
37 | "Author" refers to any designer, engineer, programmer, technical
38 | writer or other person who contributed to the Font Software.
39 |
40 | PERMISSION & CONDITIONS
41 | Permission is hereby granted, free of charge, to any person obtaining
42 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
43 | redistribute, and sell modified and unmodified copies of the Font
44 | Software, subject to the following conditions:
45 |
46 | 1) Neither the Font Software nor any of its individual components,
47 | in Original or Modified Versions, may be sold by itself.
48 |
49 | 2) Original or Modified Versions of the Font Software may be bundled,
50 | redistributed and/or sold with any software, provided that each copy
51 | contains the above copyright notice and this license. These can be
52 | included either as stand-alone text files, human-readable headers or
53 | in the appropriate machine-readable metadata fields within text or
54 | binary files as long as those fields can be easily viewed by the user.
55 |
56 | 3) No Modified Version of the Font Software may use the Reserved Font
57 | Name(s) unless explicit written permission is granted by the corresponding
58 | Copyright Holder. This restriction only applies to the primary font name as
59 | presented to the users.
60 |
61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
62 | Software shall not be used to promote, endorse or advertise any
63 | Modified Version, except to acknowledge the contribution(s) of the
64 | Copyright Holder(s) and the Author(s) or with their explicit written
65 | permission.
66 |
67 | 5) The Font Software, modified or unmodified, in part or in whole,
68 | must be distributed entirely under this license, and must not be
69 | distributed under any other license. The requirement for fonts to
70 | remain under this license does not apply to any document created
71 | using the Font Software.
72 |
73 | TERMINATION
74 | This license becomes null and void if any of the above conditions are
75 | not met.
76 |
77 | DISCLAIMER
78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
86 | OTHER DEALINGS IN THE FONT SOFTWARE.
87 |
--------------------------------------------------------------------------------
/BlazorBinding/wwwroot/css/open-iconic/ICON-LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/BlazorBinding/wwwroot/css/open-iconic/README.md:
--------------------------------------------------------------------------------
1 | [Open Iconic v1.1.1](http://useiconic.com/open)
2 | ===========
3 |
4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons)
5 |
6 |
7 |
8 | ## What's in Open Iconic?
9 |
10 | * 223 icons designed to be legible down to 8 pixels
11 | * Super-light SVG files - 61.8 for the entire set
12 | * SVG sprite—the modern replacement for icon fonts
13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats
14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats
15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px.
16 |
17 |
18 | ## Getting Started
19 |
20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections.
21 |
22 | ### General Usage
23 |
24 | #### Using Open Iconic's SVGs
25 |
26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute).
27 |
28 | ```
29 |
30 | ```
31 |
32 | #### Using Open Iconic's SVG Sprite
33 |
34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack.
35 |
36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `