1.0.2 • Published 4 years ago

@miraidesigns/sidebar v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Sidebars

Sidebars provide site navigation and can be permanent or called on-screen.


HTML

Make sure to put this as high in your <body> element as possible.

<div class="mdf-sidebar-container" aria-hidden="true">
    <aside class="mdf-sidebar mdf-sidebar--left" aria-labelledby="sidebar-title">
        <header class="mdf-sidebar__header">
            <h2 id="sidebar-title" class="mdf-sidebar__title">Sidebar</h2>

            <button class="mdf-sidebar__close" aria-label="Close sidebar">
                <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
                    <use href="icons.svg#clear"></use>
                </svg>
            </button>
        </header>

        <div class="mdf-sidebar__content">
            <nav role="navigation" aria-label="Site navigation">
                <a class="mdf-sidebar__link" href="#1">
                    Link #1
                </a>

                <a class="mdf-sidebar__link" href="#2">
                    Link #2
                </a>

                <a class="mdf-sidebar__link" href="#3">
                    Link #3
                </a>
            </nav>
        </div>

        <footer class="mdf-sidebar__footer">
            <p>Sidebar footer text</p>
        </footer>
    </aside>

    <div class="mdf-sidebar-backdrop"></div>
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/sidebar/styles';
// Configure appearance
@use '@miraidesigns/sidebar' with (
    $variable: value
);

@include sidebar.styles();

TypeScript

import { MDFSidebar } from '@miraidesigns/sidebar';

new MDFSidebar(document.querySelector('.mdf-sidebar'), {
    anchor: document.getElementById('sidebar-anchor')
});

Implementation

Classes

NameTypeDescription
mdf-sidebar-containerParentContains the sidebar and backdrop. Used for off-screen sidebars
mdf-sidebar-container--activeModifier1. Prepares the sidebar to be visible. Used for off-screen sidebars
mdf-sidebar-container--move-inModifier2. Fades-in the sidebar and allows for interaction. Used for off-screen sidebars
mdf-sidebarParentContains the header, content and footer
mdf-sidebar--leftModifierMoves the sidebar to the left of the screen. Used for off-screen sidebars
mdf-sidebar--rightModifierMoves the sidebar to the right of the screen. Used for off-screen sidebars
mdf-sidebar__headerParent / ChildContains the title and close button. Child to .mdf-sidebar
mdf-sidebar__titleChildTitle element. Child to .mdf-sidebar__header
mdf-sidebar__closeChildCloses the sidebar. Child to .mdf-sidebar__header
mdf-sidebar__contentParent / ChildContains the navigation links or other content. Child to .mdf-sidebar
mdf-sidebar__linkChildNavigation link element. Child to .mdf-sidebar__content
mdf-sidebar__footerParent / ChildFooter element. Child to .mdf-sidebar
mdf-sidebar-backdropChildSidebar backdrop. Child to .mdf-sidebar-container

Events

NameDataDescription
MDFSidebar:openednullFires when the sidebar opens
MDFSidebar:closednullFires when the sidebar closes

Properties

NameTypeDescription
.anchorHTMLElementReturns the anchor element
.containerHTMLElementReturns the sidebar container element
.contentHTMLElementReturns the sidebar main content element
.sidebarHTMLElementReturns the sidebar element
.isActive()(): booleanReturns wether or not the sidebar is active
.openSidebar(setFocus?)(boolean): voidOpen the sidebar (optionally set focus on the first item)
.closeSidebar()(): voidClose the sidebar

Options

NameTypeDefaultDescription
anchorElementnullThe anchor element that will call the sidebar
onOpen() => voidnullFunction will run when the sidebar is opened
onClose() => voidnullFunction will run when the sidebar is closed
hideOnClickbooleantrueClose the sidebar when a click is registered outside of it