Skip to content

[dev-v5] Add responsive margin and padding utility classes to modify an element’s appearance - #3208

Merged
Vincent Baaij (vnbaaij) merged 18 commits into
dev-v5from
users/dvoituron/dev-v5/spacing
Jan 22, 2025
Merged

Vincent Baaij (vnbaaij) merged 18 commits into
dev-v5from
users/dvoituron/dev-v5/spacing

Conversation

@dvoituron

@dvoituron Denis Voituron (dvoituron) commented Jan 18, 2025 •

Copy link
Copy Markdown
Collaborator

[dev-v5] Add responsive margin and padding utility classes to modify an element’s appearance

Spacing

We include a wide range of shorthand responsive margin and padding utility
classes to modify an element’s appearance.

Spacing is a way to modify the CSS padding or margin styles without creating new classes.

How it works

Use the Margin or Padding property and choose a direction.
Then add size, ranging from 0 to 8.

Spacing utilities that apply to all breakpoints, from xs to xl,
have no breakpoint abbreviation in them.
The classes are named using the format {property}{direction}-{size}
for xs and {property}{direction}-{breakpoint}-{size} for sm, md, lg, and xl.

The properties:

  • m for classes that set Margin.
  • p for classes that set padding.

The direction property applies to:

  • t for margin-top or padding-top.
  • b for margin-bottom or padding-bottom`.
  • l for margin-left or padding-left`.
  • r for margin-right or padding-right`.
  • s for margin-left/padding-left (in LTR mode) and margin-right/padding-right (in RTL mode).
  • e for margin-right/padding-right (in LTR mode) and margin-left/padding-left (in RTL mode).
  • x for margin-left/padding-left and margin-right/padding-right.
  • y for margin-top/padding-top and margin-bottom/padding-bottom.
  • a for all 4 sides.

Size

The size changes with an interval of, by default, 4 pixels (see the CSS variables below).

Positive

  • 0 sets margin or padding to 0
  • 1 sets margin or padding to 4px
  • 2 sets margin or padding to 8px
  • 3 sets margin or padding to 12px
  • 4 sets margin or padding to 16px
  • 5 sets margin or padding to 20px
  • 6 sets margin or padding to 24px
  • 7 sets margin or padding to 28px
  • 8 sets margin or padding to 32px

Negative

  • n1 sets margin or padding to -4px
  • n2 sets margin or padding to -8px
  • n3 sets margin or padding to -12px
  • n4 sets margin or padding to -16px
  • n5 sets margin or padding to -20px
  • n6 sets margin or padding to -24px
  • n7 sets margin or padding to -28px
  • n8 sets margin or padding to -32px

Example

/* margin-top: 0; */
.mt-0 {
  margin-top: var(--spacingVerticalNone) !important; 
}

/* margin-left: 4px; */
.ml-1 {
  margin-left: var(--spacingHorizontalXS) !important;
}

/* margin-right: 8px; margin-left: 8px; */
.px-2 {
  padding-right: var(--spacingHorizontalS) !important;
  padding-left:  var(--spacingHorizontalS) !important;
}

/* padding: 12px 12px; */
.pa-3 {
  padding: var(--spacingVerticalM) var(--spacingHorizontalM) !important;
}

Margin and Padding component attributes

All FluentUI Blazor components contain the Margin and Padding attributes.

You can specify a CSS value respecting the CSS padding
or CSS margin pattern.
Or you can specify a class name like defined above on this page.

If you use one of these properties to include a complete style (e.g. style=“margin: 10px;”)
then this style will be ignored. The property Style can be used to include a complete style.

Example:

<FluentButton Margin="10px" />                     => <fluent-button style="margin: 10px;" />
<FluentButton Margin="10px 20px" />                => <fluent-button style="margin: 10px 20px;" />
<FluentButton Margin="auto" />                     => <fluent-button style="margin: auto;" />
<FluentButton Padding="10% 0;" />                  => <fluent-button style="padding: 10% 0;" />

<FluentButton Margin="mt-0" />                     => <fluent-button class="mt-0" />
<FluentButton Margin="mt-0" Padding="pa-3" />      => <fluent-button class="mt-0 pa-3" />

Appendix - CSS variables

Spacing uses these CSS variables, that can be customized:

--spacingVerticalNone:    0;
--spacingVerticalXS:      4px;
--spacingVerticalS:       8px;
--spacingVerticalM:       12px;
--spacingVerticalL:       16px;
--spacingVerticalXL:      20px;
--spacingVerticalXXL:     24px;
--spacingVerticalXXXL:    28px;
--spacingVerticalXXXXL:   32px;

--spacingHorizontalNone:  0;
--spacingHorizontalXS:    4px;
--spacingHorizontalS:     8px;
--spacingHorizontalM:     12px;
--spacingHorizontalL:     16px;
--spacingHorizontalXL:    20px;
--spacingHorizontalXXL:   24px;
--spacingHorizontalXXXL:  28px;
--spacingHorizontalXXXXL: 32px;

Unit Tests

{547A4CC3-F38D-4748-B9E9-8AFBE9D4CEE2}

@github-actions

github-actions Bot commented Jan 18, 2025 •

Copy link
Copy Markdown

✅ All tests passed successfully

Details on your Workflow / Core Tests page.

@github-actions

github-actions Bot commented Jan 19, 2025 •

Copy link
Copy Markdown

Summary - Unit Tests Code Coverage

Summary
Generated on: 01/22/2025 - 11:26:53
Coverage date: 01/22/2025 - 11:26:45
Parser: Cobertura
Assemblies: 1
Classes: 58
Files: 68
Line coverage: 98.1% (1144 of 1165)
Covered lines: 1144
Uncovered lines: 21
Coverable lines: 1165
Total lines: 5344
Branch coverage: 91.6% (729 of 795)
Covered branches: 729
Total branches: 795
Method coverage: Feature is only available for sponsors
Tag: 2441_12907190156

Coverage

Microsoft.FluentUI.AspNetCore.Components - 98.1%
Name Line Branch
Microsoft.FluentUI.AspNetCore.Components 98.1% 91.6%
Microsoft.FluentUI.AspNetCore.Components.Dialog.MessageBox.FluentMessageBox 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogEventArgs 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.DialogInstance 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptions 65.5%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsFooter 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsFooterAction 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogOptionsHeader 100%
Microsoft.FluentUI.AspNetCore.Components.DialogResult 100% 100%
Microsoft.FluentUI.AspNetCore.Components.DialogResult`1 100%
Microsoft.FluentUI.AspNetCore.Components.DialogService 98.9% 81.4%
Microsoft.FluentUI.AspNetCore.Components.DialogToggleEventArgs 100%
Microsoft.FluentUI.AspNetCore.Components.Extensions.EnumExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Extensions.FluentInputExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentButton 100% 89.5%
Microsoft.FluentUI.AspNetCore.Components.FluentComponentBase 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentDialog 97.4% 89.7%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogBody 100% 91.6%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogInstance 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentDialogProvider 100% 79.1%
Microsoft.FluentUI.AspNetCore.Components.FluentGrid 100% 90%
Microsoft.FluentUI.AspNetCore.Components.FluentGridItem 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentIcon`1 100% 95.8%
Microsoft.FluentUI.AspNetCore.Components.FluentInputBase`1 100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.FluentInputImmediateBase`1 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentJSModule 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLabel 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayout 100% 71.4%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutHamburger 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutItem 100% 89.2%
Microsoft.FluentUI.AspNetCore.Components.FluentListBase`1 93.3% 94.7%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerInternal 100%
Microsoft.FluentUI.AspNetCore.Components.FluentOption 91.6% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentSelect`1 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentServiceBase`1 100%
Microsoft.FluentUI.AspNetCore.Components.FluentServiceProviderException`1 100%
Microsoft.FluentUI.AspNetCore.Components.FluentText 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentTextInput 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Icon 100% 91.1%
Microsoft.FluentUI.AspNetCore.Components.IconFromImage 100%
Microsoft.FluentUI.AspNetCore.Components.IconInfo 100%
Microsoft.FluentUI.AspNetCore.Components.IFluentLocalizer 100% 100%
Microsoft.FluentUI.AspNetCore.Components.InternalListContext`1 60%
Microsoft.FluentUI.AspNetCore.Components.Localization.LanguageResource 100% 100%
Microsoft.FluentUI.AspNetCore.Components.MessageBoxOptions 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.AppearanceExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.FluentInputAppearanceExt
ensions
83.3% 75%
Microsoft.FluentUI.AspNetCore.Components.ServiceProviderExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.SpacingExtensions 100% 97%
Microsoft.FluentUI.AspNetCore.Components.Utilities.AddTag 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.CssBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Debounce 100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Identifier 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.IdentifierContext 100% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InlineStyleBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Dispatc
herTimerExtensions
95.7% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.StyleBuilder 100% 100%
Microsoft.FluentUI.AspNetCore.Components.ZIndex 100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants