MudBlazor / MudBlazor

Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
http://mudblazor.com
MIT License
7.21k stars 1.18k forks source link

Globals: Add `DialogDefaults.DefaultFocus`, Consolidate others to their own static classes #8831

Closed danielchalmers closed 2 weeks ago

danielchalmers commented 2 weeks ago

Description

How Has This Been Tested?

Type of Changes

Checklist

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 90.04%. Comparing base (28bc599) to head (b205a85). Report is 127 commits behind head on dev.

Files Patch % Lines
src/MudBlazor/Services/MudGlobal.cs 55.55% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #8831 +/- ## ========================================== + Coverage 89.82% 90.04% +0.21% ========================================== Files 412 421 +9 Lines 11878 12292 +414 Branches 2364 2437 +73 ========================================== + Hits 10670 11068 +398 + Misses 681 672 -9 - Partials 527 552 +25 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

henon commented 2 weeks ago

In principle yes, it makes sense to have global defaults for every parameter, even those of MudDialog. I first thought, this would be better suited for DialogOptions but then, it is a parameter of a component and thus the default value would be expected to be customizable like all the other component parameters.

henon commented 2 weeks ago

When we add defaults for all components, there will be hundreds of definitions in MudGlobal. It might become quite unmanageable. You sure we shouldn't make static subclasses of MudGlobal for every component?

i.e. MudGlobal.DialogDefaults.DefaultFocus = ... MudGlobal.ButtonDefaults.Variant = ...

danielchalmers commented 2 weeks ago

@henon Do you want to implement your vision for that API separately and I rebase? Or tell me what the classes would look like and I can do it in this PR?

henon commented 2 weeks ago
public static class MudGlobal {
  public static class DialogDefaults { 
    public DefaultFocus DefaultFocus = DefaultFocus.Element;
  }
  public static class ButtonDefaults { 
    public static Variant Variant = Variant.Text;
  }
}
danielchalmers commented 2 weeks ago

@henon Done. Take a look now.

henon commented 2 weeks ago

Here is another idea, add these on top of what you already have:

    public static class OverlayDefaults
    {
        /// <summary>
        /// The default transition delay for <see cref="MudOverlay"/> and <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Delay { get; set; } = TransitionDefaults.Delay;

        /// <summary>
        /// The default transition time for components like <see cref="MudTooltip"/>, <see cref="MudOverlay"/>, <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Duration { get; set; } = TransitionDefaults.Duration;
    }

    public static class PickerDefaults
    {
        /// <summary>
        /// The default transition delay for <see cref="MudOverlay"/> and <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Delay { get; set; } = TransitionDefaults.Delay;

        /// <summary>
        /// The default transition time for components like <see cref="MudTooltip"/>, <see cref="MudOverlay"/>, <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Duration { get; set; } = TransitionDefaults.Duration;
    }

    public static class TooltipDefaults
    {
        /// <summary>
        /// The default transition delay for <see cref="MudOverlay"/> and <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Delay { get; set; } = TransitionDefaults.Delay;

        /// <summary>
        /// The default transition time for components like <see cref="MudTooltip"/>, <see cref="MudOverlay"/>, <see cref="MudPicker{T}"/>.
        /// </summary>
        public static TimeSpan Duration { get; set; } = TransitionDefaults.Duration;
    }

That way, on top of changing the delay and transition duration for all via TransitionDefaults we can also set them differently for overlay, picker and tooltip.

danielchalmers commented 2 weeks ago

@henon Good idea. Added.