Skip to content

Commit 32a4c0a

Browse files
authored
refactor(LayoutSplitebar): add min/max default value (#5448)
* style: 增加动画效果 * refactor: 更新代码 * chore: bump version 9.3.1-beta35 * feat: 支持默认值 * refactor: 支持主题样式 * refactor: 支持 Layout 收缩状态 * refactor: 增加异常保护逻辑
1 parent 10f7564 commit 32a4c0a

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
@inherits BootstrapModuleComponentBase
33
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true)]
44

5-
<CascadingValue Value="this" IsFixed="true">
6-
@if (_init)
7-
{
5+
@if (_init)
6+
{
7+
<CascadingValue Value="this" IsFixed="true">
88
@if (IsAuthenticated)
99
{
1010
<section @attributes="AdditionalAttributes" class="@ClassString" style="@StyleString">
@@ -60,8 +60,8 @@
6060
{
6161
@RenderMain
6262
}
63-
}
64-
</CascadingValue>
63+
</CascadingValue>
64+
}
6565

6666
@code {
6767
RenderFragment<bool> RenderHeader => collapse =>

src/BootstrapBlazor/Components/Layout/Layout.razor.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
}
8585

8686
.has-sidebar {
87-
/*left-right*/
8887
position: relative;
8988
flex: 1;
9089

@@ -267,14 +266,17 @@
267266
position: relative;
268267
width: var(--bb-layout-sidebar-width);
269268
transform: translateX(0);
270-
transition: width .3s linear;
271269
flex-shrink: 0;
272270

273271
.layout-menu {
274272
border-right: 1px solid var(--bs-border-color);
275273
}
276274
}
277275

276+
&:not(.drag) .layout-side {
277+
transition: width .3s linear;
278+
}
279+
278280
&.has-sidebar {
279281
.layout-side {
280282
&.is-fixed-header {

src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,38 @@ export function init(id) {
66
return;
77
}
88

9-
const min = parseFloat(el.getAttribute("data-bb-min") ?? "0");
10-
const max = parseFloat(el.getAttribute("data-bb-max") ?? "0");
9+
const min = parseFloat(el.getAttribute("data-bb-min") ?? "-1");
10+
const max = parseFloat(el.getAttribute("data-bb-max") ?? "-1");
1111
const selector = el.getAttribute("data-bb-selector") ?? ".layout";
1212
const section = document.querySelector(selector);
13+
if (section === null) {
14+
log.warning(`LayoutSplitebar: selector ${selector} not found`);
15+
return;
16+
}
17+
1318
const bar = el.querySelector(".layout-splitebar-body");
1419
let originX = 0;
1520
let width = 0;
1621
Drag.drag(bar,
1722
e => {
18-
bar.classList.add('drag')
23+
section.classList.add('drag')
1924
width = parseInt(getComputedStyle(section).getPropertyValue('--bb-layout-sidebar-width'))
2025
originX = e.clientX || e.touches[0].clientX
2126
},
2227
e => {
2328
const eventX = e.clientX || (e.touches.length > 0 && e.touches[0].clientX)
2429
const moveX = eventX - originX
2530
const newWidth = width + moveX
26-
if (newWidth >= min && newWidth <= max) {
27-
section.style.setProperty('--bb-layout-sidebar-width', `${newWidth}px`)
31+
if (min > -1 && newWidth < min) {
32+
newWidth = min
33+
}
34+
if (max > -1 && newWidth > max) {
35+
newWidth = max
2836
}
37+
section.style.setProperty('--bb-layout-sidebar-width', `${newWidth}px`)
2938
},
3039
e => {
31-
bar.classList.remove('drag')
40+
section.classList.remove('drag')
3241
}
3342
)
3443
}

src/BootstrapBlazor/Components/Layout/LayoutSplitebar.razor.scss

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,35 @@
88
display: none;
99

1010
.layout-splitebar-body {
11+
--bb-splitebar-body-hover-bg: #{$bb-splitebar-body-hover-bg};
12+
--bb-splitebar-body-drag-hover-bg: #{$bb-splitebar-body-drag-hover-bg};
1113
position: absolute;
1214
inset: 0px -2px;
1315
cursor: col-resize;
1416
background-color: transparent;
1517
border-radius: 4px;
18+
transition: background .3s linear;
1619

1720
&:hover {
18-
background-color: var(--bb-sidebar-body-hover-bg);
21+
background-color: var(--bb-splitebar-body-hover-bg);
1922
}
23+
}
24+
}
2025

21-
&.drag,
22-
&.drag:hover {
23-
background-color: var(--bb-sidebar-body-drag-hover-bg);
26+
.drag {
27+
.layout-splitebar {
28+
.layout-splitebar-body:hover {
29+
background-color: var(--bb-splitebar-body-drag-hover-bg);
2430
}
2531
}
2632
}
2733

34+
.is-collapsed {
35+
.layout-splitebar-body {
36+
display: none;
37+
}
38+
}
39+
2840
@media(min-width: 768px) {
2941
.layout-splitebar {
3042
display: block;

src/BootstrapBlazor/wwwroot/scss/theme/bootstrapblazor.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ $bb-layout-menu-item-hover-bg: #409eff;
346346
$bb-layout-logo-border-color: #d5d5d5;
347347
$bb-layout-logo-bg: #0e77e3;
348348

349+
// LayoutSplitebar
350+
$bb-splitebar-body-hover-bg: rgba(175, 184, 193, 0.2);
351+
$bb-splitebar-body-drag-hover-bg: rgb(9, 105, 218);
352+
349353
// Light
350354
$bb-light-bg: radial-gradient(circle, #fff, #aaa, #333);
351355
$bb-light-danger-start-color: #e17777;

0 commit comments

Comments
 (0)