From e1ee1164767624fc0c1890a9b23679ad6f34e1fa Mon Sep 17 00:00:00 2001 From: Chris Sainty Date: Thu, 14 Jul 2022 21:19:15 +0100 Subject: [PATCH] Restructure of markup and overhaul of styling (#410) * Initial rework of HTML with the addition of modal sizing * Fixed broken test and added new ones for Size feature * Fix for bubbling click events * Moved to isolated CSS. Renamed CSS classes. Simplified animations. * Fixed broken tests --- samples/BlazorServer/Pages/Animation.razor | 29 +- samples/BlazorServer/Pages/Position.razor | 5 +- .../Pages/ScrollableContent.razor | 52 -- samples/BlazorServer/Pages/Size.razor | 69 +++ samples/BlazorServer/Pages/_Layout.cshtml | 1 - samples/BlazorServer/Shared/NavMenu.razor | 10 +- .../Shared/YesNoPromptAnimation.razor | 2 +- samples/BlazorServer/wwwroot/css/site.css | 12 + .../BlazorWebAssembly/Pages/Animation.razor | 29 +- samples/BlazorWebAssembly/Pages/Index.razor | 4 +- .../BlazorWebAssembly/Pages/Position.razor | 5 +- .../Pages/ScrollableContent.razor | 52 -- samples/BlazorWebAssembly/Pages/Size.razor | 69 +++ .../BlazorWebAssembly/Shared/CodeBlock.razor | 30 ++ .../Shared/CodeBlock.razor.js | 3 + .../BlazorWebAssembly/Shared/NavMenu.razor | 10 +- .../Shared/YesNoPromptAnimation.razor | 2 +- samples/BlazorWebAssembly/wwwroot/css/app.css | 12 + .../wwwroot/css/github.min.css | 10 + samples/BlazorWebAssembly/wwwroot/index.html | 4 +- .../wwwroot/js/cshtml-razor.min.js | 67 +++ .../wwwroot/js/highlight.min.js | 491 ++++++++++++++++++ src/Blazored.Modal/BlazoredModal.razor | 52 +- src/Blazored.Modal/BlazoredModal.razor.js | 7 + .../BlazoredModalInstance.razor | 51 +- .../BlazoredModalInstance.razor.cs | 120 +++-- .../BlazoredModalInstance.razor.css | 125 +++++ .../CascadingBlazoredModal.razor | 9 +- .../Configuration/ModalAnimation.cs | 25 - .../Configuration/ModalAnimationType.cs | 7 + .../Configuration/ModalOptions.cs | 5 +- .../Configuration/ModalPosition.cs | 3 +- src/Blazored.Modal/Configuration/ModalSize.cs | 10 + src/Blazored.Modal/wwwroot/blazored-modal.css | 98 ---- tests/Blazored.Modal.Tests/DisplayTests.cs | 20 +- .../Blazored.Modal.Tests/ModalOptionsTests.cs | 101 ++-- 36 files changed, 1172 insertions(+), 429 deletions(-) delete mode 100644 samples/BlazorServer/Pages/ScrollableContent.razor create mode 100644 samples/BlazorServer/Pages/Size.razor delete mode 100644 samples/BlazorWebAssembly/Pages/ScrollableContent.razor create mode 100644 samples/BlazorWebAssembly/Pages/Size.razor create mode 100644 samples/BlazorWebAssembly/Shared/CodeBlock.razor create mode 100644 samples/BlazorWebAssembly/Shared/CodeBlock.razor.js create mode 100644 samples/BlazorWebAssembly/wwwroot/css/github.min.css create mode 100644 samples/BlazorWebAssembly/wwwroot/js/cshtml-razor.min.js create mode 100644 samples/BlazorWebAssembly/wwwroot/js/highlight.min.js create mode 100644 src/Blazored.Modal/BlazoredModal.razor.js create mode 100644 src/Blazored.Modal/BlazoredModalInstance.razor.css delete mode 100644 src/Blazored.Modal/Configuration/ModalAnimation.cs create mode 100644 src/Blazored.Modal/Configuration/ModalAnimationType.cs create mode 100644 src/Blazored.Modal/Configuration/ModalSize.cs delete mode 100644 src/Blazored.Modal/wwwroot/blazored-modal.css diff --git a/samples/BlazorServer/Pages/Animation.razor b/samples/BlazorServer/Pages/Animation.razor index c317406a..ae99bdd8 100644 --- a/samples/BlazorServer/Pages/Animation.razor +++ b/samples/BlazorServer/Pages/Animation.razor @@ -5,7 +5,7 @@

- By default, the modal is shown without animation. The modal can be set to no animation, Fade in, Fade out or both. + By default, the modal is shown with a subtle fade in out animation. However, this can be disabled so the modal shows and hides immediately.

@@ -13,9 +13,9 @@

- @("var options = new ModalOptions() { Animation = ModalAnimation.FadeIn(2) };") + @("var options = new ModalOptions() { AnimationType = ModalAnimation.None };")
- @("Modal.Show(\"Animation: Fade-In\", options);") + @("Modal.Show(\"Animation Type: None\", options);")

@@ -26,48 +26,41 @@

- @(" ") + @(" ")

- - - - - - + +

- It is also possible to have multiple modals (like in the Multiple Modals example) with different animations. With the below modal, the first modal will only fade-in with a duration of 2 seconds. The second modal will fade-in and fade-out in 5.0 seconds. + It is also possible to have multiple modals (like in the Multiple Modals example) with different animations. With the below modal, the first modal will appear without an animation. The second modal will fade-in and fade-out.

@code { - [CascadingParameter] public IModalService Modal { get; set; } = default!; - private double _duration = 1.0; - void AnimationDefault() { Modal.Show("Default Animation"); } - void AnimationCustom(ModalAnimation animation) + void NoAnimation() { - var options = new ModalOptions { Animation = animation }; + var options = new ModalOptions { AnimationType = ModalAnimationType.None }; - Modal.Show($"Animation: {animation.Type}", options); + Modal.Show("Animation Type: None", options); } void MultipleModals() { var options = new ModalOptions { - Animation = ModalAnimation.FadeIn(2) + AnimationType = ModalAnimationType.None }; Modal.Show("Multiple Modals", options); diff --git a/samples/BlazorServer/Pages/Position.razor b/samples/BlazorServer/Pages/Position.razor index c0bdb1e7..1e5c7efb 100644 --- a/samples/BlazorServer/Pages/Position.razor +++ b/samples/BlazorServer/Pages/Position.razor @@ -35,7 +35,8 @@ - + + @@ -46,7 +47,7 @@ void PositionCenter() { - Modal.Show("Centered Modal (Default)"); + Modal.Show("Top Center Modal (Default)"); } void PositionCustom(ModalPosition position) diff --git a/samples/BlazorServer/Pages/ScrollableContent.razor b/samples/BlazorServer/Pages/ScrollableContent.razor deleted file mode 100644 index c54c75a3..00000000 --- a/samples/BlazorServer/Pages/ScrollableContent.razor +++ /dev/null @@ -1,52 +0,0 @@ -@page "/scrollablecontent" - -

Scrollable Content

- -
- -

- By default, a modals content will not scroll if the contents height is greater than the viewports height.
- By setting ContentScrollable to true the Modal will include scroll bars allowing a user to scroll all the content. -

- -
-
Setting on a per modal basis
-
-

- - @("var options = new ModalOptions() { ContentScrollable = true };") - -

-
-
- -
-
Setting globally for all modals
-
-

- - @("") - -

-
-
- - - - -@code { - - [CascadingParameter] public IModalService Modal { get; set; } = default!; - - void ContentScrollableEnabled() - { - var options = new ModalOptions { ContentScrollable = true }; - - Modal.Show("Content Scrollable", options); - } - - void ContentScrollableDefault() - { - Modal.Show("Default Setting"); - } -} \ No newline at end of file diff --git a/samples/BlazorServer/Pages/Size.razor b/samples/BlazorServer/Pages/Size.razor new file mode 100644 index 00000000..cc70de43 --- /dev/null +++ b/samples/BlazorServer/Pages/Size.razor @@ -0,0 +1,69 @@ +@page "/size" + +

Sizing the modal

+ +
+ +

+ The modal has a default width. However, this can be changed by setting the Size option. +

+

+ There are 5 different sizes available: +

    +
  • Small - 300px
  • +
  • Medium - 500px (default)
  • +
  • Large - 800px
  • +
  • Extra Large - 1140px
  • +
  • Custom - Provide your own class, via the SizeCustomClass parameter, which sets the width
  • +
+

+ +
+
Setting on a per modal basis
+
+

+ + @("var options = new ModalOptions() { Size = ModalSize.Large };") +
+ @("Modal.Show(\"Size: Large\", options);") +
+

+
+
+ +
+
Setting globally for all modals
+
+

+ + @("") + +

+
+
+ + + + + + + +@code { + + [CascadingParameter] public IModalService Modal { get; set; } = default!; + + void DefaultSize() + { + Modal.Show("Size: Medium (Default)"); + } + + void SetSize(ModalSize size) + { + var options = new ModalOptions { Size = size }; + + if (size == ModalSize.Custom) + options.SizeCustomClass = "my-custom-size"; + + Modal.Show($"Size: {size}", options); + } +} \ No newline at end of file diff --git a/samples/BlazorServer/Pages/_Layout.cshtml b/samples/BlazorServer/Pages/_Layout.cshtml index 450625c6..304ad947 100644 --- a/samples/BlazorServer/Pages/_Layout.cshtml +++ b/samples/BlazorServer/Pages/_Layout.cshtml @@ -9,7 +9,6 @@ - diff --git a/samples/BlazorServer/Shared/NavMenu.razor b/samples/BlazorServer/Shared/NavMenu.razor index 80434503..50212a83 100644 --- a/samples/BlazorServer/Shared/NavMenu.razor +++ b/samples/BlazorServer/Shared/NavMenu.razor @@ -14,6 +14,11 @@ Home + - + -