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

SideNav should overlay Content in UIShell #1585

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions src/UIShell/Content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/** Specify the id for the main element */
export let id = "main-content";

import { isSideNavCollapsed, isSideNavRail } from "./navStore";
import { isSideNavExpanded, isSideNavRail } from "./navStore";

/**
* By default, the `SideNav` applies a left margin of `3rem` to `Content`
Expand All @@ -11,14 +11,14 @@
* We manually unset the left margin if the `SideNav`
* is collapsed and if it's not the `rail` variant.
*/
$: unsetLeftMargin = $isSideNavCollapsed && !$isSideNavRail;
$: unsetLeftMargin = !$isSideNavRail && !$isSideNavExpanded;
</script>

<main
id="{id}"
class:bx--content="{true}"
style="{unsetLeftMargin ? 'margin-left: 0' : ''}"
{...$$restProps}
style="{unsetLeftMargin ? 'margin-left: 0;' : ''} {$$restProps.style}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this should be changed since $$restProps.style will override the attribute.

>
<slot />
</main>
15 changes: 9 additions & 6 deletions src/UIShell/SideNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@
import {
shouldRenderHamburgerMenu,
isSideNavCollapsed,
isSideNavFixed,
isSideNavRail,
isSideNavExpanded,
} from "./navStore";

const dispatch = createEventDispatcher();

let winWidth = undefined;

$: dispatch(isOpen ? "open" : "close");
$: $isSideNavCollapsed = !isOpen;
$: $isSideNavExpanded = !rail && winWidth >= expansionBreakpoint;
$: $isSideNavCollapsed = !$isSideNavExpanded;
$: $isSideNavFixed = !rail & isOpen;
$: $isSideNavRail = rail;

onMount(() => {
Expand Down Expand Up @@ -72,11 +76,10 @@
class:bx--side-nav__navigation="{true}"
class:bx--side-nav="{true}"
class:bx--side-nav--ux="{true}"
class:bx--side-nav--expanded="{rail && winWidth >= expansionBreakpoint
? false
: isOpen}"
class:bx--side-nav--collapsed="{!isOpen && !rail}"
class:bx--side-nav--rail="{rail}"
class:bx--side-nav--fixed="{$isSideNavFixed}"
class:bx--side-nav--expanded="{$isSideNavExpanded}"
class:bx--side-nav--collapsed="{$isSideNavCollapsed}"
class:bx--side-nav--rail="{$isSideNavRail}"
{...$$restProps}
>
<slot />
Expand Down
4 changes: 4 additions & 0 deletions src/UIShell/navStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { writable } from "svelte/store";

export const shouldRenderHamburgerMenu = writable(false);

export const isSideNavExpanded = writable(false);

export const isSideNavCollapsed = writable(false);

export const isSideNavFixed = writable(false);

export const isSideNavRail = writable(false);