React List Overview

    The Ignite UI for React List element is extremely useful when presenting a group of items. You can create a simple list of textual items, or a more complex one, containing an array of different layout elements. The IgrList component displays rows of items and supports one or more headers as well. Each list item is completely templatable and will support any valid HTML or other components.

    React List Example

    The following example represents a list populated with contacts with a name and a phone number properties. The IgrList component demonstrated below uses the IgrAvatar and IgrButton elements to enrich the user experience and expose the capabilities of setting avatar picture and buttons for text and call actions.

    Usage

    Em sua essência, o componente web de lista permite que você exiba facilmente uma lista vertical de itens.

    First, you need to the install the corresponding Ignite UI for React npm package by running the following command:

    npm install igniteui-react
    

    You will then need to import the IgrList, its necessary CSS, and register its module, like so:

    import { IgrListModule, IgrList, IgrListHeader, IgrListItem } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    
    IgrListModule.register();
    

    For a complete introduction to the Ignite UI for React, read the Getting Started topic.

    Add List Items

    Agora, podemos adicionar o seguinte código para obter uma lista simples de itens:

    <IgrList>
        <IgrListHeader>
            <span>Header</span>
        </IgrListHeader>
        <IgrListItem>
            <h2 slot="title">Item 1</h2>
        </IgrListItem>
        <IgrListItem>
            <h2 slot="title">Item 2</h2>
        </IgrListItem>
        <IgrListItem>
            <h2 slot="title">Item 3</h2>
        </IgrListItem>
    </IgrList>
    

    Se tudo correr bem, você deverá ver o seguinte no seu navegador:

    Vamos melhorar um pouco o nosso jogo e aprimorar os itens da nossa lista. Digamos que queremos criar uma lista de contatos com um nome e um número de telefone exibidos sob o nome. Para conseguir isso, podemos usar alguns dos slots que vêm com os itens da lista, conforme demonstrado no próximo exemplo:

    <IgrList>
        <IgrListHeader>
            <span>Contacts</span>
        </IgrListHeader>
        <IgrListItem>
            <h2 slot="title">Terrance Orta</h2>
            <span slot="subtitle">770-504-2217</span>
        </IgrListItem>
        <IgrListItem>
            <h2 slot="title">Richard Mahoney</h2>
            <span slot="subtitle">423-676-2869</span>
        </IgrListItem>
        <IgrListItem>
            <h2 slot="title">Donna Price</h2>
            <span slot="subtitle">859-496-2817</span>
        </IgrListItem>
    </IgrList>
    

    Depois de implementar o código acima, nosso componente de lista agora deve ficar assim:

    Adding Avatar and Buttons

    We can use some of our other components in conjunction with the IgrList component to enrich the experience and add some functionality. We can have a nice picture avatar to the left of the name and phone values. Additionally, we can add some buttons to the right of them to allow the user to text and call contacts, so let's update our contacts list component to show the avatar and the buttons. We can do that by using some of the list item's slots.

    <IgrList>
        <IgrListHeader>
            <span>Contacts</span>
        </IgrListHeader>
        <IgrListItem>
            <div slot="start">
                <IgrAvatar src="https://static.infragistics.com/xplatform/images/avatars/8.jpg" shape="circle" />
            </div>
            <h2 slot="title">Terrance Orta</h2>
            <span slot="subtitle">770-504-2217</span>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Text</span>
                </IgrButton>
            </div>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Call</span>
                </IgrButton>
            </div>
        </IgrListItem>
        <IgrListItem>
            <div slot="start">
                <IgrAvatar src="https://static.infragistics.com/xplatform/images/avatars/17.jpg" shape="circle" />
            </div>
            <h2 slot="title">Richard Mahoney</h2>
            <span slot="subtitle">423-676-2869</span>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Text</span>
                </IgrButton>
            </div>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Call</span>
                </IgrButton>
            </div>
        </IgrListItem>
        <IgrListItem>
            <div slot="start">
                <IgrAvatar src="https://static.infragistics.com/xplatform/images/avatars/9.jpg" shape="circle" />
            </div>
            <h2 slot="title">Donna Price</h2>
            <span slot="subtitle">859-496-2817</span>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Text</span>
                </IgrButton>
            </div>
            <div slot="end">
                <IgrButton variant="outlined">
                    <span>Call</span>
                </IgrButton>
            </div>
        </IgrListItem>
    </IgrList>
    

    The start slot is meant to be used for adding some kind of media before all other content of our list items. The target element, in our case the IgrAvatar component, will also be provided with a default position and spacing.

    The end slot is meant to be used for list items that have some kind of action or metadata, represented, for example, by a switch, a button, a checkbox, etc. We will use IgrButton components.

    Vamos também permitir que o usuário altere o tamanho da lista usando a variável CSS--ig-size. Adicionaremos alguns botões de opção para exibir todos os valores de tamanho. Dessa forma, sempre que um for selecionado, alteraremos o tamanho da lista.

    <IgrRadioGroup alignment="horizontal">
        <IgrRadio value="small" labelPosition="after" change={this.onRadioChange}>
            <span>Small</span>
        </IgrRadio>
        <IgrRadio value="medium" labelPosition="after" change={this.onRadioChange}>
            <span>Medium</span>
        </IgrRadio>
        <IgrRadio value="large" labelPosition="after" checked={true} change={this.onRadioChange}>
            <span>Large</span>
        </IgrRadio>
    </IgrRadioGroup>
    
    <IgrList size={this.state.listSize} />
    
    public onRadioChange(e: any) {
        if (e.checked == true) {
            this.setState({ listSize: e.value });
        }
    }
    

    O resultado da implementação do código acima deve ser semelhante ao seguinte:

    Styling

    The IgrList exposes several CSS parts, giving you full control over its style:

    Nome Descrição
    start The start container.
    end The end container.
    content The header and custom content container.
    header The title and subtitle container.
    title The title container.
    subtitle The subtitle container.
    igc-list-header {
      font-size: 20px;
      font-weight: 700;
      color: var(--ig-primary-700);
    }
    
    igc-list-item::part(title) {
      font-size: 18px;
      color: var(--ig-primary-600);
    }
    
    igc-list-item::part(subtitle) {
      color: var(--ig-primary-300);
    }
    

    In this article we covered a lot of ground with the IgrList component. First, we created a simple list with text items. Then, we created a list of contact items and added functionality to them by using some additional Ignite UI for React components, like the IgrAvatar and IgrButton. Finally, we changed the component's appearance through the exposed CSS parts.

    API References

    Additional Resources