|
| 1 | +<MudGrid> |
| 2 | + <MudItem xs="12" sm="8" > |
| 3 | + <div class="d-flex flex-wrap gap-4 align-center justify-space-between"> |
| 4 | + <MudCard Style="height: 280px; width: 240px"> |
| 5 | + <MudCardHeader Class="mud-theme-primary"> |
| 6 | + <MudText>Area: id1</MudText> |
| 7 | + </MudCardHeader> |
| 8 | + |
| 9 | + <MudCardContent Class="id1"> |
| 10 | + <MudText Class="mb-4">Teleported content shows below me</MudText> |
| 11 | + <MudDivider /> |
| 12 | + </MudCardContent> |
| 13 | + </MudCard> |
| 14 | + |
| 15 | + <MudCard Style="height: 280px; width: 240px"> |
| 16 | + <MudCardHeader Class="mud-theme-secondary"> |
| 17 | + <MudText>Area: id2</MudText> |
| 18 | + </MudCardHeader> |
| 19 | + |
| 20 | + <MudCardContent Class="id2 d-flex flex-column align-center justify-center"> |
| 21 | + <MudButton Class="mb-4" Variant="Variant.Filled" Color="Color.Primary" OnClick="@ToggleOpen">Open Popover</MudButton> |
| 22 | + <MudPopover Open="@_isOpen" Fixed="true" Class="id2-popover d-flex flex-column justify-center" Style="width: 300px"> |
| 23 | + <MudButton OnClick="@ToggleOpen" Class="my-4" Color="Color.Error">Close</MudButton> |
| 24 | + </MudPopover> |
| 25 | + </MudCardContent> |
| 26 | + </MudCard> |
| 27 | + |
| 28 | + <MudCard Style="height: 280px; width: 240px"> |
| 29 | + <MudCardHeader Class="mud-theme-tertiary"> |
| 30 | + <MudText>Area: id3</MudText> |
| 31 | + </MudCardHeader> |
| 32 | + |
| 33 | + <MudCardContent> |
| 34 | + <div class="id3"> |
| 35 | + |
| 36 | + </div> |
| 37 | + <MudDivider /> |
| 38 | + <MudText>Teleported content shows above me</MudText> |
| 39 | + </MudCardContent> |
| 40 | + </MudCard> |
| 41 | + </div> |
| 42 | + |
| 43 | + <MudCard Class="mt-4"> |
| 44 | + <MudCardHeader Class="mud-theme-info"> |
| 45 | + <MudText>Teleport Container</MudText> |
| 46 | + </MudCardHeader> |
| 47 | + |
| 48 | + <MudCardContent> |
| 49 | + <MudTeleport @ref="_teleport" To="@_id" ReturnWhenNotFound="_returnWhenNotFound" OwnClass="@_ownClass"> |
| 50 | + <div class="d-flex flex-column align-center justify-center my-4"> |
| 51 | + <MudText Align="Align.Center">@(_id == null || _id == "teleport" ? "Waiting for teleport" : "Teleported text")</MudText> |
| 52 | + <MudButton OnClick="Teleport" Variant="Variant.Filled">Teleport</MudButton> |
| 53 | + @if (_id == "id2" || _id == ".id2") |
| 54 | + { |
| 55 | + <MudButton Class="mt-2" OnClick="TeleportIntoPopover" Color="Color.Info" Variant="Variant.Filled">Teleport Into Popover</MudButton> |
| 56 | + } |
| 57 | + </div> |
| 58 | + </MudTeleport> |
| 59 | + </MudCardContent> |
| 60 | + </MudCard> |
| 61 | + |
| 62 | + </MudItem> |
| 63 | + |
| 64 | + <MudItem xs="12" sm="4"> |
| 65 | + <MudStack Spacing="4"> |
| 66 | + <MudTextFieldExtended @bind-Value="_id" Label="To" Immediate="true" autocomplete="new-password" Variant="Variant.Outlined" /> |
| 67 | + <MudSwitchM3 @bind-Checked="_returnWhenNotFound" Label="Return When Not Found" Color="Color.Secondary" /> |
| 68 | + <MudTextFieldExtended @bind-Value="_ownClass" Label="Own Class" Immediate="true" Variant="Variant.Outlined" /> |
| 69 | + <MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="@(async() => { _id = null; await _teleport.Reset(); })">Reset</MudButton> |
| 70 | + </MudStack> |
| 71 | + </MudItem> |
| 72 | +</MudGrid> |
| 73 | + |
| 74 | +@code{ |
| 75 | + MudTeleport _teleport; |
| 76 | + string _id; |
| 77 | + bool _returnWhenNotFound = false; |
| 78 | + string _ownClass; |
| 79 | + |
| 80 | + private void Teleport() |
| 81 | + { |
| 82 | + if (_id != null && _id.Contains("id2")) |
| 83 | + { |
| 84 | + _id = "id3"; |
| 85 | + } |
| 86 | + else if (_id == "id1" || _id == ".id1") |
| 87 | + { |
| 88 | + _id = "id2"; |
| 89 | + } |
| 90 | + else |
| 91 | + { |
| 92 | + _id = "id1"; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private void TeleportIntoPopover() |
| 97 | + { |
| 98 | + _id = "id2-popover"; |
| 99 | + } |
| 100 | + |
| 101 | + public bool _isOpen; |
| 102 | + |
| 103 | + public void ToggleOpen() |
| 104 | + { |
| 105 | + _isOpen = !_isOpen; |
| 106 | + } |
| 107 | +} |
0 commit comments