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
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel;

namespace Bit.BlazorUI;
namespace Bit.BlazorUI;

/// <summary>
/// DropMenu component is a versatile dropdown menu used in Blazor applications. It allows you to create a button that, when clicked, opens a callout or dropdown menu.
Expand Down Expand Up @@ -58,6 +56,11 @@ public partial class BitDropMenu : BitComponentBase
/// </summary>
[Parameter] public EventCallback OnDismiss { get; set; }

/// <summary>
/// The position of the responsive panel to show on the screen.
/// </summary>
[Parameter] public BitPanelPosition? PanelPosition { get; set; }

/// <summary>
/// The id of the element which needs to be scrollable in the content of the callout of the drop menu.
/// </summary>
Expand Down Expand Up @@ -163,7 +166,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await _js.BitSwipesSetup(
id: _calloutId,
trigger: 0.25m,
position: BitPanelPosition.End,
position: PanelPosition ?? BitPanelPosition.End,
isRtl: Dir is BitDir.Rtl,
orientationLock: BitSwipeOrientation.Horizontal,
dotnetObj: _dotnetObj,
Expand Down Expand Up @@ -244,6 +247,15 @@ private string GetCalloutCssClasses()
classes.Add("bit-drm-res");
}

classes.Add(PanelPosition switch
{
BitPanelPosition.Start => "bit-drm-sta",
BitPanelPosition.End => "bit-drm-end",
BitPanelPosition.Top => "bit-drm-top",
BitPanelPosition.Bottom => "bit-drm-btm",
_ => "bit-drm-end"
});

return string.Join(' ', classes).Trim();
}

Expand Down
42 changes: 31 additions & 11 deletions src/BlazorUI/Bit.BlazorUI/Components/Navs/DropMenu/BitDropMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
font-weight: $tg-font-weight;
background-color: $clr-bg-pri;
border-radius: $shp-border-radius;
--bit-drm-transform-factor: 1;

&.bit-rtl {
--bit-drm-transform-factor: -1;
}

@media (hover: hover) {
&:hover {
Expand Down Expand Up @@ -83,26 +88,41 @@

.bit-drm-res {
@include lt-sm {
top: 0;
right: 0;
opacity: 0;
height: 100%;
display: block;
overflow: hidden;
max-height: unset;
animation-name: unset;
transform: translateX(100%);
box-shadow: $box-shadow-callout;
transition: transform 200ms ease-out, opacity 100ms linear;
}
}

.bit-rtl {
.bit-drm-res {
@include lt-sm {
left: 0;
right: unset;
transform: translateX(-100%);
&.bit-drm-sta {
inset-block: 0;
inset-inline-start: 0;
transform: translateX(calc(var(--bit-drm-transform-factor) * -100%));
}

&.bit-drm-end {
inset-block: 0;
inset-inline-end: 0;
transform: translateX(calc(var(--bit-drm-transform-factor) * 100%));
}

&.bit-drm-top {
top: 0;
width: 100%;
max-width: 100%;
inset-inline: 0;
transform: translateY(-100%);
}

&.bit-drm-btm {
bottom: 0;
width: 100%;
max-width: 100%;
inset-inline: 0;
transform: translateY(100%);
}
}
}
18 changes: 14 additions & 4 deletions src/BlazorUI/Bit.BlazorUI/Scripts/Swipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@
if (!e.cancelable) return;

if (touchOnScrollContainer) {
const isScrollAtLeft = Math.abs(scrollContainer!.scrollLeft) <= 2;
const isScrollAtRight = scrollContainer!.scrollLeft + scrollContainer!.clientWidth >= (scrollContainer!.scrollWidth - 2);

const [isScrollAtLeft, isScrollAtRight] = calcScrolls();

if (diffX < 0 && (isRtl ? isScrollAtRight : isScrollAtLeft)) return;
if (diffX > 0 && (isRtl ? isScrollAtLeft : isScrollAtRight)) return;
}
Expand All @@ -135,6 +134,7 @@

const onEnd = async (e: TouchEvent | PointerEvent): Promise<void> => {
touchOnScrollContainer = false;

if (startX === -1 || startY === -1) return;

startX = startY = -1;
Expand Down Expand Up @@ -186,7 +186,10 @@
scrollContainer.addEventListener('touchstart', e => {
touchOnScrollContainer = true;

if (Math.abs(scrollContainer.scrollLeft) <= 2) return;
const [isScrollAtLeft, isScrollAtRight] = calcScrolls();

if (position === BitSwipePosition.End && isScrollAtLeft) return;
if (position === BitSwipePosition.Start && isScrollAtRight) return;

e.stopPropagation();
});
Expand Down Expand Up @@ -215,6 +218,13 @@
}
});
Swipes._swipes.push(swipe);

const calcScrolls = () => {
const isScrollAtLeft = Math.abs(scrollContainer!.scrollLeft) <= 2;
const isScrollAtRight = Math.abs(scrollContainer!.scrollLeft) + scrollContainer!.clientWidth >= (scrollContainer!.scrollWidth - 2);

return [isScrollAtLeft, isScrollAtRight];
}
}

public static dispose(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,21 @@

<DemoExample Title="Responsive" RazorCode="@example3RazorCode" Id="example3">
<div>Rendering the callout in responsive mode on small screens.</div><br />
<BitDropMenu Text="Responsive" Responsive ScrollContainerId="sc-con">
<div style="max-width:200px;overflow:auto" id="sc-con">
<BitStack Gap="1rem" Style="padding:0.5rem">

<BitDropMenu Text="End PanelPosition" Responsive ScrollContainerId="sc-con1" PanelPosition="BitPanelPosition.End">
<div style="max-width:200px;overflow:auto" id="sc-con1">
<BitStack FitWidth Gap="1rem" Style="padding:0.5rem">
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content This is the content This is the content</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content</BitText>
</BitStack>
</div>
</BitDropMenu>
<br />
<BitDropMenu Text="Start PanelPosition" Responsive ScrollContainerId="sc-con2" PanelPosition="BitPanelPosition.Start">
<div style="max-width:200px;overflow:auto" id="sc-con2">
<BitStack FitWidth Gap="1rem" Style="padding:0.5rem">
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content This is the content This is the content</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>This is the content</BitText>
Expand Down Expand Up @@ -142,8 +154,18 @@
</BitStack>
</BitDropMenu>
<br />
<BitDropMenu Text="ریسپانسیو منو" Dir="BitDir.Rtl" Responsive ScrollContainerId="sc-con-rtl">
<div style="max-width:200px;overflow:auto" id="sc-con-rtl">
<BitDropMenu Text="ریسپانسیو منو در انتها" Dir="BitDir.Rtl" Responsive ScrollContainerId="sc-con-rtl1">
<div style="max-width:200px;overflow:auto" id="sc-con-rtl1">
<BitStack Gap="1rem" Style="padding:0.5rem">
<BitText Typography="BitTypography.Subtitle1" NoWrap>این یک محتوای تستی می باشد این یک محتوای تستی می باشد این یک محتوای تستی می باشد</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>این یک محتوای تستی می باشد</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>این یک محتوای تستی می باشد</BitText>
</BitStack>
</div>
</BitDropMenu>
<br />
<BitDropMenu Text="ریسپانسیو منو در ابتدا" Dir="BitDir.Rtl" Responsive ScrollContainerId="sc-con-rtl2" PanelPosition="BitPanelPosition.Start">
<div style="max-width:200px;overflow:auto" id="sc-con-rtl2">
<BitStack Gap="1rem" Style="padding:0.5rem">
<BitText Typography="BitTypography.Subtitle1" NoWrap>این یک محتوای تستی می باشد این یک محتوای تستی می باشد این یک محتوای تستی می باشد</BitText>
<BitText Typography="BitTypography.Subtitle1" NoWrap>این یک محتوای تستی می باشد</BitText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,24 @@ public partial class BitDropMenuDemo
</BitDropMenu>";

private readonly string example3RazorCode = @"
<BitDropMenu Text=""Responsive"" Responsive ScrollContainerId=""sc-con"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con"">
<BitStack Gap=""1rem"" Style=""padding:0.5rem"">
<BitDropMenu Text=""End PanelPosition"" Responsive ScrollContainerId=""sc-con1"" PanelPosition=""BitPanelPosition.End"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con1"">
<BitStack FitWidth Gap=""1rem"" Style=""padding:0.5rem"">
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content This is the content This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"">This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"">This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"">This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
</BitStack>
</div>
</BitDropMenu>

<BitDropMenu Text=""Start PanelPosition"" Responsive ScrollContainerId=""sc-con2"" PanelPosition=""BitPanelPosition.Start"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con2"">
<BitStack FitWidth Gap=""1rem"" Style=""padding:0.5rem"">
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content This is the content This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>This is the content</BitText>
</BitStack>
</div>
</BitDropMenu>";
Expand Down Expand Up @@ -150,8 +161,18 @@ public partial class BitDropMenuDemo
</BitStack>
</BitDropMenu>

<BitDropMenu Text=""ریسپانسیو منو"" Dir=""BitDir.Rtl"" Responsive ScrollContainerId=""sc-con-rtl"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con-rtl"">
<BitDropMenu Text=""ریسپانسیو منو در انتها"" Dir=""BitDir.Rtl"" Responsive ScrollContainerId=""sc-con-rtl1"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con-rtl1"">
<BitStack Gap=""1rem"" Style=""padding:0.5rem"">
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>این یک محتوای تستی می باشد این یک محتوای تستی می باشد این یک محتوای تستی می باشد</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>این یک محتوای تستی می باشد</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>این یک محتوای تستی می باشد</BitText>
</BitStack>
</div>
</BitDropMenu>

<BitDropMenu Text=""ریسپانسیو منو در ابتدا"" Dir=""BitDir.Rtl"" Responsive ScrollContainerId=""sc-con-rtl2"" PanelPosition=""BitPanelPosition.Start"">
<div style=""max-width:200px;overflow:auto"" id=""sc-con-rtl2"">
<BitStack Gap=""1rem"" Style=""padding:0.5rem"">
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>این یک محتوای تستی می باشد این یک محتوای تستی می باشد این یک محتوای تستی می باشد</BitText>
<BitText Typography=""BitTypography.Subtitle1"" NoWrap>این یک محتوای تستی می باشد</BitText>
Expand Down
Loading