Skip to content

Commit

Permalink
Added automatic ModalSize which sizes the modal based on the componen…
Browse files Browse the repository at this point in the history
…t being rendered (#464)
  • Loading branch information
chrissainty authored Oct 14, 2022
1 parent 852ec5b commit 20e3cef
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/docs/configuration/size.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sidebar_position: 1

The width of a modal can be configured using the `Size` option. Blazored Modal has a range of built-in sizes as well as the ability to define a custom size.

- Automatic (Size is determined by the content)
- Small (300px)
- Medium (500px)
- Large (800px)
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorServer/Pages/Size.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</div>
</div>

<button @onclick="@(() => SetSize(ModalSize.Automatic))" class="btn btn-secondary">Automatic</button>
<button @onclick="@(() => SetSize(ModalSize.Small))" class="btn btn-secondary">Small</button>
<button @onclick="DefaultSize" class="btn btn-primary">Medium (default)</button>
<button @onclick="@(() => SetSize(ModalSize.Large))" class="btn btn-secondary">Large</button>
Expand Down
1 change: 1 addition & 0 deletions samples/BlazorWebAssembly/Pages/Size.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</div>
</div>

<button @onclick="@(() => SetSize(ModalSize.Automatic))" class="btn btn-secondary">Automatic</button>
<button @onclick="@(() => SetSize(ModalSize.Small))" class="btn btn-secondary">Small</button>
<button @onclick="DefaultSize" class="btn btn-primary">Medium (default)</button>
<button @onclick="@(() => SetSize(ModalSize.Large))" class="btn btn-secondary">Large</button>
Expand Down
3 changes: 3 additions & 0 deletions src/Blazored.Modal/BlazoredModalInstance.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ private string SetSize()
return GlobalModalOptions.SizeCustomClass;

throw new InvalidOperationException("Size set to Custom without a SizeCustomClass set");

case ModalSize.Automatic:
return "size-automatic";

default:
return "size-medium";
Expand Down
7 changes: 7 additions & 0 deletions src/Blazored.Modal/BlazoredModalInstance.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
margin-right: auto;
}

.size-automatic {
width: -moz-fit-content;
width: fit-content;
margin-left: auto;
margin-right: auto;
}

.bm-header {
display: flex;
align-items: flex-start;
Expand Down
3 changes: 2 additions & 1 deletion src/Blazored.Modal/Configuration/ModalSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum ModalSize
Medium,
Large,
ExtraLarge,
Custom
Custom,
Automatic
}

0 comments on commit 20e3cef

Please sign in to comment.