Skip to content

Commit 0a02a32

Browse files
committed
refactor(Sidebar): refactor responsive behavior
1 parent 8f9ba8e commit 0a02a32

File tree

4 files changed

+32
-37
lines changed

4 files changed

+32
-37
lines changed

js/src/sidebar.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ const CLASS_NAME_SHOW = 'show'
4343
const CLASS_NAME_SIDEBAR = 'sidebar'
4444
const CLASS_NAME_SIDEBAR_NARROW = 'sidebar-narrow'
4545
const CLASS_NAME_SIDEBAR_OVERLAID = 'sidebar-overlaid'
46-
const CLASS_NAME_SIDEBAR_SELF_HIDDING = 'sidebar-self-hidding'
4746
const CLASS_NAME_SIDEBAR_NARROW_UNFOLDABLE = 'sidebar-narrow-unfoldable'
4847

49-
// eslint-disable-next-line prefer-regex-literals
5048
const REGEXP_SIDEBAR_SELF_HIDING = /sidebar-self-hiding/
51-
// const REGEXP_SIDEBAR_SHOW = new RegExp('sidebar.*show')
5249
const REGEXP_SIDEBAR_SHOW_BREAKPOINT = /sidebar-(sm|md|lg|xl|xxl)-show/
5350

5451
const EVENT_HIDE = `hide${EVENT_KEY}`
@@ -100,12 +97,6 @@ class Sidebar extends BaseComponent {
10097
show() {
10198
EventHandler.trigger(this._element, EVENT_SHOW)
10299

103-
// if (typeof breakpoint !== 'undefined') {
104-
// this._breakpoint = breakpoint
105-
// }
106-
107-
// this._element.classList.add(this._createShowClass())
108-
109100
if (this._element.classList.contains(CLASS_NAME_HIDE)) {
110101
this._element.classList.remove(CLASS_NAME_HIDE)
111102
}
@@ -144,16 +135,6 @@ class Sidebar extends BaseComponent {
144135

145136
this._element.classList.add(CLASS_NAME_HIDE)
146137

147-
// if (!this._element.className.match(REGEXP_SIDEBAR_SELF_HIDING)) {
148-
// this._element.classList.add(CLASS_NAME_HIDE)
149-
// }
150-
151-
// this._element.classList.forEach(className => {
152-
// if (className.match(REGEXP_SIDEBAR_SHOW)) {
153-
// this._element.classList.remove(className)
154-
// }
155-
// })
156-
157138
if (this._isMobile()) {
158139
this._removeBackdrop()
159140
}
@@ -176,19 +157,11 @@ class Sidebar extends BaseComponent {
176157
}
177158

178159
toggle() {
179-
// eslint-disable-next-line no-console
180-
console.log(this._show)
181160
if (this._show) {
182161
this.hide()
183162
return
184163
}
185164

186-
// if (breakpoint === 'all') {
187-
// this._breakpoint = false
188-
// this.show(this._breakpoint)
189-
// return
190-
// }
191-
192165
this.show()
193166
}
194167

scss/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ $enable-important-utilities: true !default;
263263

264264
// Set mobile breakpoint
265265

266-
$mobile-breakpoint: lg !default;
266+
$mobile-breakpoint: md !default;
267267

268268
// Prefix for :root CSS variables
269269

scss/sidebar/_sidebar-narrow.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@
5151

5252
.sidebar-narrow {
5353
@extend %sidebar-narrow;
54+
~ * {
55+
--#{$variable-prefix}sidebar-occupy: #{$sidebar-narrow-width};
56+
}
5457
}
5558

5659
.sidebar-narrow-unfoldable {
5760
position: fixed !important;
5861
z-index: $zindex-fixed + 1;
5962

63+
~ * {
64+
--#{$variable-prefix}sidebar-occupy: #{$sidebar-narrow-width};
65+
}
66+
6067
&:not(:hover) {
6168
@extend %sidebar-narrow;
6269
}
@@ -72,10 +79,6 @@
7279
transform: rotate(0deg);
7380
}
7481
}
75-
76-
~ * {
77-
--#{$variable-prefix}sidebar-width: #{$sidebar-narrow-width};
78-
}
7982
}
8083

8184
// Responsive behavior

scss/sidebar/_sidebar.scss

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
box-shadow: none;
1515
@include transition($sidebar-transition);
1616

17-
+ [data-coreui-reliant="sidebar"] {
18-
@include transition($sidebar-reliant-transition);
17+
~ * {
18+
--#{$variable-prefix}sidebar-occupy: #{$sidebar-width};
1919
}
2020

21-
@include media-breakpoint-down(breakpoint-before($mobile-breakpoint)) {
21+
// + [data-coreui-reliant="sidebar"] {
22+
// @include transition($sidebar-reliant-transition);
23+
// }
24+
25+
@include media-breakpoint-down($mobile-breakpoint) {
2226
// Some of our components use this property to detect if the sidebar has mobile behavior.
2327
--is-mobile: true;
2428
position: fixed;
@@ -32,6 +36,10 @@
3236
&.sidebar-right {
3337
right: 0;
3438
}
39+
40+
~ * {
41+
--#{$variable-prefix}sidebar-occupy: 0;
42+
}
3543
}
3644

3745
&:not(.sidebar-right){
@@ -57,13 +65,21 @@
5765
&.sidebar-right {
5866
margin-right: - $sidebar-width;
5967
}
68+
69+
~ * {
70+
--#{$variable-prefix}sidebar-occupy: 0;
71+
}
6072
}
6173

6274
@each $width, $value in $sidebar-widths {
6375
&.sidebar-#{$width} {
6476
flex: 0 0 $value;
6577
width: $value;
6678

79+
~ * {
80+
--#{$variable-prefix}sidebar-occupy: #{$value};
81+
}
82+
6783
&:not(.sidebar-right).hide {
6884
margin-left: - $value;
6985
}
@@ -177,7 +193,7 @@
177193
background-color: var(--#{$variable-prefix}sidebar-toggler-bg, $sidebar-toggler-bg);
178194
border: 0;
179195

180-
@include media-breakpoint-down(breakpoint-before($mobile-breakpoint)) {
196+
@include media-breakpoint-down($mobile-breakpoint) {
181197
display: none;
182198
}
183199

@@ -214,7 +230,7 @@
214230

215231
// Backdrop background
216232
.sidebar-backdrop {
217-
@include media-breakpoint-down(breakpoint-before($mobile-breakpoint)) {
233+
@include media-breakpoint-down($mobile-breakpoint) {
218234
position: fixed;
219235
top: 0;
220236
left: 0;
@@ -253,6 +269,9 @@
253269
}
254270
}
255271
}
272+
~ * {
273+
--#{$variable-prefix}sidebar-occupy: 0;
274+
}
256275
}
257276
}
258277
}

0 commit comments

Comments
 (0)