Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion examples/Demo/Shared/Microsoft.Fast.Components.FluentUI.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions examples/Demo/Shared/Pages/Dialog/DialogPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</p>
<p>
The <code>DialogService</code> is a service which can be used to show different types of dialogs. It is registered as a scoped service, so it can be injected into
pages/components that want to use it. For more information on the <code>DialosService</code>, see the <a href="DialogService">Dialog Service</a> page.
pages/components that want to use it. For more information on the <code>DialogService</code>, see the <a href="DialogService">Dialog Service</a> page.
</p>
<p>
When using the <code>DialogService</code>, for displaying a regular dialog, the dialog will always be shown centered on the screen.
Expand All @@ -58,8 +58,13 @@

<DemoSection Title="Dialog Services" Component="@typeof(DialogServiceExample)" AdditionalFiles="@(new[] {"SimpleDialog.razor"})">
<Description>
This example shows how to use the <code>DialogService</code> to show a dialog. The content of the dialog is specified by
a component which implements <code>IDialogContentComponent&lt;T&gt;</code>. Here that is done in <code>SimpleDialog.razor</code>. The dialog is automatically styled and centered.
<p>
This example shows how to use the <code>DialogService</code> to show a dialog. The content of the dialog is specified by
a component which implements <code>IDialogContentComponent&lt;T&gt;</code>. Here that is done in <code>SimpleDialog.razor</code>. The dialog is automatically styled and centered.
</p>
<p>
Interaction with parent dialog can be made by injecting FluentDialog as Cascading Parameter.
</p>
</Description>
</DemoSection>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
Title = $"Hello {simplePerson.Firstname}",
OnDialogResult = DialogService.CreateDialogCallback(this, HandlePanel),
PrimaryAction = "Yes",
PrimaryActionEnabled = false,
SecondaryAction = "No",
Width = "500px",
Height = "400px",
Height = "500px",
Content = simplePerson,
};
DialogService.ShowDialog<SimpleDialog, SimplePerson>(parameters);
Expand Down
17 changes: 17 additions & 0 deletions examples/Demo/Shared/Pages/Dialog/Examples/SimpleDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@
<FluentTextField @bind-Value="@Content.Lastname">Your lastname:</FluentTextField>
<FluentNumberField @bind-Value="@Content.Age">Your age:</FluentNumberField>

@if (Dialog != null)
{
<FluentStack Orientation="Orientation.Vertical" Style="border: 1px solid red; padding: 10px">
<span>This section is visible only when component is hosted inside a Dialog</span>
<FluentButton OnClick="@(() => ToggleDialogPrimaryActionButton(true))">Enable Dialog Primary Action</FluentButton>
<FluentButton OnClick="@(() => ToggleDialogPrimaryActionButton(false))">Disable Dialog Primary Action</FluentButton>
</FluentStack>
}

@code {
[Parameter]
public SimplePerson Content { get; set; } = default!;

[CascadingParameter]
public FluentDialog? Dialog { get; set; }

private void ToggleDialogPrimaryActionButton(bool enable)
{
Dialog!.TogglePrimaryActionButton(enable);
}
}
6 changes: 4 additions & 2 deletions src/Core/Components/Dialog/FluentDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@
{
<FluentButton title="@_parameters.PrimaryAction"
@onclick="@(() => CloseAsync<object?>(Instance!.Content ??= true))"
Appearance="Appearance.Accent">
Appearance="Appearance.Accent"
Disabled="@(!_parameters.PrimaryActionEnabled)">
@_parameters.PrimaryAction
</FluentButton>
}
@if (_parameters.ShowSecondaryAction)
{
<FluentButton title="@_parameters.SecondaryAction"
@onclick="@(() => CancelAsync<object?>(Instance!.Content ??= false))"
Appearance="Appearance.Neutral">
Appearance="Appearance.Neutral"
Disabled="@(!_parameters.SecondaryActionEnabled)">
@_parameters.SecondaryAction
</FluentButton>
}
Expand Down
12 changes: 12 additions & 0 deletions src/Core/Components/Dialog/FluentDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ public void Hide()
StateHasChanged();
}

public void TogglePrimaryActionButton(bool isEnabled)
{
_parameters.PrimaryActionEnabled = isEnabled;
StateHasChanged();
}

public void ToggleSecondaryActionButton(bool isEnabled)
{
_parameters.SecondaryActionEnabled = isEnabled;
StateHasChanged();
}

public async Task CancelAsync() => await CloseAsync(DialogResult.Cancel());

public async Task CancelAsync<T>(T returnValue) => await CloseAsync(DialogResult.Cancel(returnValue));
Expand Down
10 changes: 10 additions & 0 deletions src/Core/Components/Dialog/Parameters/DialogParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ public class DialogParameters : ComponentParameters, IDialogParameters
/// </summary>
public string? PrimaryAction { get; set; } = "Ok"; //DialogResources.ButtonPrimary;

/// <summary>
/// When true, primary action's button is enabled.
/// </summary>
public bool PrimaryActionEnabled { get; set; } = true;

//public EventCallback<DialogResult>? OnPrimaryAction { get; set; } = default!;

/// <summary>
/// Text to display for the secondary action.
/// </summary>
public string? SecondaryAction { get; set; } = "Cancel"; //DialogResources.ButtonSecondary;

/// <summary>
/// When true, secondary action's button is enabled.
/// </summary>
public bool SecondaryActionEnabled { get; set; } = true;

//public EventCallback<DialogResult>? OnSecondaryAction { get; set; } = default!;

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Components/Dialog/Parameters/IDialogParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public interface IDialogParameters
bool ShowTitle { get; set; }
bool ShowDismiss { get; set; }
string? PrimaryAction { get; set; }
bool PrimaryActionEnabled { get; set; }
//EventCallback<DialogResult>? OnPrimaryAction { get; set; }
string? SecondaryAction { get; set; }
bool SecondaryActionEnabled { get; set; }
//EventCallback<DialogResult>? OnSecondaryAction { get; set; }
string? Width { get; set; }
string? Height { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Components/Dialog/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ public void ShowDialog<T, TContent>(DialogParameters<TContent> parameters)
ShowDismiss = parameters.ShowDismiss,
ShowTitle = parameters.ShowTitle,
PrimaryAction = parameters.PrimaryAction,
PrimaryActionEnabled = parameters.PrimaryActionEnabled,
SecondaryAction = parameters.SecondaryAction,
SecondaryActionEnabled = parameters.SecondaryActionEnabled,
Width = parameters.Width,
Height = parameters.Height,
AriaLabel = $"{parameters.Title}",
Expand Down