Skip to content
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

Add details to sidebar documentation #265

Merged
merged 1 commit into from
Jan 31, 2025
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
2 changes: 0 additions & 2 deletions src/stories/Components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const createSidebarItem = ({ type, icon, label }, activeLink) => {

export const createSidebar = ({
size = 'drawer',
responsive = false,
style = 'default',
brand = true,
padded = false,
Expand Down Expand Up @@ -60,7 +59,6 @@ export const createSidebar = ({
'sidebar',
style === 'default' ? '' : `sidebar--${style}`,
`sidebar--${size}`,
responsive ? 'sidebar--responsive' : '',
padded ? 'sidebar--padded' : '',
]
.filter(Boolean)
Expand Down
46 changes: 43 additions & 3 deletions src/stories/Components/Sidebar/Sidebar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ For instructions on how to integrate a sidebar into your applications layout, se

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

`.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.

```html
<div class="sidebar sidebar--drawer sidebar--responsive">...</div>
<div class="sidebar sidebar--drawer">...</div>
```

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

## Responsive Sidebar

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.

```js
const sidebarStyleOptions = {
drawer: 'sidebar--drawer',
compact: 'sidebar--compact',
rail: 'sidebar--rail',
}

const getSidebarStyle = (width) => {
let newStyle = sidebarStyleOptions['drawer']

if (window.innerWidth <= 1024) {
newStyle = sidebarStyleOptions['compact']
}

if (window.innerWidth <= 768) {
newStyle = sidebarStyleOptions['rail']
}

return newStyle
}

const applySidebarStyle = (newStyle) => {
const sidebar = document.getElementById('sidebar')
sidebar.classList.remove(sidebarStyleOptions['drawer'])
sidebar.classList.remove(sidebarStyleOptions['compact'])
sidebar.classList.remove(sidebarStyleOptions['rail'])
sidebar.classList.add(newStyle)
}

// Initial Page Load
applySidebarStyle(getSidebarStyle(window.innerWidth))

// Window Resize
window.addEventListener('resize', (event) => {
applySidebarStyle(getSidebarStyle(window.innerWidth))
})
```

## Playground

<Canvas of={SidebarStories.DefaultDrawer} />
Expand Down
1 change: 0 additions & 1 deletion src/stories/Components/Sidebar/Sidebar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default {
control: { type: 'select' },
options: ['drawer', 'compact', 'rail'],
},
responsive: { control: 'boolean' },
padded: { control: 'boolean' },
style: {
control: { type: 'select' },
Expand Down