-
-
Notifications
You must be signed in to change notification settings - Fork 364
feat(LayoutSidebar): add LayoutSplitebar component #5438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
76b40b6
feat: 增加 ShowSidebar 参数
ArgoZhang a0dccee
feat: 增加 LayoutSidebar 组件
ArgoZhang ea2bddd
doc: 更新拖动栏组件
ArgoZhang c31f90b
chore: 增加样式
ArgoZhang 3b21c0a
refactor: 更新参数
ArgoZhang 74f701a
refactor: 精简代码
ArgoZhang d54d0b4
style: 更新样式
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @namespace BootstrapBlazor.Components | ||
| @inherits BootstrapModuleComponentBase | ||
| @attribute [BootstrapModuleAutoLoader("Layout/LayoutSidebar.razor.js")] | ||
|
|
||
| <div id="@Id" class="layout-sidebar" | ||
| data-bb-min="@_minWidthString" data-bb-max="@_maxWidthString" data-bb-selector="@ContainerSelector"> | ||
| <div class="layout-sidebar-body"></div> | ||
| </div> |
35 changes: 35 additions & 0 deletions
35
src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
||
| /// <summary> | ||
| /// LayoutSidebar 组件 | ||
| /// </summary> | ||
| public partial class LayoutSidebar | ||
| { | ||
| /// <summary> | ||
| /// 获得/设置 容器选择器 默认 null 未设置 | ||
| /// 组件拖动后设置容器 style="--bb-layout-sidebar-width: 200px;" 用于宽度调整 | ||
| /// </summary> | ||
| [Parameter] | ||
| public string? ContainerSelector { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 最小宽度 默认 null 未设置 | ||
| /// </summary> | ||
| [Parameter] | ||
| public int? Min { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 最大宽度 默认 null 未设置 | ||
| /// </summary> | ||
| [Parameter] | ||
| public int? Max { get; set; } | ||
|
|
||
| private string? _minWidthString => Min.HasValue ? $"{Min}" : null; | ||
|
|
||
| private string? _maxWidthString => Max.HasValue ? $"{Max}" : null; | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import Drag from "../../modules/drag.js" | ||
| import Data from "../../modules/data.js" | ||
|
|
||
| export function init(id) { | ||
| const el = document.getElementById(id); | ||
| if (el === null) { | ||
| return; | ||
| } | ||
|
|
||
| const min = parseFloat(el.getAttribute("data-bb-min") ?? "0"); | ||
| const max = parseFloat(el.getAttribute("data-bb-max") ?? "0"); | ||
| const selector = el.getAttribute("data-bb-selector"); | ||
| const section = document.querySelector(selector); | ||
| const bar = el.querySelector(".layout-sidebar-body"); | ||
| let originX = 0; | ||
| let width = 0; | ||
| Drag.drag(bar, | ||
| e => { | ||
| bar.classList.add('drag') | ||
| width = parseInt(getComputedStyle(section).getPropertyValue('--bb-layout-sidebar-width')) | ||
| originX = e.clientX || e.touches[0].clientX | ||
| }, | ||
| e => { | ||
| const eventX = e.clientX || (e.touches.length > 0 && e.touches[0].clientX) | ||
| const moveX = eventX - originX | ||
| const newWidth = width + moveX | ||
| if (newWidth >= min && newWidth <= max) { | ||
| section.style.setProperty('--bb-layout-sidebar-width', `${newWidth}px`) | ||
| } | ||
| }, | ||
| e => { | ||
| bar.classList.remove('drag') | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| export function dispose(id) { | ||
| const el = document.getElementById(id); | ||
| if (el) { | ||
| const bar = el.querySelector(".layout-sidebar-body"); | ||
| if (bar) { | ||
| Drag.dispose(bar); | ||
| } | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/BootstrapBlazor/Components/Layout/LayoutSidebar.razor.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| .layout-sidebar { | ||
| width: 1px; | ||
| position: absolute; | ||
| top: 0; | ||
| right: -1px; | ||
| bottom: 0; | ||
| background-color: var(--bs-border-color); | ||
| display: none; | ||
|
|
||
| .layout-sidebar-body { | ||
| position: absolute; | ||
| inset: 0px -2px; | ||
| cursor: col-resize; | ||
| background-color: transparent; | ||
| border-radius: 4px; | ||
|
|
||
| &:hover { | ||
| background-color: var(--bb-sidebar-body-hover-bg); | ||
| } | ||
|
|
||
| &.drag, | ||
| &.drag:hover { | ||
| background-color: var(--bb-sidebar-body-drag-hover-bg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @media(min-width: 768px) { | ||
| .layout-sidebar { | ||
| display: block; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.