Skip to content

Commit

Permalink
Container breakpoints (#2867)
Browse files Browse the repository at this point in the history
* Add Breakpoint on Container component

* Document Breakpoint attribute
  • Loading branch information
stsrki authored Sep 3, 2021
1 parent af58f4c commit 9091a0d
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Documentation/Blazorise.Docs/Layouts/DocsLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@
</BarMenu>
</Bar>
</LayoutHeader>
<LayoutContent Padding="Padding.Is0.OnX.Is4.OnY.Is4.OnDesktop">
<Container>
<LayoutContent Padding="Padding.Is0.OnX.Is4.OnY.Is4.OnWidescreen">
<Container Breakpoint="Breakpoint.Widescreen">
@Body
</Container>
</LayoutContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="blazorise-codeblock">
<div class="html"><pre>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Container</span> <span class="htmlAttributeName">Breakpoint</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Breakpoint</span><span class="enumValue">.Tablet</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Alert</span> <span class="htmlAttributeName">Color</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Color</span><span class="enumValue">.Primary</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Visible</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="keyword">true</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
100% wide until tablet breakpoint
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Alert</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Container</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Container</span> <span class="htmlAttributeName">Breakpoint</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Breakpoint</span><span class="enumValue">.Desktop</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Alert</span> <span class="htmlAttributeName">Color</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Color</span><span class="enumValue">.Primary</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Visible</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="keyword">true</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
100% wide until desktop breakpoint
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Alert</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Container</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Container</span> <span class="htmlAttributeName">Breakpoint</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Breakpoint</span><span class="enumValue">.Widescreen</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Alert</span> <span class="htmlAttributeName">Color</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Color</span><span class="enumValue">.Primary</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Visible</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="keyword">true</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
100% wide until widescreen breakpoint
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Alert</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Container</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Container</span> <span class="htmlAttributeName">Breakpoint</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Breakpoint</span><span class="enumValue">.FullHD</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;</span><span class="htmlElementName">Alert</span> <span class="htmlAttributeName">Color</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="enum">Color</span><span class="enumValue">.Primary</span><span class="quot">&quot;</span> <span class="htmlAttributeName">Visible</span><span class="htmlOperator">=</span><span class="quot">&quot;</span><span class="keyword">true</span><span class="quot">&quot;</span><span class="htmlTagDelimiter">&gt;</span>
100% wide until full-hd breakpoint
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Alert</span><span class="htmlTagDelimiter">&gt;</span>
<span class="htmlTagDelimiter">&lt;/</span><span class="htmlElementName">Container</span><span class="htmlTagDelimiter">&gt;</span>
</pre></div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@namespace Blazorise.Docs.Docs.Examples

<Container Breakpoint="Breakpoint.Tablet">
<Alert Color="Color.Primary" Visible="true">
100% wide until tablet breakpoint
</Alert>
</Container>
<Container Breakpoint="Breakpoint.Desktop">
<Alert Color="Color.Primary" Visible="true">
100% wide until desktop breakpoint
</Alert>
</Container>
<Container Breakpoint="Breakpoint.Widescreen">
<Alert Color="Color.Primary" Visible="true">
100% wide until widescreen breakpoint
</Alert>
</Container>
<Container Breakpoint="Breakpoint.FullHD">
<Alert Color="Color.Primary" Visible="true">
100% wide until full-hd breakpoint
</Alert>
</Container>
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@
<DocsPageSectionSource Code="ContainerFluidExample" />
</DocsPageSection>

<DocsPageSection>
<DocsPageSectionHeader Title="Responsive">
Responsive containers allow you to specify a class that is 100% wide until the specified breakpoint is reached,
after which we apply <Code>max-widths</Code> for each of the higher breakpoints. For example, <Code>Breakpoint.Tablet</Code>
is 100% wide to start until the <Code>Tablet</Code> breakpoint is reached, where it will scale up
with <Code>Desktop</Code>, <Code>Widescreen</Code>, and <Code>FullHD</Code>.
</DocsPageSectionHeader>
<DocsPageSectionContent Outlined FullWidth>
<ContainerBreakpointExample />
</DocsPageSectionContent>
<DocsPageSectionSource Code="ContainerBreakpointExample" />
</DocsPageSection>

<DocsPageSubtitle>
Attributes
</DocsPageSubtitle>
Expand All @@ -101,6 +114,9 @@
</DocsAttributes>

<DocsAttributes Title="Container">
<DocsAttributesItem Name="Breakpoint" Type="Breakpoint" Default="None">
Makes a full width container that is 100% wide until the specified breakpoint is reached.
</DocsAttributesItem>
<DocsAttributesItem Name="Fluid" Type="bool" Default="false">
Makes a full width container, spanning the entire width of the viewport.
</DocsAttributesItem>
Expand Down
3 changes: 2 additions & 1 deletion Source/Blazorise.AntDesign/AntDesignClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ public override string DropdownDirection( Direction direction )

#region Container

public override string Container() => "ant-container";
public override string Container( Breakpoint breakpoint )
=> breakpoint != Breakpoint.None && breakpoint != Breakpoint.Mobile ? $"ant-container-{ToBreakpoint( breakpoint )}" : "ant-container";

public override string ContainerFluid() => "ant-container-fluid";

Expand Down
8 changes: 4 additions & 4 deletions Source/Blazorise.AntDesign/Styles/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
}

@media (min-width: 576px) {
.ant-container {
.ant-container, .ant-container-sm {
max-width: 540px;
}
}

@media (min-width: 768px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md {
max-width: 720px;
}
}

@media (min-width: 992px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md, .ant-container-lg {
max-width: 960px;
}
}

@media (min-width: 1200px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md, .ant-container-lg, .ant-container-xl {
max-width: 1140px;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Blazorise.AntDesign/wwwroot/blazorise.antdesign.css
Original file line number Diff line number Diff line change
Expand Up @@ -1497,19 +1497,19 @@
margin-left: auto; }

@media (min-width: 576px) {
.ant-container {
.ant-container, .ant-container-sm {
max-width: 540px; } }

@media (min-width: 768px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md {
max-width: 720px; } }

@media (min-width: 992px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md, .ant-container-lg {
max-width: 960px; } }

@media (min-width: 1200px) {
.ant-container {
.ant-container, .ant-container-sm, .ant-container-md, .ant-container-lg, .ant-container-xl {
max-width: 1140px; } }

.ant-container-fluid {
Expand Down
3 changes: 2 additions & 1 deletion Source/Blazorise.Bootstrap/BootstrapClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ public override string DropdownDirection( Direction direction )

#region Container

public override string Container() => "container";
public override string Container( Breakpoint breakpoint )
=> breakpoint != Breakpoint.None && breakpoint != Breakpoint.Mobile ? $"container-{ToBreakpoint( breakpoint )}" : "container";

public override string ContainerFluid() => "container-fluid";

Expand Down
3 changes: 2 additions & 1 deletion Source/Blazorise.Bulma/BulmaClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ public override string DropdownDirection( Direction direction )

#region Container

public override string Container() => "container";
public override string Container( Breakpoint breakpoint )
=> breakpoint > Breakpoint.Desktop ? $"container is-{ToBreakpoint( breakpoint )}" : "container";

public override string ContainerFluid() => "container-fluid";

Expand Down
19 changes: 18 additions & 1 deletion Source/Blazorise/Components/Container/Container.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public partial class Container : BaseComponent
{
#region Members

private Breakpoint breakpoint;

private bool fluid;

#endregion
Expand All @@ -24,7 +26,7 @@ protected override void BuildClasses( ClassBuilder builder )
if ( Fluid )
builder.Append( ClassProvider.ContainerFluid() );
else
builder.Append( ClassProvider.Container() );
builder.Append( ClassProvider.Container( Breakpoint ) );

base.BuildClasses( builder );
}
Expand All @@ -33,6 +35,21 @@ protected override void BuildClasses( ClassBuilder builder )

#region Properties

/// <summary>
/// Makes a full width container that is 100% wide until the specified breakpoint is reached.
/// </summary>
[Parameter]
public Breakpoint Breakpoint
{
get => breakpoint;
set
{
breakpoint = value;

DirtyClasses();
}
}

/// <summary>
/// Makes a full width container, spanning the entire width of the viewport.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Interfaces/IClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public interface IClassProvider

#region Container

string Container();
string Container( Breakpoint breakpoint );

string ContainerFluid();

Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Providers/ClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public abstract class ClassProvider : IClassProvider

#region Container

public abstract string Container();
public abstract string Container( Breakpoint breakpoint );

public abstract string ContainerFluid();

Expand Down
2 changes: 1 addition & 1 deletion Source/Blazorise/Providers/EmptyClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class EmptyClassProvider : IClassProvider

#region Container

public string Container() => null;
public string Container( Breakpoint breakpoint ) => null;

public string ContainerFluid() => null;

Expand Down

0 comments on commit 9091a0d

Please sign in to comment.