Skip to content

Commit fae03f1

Browse files
Remove responsive references and add javascript snippet for how to achieve it (#265)
This PR updates the documentation around sidebars to remove unneeded references and also includes a javascript snippet for how to make your sidebar responsive.
1 parent 7d630b9 commit fae03f1

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/stories/Components/Sidebar/Sidebar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const createSidebarItem = ({ type, icon, label }, activeLink) => {
2121

2222
export const createSidebar = ({
2323
size = 'drawer',
24-
responsive = false,
2524
style = 'default',
2625
brand = true,
2726
padded = false,
@@ -60,7 +59,6 @@ export const createSidebar = ({
6059
'sidebar',
6160
style === 'default' ? '' : `sidebar--${style}`,
6261
`sidebar--${size}`,
63-
responsive ? 'sidebar--responsive' : '',
6462
padded ? 'sidebar--padded' : '',
6563
]
6664
.filter(Boolean)

src/stories/Components/Sidebar/Sidebar.mdx

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ For instructions on how to integrate a sidebar into your applications layout, se
2121

2222
`.sidebar--drawer`, `.sidebar--compact`, and `.sidebar--rail` are used to denote which style of sidebar you would like to use.
2323

24-
`.sidebar--responsive` can be added to a drawer to allow for a sidebar that responsively changes from the larger state (compact or drawer) to the rail when the screen is smaller. e.g.
25-
2624
```html
27-
<div class="sidebar sidebar--drawer sidebar--responsive">...</div>
25+
<div class="sidebar sidebar--drawer">...</div>
2826
```
2927

3028
Any [Button](?path=/docs/navigation-components-button--docs#default) style can be used for the links.
@@ -33,6 +31,48 @@ Any [Button](?path=/docs/navigation-components-button--docs#default) style can b
3331
- Compact will use the `.icon-with-label` style
3432
- Rail will use the `.btn--icon` style and hide the label
3533

34+
## Responsive Sidebar
35+
36+
The sidebar can be made responsive with a little snippet of Javascript. This allows for the sidebar to change from the larger state (compact or drawer) to the rail when the screen is smaller. e.g.
37+
38+
```js
39+
const sidebarStyleOptions = {
40+
drawer: 'sidebar--drawer',
41+
compact: 'sidebar--compact',
42+
rail: 'sidebar--rail',
43+
}
44+
45+
const getSidebarStyle = (width) => {
46+
let newStyle = sidebarStyleOptions['drawer']
47+
48+
if (window.innerWidth <= 1024) {
49+
newStyle = sidebarStyleOptions['compact']
50+
}
51+
52+
if (window.innerWidth <= 768) {
53+
newStyle = sidebarStyleOptions['rail']
54+
}
55+
56+
return newStyle
57+
}
58+
59+
const applySidebarStyle = (newStyle) => {
60+
const sidebar = document.getElementById('sidebar')
61+
sidebar.classList.remove(sidebarStyleOptions['drawer'])
62+
sidebar.classList.remove(sidebarStyleOptions['compact'])
63+
sidebar.classList.remove(sidebarStyleOptions['rail'])
64+
sidebar.classList.add(newStyle)
65+
}
66+
67+
// Initial Page Load
68+
applySidebarStyle(getSidebarStyle(window.innerWidth))
69+
70+
// Window Resize
71+
window.addEventListener('resize', (event) => {
72+
applySidebarStyle(getSidebarStyle(window.innerWidth))
73+
})
74+
```
75+
3676
## Playground
3777

3878
<Canvas of={SidebarStories.DefaultDrawer} />

src/stories/Components/Sidebar/Sidebar.stories.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default {
1010
control: { type: 'select' },
1111
options: ['drawer', 'compact', 'rail'],
1212
},
13-
responsive: { control: 'boolean' },
1413
padded: { control: 'boolean' },
1514
style: {
1615
control: { type: 'select' },

0 commit comments

Comments
 (0)