Web Components 탐색 서랍 개요

    Ignite UI for Web Components 콘텐츠 내에서 확장하거나 축소할 수 있는 측면 탐색을 제공합니다. 미니 버전은 닫혀 있어도 탐색에 빠르게 액세스할 수 있습니다. 콘텐츠는 완전히 사용자 정의할 수 있으며 기본 메뉴 항목 스타일도 제공합니다.

    Web Components Navigation Drawer Example

    This sample demonstrates how to create IgcNavDrawerComponent component.

    Usage

    먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.

    npm install igniteui-webcomponents
    
    import { defineComponents, IgcNavDrawerComponent } from 'igniteui-webcomponents';
    
    defineComponents(IgcNavDrawerComponent);
    

    Ignite UI for Web Components에 대한 완전한 소개는 '시작 주제'를 읽어보세요.

    Adding Navigation Drawer Items

    The simplest way to start using the IgcNavDrawerComponent is as follows:

    <igc-nav-drawer open="true">
        <igc-nav-drawer-header-item>
            Sample Drawer
        </igc-nav-drawer-header-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="home"></igc-icon>
            <span slot="content">Home</span>
        </igc-nav-drawer-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="search"></igc-icon>
            <span slot="content">Search</span>
        </igc-nav-drawer-item>
    </igc-nav-drawer>
    

    모든 것이 순조롭게 진행되면 브라우저에 다음이 표시됩니다.

    While any content can be provided in the drawer, the IgcNavDrawerItemComponent is available to apply out-of-the-box styling to the items.

    To enhance our component a bit, we can use it in conjunction with the IgcNavbarComponent. This way we can achieve a more completed look and use the drawer's methods. Let's look at how we can use this in the next example:

    <igc-navbar>
      <igc-icon slot="start" name="menu" id="menu"></igc-icon>
      <h2>Home</h2>
    </igc-navbar>
    
    <igc-nav-drawer id="navDrawer">
        <igc-nav-drawer-header-item>
            Sample Drawer
        </igc-nav-drawer-header-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="home"></igc-icon>
            <span slot="content">Home</span>
        </igc-nav-drawer-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="search"></igc-icon>
            <span slot="content">Search</span>
        </igc-nav-drawer-item>
    </igc-nav-drawer>
    

    Let's also add some radio buttons to display all position values. This way whenever one gets selected, we will change the position of the drawer.

    // ...
    import { defineComponents, IgcNavDrawerComponent, IgcRadioComponent, IgcRadioGroupComponent } from 'igniteui-webcomponents';
    
    defineComponents(IgcNavDrawerComponent, IgcRadioComponent, IgcRadioGroupComponent);
    this.navDrawer = document.getElementById('navDrawer') as IgcNavDrawerComponent;
    this.radioGroup = document.getElementById('radio-group') as IgcRadioGroupComponent;
    this.radioGroup.addEventListener('click', (radio: any) => {
        this.navDrawer.position = radio.target.value;
    });
    
    <igc-radio-group id="radio-group" alignment="horizontal">
        <igc-radio name="position" value="start" label-position="after" checked>Start</igc-radio>
        <igc-radio name="position" value="end" label-position="after">End</igc-radio>
        <igc-radio name="position" value="top" label-position="after">Top</igc-radio>
        <igc-radio name="position" value="bottom" label-position="after">Bottom</igc-radio>
    </igc-radio-group>
    

    마지막으로 탐색 창을 열고 닫는 방법이 필요합니다. 이를 달성하는 방법에는 몇 가지가 있지만 이 예에서는 다음을 수행합니다.

    // ...
    const menu = document.getElementById('menu');
    const navDrawer = document.querySelector('igc-nav-drawer') as IgcNavDrawerComponent;
    
    menu!.addEventListener('click', () => {
        navDrawer.show();
    })
    
    document.getElementById('root')!.onclick = (e) => {
        if (e.target != document.getElementById('navDrawer')) {
            navDrawer.hide();
        }
    }
    

    모든 것이 순조롭게 진행되면 구성 요소는 이제 다음과 같이 보일 것입니다.

    Mini Variant

    With the mini variant, the Navigation Drawer changes its width instead of closing. It is used to maintain quick navigation, available at all times, leaving just the icons. To achieve that, you only need to set up the mini slot of the drawer.

    <igc-nav-drawer position="start">
        <igc-nav-drawer-header-item>Sample Drawer</igc-nav-drawer-header-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="home"></igc-icon>
            <span slot="content">Home</span>
        </igc-nav-drawer-item>
        <igc-nav-drawer-item>
            <igc-icon slot="icon" name="search"></igc-icon>
            <span slot="content">Search</span>
        </igc-nav-drawer-item>
        <div slot="mini">
            <igc-nav-drawer-item>
                <igc-icon slot="icon" name="home"></igc-icon>
            </igc-nav-drawer-item>
            <igc-nav-drawer-item>
                <igc-icon slot="icon" name="search"></igc-icon>
            </igc-nav-drawer-item>
        </div>
    </igc-nav-drawer>
    

    결과는 다음과 같습니다.

    Styling

    The IgcNavDrawerComponent exposes several CSS parts - base, main, and mini, giving you full control over their styling.

    igc-nav-drawer::part(base) {
      background: var(--ig-secondary-500);
    }
    
    igc-nav-drawer-item::part(base) {
      color: var(--ig-secondary-500-contrast);
    }
    
    igc-nav-drawer-item::part(base):hover {
      background-color: var(--ig-gray-800);
    }
    
    igc-nav-drawer-item[active]::part(base) {
      background: var(--ig-warn-500);
      color: var(--ig-warn-500-contrast);
    }
    
    igc-nav-drawer-header-item {
      color: var(--ig-warn-500);
    }
    

    API References

    Additional Resources